Class SrpAuthHandler
- Namespace
- AppleTvControlLibrary.Auth
- Assembly
- AppleTv.Hap.dll
Handle SRP crypto routines for auth and key derivation.
public sealed class SrpAuthHandler
- Inheritance
-
SrpAuthHandler
- Inherited Members
Remarks
The SRP math here is ported from srptools (the library pyatv itself depends on for its SRP implementation), not from a generic SRP-6a reference, since the two differ in a few details (padding, hash argument ordering) that must match byte-for-byte for the HAP handshake to succeed.
Constructors
SrpAuthHandler()
Initializes a new instance of the SrpAuthHandler class.
public SrpAuthHandler()
Properties
PairingId
Gets or sets the pairing id used as the client identifier during pair-verify.
public byte[] PairingId { get; set; }
Property Value
- byte[]
Remarks
pyatv exposes this as a mutable public attribute so callers can override it once
credentials are known externally (i.e. not from a pairing performed by this instance);
see MrpProtocol.start — pyatv/protocols/mrp/protocol.py line 137-140 as of pyatv 0.18.0.
SharedKey
Gets the shared secret (SRP session key) established during pair-setup.
public byte[] SharedKey { get; }
Property Value
- byte[]
Methods
HkdfExpand(string, string, byte[])
Derives encryption keys from a shared secret using HKDF-SHA512.
public static byte[] HkdfExpand(string salt, string info, byte[] sharedSecret)
Parameters
saltstringThe HKDF salt string.
infostringThe HKDF info string.
sharedSecretbyte[]The shared secret to derive from.
Returns
- byte[]
32 bytes of derived key material.
Initialize()
Initialize operation by generating new keys.
public (byte[] AuthPublic, byte[] PublicBytes) Initialize()
Returns
- (byte[] AuthPublic, byte[] PublicBytes)
A tuple of (auth public key, verify public key).
Step1(int)
First pairing step. Sets up the SRP client session with the given PIN.
public void Step1(int pin)
Parameters
pinintThe PIN code entered by the user.
Step2(byte[], byte[])
Second pairing step. Processes the device's public key and salt.
public (byte[] PubKey, byte[] Proof) Step2(byte[] atvPubKey, byte[] atvSalt)
Parameters
Returns
- (byte[] AuthPublic, byte[] PublicBytes)
A tuple of (client public key, client proof).
Step3(string?)
Third pairing step. Builds the encrypted TLV payload with device identity.
public byte[] Step3(string? name = null)
Parameters
namestringAn optional display name to include.
Returns
- byte[]
The encrypted TLV8 payload.
Step4(byte[])
Last pairing step. Decrypts and parses the final device response.
public HapCredentials Step4(byte[] encryptedData)
Parameters
encryptedDatabyte[]The encrypted TLV8 payload from the device.
Returns
- HapCredentials
The resulting credentials for the paired device.
Verify1(HapCredentials, byte[], byte[])
First verification step.
public byte[] Verify1(HapCredentials credentials, byte[] sessionPubKey, byte[] encrypted)
Parameters
credentialsHapCredentialsThe credentials of the device being verified.
sessionPubKeybyte[]The device's X25519 public key.
encryptedbyte[]Encrypted TLV8 payload containing the device identifier and signature.
Returns
- byte[]
Encrypted TLV8 payload to send back to the device.
Verify2(string, string, string)
Last verification step. Derives the output and input encryption keys.
public (byte[] OutputKey, byte[] InputKey) Verify2(string salt, string outputInfo, string inputInfo)
Parameters
saltstringThe HKDF salt string.
outputInfostringThe HKDF info string for the output key.
inputInfostringThe HKDF info string for the input key.
Returns
- (byte[] AuthPublic, byte[] PublicBytes)
A tuple of (output key, input key).