From 833a41e3117382f480eae69d473b8dcd00539251 Mon Sep 17 00:00:00 2001 From: dreid Date: Tue, 20 Jun 2006 13:41:51 +0000 Subject: First dump of some ssl sockets code. This follows the methodology of the patch, but attempts to break out everything that is specific to OpenSSL into a seperate file. The rationale shouldn't be hard to follow. This does makes things slightly moer complex and adds another layer of indirection, but there shouldn't be much of a hit because of it. Hopefully this will be generic enough that some windows person can add win32 support? The test app runs, but is about as basic a test as you could write :-) Should add a "server" test to handle bind/listen/accept cases as these are presently untested. Error handling needs to be beefed up, especially on the read/write, but this is just a first dump to get the code out there and into the public arena. git-svn-id: http://svn.apache.org/repos/asf/apr/apr-util/trunk@415639 13f79535-47bb-0310-9956-ffa450edef68 --- include/apr_ssl.h | 78 +++++++++++++++++++++++++++++++ include/private/apr_ssl_openssl_private.h | 36 ++++++++++++++ include/private/apr_ssl_private.h | 71 ++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 include/apr_ssl.h create mode 100644 include/private/apr_ssl_openssl_private.h create mode 100644 include/private/apr_ssl_private.h (limited to 'include') diff --git a/include/apr_ssl.h b/include/apr_ssl.h new file mode 100644 index 00000000..da8df8c7 --- /dev/null +++ b/include/apr_ssl.h @@ -0,0 +1,78 @@ +/* Copyright 2000-2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APR_SSL_H +#define APR_SSL_H + +#include "apu.h" +#include "apr.h" +#include "apr_errno.h" +#include "apr_pools.h" +#include "apr_network_io.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file apr_ssl.h + * @brief APR-UTIL SSL socket functions + */ +/** + * @defgroup APR_Util_SSL SSL socket routines + * @ingroup APR_Util + * @{ + */ +/** + * Structure for referencing an ssl "factory" + */ +typedef struct apr_ssl_factory apr_ssl_factory_t; +typedef struct apr_ssl_socket apr_ssl_socket_t; + +APU_DECLARE(apr_status_t) apr_ssl_factory_create(apr_ssl_factory_t **, + const char *, const char *, const char *, apr_pool_t *); + + + +APU_DECLARE(apr_status_t) apr_ssl_socket_create(apr_ssl_socket_t **, + int, int, int, + apr_ssl_factory_t *, + apr_pool_t *); + +APU_DECLARE(apr_status_t) apr_ssl_socket_close(apr_ssl_socket_t *); + +APU_DECLARE(apr_status_t) apr_ssl_socket_connect(apr_ssl_socket_t *, apr_sockaddr_t *); + +APU_DECLARE(apr_status_t) apr_ssl_socket_send(apr_ssl_socket_t *, + const char *, + apr_size_t *); + +APU_DECLARE(apr_status_t) apr_ssl_socket_recv(apr_ssl_socket_t *, + char *, apr_size_t *); + +APU_DECLARE(apr_status_t) apr_ssl_socket_bind(apr_ssl_socket_t *, apr_sockaddr_t *); + +APU_DECLARE(apr_status_t) apr_ssl_socket_listen(apr_ssl_socket_t *, apr_int32_t); + +APU_DECLARE(apr_status_t) apr_ssl_socket_accept(apr_ssl_socket_t **, + apr_ssl_socket_t *, + apr_pool_t *); +/** @} */ +#ifdef __cplusplus +} +#endif + +#endif /* !APR_DBM_H */ diff --git a/include/private/apr_ssl_openssl_private.h b/include/private/apr_ssl_openssl_private.h new file mode 100644 index 00000000..c7b6e990 --- /dev/null +++ b/include/private/apr_ssl_openssl_private.h @@ -0,0 +1,36 @@ +/* Copyright 2000-2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APR_SSL_OPENSSL_PRIVATE_H +#define APR_SSL_OPENSSL_PRIVATE_H + +#ifdef APU_HAVE_OPENSSL + +#include + +struct _apu_ssl_data { + SSL_CTX *ctx; + const EVP_MD *md; +}; + +struct _apu_ssl_socket_data { + SSL *ssl; +}; + + +#endif /* APU_HAVE_OPENSSL */ + +#endif /* ! APR_SSL_OPENSSL_PRIVATE_H */ diff --git a/include/private/apr_ssl_private.h b/include/private/apr_ssl_private.h new file mode 100644 index 00000000..c144a215 --- /dev/null +++ b/include/private/apr_ssl_private.h @@ -0,0 +1,71 @@ +/* Copyright 2000-2006 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef APR_SSL_PRIVATE_H +#define APR_SSL_PRIVATE_H + +#include "apr.h" +#include "apr_errno.h" +#include "apr_pools.h" +#include "apr_ssl.h" + +#include "apu.h" +#include "apr_network_io.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @internal */ + +typedef struct _apu_ssl_data _apu_ssl_data_t; +typedef struct _apu_ssl_socket_data _apu_ssl_socket_data_t; + +/** + * SSL factory structure + */ +struct apr_ssl_factory { + apr_pool_t *pool; + _apu_ssl_data_t *sslData; +}; + +struct apr_ssl_socket { + apr_pool_t *pool; + apr_socket_t *plain; + apr_ssl_factory_t *factory; + int connected; + _apu_ssl_socket_data_t *sslData; +}; + +/** + * The following functions are provided by the implementations of + * SSL libraries. + */ + +apr_status_t _ssl_init(void); +apr_status_t _ssl_factory_create(apr_ssl_factory_t *, const char *, const char *, const char *); +apr_status_t _ssl_socket_create(apr_ssl_socket_t *sslSock, apr_ssl_factory_t *asf); +apr_status_t _ssl_socket_close(apr_ssl_socket_t *); +apr_status_t _ssl_connect(apr_ssl_socket_t *); +apr_status_t _ssl_send(apr_ssl_socket_t *, const char *, apr_size_t *); +apr_status_t _ssl_socket_recv(apr_ssl_socket_t *, char *, apr_size_t *); +apr_status_t _ssl_accept(apr_ssl_socket_t *, apr_ssl_socket_t *, apr_pool_t *); + +#ifdef __cplusplus +} +#endif + +#endif /* APR_SSL_PRIVATE_H */ -- cgit v1.2.1