ssl_util.c revision bb0b94431dc9a1591a0a38a6c48925c6d9213c83
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** _ __ ___ ___ __| | ___ ___| | mod_ssl
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** Utility Functions
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* ====================================================================
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * The Apache Software License, Version 1.1
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * reserved.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Redistribution and use in source and binary forms, with or without
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * modification, are permitted provided that the following conditions
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * are met:
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * 1. Redistributions of source code must retain the above copyright
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * notice, this list of conditions and the following disclaimer.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * 2. Redistributions in binary form must reproduce the above copyright
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * notice, this list of conditions and the following disclaimer in
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * the documentation and/or other materials provided with the
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * distribution.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * 3. The end-user documentation included with the redistribution,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * if any, must include the following acknowledgment:
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * "This product includes software developed by the
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * Apache Software Foundation (http://www.apache.org/)."
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * Alternately, this acknowledgment may appear in the software itself,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * if and wherever such third-party acknowledgments normally appear.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * 4. The names "Apache" and "Apache Software Foundation" must
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * not be used to endorse or promote products derived from this
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * software without prior written permission. For written
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * permission, please contact apache@apache.org.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * 5. Products derived from this software may not be called "Apache",
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * nor may "Apache" appear in their name, without prior written
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * permission of the Apache Software Foundation.
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
d86ef5503dcbc38e87c0e03cd3e1f16458cb6323rse * SUCH DAMAGE.
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * ====================================================================
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse /* ``Every day of my life
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse I am forced to add another
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse name to the list of people
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse who piss me off!''
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse -- Calvin */
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse/* _________________________________________________________________
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** Utility Functions
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse** _________________________________________________________________
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse unsigned int port;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if (s->port != 0)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse for (; *s; ++s)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrsevoid ssl_util_uuencode(char *szTo, const char *szFrom, BOOL bPad)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse (const unsigned char *)szFrom,
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse unsigned char *szTo, const unsigned char *szFrom, int nLength, BOOL bPad)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse const unsigned char *s;
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *szTo++ = ssl_util_uuencode_six2pr[(s[0] << 4 | s[1] >> 4) & 0x3f];
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if (--nLength == 0) {
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse *szTo++ = ssl_util_uuencode_six2pr[(s[1] << 2 | s[2] >> 6) & 0x3f];
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if (--nLength == 0) {
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rseapr_file_t *ssl_util_ppopen(server_rec *s, apr_pool_t *p, char *cmd)
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse if (apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_FULL_BLOCK,
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse if (apr_procattr_cmdtype_set(procattr, APR_PROGRAM) != APR_SUCCESS)
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse if ((proc = (apr_proc_t *)apr_pcalloc(p, sizeof(apr_proc_t))) == NULL)
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse if (apr_proc_create(proc, cmd, NULL, NULL, procattr, p) != APR_SUCCESS)
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rsevoid ssl_util_ppclose(server_rec *s, apr_pool_t *p, apr_file_t *fp)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Run a filter program and read the first line of its stdout output
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rsechar *ssl_util_readfilter(server_rec *s, apr_pool_t *p, char *cmd)
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse for (k = 0; apr_file_read(fp, &c, &nbytes) == APR_SUCCESS
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rseBOOL ssl_util_path_check(ssl_pathcheck_t pcm, char *path, apr_pool_t *p)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrsessl_algo_t ssl_util_algotypeof(X509 *pCert, EVP_PKEY *pKey)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse switch (t) {
bb0b94431dc9a1591a0a38a6c48925c6d9213c83rse apr_pool_t *p, const char *cpLine, const char *cpMatch, char *cpSubst)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Pass 1: find substitution locations and calculate sizes
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse if (i == 0)
cc003103e52ff9d5fe9bed567ef9438613ab4fbfrse * Pass 2: allocate memory and assemble result