Table of Contents

Class Token

Namespace
VpnHood.Core.Common.Tokens
Assembly
VpnHood.Core.Common.dll

Represents an access key: what a client needs to connect to a VPN's servers, and the access it gives.

public class Token
Inheritance
Token
Inherited Members

Remarks

The key travels as text, ToAccessKey()'s form, whose JSON names are the short ones of the properties' attributes, part of the VPN's contract.

Properties

ClientPolicies

Gets or sets what the key's issuer offers the people of each set of countries, or null.

[JsonPropertyName("cpols")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public ClientPolicy[]? ClientPolicies { get; set; }

Property Value

ClientPolicy[]

Remarks

An app takes the policy whose ClientCountries holds the device's country, else one that holds *.

IsPublic

Gets or sets a value indicating whether the key is a public one, shared by many people.

[JsonPropertyName("ispub")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public bool IsPublic { get; set; }

Property Value

bool

IssuedAt

Gets or sets when the key was issued, in UTC; MinValue in a key that does not say.

[JsonPropertyName("iat")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public DateTime IssuedAt { get; set; }

Property Value

DateTime

Name

Gets or sets the access key's name, which an app shows, or null.

[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required string? Name { get; set; }

Property Value

string

Secret

Gets or sets the access's secret, which the client proves to the server.

[JsonPropertyName("sec")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required byte[] Secret { get; set; }

Property Value

byte[]

ServerToken

Gets or sets the server token: how the client finds the servers and trusts them.

[JsonPropertyName("ser")]
public required ServerToken ServerToken { get; set; }

Property Value

ServerToken

SupportId

Gets or sets the ID by which the key's issuer knows it in support, or null.

[JsonPropertyName("sid")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required string? SupportId { get; set; }

Property Value

string

Tags

Gets or sets the key's tags, such as those of TokenRegisteredTags. The default is empty.

[JsonPropertyName("tags")]
public string[] Tags { get; set; }

Property Value

string[]

TokenId

Gets or sets the ID by which the servers know the access.

[JsonPropertyName("tid")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public required string TokenId { get; set; }

Property Value

string

Version

Gets the access key's format version: always 4.

[JsonPropertyName("v")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int Version { get; }

Property Value

int

Methods

FromAccessKey(string)

Reads an access key from its text: the Base64 of its JSON, after vh:, vh://, vhkey: or vhkey://, if any.

public static Token FromAccessKey(string base64)

Parameters

base64 string

The text. Surrounding white space and quotes, a trailing /, as Windows adds to a link, and missing Base64 padding are allowed.

Returns

Token

The access key.

Exceptions

FormatException

The text is no valid Base64, or an endpoint or a duration in the key is not valid.

NotSupportedException

The key's version is not 4.

JsonException

The text is not a valid access key's JSON.

InvalidDataException

The JSON is null.

OverflowException

A duration in the key is out of range.

ToAccessKey()

Writes the access key as text: vh: and the Base64 of its JSON, with the properties at their defaults left out, but for those marked to be always written, such as Name.

public string ToAccessKey()

Returns

string

The access key.