System.Tether.Manager.TTetheringAdapter.CheckToken

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function CheckToken(const AManager, Seed, Token: string): Boolean;

C++

bool __fastcall CheckToken(const System::UnicodeString AManager, const System::UnicodeString Seed, const System::UnicodeString Token);

Properties

Type Visibility Source Unit Parent
function protected
System.Tether.Manager.pas
System.Tether.Manager.hpp
System.Tether.Manager TTetheringAdapter

Description

Returns True if the specified hash matches a hash of the concatenation of the hash from the last connection to the remote manager and the specified seed. It returns False otherwise.

TTetheringNetworkAdapterCommon and TTetheringBluetoothAdapter use CheckToken to validate a hash from a remote manager which was previously paired to the manager of your adapter.

After the manager of your adapter and the manager of a remote adapter successfully pair with each other, each manager stores in memory the ID of the other manager and the hash that both managers shared during the pairing.

At some point, those managers may disconnect from each other. If they reconnect afterwards and the manager of the remote adapter tries to pair with your manager again, and as long as your manager is password-protected (otherwise the pairing happens automatically), the pairing operation does not require that the passwords of each manager match. Instead, the adapters check the hashes generated during the previous pairing operation that were stored by each manager in memory:

  1. If the manager of your adapter is password-protected (TTetheringManager.Password is not an empty string), your adapter generates a random seed for connections with the remote adapter. Your adapter then sends this seed to the remote adapter.
  2. The remote adapter generates a hash of the concatenation of the hash from the last connection between the managers (that both managers saved in memory) and the seed that your manager previously sends. Then the remote adapter sends this hash to your adapter.
  3. Your adapter generates a hash of the concatenation of the hash from the last connection between the managers (that both managers saved in memory) and the seed that your adapter previously generated for connections with the remote adapter. Then your adapter checks whether or not this hash matches the hash that the remote adapter sends.

CheckToken is responsible for the last step of the process. CheckToken generates a hash of the concatenation of the hash from the last connection to AManager and Seed, and it returns True if this hash matches Token. It returns False if hashes do not match.

Subclasses of TTetheringAdapter must implement their own system for generating and managing seeds, and use CheckToken to validate hashes from remote adapters against a seed and the hash from the last connection between both managers.

Hashes from previous pairings are stored in memory by default. If you want pairing data to be persistent, so that restarting your application does not reset pairing data, you must create a subclass of TTetheringCustomStorage and pass an instance to your manager on your handler for the TTetheringManager.OnRequestStorage event.

See Also