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 11272613SkrisThe internal certificate store of OpenSSL can hold two private key/certificate 11372613Skrispairs at a time: one key/certificate of type RSA and one key/certificate 11472613Skrisof type DSA. The certificate used depends on the cipher select, see 11572613Skrisalso L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>. 11672613Skris 11772613SkrisWhen reading certificates and private keys from file, files of type 11872613SkrisSSL_FILETYPE_ASN1 (also known as B<DER>, binary encoding) can only contain 11972613Skrisone certificate or private key, consequently 12072613SkrisSSL_CTX_use_certificate_chain_file() is only applicable to PEM formatting. 12172613SkrisFiles of type SSL_FILETYPE_PEM can contain more than one item. 12272613Skris 12372613SkrisSSL_CTX_use_certificate_chain_file() adds the first certificate found 12472613Skrisin the file to the certificate store. The other certificates are added 12572613Skristo the store of chain certificates using 12672613SkrisL<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)>. 12772613SkrisThere exists only one extra chain store, so that the same chain is appended 12876866Skristo both types of certificates, RSA and DSA! If it is not intended to use 12972613Skrisboth type of certificate at the same time, it is recommended to use the 13072613SkrisSSL_CTX_use_certificate_chain_file() instead of the 13172613SkrisSSL_CTX_use_certificate_file() function in order to allow the use of 13272613Skriscomplete certificate chains even when no trusted CA storage is used or 13372613Skriswhen the CA issuing the certificate shall not be added to the trusted 13472613SkrisCA storage. 13572613Skris 13672613SkrisIf additional certificates are needed to complete the chain during the 13772613SkrisTLS negotiation, CA certificates are additionally looked up in the 13872613Skrislocations of trusted CA certificates, see 13972613SkrisL<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>. 14072613Skris 14172613SkrisThe private keys loaded from file can be encrypted. In order to successfully 14272613Skrisload encrypted keys, a function returning the passphrase must have been 14372613Skrissupplied, see 14472613SkrisL<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>. 14572613Skris(Certificate files might be encrypted as well from the technical point 14672613Skrisof view, it however does not make sense as the data in the certificate 14772613Skrisis considered public anyway.) 14872613Skris 14972613Skris=head1 RETURN VALUES 15072613Skris 15172613SkrisOn success, the functions return 1. 15272613SkrisOtherwise check out the error stack to find out the reason. 15372613Skris 15472613Skris=head1 SEE ALSO 15572613Skris 15672613SkrisL<ssl(3)|ssl(3)>, L<SSL_new(3)|SSL_new(3)>, L<SSL_clear(3)|SSL_clear(3)>, 15772613SkrisL<SSL_CTX_load_verify_locations(3)|SSL_CTX_load_verify_locations(3)>, 15872613SkrisL<SSL_CTX_set_default_passwd_cb(3)|SSL_CTX_set_default_passwd_cb(3)>, 15972613SkrisL<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>, 160100928SnectarL<SSL_CTX_set_client_cert_cb(3)|SSL_CTX_set_client_cert_cb(3)>, 16172613SkrisL<SSL_CTX_add_extra_chain_cert(3)|SSL_CTX_add_extra_chain_cert(3)> 16272613Skris 163160814Ssimon=head1 HISTORY 164160814Ssimon 165160814SsimonSupport for DER encoded private keys (SSL_FILETYPE_ASN1) in 166160814SsimonSSL_CTX_use_PrivateKey_file() and SSL_use_PrivateKey_file() was added 167160814Ssimonin 0.9.8 . 168160814Ssimon 16972613Skris=cut 170