Sinetex.Header (sinetex v0.1.0)

Copy Markdown View Source

The 588-byte security header (Manual de Segurança do SFN §5.1, Table 1).

Field names follow the manual:

FieldSizeContent
c012header size, always 588
c021protocol version (0x02, 0x03; 0x00 for clear text)
c031error code, 0x00 when there is no error
c041special treatment indicator
c051reserved, 0x00
c061recipient key algorithm (0x02 = RSA-2048)
c071symmetric algorithm (0x01 = 3DES, 0x02 = AES-256)
c081sender key algorithm (0x02 = RSA-2048)
c091hash algorithm (0x03 = SHA-256)
c101certification authority (PC) of the recipient certificate
c1132serial number of the recipient certificate (Sinetex.Serial)
c121certification authority (PC) of the sender certificate
c1332serial number of the sender certificate
c14256symmetric key encrypted with RSAES-PKCS1-v1_5
c15256signature, RSASSA-PKCS1-v1_5

c01 is read and written as a big-endian 16-bit integer.

The header is not covered by the signature: the protocol only signs the content. Sinetex.open/2 checks every field against the certificates involved, but bytes such as C03, C04 and C05 can be changed in transit without breaking the signature.

Summary

Functions

Splits an envelope into its header and body.

Returns true for the "empty" header of §5.6.3: every field zeroed except C01. The body of such an envelope is in clear text, neither signed nor encrypted.

Encodes a header into its 588 bytes.

The header size in bytes: 588.

Types

t()

@type t() :: %Sinetex.Header{
  c01: 0..65535,
  c02: byte(),
  c03: byte(),
  c04: byte(),
  c05: byte(),
  c06: byte(),
  c07: byte(),
  c08: byte(),
  c09: byte(),
  c10: byte(),
  c11: <<_::256>>,
  c12: byte(),
  c13: <<_::256>>,
  c14: <<_::2048>>,
  c15: <<_::2048>>
}

Functions

decode(envelope)

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

Splits an envelope into its header and body.

Only the layout is decoded; field values are not validated. Returns {:error, :too_short} if there are fewer than 588 bytes.

empty?(header)

@spec empty?(t()) :: boolean()

Returns true for the "empty" header of §5.6.3: every field zeroed except C01. The body of such an envelope is in clear text, neither signed nor encrypted.

encode(h)

@spec encode(t()) :: <<_::4704>>

Encodes a header into its 588 bytes.

Raises ArgumentError if a field does not fit its size.

size()

@spec size() :: 588

The header size in bytes: 588.