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
=
#'DHParameter'{} | {namedCurve, oid()} | #'ECParameters'{} | {rsa, Size::integer(), PubExp::integer()}
Union of
Note that the actual supported dss_digest_type depends on the underlying crypto library. In OpenSSL version >= 1.0.1 the listed digest are supported, while in 1.0.0 only sha, sha224 and sha256 are supported. In version 0.9.8 only sha is supported.
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. Note that except for Diffie-Hellman
the public key is included in the private key structure. See also
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}
Defaults to false. When revocation status can not be determined, and this option is set to true, details of why no CRLs where accepted are included in the return value.
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.
Creates certificate configuration(s) consisting of certificate and its private key plus CA certificate bundle, for a client and a server, intended to facilitate automated testing of applications using X509-certificates, often through SSL/TLS. The test data can be used when you have control over both the client and the server in a test scenario.
When this function is called with a map containing
client and server chain specifications;
it generates both a client and a server certificate chain
where the
When this function is called with a list of certificate options;
it generates a configuration with just one node certificate
where
The
Hash algorithm to be used for signing the certificate together with the key option. Defaults to sha that is sha1.
Parameters to be used to call public_key:generate_key/1, to generate a key, or an existing key. Defaults to generating an ECDSA key. Note this could fail if Erlang/OTP is compiled with a very old cryptolib.
The validity period of the certificate.
Extensions to include in the certificate.
Default extensions included in CA certificates if not otherwise specified are:
[#'Extension'{extnID = ?'id-ce-keyUsage',
extnValue = [keyCertSign, cRLSign],
critical = false},
#'Extension'{extnID = ?'id-ce-basicConstraints',
extnValue = #'BasicConstraints'{cA = true},
critical = true}]
Default extensions included in the server peer cert if not otherwise specified are:
[#'Extension'{extnID = ?'id-ce-keyUsage',
extnValue = [digitalSignature, keyAgreement],
critical = false},
#'Extension'{extnID = ?'id-ce-subjectAltName',
extnValue = [{dNSName, Hostname}],
critical = false}]
Hostname is the result of calling net_adm:localhost() in the Erlang node where this funcion is called.
Note that the generated certificates and keys does not provide a formally correct PKIX-trust-chain and they can not be used to achieve real security. This function is provided for testing purposes only.
Generates a root certificate that can be used
in multiple calls to
Verifies PKIX x.509 certificate signature.
This function checks that the Presented Identifier (e.g hostname) in a peer certificate
is in agreement with at least one of the Reference Identifier that the client expects to be connected to.
The function is intended to be added as an extra client check of the peer certificate when performing
See
The
The
The options are:
fun(....) -> true; % My special case
(_, _) -> default % all others falls back to the inherit tests
end
The return value of calling this function is intended to be used in the
The returned fun augments the verify hostname matching according to the specific rules for the protocol in the argument.
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