Table of Contents

Class ContinuationTokenSigner

Namespace
DynaSharp
Assembly
DynaSharp.dll

The keys that sign and check the ContinuationToken of the paged reads of a client, so that a client of a web API can no longer pick its position: a token it made up or edited, or one of another query, fails before a request goes out. Set it as TokenSigner. Every instance of a service that hands out tokens and takes them back holds the same keys, as it would for cookies.

public sealed class ContinuationTokenSigner
Inheritance
ContinuationTokenSigner
Inherited Members

Remarks

A token is signed with HMAC-SHA256 under the first key. It is checked against every key, in order, with a comparison that takes the same time whatever the bytes are, so a key is rotated in three steps: add the new key behind the old one on every instance, move it to the front once all of them have it, and drop the old key once the tokens that it signed may have expired from the clients. A token under a key that is gone fails as a forged one does.

Signing is not encryption: a signed token still shows the key values of the last item to whoever holds it, see ContinuationToken. What the signature covers, and so what a token cannot be moved to, is the table, the index and the key condition of the read, with the partitions of a fan-out. The filter, the projection, the limit and the direction of a plain read are not part of it: a token goes on with another filter or page size of the same query, as it does unsigned.

Each key is copied, so the arrays can be cleared after this is made. The object holds the keys and nothing else, is safe to share between clients and threads, and prints its type name only.

Constructors

ContinuationTokenSigner(params ReadOnlySpan<byte[]>)

Initializes a new instance of the ContinuationTokenSigner class.

public ContinuationTokenSigner(params ReadOnlySpan<byte[]> keys)

Parameters

keys ReadOnlySpan<byte[]>

The keys, the one that signs first, then those that are still accepted. Each is random bytes of at least MinKeyLength, for example from RandomNumberGenerator.GetBytes(32), kept as a secret of the service and read with Convert.FromBase64String.

Exceptions

ArgumentException

There is no key, or a key is shorter than MinKeyLength.

ArgumentNullException

A key is null.

Fields

MinKeyLength

The shortest key, in bytes: 32, the output of SHA-256, which is what HMAC-SHA256 needs to be as strong as it can be.

public const int MinKeyLength = 32

Field Value

int