Provides functions to handle public-key infrastructure,
for details see
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.
Selects a group for Diffie-Hellman key exchange with the key size in the range
First a size, as close as possible to SuggestedSize, is selected. Then one group with that key size
is randomly selected from the specified set of groups. If no size within the limits of
The default set of groups is listed in
$> cd $ERL_TOP/lib/public_key/priv/ $> generate ---- wait until all background jobs has finished. It may take several days ! $> cat moduli-* > moduli $> cd ..; make
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.
Checks whether the given distribution point matches the Issuing Distribution Point of the CRL, as described in RFC 5280. If the CRL doesn't have an Issuing Distribution Point extension, the distribution point always matches.
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.
This function checks that the Presented Identifier (e.g hostname) in a peer certificate
conforms with the Expected Identifier that the client wants to connect to.
This functions is intended to be added as an extra client check to the peer certificate when performing
See
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
Calculates a ssh fingerprint from a public host key as openssh does.
The algorithm in
Examples:
2> public_key:ssh_hostkey_fingerprint(Key).
"f5:64:a6:c1:5a:cb:9f:0a:10:46:a2:5c:3e:2f:57:84"
3> public_key:ssh_hostkey_fingerprint(md5,Key).
"MD5:f5:64:a6:c1:5a:cb:9f:0a:10:46:a2:5c:3e:2f:57:84"
4> public_key:ssh_hostkey_fingerprint(sha,Key).
"SHA1:bSLY/C4QXLDL/Iwmhyg0PGW9UbY"
5> public_key:ssh_hostkey_fingerprint(sha256,Key).
"SHA256:aZGXhabfbf4oxglxltItWeHU7ub3Dc31NcNw2cMJePQ"
6> public_key:ssh_hostkey_fingerprint([sha,sha256],Key).
["SHA1:bSLY/C4QXLDL/Iwmhyg0PGW9UbY",
"SHA256:aZGXhabfbf4oxglxltItWeHU7ub3Dc31NcNw2cMJePQ"]
Verifies a digital signature.
Generates a short hash of an issuer name. The hash is returned as a string containing eight hexadecimal digits.
The return value of this function is the same as the result
of the commands