172613Skris=pod 272613Skris 372613Skris=head1 NAME 472613Skris 572613SkrisSSL_CTX_use_certificate, SSL_CTX_use_certificate_ASN1, SSL_CTX_use_certificate_file, SSL_use_certificate, SSL_use_certificate_ASN1, SSL_use_certificate_file, SSL_CTX_use_certificate_chain_file, SSL_CTX_use_PrivateKey, SSL_CTX_use_PrivateKey_ASN1, SSL_CTX_use_PrivateKey_file, SSL_CTX_use_RSAPrivateKey, SSL_CTX_use_RSAPrivateKey_ASN1, SSL_CTX_use_RSAPrivateKey_file, SSL_use_PrivateKey_file, SSL_use_PrivateKey_ASN1, SSL_use_PrivateKey, SSL_use_RSAPrivateKey, SSL_use_RSAPrivateKey_ASN1, SSL_use_RSAPrivateKey_file, SSL_CTX_check_private_key, SSL_check_private_key - load certificate and key data 672613Skris 772613Skris=head1 SYNOPSIS 872613Skris 972613Skris #include <openssl/ssl.h> 1072613Skris 1172613Skris int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); 1272613Skris int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d); 1372613Skris int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); 1472613Skris int SSL_use_certificate(SSL *ssl, X509 *x); 1572613Skris int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len); 1672613Skris int SSL_use_certificate_file(SSL *ssl, const char *file, int type); 1772613Skris 1872613Skris int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); 1972613Skris 2072613Skris int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); 2172613Skris int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, unsigned char *d, 2272613Skris long len); 2372613Skris int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); 2472613Skris int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); 2572613Skris int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len); 2672613Skris int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type); 2772613Skris int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); 2872613Skris int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len); 2972613Skris int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); 3072613Skris int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); 3172613Skris int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); 3272613Skris int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); 3372613Skris 34160814Ssimon int SSL_CTX_check_private_key(const SSL_CTX *ctx); 35160814Ssimon int SSL_check_private_key(const SSL *ssl); 3672613Skris 3772613Skris=head1 DESCRIPTION 3872613Skris 3972613SkrisThese functions load the certificates and private keys into the SSL_CTX 4072613Skrisor SSL object, respectively. 4172613Skris 4272613SkrisThe SSL_CTX_* class of functions loads the certificates and keys into the 4372613SkrisSSL_CTX object B<ctx>. The information is passed to SSL objects B<ssl> 4472613Skriscreated from B<ctx> with L<SSL_new(3)|SSL_new(3)> by copying, so that 4572613Skrischanges applied to B<ctx> do not propagate to already existing SSL objects. 4672613Skris 4772613SkrisThe SSL_* class of functions only loads certificates and keys into a 4872613Skrisspecific SSL object. The specific information is kept, when 4972613SkrisL<SSL_clear(3)|SSL_clear(3)> is called for this SSL object. 5072613Skris 5172613SkrisSSL_CTX_use_certificate() loads the certificate B<x> into B<ctx>, 5272613SkrisSSL_use_certificate() loads B<x> into B<ssl>. The rest of the 5372613Skriscertificates needed to form the complete certificate chain can be 5472613Skrisspecified using the 5572613SkrisL<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)> 5672613Skrisfunction. 5772613Skris 5872613SkrisSSL_CTX_use_certificate_ASN1() loads the ASN1 encoded certificate from 5972613Skristhe memory location B<d> (with length B<len>) into B<ctx>, 6072613SkrisSSL_use_certificate_ASN1() loads the ASN1 encoded certificate into B<ssl>. 6172613Skris 6272613SkrisSSL_CTX_use_certificate_file() loads the first certificate stored in B<file> 6372613Skrisinto B<ctx>. The formatting B<type> of the certificate must be specified 6472613Skrisfrom the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1. 6572613SkrisSSL_use_certificate_file() loads the certificate from B<file> into B<ssl>. 6672613SkrisSee the NOTES section on why SSL_CTX_use_certificate_chain_file() 6772613Skrisshould be preferred. 6872613Skris 6972613SkrisSSL_CTX_use_certificate_chain_file() loads a certificate chain from 7072613SkrisB<file> into B<ctx>. The certificates must be in PEM format and must 71120631Snectarbe sorted starting with the subject's certificate (actual client or server 72120631Snectarcertificate), followed by intermediate CA certificates if applicable, and 73120631Snectarending at the highest level (root) CA. 7472613SkrisThere is no corresponding function working on a single SSL object. 7572613Skris 7672613SkrisSSL_CTX_use_PrivateKey() adds B<pkey> as private key to B<ctx>. 7772613SkrisSSL_CTX_use_RSAPrivateKey() adds the private key B<rsa> of type RSA 7872613Skristo B<ctx>. SSL_use_PrivateKey() adds B<pkey> as private key to B<ssl>; 7972613SkrisSSL_use_RSAPrivateKey() adds B<rsa> as private key of type RSA to B<ssl>. 80160814SsimonIf a certificate has already been set and the private does not belong 81160814Ssimonto the certificate an error is returned. To change a certificate, private 82160814Ssimonkey pair the new certificate needs to be set with SSL_use_certificate() 83160814Ssimonor SSL_CTX_use_certificate() before setting the private key with 84160814SsimonSSL_CTX_use_PrivateKey() or SSL_use_PrivateKey(). 8572613Skris 86160814Ssimon 8772613SkrisSSL_CTX_use_PrivateKey_ASN1() adds the private key of type B<pk> 8872613Skrisstored at memory location B<d> (length B<len>) to B<ctx>. 8972613SkrisSSL_CTX_use_RSAPrivateKey_ASN1() adds the private key of type RSA 9072613Skrisstored at memory location B<d> (length B<len>) to B<ctx>. 9172613SkrisSSL_use_PrivateKey_ASN1() and SSL_use_RSAPrivateKey_ASN1() add the private 9272613Skriskey to B<ssl>. 9372613Skris 9472613SkrisSSL_CTX_use_PrivateKey_file() adds the first private key found in 9572613SkrisB<file> to B<ctx>. The formatting B<type> of the certificate must be specified 9672613Skrisfrom the known types SSL_FILETYPE_PEM, SSL_FILETYPE_ASN1. 9772613SkrisSSL_CTX_use_RSAPrivateKey_file() adds the first private RSA key found in 9872613SkrisB<file> to B<ctx>. SSL_use_PrivateKey_file() adds the first private key found 9972613Skrisin B<file> to B<ssl>; SSL_use_RSAPrivateKey_file() adds the first private 10072613SkrisRSA key found to B<ssl>. 10172613Skris 10272613SkrisSSL_CTX_check_private_key() checks the consistency of a private key with 10372613Skristhe corresponding certificate loaded into B<ctx>. If more than one 10472613Skriskey/certificate pair (RSA/DSA) is installed, the last item installed will 10572613Skrisbe checked. If e.g. the last item was a RSA certificate or key, the RSA 10672613Skriskey/certificate pair will be checked. SSL_check_private_key() performs 10772613Skristhe same check for B<ssl>. If no key/certificate was explicitly added for 10872613Skristhis B<ssl>, the last item added into B<ctx> will be checked. 10972613Skris 11072613Skris=head1 NOTES 11172613Skris 112290207SjkimThe internal certificate store of OpenSSL can hold several private 113290207Sjkimkey/certificate pairs at a time. The certificate used depends on the 114290207Sjkimcipher selected, see also L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>. 11572613Skris 11672613SkrisWhen reading certificates and private keys from file, files of type 11772613SkrisSSL_FILETYPE_ASN1 (also known as B<DER>, binary encoding) can only contain 11872613Skrisone certificate or private key, consequently 11972613SkrisSSL_CTX_use_certificate_chain_file() is only applicable to PEM formatting. 12072613SkrisFiles of type SSL_FILETYPE_PEM can contain more than one item. 12172613Skris 12272613SkrisSSL_CTX_use_certificate_chain_file() adds the first certificate found 12372613Skrisin the file to the certificate store. The other certificates are added 124290207Sjkimto the store of chain certificates using L<SSL_CTX_add1_chain_cert(3)|SSL_CTX_add1_chain_cert(3)>. Note: versions of OpenSSL before 1.0.2 only had a single 125290207Sjkimcertificate chain store for all certificate types, OpenSSL 1.0.2 and later 126290207Sjkimhave a separate chain store for each type. SSL_CTX_use_certificate_chain_file() 127290207Sjkimshould be used instead of the SSL_CTX_use_certificate_file() function in order 128290207Sjkimto allow the use of complete certificate chains even when no trusted CA 129290207Sjkimstorage is used or when the CA issuing the certificate shall not be added to 130290207Sjkimthe trusted CA storage. 13172613Skris 13272613SkrisIf additional certificates are needed to complete the chain during the 13372613SkrisTLS negotiation, CA certificates are additionally looked up in the 13472613Skrislocations of trusted CA certificates, see 13572613SkrisL<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>. 13672613Skris 13772613SkrisThe private keys loaded from file can be encrypted. In order to successfully 13872613Skrisload encrypted keys, a function returning the passphrase must have been 13972613Skrissupplied, see 14072613SkrisL<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>. 14172613Skris(Certificate files might be encrypted as well from the technical point 14272613Skrisof view, it however does not make sense as the data in the certificate 14372613Skrisis considered public anyway.) 14472613Skris 14572613Skris=head1 RETURN VALUES 14672613Skris 14772613SkrisOn success, the functions return 1. 14872613SkrisOtherwise check out the error stack to find out the reason. 14972613Skris 15072613Skris=head1 SEE ALSO 15172613Skris 15272613SkrisL<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>, 15372613SkrisL<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>, 15472613SkrisL<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>, 15572613SkrisL<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>, 156100928SnectarL<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>, 15772613SkrisL<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)> 15872613Skris 159160814Ssimon=head1 HISTORY 160160814Ssimon 161160814SsimonSupport for DER encoded private keys (SSL_FILETYPE_ASN1) in 162160814SsimonSSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() was added 163160814Ssimonin 0.9.8 . 164160814Ssimon 16572613Skris=cut 166