ExCEP. Codec. AuthAsdu
(ex_cep v0.1.1)
Copy Markdown
Binary Authentication ASDU codec per CSG CEP TS2.2 Section 5 (Tables 3, 4, 5).
Three-Way Handshake
- Gateway -> Cluster:
AuthRequest(0x01) with gateway IP, 64-byte UTF-8 name, 8-byter1 - Cluster -> Gateway:
AuthResponse(0x02) with cluster IP, 64-byte UTF-8 name,r1, 8-byter2 - Gateway -> Cluster:
AuthConfirm(0x03) withr2
All three frames carry auth?: true, signed?: true in the APDU control byte and a 64-byte
SM2 signature covering the 32-byte APDU header and the binary ASDU payload.
Summary
Functions
Decodes a binary authentication ASDU.
Encodes an authentication ASDU struct into binary (excluding the trailing 64B APDU signature).
Generates an 8-byte cryptographically random challenge (r1 or r2).
Verifies an embedded 64-byte SM2 signature when a peer places the auth signature inside
the ASDU body (frame.signed? == false) instead of as the APDU trailer (frame.signed? == true).
If frame.signed? == true, verification was already performed by ExCEP.Codec.Frame.
Types
@type t() :: ExCEP.Codec.AuthAsdu.Request.t() | ExCEP.Codec.AuthAsdu.Response.t() | ExCEP.Codec.AuthAsdu.Confirm.t()
Functions
Decodes a binary authentication ASDU.
Accepts both the standard body-only form (when the 64-byte SM2 signature is carried as the
APDU trailer with bit0 = 1) and the embedded-signature form (trailing 64 bytes inside ASDU).
Encodes an authentication ASDU struct into binary (excluding the trailing 64B APDU signature).
@spec random_nonce() :: <<_::64>>
Generates an 8-byte cryptographically random challenge (r1 or r2).
@spec verify_embedded_signature(ExCEP.Codec.Frame.t(), {module(), term()} | nil) :: :ok | {:error, term()}
Verifies an embedded 64-byte SM2 signature when a peer places the auth signature inside
the ASDU body (frame.signed? == false) instead of as the APDU trailer (frame.signed? == true).
If frame.signed? == true, verification was already performed by ExCEP.Codec.Frame.