pub struct HapPairSetupSrpServer { /* private fields */ }Expand description
The accessory (server) half of HAP Pair Setup’s SRP-6a exchange.
This is the counterpart of PairSetupClient’s SRP portion (M2–M4),
packaged for a reference accessory to drive Pair Setup without touching the
crate-internal SRP generics: it fixes the HAP group (RFC 5054 Appendix A
3072-bit, g = 5), the hash (SHA-512), and the SRP username ("Pair-Setup"),
and normalises the setup code exactly as PairSetupClient does so the two
derive the same verifier.
Construct one per pairing attempt with new
(a fresh random salt and private ephemeral b), send M2 as
State=2, Salt=salt, PublicKey=
b_pub_bytes, then on M3 compute the
session key from the controller’s A with
session_key and verify its proof with
verify_m1_prove_m2.
Implementations§
Source§impl HapPairSetupSrpServer
impl HapPairSetupSrpServer
Sourcepub fn new(setup_code: &str) -> Result<(Self, Vec<u8>)>
pub fn new(setup_code: &str) -> Result<(Self, Vec<u8>)>
Build a Pair Setup SRP server for setup_code, returning it together with
the 16-byte SRP salt to send in M2.
setup_code is accepted hyphenated ("123-45-678") or as bare digits
("12345678"); it is normalised to the canonical XXX-XX-XXX form —
identically to PairSetupClient::new — before use as the SRP password.
The salt and the private ephemeral b are drawn from the OS CSPRNG.
§Errors
Returns CryptoError only if the embedded HAP group is rejected (which
the fixed constant never triggers).
Sourcepub fn b_pub_bytes(&self) -> Vec<u8> ⓘ
pub fn b_pub_bytes(&self) -> Vec<u8> ⓘ
PAD(B) — the accessory’s SRP public ephemeral in wire form (384 bytes),
sent as PublicKey in M2.
Sourcepub fn session_key(&self, a_pub_bytes: &[u8]) -> Result<Vec<u8>>
pub fn session_key(&self, a_pub_bytes: &[u8]) -> Result<Vec<u8>>
Compute the SRP session key K from the controller’s public ephemeral
A (the PublicKey bytes received in M3).
§Errors
Returns CryptoError::SrpBadParameters if A is zero mod N, or
CryptoError::SrpProofMismatch if the scrambler u is zero.
Sourcepub fn verify_m1_prove_m2(
&self,
a_pub_bytes: &[u8],
m1: &[u8],
) -> Result<Vec<u8>>
pub fn verify_m1_prove_m2( &self, a_pub_bytes: &[u8], m1: &[u8], ) -> Result<Vec<u8>>
Verify the controller’s proof M1 (from M3) against its public ephemeral
A, returning the accessory proof M2 to send in M4.
The session key is recomputed from A internally, so this is
self-contained; callers that also need K (to derive the M5/M6 keys)
should call session_key once and
keep the result.
§Errors
Returns CryptoError::SrpProofMismatch if M1 does not verify (the
wrong setup code), or the errors of
session_key.