This module provides functions to handle public-key infrastructure. It can encode/decode different file formats (PEM, OpenSSH), sign and verify digital signatures, and validate certificate paths and certificate revocation lists.
All records used in this Reference Manual
are generated from ASN.1 specifications
and are documented in the User's Guide. See
Use the following include directive to get access to the records and constant macros described here and in the User's Guide:
-include_lib("public_key/include/public_key.hrl").
The following data types are used in the functions for
Object identifier, a tuple of integers as generated by the
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
Union of
=
=
=
=
=
=
Computes shared secret.
Public-key decryption using the private key. See also
Public-key decryption using the public key. See also
Decodes a public-key ASN.1 DER encoded entity.
Encodes a public-key entity with ASN.1 DER encoding.
Public-key encryption using the private key.
See also
Public-key encryption using the public key. See also
Generates a new keypair.
Decodes PEM binary data and returns entries as ASN.1 DER encoded entities.
Creates a PEM binary.
Decodes a PEM entry.
Creates a PEM entry that can be feed to
Decodes an ASN.1 DER-encoded PKIX certificate. Option
DER encodes a PKIX x509 certificate or part of such a
certificate. This function must be used for encoding certificates or parts of certificates
that are decoded/created in the
Checks if
Checks if a certificate is a fixed Diffie-Hellman certificate.
Checks if a certificate is self-signed.
Returns the issuer id.
Normalizes an issuer name so that it can be easily compared to another issuer name.
Performs a basic path validation according to
Available options:
The fun must be defined as:
fun(OtpCert :: #'OTPCertificate'{},
Event :: {bad_cert, Reason :: atom() | {revoked, atom()}} |
{extension, #'Extension'{}},
InitialUserState :: term()) ->
{valid, UserState :: term()} |
{valid_peer, UserState :: term()} |
{fail, Reason :: term()} |
{unknown, UserState :: term()}.
If the verify callback fun returns
Possible reasons for a bad certificate:
Certificate is no longer valid as its expiration date has passed.
Certificate issuer name does not match the name of the issuer certificate in the chain.
Certificate was not signed by its issuer certificate in the chain.
Invalid Subject Alternative Name extension.
Certificate, required to have the basic constraints extension, does not have a basic constraints extension.
Certificate key is used in an invalid way according to the key-usage extension.
Certificate has been revoked.
Application-specific error reason that is to be checked by the
Returns the issuer of the
Performs CRL validation. It is intended to be called from
the verify fun of
Available options:
The fun has the following type specification:
fun(#'DistributionPoint'{}, #'CertificateList'{}) ->
#'CertificateList'{}
The fun uses the information in the distribution point to access the latest possible version of the CRL. If this fun is not specified, Public Key uses the default implementation:
fun(_DP, CRL) -> CRL end
The fun has the following type specification:
fun(#'DistributionPoint'{}, #'CertificateList'{},
{rdnSequence,[#'AttributeTypeAndValue'{}]}, term()) ->
{ok, #'OTPCertificate'{}, [der_encoded]}
The fun returns the root certificate and certificate chain that has signed the CRL.
fun(DP, CRL, Issuer, UserState) -> {ok, RootCert, CertChain}
Verify that
Creates a distribution point for CRLs issued by the same issuer as
Extracts distribution points from the certificates extensions.
Signs an 'OTPTBSCertificate'. Returns the corresponding DER-encoded certificate.
Translates signature algorithm OID to Erlang digest and signature types.
Verifies PKIX x.509 certificate signature.
Creates a digital signature.
Decodes an SSH file-binary. In the case of
{headers, [{string(), utf8_string()}]}
{bits, integer()} - In SSH version 1 files.
{bits, integer()} - In SSH version 1 files.
Encodes a list of SSH file entries (public keys and attributes) to a binary. Possible
attributes depend on the file type, see
Veryfies a digital signature.