ssl_util_ssl.c revision 44985e4f931d3a75a7e5108705010cc21605ee34
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny/* Licensed to the Apache Software Foundation (ASF) under one or more
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * contributor license agreements. See the NOTICE file distributed with
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * this work for additional information regarding copyright ownership.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * The ASF licenses this file to You under the Apache License, Version 2.0
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * (the "License"); you may not use this file except in compliance with
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * the License. You may obtain a copy of the License at
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * Unless required by applicable law or agreed to in writing, software
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * distributed under the License is distributed on an "AS IS" BASIS,
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * See the License for the specific language governing permissions and
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * limitations under the License.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * _ __ ___ ___ __| | ___ ___| | mod_ssl
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * | | | | | | (_) | (_| | \__ \__ \ |
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * |_| |_| |_|\___/ \__,_|___|___/___/_|
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * Additional Utility Functions for OpenSSL
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny/* _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** Additional High-Level Functions for OpenSSL
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny/* we initialize this index at startup time
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * and never write to it at request time,
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * so this static is thread safe.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * also note that OpenSSL increments at static variable when
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * SSL_get_ex_new_index() is called, so we _must_ do this at startup.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* we _do_ need to call this twice */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny for (i=0; i<=1; i++) {
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny "Second Application Data for SSL",
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return (void *)SSL_get_ex_data(ssl, SSL_app_data2_idx);
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny SSL_set_ex_data(ssl, SSL_app_data2_idx, (char *)arg);
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny/* _________________________________________________________________
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny** High-Level Certificate / Private Key Loading
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan ZelenyX509 *SSL_read_X509(char* filename, X509 **x509, pem_password_cb *cb)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* 1. try PEM (= DER+Base64+headers) */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* 2. try DER+Base64 */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* 3. try plain DER */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan ZelenyEVP_PKEY *SSL_read_PrivateKey(char* filename, EVP_PKEY **key, pem_password_cb *cb, void *s)
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina /* 1. try PEM (= DER+Base64+headers) */
92ec40e6aa25f75903ffdb166a8ec56b67bfd77dPavel Březina if ((bioS=BIO_new_file(filename, "r")) == NULL)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* 2. try DER+Base64 */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if ((bioS = BIO_new_file(filename, "r")) == NULL)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* 3. try plain DER */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny if ((bioS = BIO_new_file(filename, "r")) == NULL)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny/* _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** Smart shutdown
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * Repeat the calls, because SSL_shutdown internally dispatches through a
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * little state machine. Usually only one or two interation should be
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * needed, so we restrict the total number of restrictions in order to
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * avoid process hangs in case the client played bad with the socket
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * connection and OpenSSL cannot recognize it.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny for (i = 0; i < 4 /* max 2x pending + 2x data = 4 */; i++) {
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny/* _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** Certificate Revocation List (CRL) Storage
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny** _________________________________________________________________
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan ZelenyX509_STORE *SSL_X509_STORE_create(char *cpFile, char *cpPath)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny pLookup = X509_STORE_add_lookup(pStore, X509_LOOKUP_file());
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny rv = X509_LOOKUP_load_file(pLookup, cpFile, X509_FILETYPE_PEM);
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny pLookup = X509_STORE_add_lookup(pStore, X509_LOOKUP_hash_dir());
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny rv = X509_LOOKUP_add_dir(pLookup, cpPath, X509_FILETYPE_PEM);
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zelenyint SSL_X509_STORE_lookup(X509_STORE *pStore, int nType,
int rc;
return rc;
SSL_CIPHER *c;
char *cpCipherSuite;
char *cp;
cp += l;
return cpCipherSuite;
int ext_nid;
if (sk) {
return is_sgc;
char *cp;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
int len;
return NULL;
return result;
int i, nid;
return TRUE;
return FALSE;
const char *filename)
return FALSE;
return FALSE;
return TRUE;
const char *pathname)
* ssl_engine_init.c, only the call to handle the fullname is different,
const char *fullname;
return FALSE;
NULL);
return ok;
int len=0;
while (can_proceed) {
can_proceed = 0;
len++;
return len;
unsigned long err;
if (skipfirst) {
while (ERR_get_error() > 0) ;
char *cp;
return str;