eta_nexus.util.auth_utils module

class eta_nexus.util.auth_utils.KeyCertPair(key: PrivateKey, cert: x509.Certificate)[source]

Bases: ABC

KeyCertPair is a wrapper for an RSA private key file and a corresponding x509 certificate. Implementations provide a contextmanager “tempfiles”, which provides access to the certificate files and the properties key and cert, which contain the RSA key and certificate information.

property key: PrivateKey

RSA private key for the certificate.

property cert: Certificate

x509 certificate information.

abstract tempfiles() Generator[source]

Accessor for temporary certificate files.

abstract property key_path: str

Path to the key file.

abstract property cert_path: str

Path to the certificate file.

class eta_nexus.util.auth_utils.SelfsignedKeyCertPair(common_name: str, passphrase: str | None = None, country: str | None = None, province: str | None = None, city: str | None = None, organization: str | None = None)[source]

Bases: KeyCertPair

Self signed key and certificate pair for use with the connections.

Parameters:
  • common_name – Common name the certificate should be valid for.

  • passphrase – Pass phrase for encryption of the private key.

  • country – Country code for the certificate owner, for example “DE” or “US”.

  • province – Province name of the certificate owner. Empty by default.

  • city – City name of the certificate owner. Empty by default.

  • organization – Name of the certificate owner’s organization. “OPC UA Client” by default.

generate_cert(common_name: str, country: str | None = None, province: str | None = None, city: str | None = None, organization: str | None = None) tuple[RSAPrivateKey, Certificate][source]

Generate a self signed key and certificate pair for use with the connections.

Parameters:
  • common_name – Common name the certificate should be valid for.

  • country – Alpha-2 country code for the certificate owner. Empty by default.

  • province – Province name of the certificate owner. Empty by default.

  • city – City name of the certificate owner. Empty by default.

  • organization – Name of the certificate owner’s organization. “OPC UA Client” by default.

Returns:

Tuple of RSA private key and x509 certificate.

store_tempfile() tuple[str, str][source]

Store the key and certificate as named temporary files. The function returns the names of the two files.

Returns:

Tuple of name of the key file and name of the certificate file.

tempfiles() Generator[source]

Accessor for temporary certificate files.

property key_path: str

Path to the key file.

property cert_path: str

Path to the certificate file.

class eta_nexus.util.auth_utils.PEMKeyCertPair(key_path: Path, cert_path: Path, passphrase: str | None)[source]

Bases: KeyCertPair

Load a PEM formatted key and certificate pair from files.

Parameters:
  • key_path – Path to the PEM formatted RSA private key file.

  • cert_path – Path to the PEM formatted certificate file.

  • passphrase – Pass phrase for encryption of the private key.

tempfiles() Generator[source]

Accessor for temporary certificate files.

property key_path: str

Path to the key file.

property cert_path: str

Path to the certificate file.