public_key
API module for public-key infrastructure.
- Provided by: erlang-manpages (Version: 1:18.3-dfsg-1ubuntu3.1)
- Source: erlang
- Report a bug
API module for public-key infrastructure.
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 Public-key Records.
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 public_key:
| 'RSAPrivateKey'
| 'RSAPublicKey'
| 'DSAPrivateKey'
| 'DSAPublicKey'
| 'DHParameter'
| 'SubjectPublicKeyInfo'
| 'PrivateKeyInfo'
| 'CertificationRequest'
| 'CertificateList'
| 'ECPrivateKey'
| 'EcpkParameters'
not_encrypted | cipher_info()}
| {#'PBEParameter{}, digest_type()} | #'PBES2-params'{}}
| 'rsa_pkcs1_oaep_padding'
| 'rsa_no_padding'
| keyCompromise
| cACompromise
| affiliationChanged
| superseded
| cessationOfOperation
| certificateHold
| privilegeWithdrawn
| aACompromise
| rfc4716_public_key
| known_hosts
| auth_keys
compute_key(OthersKey, MyKey)->
compute_key(OthersKey, MyKey, Params)->
Types:
Computes shared secret.
decrypt_private(CipherText, Key) -> binary()
decrypt_private(CipherText, Key, Options) -> binary()
Types:
Public-key decryption using the private key. See also crypto:private_decrypt/4
decrypt_public(CipherText, Key) - > binary()
decrypt_public(CipherText, Key, Options) - > binary()
Types:
Public-key decryption using the public key. See also crypto:public_decrypt/4
der_decode(Asn1type, Der) -> term()
Types:
Decodes a public-key ASN.1 DER encoded entity.
der_encode(Asn1Type, Entity) -> der_encoded()
Types:
Encodes a public-key entity with ASN.1 DER encoding.
dh_gex_group(MinSize, SuggestedSize, MaxSize, Groups) ->
{ok, {Size,Group}} | {error,Error}
Types:
Selects a group for Diffie-Hellman key exchange with the key size in the range MinSize...MaxSize and as close to SuggestedSize as possible. If Groups == undefined a default set will be used, otherwise the group is selected from Groups.
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 MinSize and MaxSize is available, {error,no_group_found} is returned.
The default set of groups is listed in lib/public_key/priv/moduli. This file may be regenerated like this:
$> 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
encrypt_private(PlainText, Key) -> binary()
Types:
Public-key encryption using the private key. See also crypto:private_encrypt/4.
encrypt_public(PlainText, Key) -> binary()
Types:
Public-key encryption using the public key. See also crypto:public_encrypt/4.
generate_key(Params) -> {Public::binary(),
Private::binary()} | #'ECPrivateKey'{}
Types:
Generates a new keypair.
pem_decode(PemBin) -> [pem_entry()]
Types:
Decodes PEM binary data and returns entries as ASN.1 DER encoded entities.
pem_encode(PemEntries) -> binary()
Types:
Creates a PEM binary.
pem_entry_decode(PemEntry) -> term()
pem_entry_decode(PemEntry, Password) -> term()
Types:
Decodes a PEM entry. pem_decode/1 returns a list of PEM entries. Notice that if the PEM entry is of type 'SubjectPublickeyInfo', it is further decoded to an rsa_public_key() or dsa_public_key().
pem_entry_encode(Asn1Type, Entity) -> pem_entry()
pem_entry_encode(Asn1Type, Entity, {CipherInfo, Password}) ->
pem_entry()
Types:
Creates a PEM entry that can be feed to pem_encode/1.
pkix_decode_cert(Cert, otp|plain) -> #'Certificate'{} |
#'OTPCertificate'{}
Types:
Decodes an ASN.1 DER-encoded PKIX certificate. Option otp uses the customized ASN.1 specification OTP-PKIX.asn1 for decoding and also recursively decode most of the standard parts.
pkix_encode(Asn1Type, Entity, otp | plain) ->
der_encoded()
Types:
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 otp format, whereas for the plain format this function directly calls der_encode/2.
pkix_is_issuer(Cert, IssuerCert) -> boolean()
Types:
Checks if IssuerCert issued Cert.
pkix_is_fixed_dh_cert(Cert) -> boolean()
Types:
Checks if a certificate is a fixed Diffie-Hellman certificate.
pkix_is_self_signed(Cert) -> boolean()
Types:
Checks if a certificate is self-signed.
pkix_issuer_id(Cert, IssuedBy) -> {ok, IssuerID} | {error,
Reason}
Types:
Returns the issuer id.
pkix_normalize_name(Issuer) -> Normalized
Types:
Normalizes an issuer name so that it can be easily compared to another issuer name.
pkix_path_validation(TrustedCert, CertChain, Options) ->
{ok, {PublicKeyInfo, PolicyTree}} | {error, {bad_cert, Reason}}
Types:
Performs a basic path validation according to RFC 5280. However, CRL validation is done separately by pkix_crls_validate/3 and is to be called from the supplied verify_fun.
Available options:
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 {fail, Reason}, the verification process is immediately stopped. If the verify callback fun returns {valid, UserState}, the verification process is continued. This can be used to accept specific path validation errors, such as selfsigned_peer, as well as verifying application-specific extensions. If called with an extension unknown to the user application, the return value {unknown, UserState} is to be used.
Possible reasons for a bad certificate:
pkix_crl_issuer(CRL) -> issuer_name()
Types:
Returns the issuer of the CRL.
pkix_crls_validate(OTPCertificate, DPAndCRLs, Options) ->
CRLStatus()
Types:
Performs CRL validation. It is intended to be called from the verify fun of pkix_path_validation/3 .
Available options:
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
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}
pkix_crl_verify(CRL, Cert) -> boolean()
Types:
Verify that Cert is the CRL signer.
pkix_dist_point(Cert) -> DistPoint
Types:
Creates a distribution point for CRLs issued by the same issuer as Cert. Can be used as input to pkix_crls_validate/3
pkix_dist_points(Cert) -> DistPoints
Types:
Extracts distribution points from the certificates extensions.
pkix_sign(#'OTPTBSCertificate'{}, Key) -> der_encoded()
Types:
Signs an 'OTPTBSCertificate'. Returns the corresponding DER-encoded certificate.
pkix_sign_types(AlgorithmId) -> {DigestType,
SignatureType}
Types:
Translates signature algorithm OID to Erlang digest and signature types.
pkix_verify(Cert, Key) -> boolean()
Types:
Verifies PKIX x.509 certificate signature.
sign(Msg, DigestType, Key) -> binary()
Types:
Creates a digital signature.
ssh_decode(SshBin, Type) -> [{public_key(),
Attributes::list()}]
Types:
Decodes an SSH file-binary. In the case of known_hosts or auth_keys, the binary can include one or more lines of the file. Returns a list of public keys and their attributes, possible attribute values depends on the file type represented by the binary.
ssh_encode([{Key, Attributes}], Type) -> binary()
Types:
Encodes a list of SSH file entries (public keys and attributes) to a binary. Possible attributes depend on the file type, see ssh_decode/2 .
verify(Msg, DigestType, Signature, Key) -> boolean()
Types:
Verifies a digital signature.