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

  1. Gateway -> Cluster: AuthRequest (0x01) with gateway IP, 64-byte UTF-8 name, 8-byte r1
  2. Cluster -> Gateway: AuthResponse (0x02) with cluster IP, 64-byte UTF-8 name, r1, 8-byte r2
  3. Gateway -> Cluster: AuthConfirm (0x03) with r2

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

Functions

decode(arg1)

@spec decode(binary()) :: {:ok, t()} | {:error, term()}

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).

encode(arg1)

@spec encode(t()) :: {:ok, binary()} | {:error, term()}

Encodes an authentication ASDU struct into binary (excluding the trailing 64B APDU signature).

random_nonce()

@spec random_nonce() :: <<_::64>>

Generates an 8-byte cryptographically random challenge (r1 or r2).

verify_embedded_signature(frame, signer)

@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.