ADS.Certificate (yaads v0.1.0)

Copy Markdown View Source

X.509 certificates for Secure ADS, as DER binaries.

With self-signed certificates, each side makes its own, and knows the other's by its fingerprint. The client's is made once and kept, since the PLC remembers it when the route is added:

{cert, key} = ADS.Certificate.self_signed("scada")
:ok = ADS.Certificate.write("scada.pem", cert)
:ok = ADS.Certificate.write_key("scada.key", key)
ADS.Certificate.fingerprint(cert)

With a CA, the certificates come from it, and these functions read them.

Summary

Functions

A certificate's fingerprint: the SHA-256 of its DER, as 64 hexadecimal digits, as TwinCAT shows its own in the About TwinCAT dialog.

Reads a certificate from a DER or PEM file.

Reads a private key from a PEM file.

Makes a self-signed certificate and its private key, with a common name: the name of the client, as the PLC compares it with the route unless told to ignore it.

Writes a certificate as DER, or PEM if the path ends in .pem.

Writes an RSA private key as PEM.

Types

private_key()

@type private_key() :: tuple()

t()

@type t() :: binary()

Functions

fingerprint(der)

@spec fingerprint(t()) :: String.t()

A certificate's fingerprint: the SHA-256 of its DER, as 64 hexadecimal digits, as TwinCAT shows its own in the About TwinCAT dialog.

read(path)

@spec read(Path.t()) :: t()

Reads a certificate from a DER or PEM file.

read_key(path)

@spec read_key(Path.t()) :: private_key()

Reads a private key from a PEM file.

self_signed(name, opts \\ [])

@spec self_signed(String.t(), keyword()) :: {t(), private_key()}

Makes a self-signed certificate and its private key, with a common name: the name of the client, as the PLC compares it with the route unless told to ignore it.

  • :hostnames - DNS names and IP addresses for its subject alternative name (default the common name)
  • :days - how long it's valid (default 3650)
  • :key_size - RSA key bits (default 2048)

write(path, der)

@spec write(Path.t(), t()) :: :ok | {:error, File.posix()}

Writes a certificate as DER, or PEM if the path ends in .pem.

write_key(path, key)

@spec write_key(Path.t(), private_key()) :: :ok | {:error, File.posix()}

Writes an RSA private key as PEM.