]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/support.h
Author: Leonid Evdokimov <leon@darkk.net.ru>
[thirdparty/squid.git] / src / ssl / support.h
1
2 /*
3 * $Id$
4 *
5 * AUTHOR: Benno Rice
6 *
7 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from the
11 * Internet community. Development is led by Duane Wessels of the
12 * National Laboratory for Applied Network Research and funded by the
13 * National Science Foundation. Squid is Copyrighted (C) 1998 by
14 * Duane Wessels and the University of California San Diego. Please
15 * see the COPYRIGHT file for full details. Squid incorporates
16 * software developed and/or copyrighted by other sources. Please see
17 * the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #ifndef SQUID_SSL_SUPPORT_H
36 #define SQUID_SSL_SUPPORT_H
37
38 #include "ssl/gadgets.h"
39
40 #if HAVE_OPENSSL_SSL_H
41 #include <openssl/ssl.h>
42 #endif
43 #if HAVE_OPENSSL_X509V3_H
44 #include <openssl/x509v3.h>
45 #endif
46 #if HAVE_OPENSSL_ERR_H
47 #include <openssl/err.h>
48 #endif
49 #if HAVE_OPENSSL_ENGINE_H
50 #include <openssl/engine.h>
51 #endif
52
53 /**
54 \defgroup ServerProtocolSSLAPI Server-Side SSL API
55 \ingroup ServerProtocol
56 */
57
58 /// \ingroup ServerProtocolSSLAPI
59 SSL_CTX *sslCreateServerContext(const char *certfile, const char *keyfile, int version, const char *cipher, const char *options, const char *flags, const char *clientCA, const char *CAfile, const char *CApath, const char *CRLfile, const char *dhpath, const char *context);
60
61 /// \ingroup ServerProtocolSSLAPI
62 SSL_CTX *sslCreateClientContext(const char *certfile, const char *keyfile, int version, const char *cipher, const char *options, const char *flags, const char *CAfile, const char *CApath, const char *CRLfile);
63
64 /// \ingroup ServerProtocolSSLAPI
65 int ssl_read_method(int, char *, int);
66
67 /// \ingroup ServerProtocolSSLAPI
68 int ssl_write_method(int, const char *, int);
69
70 /// \ingroup ServerProtocolSSLAPI
71 void ssl_shutdown_method(int);
72
73
74 /// \ingroup ServerProtocolSSLAPI
75 const char *sslGetUserEmail(SSL *ssl);
76
77 /// \ingroup ServerProtocolSSLAPI
78 typedef char const *SSLGETATTRIBUTE(SSL *, const char *);
79
80 /// \ingroup ServerProtocolSSLAPI
81 SSLGETATTRIBUTE sslGetUserAttribute;
82
83 /// \ingroup ServerProtocolSSLAPI
84 SSLGETATTRIBUTE sslGetCAAttribute;
85
86 /// \ingroup ServerProtocolSSLAPI
87 const char *sslGetUserCertificatePEM(SSL *ssl);
88
89 /// \ingroup ServerProtocolSSLAPI
90 const char *sslGetUserCertificateChainPEM(SSL *ssl);
91
92 namespace Ssl
93 {
94 /**
95 \ingroup ServerProtocolSSLAPI
96 * Decide on the kind of certificate and generate a CA- or self-signed one
97 */
98 SSL_CTX *generateSslContext(char const *host, Ssl::X509_Pointer const & signedX509, Ssl::EVP_PKEY_Pointer const & signedPkey);
99
100 /**
101 \ingroup ServerProtocolSSLAPI
102 * Check date of certificate signature. If there is out of date error fucntion
103 * returns false, true otherwise.
104 */
105 bool verifySslCertificateDate(SSL_CTX * sslContext);
106
107 /**
108 \ingroup ServerProtocolSSLAPI
109 * Read private key and certificate from memory and generate SSL context
110 * using their.
111 */
112 SSL_CTX * generateSslContextUsingPkeyAndCertFromMemory(const char * data);
113
114 /**
115 \ingroup ServerProtocolSSLAPI
116 * Iterates over the X509 common and alternate names and to see if matches with given data
117 * using the check_func.
118 \param peer_cert The X509 cert to check
119 \param check_data The data with which the X509 CNs compared
120 \param check_func The function used to match X509 CNs. The CN data passed as ASN1_STRING data
121 \return 1 if any of the certificate CN matches, 0 if none matches.
122 */
123 int matchX509CommonNames(X509 *peer_cert, void *check_data, int (*check_func)(void *check_data, ASN1_STRING *cn_data));
124
125 /**
126 \ingroup ServerProtocolSSLAPI
127 * Convert a given ASN1_TIME to a string form.
128 \param tm the time in ASN1_TIME form
129 \param buf the buffer to write the output
130 \param len write at most len bytes
131 \return The number of bytes written
132 */
133 int asn1timeToString(ASN1_TIME *tm, char *buf, int len);
134
135 } //namespace Ssl
136
137 #ifdef _SQUID_MSWIN_
138
139 #ifdef __cplusplus
140
141 /** \cond AUTODOCS-IGNORE */
142 namespace Squid
143 {
144 /** \endcond */
145
146 /// \ingroup ServerProtocolSSLAPI
147 inline
148 int SSL_set_fd(SSL *ssl, int fd)
149 {
150 return ::SSL_set_fd(ssl, _get_osfhandle(fd));
151 }
152
153 /// \ingroup ServerProtocolSSLAPI
154 #define SSL_set_fd(ssl,fd) Squid::SSL_set_fd(ssl,fd)
155
156 } /* namespace Squid */
157
158 #else
159
160 /// \ingroup ServerProtocolSSLAPI
161 #define SSL_set_fd(s,f) (SSL_set_fd(s, _get_osfhandle(f)))
162
163 #endif /* __cplusplus */
164
165 #endif /* _SQUID_MSWIN_ */
166
167 #endif /* SQUID_SSL_SUPPORT_H */