Fix openssl support
[sxemacs] / src / openssl.h
1 /*
2   openssl.h -- Emacs Lisp binding to OpenSSL ciphers and digests
3   Copyright (C) 2005 Sebastian Freundt
4
5   Author:  Sebastian Freundt <hroptatyr@sxemacs.org>
6
7 This file is part of SXEmacs
8
9 SXEmacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 SXEmacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
21
22
23 #ifndef INCLUDED_openssl_h_
24 #define INCLUDED_openssl_h_ 1
25
26 /* this is to determine what has been configured */
27 #ifdef HAVE_OPENSSL_OPENSSLCONF_H
28 #include <openssl/opensslconf.h>
29 #endif
30
31 #ifdef HAVE_OPENSSL_EVP_H
32 #include <openssl/evp.h>
33 #endif
34
35 #ifdef HAVE_OPENSSL_RAND_H
36 #include <openssl/rand.h>
37 #endif
38
39 #ifdef HAVE_OPENSSL_HMAC_H
40 #include <openssl/hmac.h>
41 #endif
42
43 /* special asymmetric crypto systems */
44 #ifdef HAVE_OPENSSL_RSA_H
45 #ifndef OPENSSL_NO_RSA
46 #include <openssl/rsa.h>
47 #endif
48 #endif
49
50 #ifdef HAVE_OPENSSL_DSA_H
51 #ifndef OPENSSL_NO_DSA
52 #include <openssl/dsa.h>
53 #endif
54 #endif
55
56 #ifdef HAVE_OPENSSL_EC_H
57 #ifndef OPENSSL_NO_EC
58 #include <openssl/ec.h>
59 #endif
60 #endif
61
62 #ifdef HAVE_OPENSSL_ECDH_H
63 #ifndef OPENSSL_NO_ECDH
64 #include <openssl/ecdh.h>
65 #endif
66 #endif
67
68 #ifdef HAVE_OPENSSL_ECDSA_H
69 #ifndef OPENSSL_NO_ECDSA
70 #include <openssl/ecdsa.h>
71 #endif
72 #endif
73
74 #ifdef HAVE_OPENSSL_DH
75 #ifndef OPENSSL_NO_DH
76 #include <openssl/dh.h>
77 #endif
78 #endif
79
80 #if defined HAVE_OPENSSL_X509_H
81 # include <openssl/x509.h>
82 #endif
83 #if defined HAVE_OPENSSL_PEM_H
84 # include <openssl/pem.h>
85 #endif
86 #if defined HAVE_OPENSSL_SSL_H
87 # include <openssl/ssl.h>
88 #endif
89 #if defined HAVE_OPENSSL_BIO_H
90 # include <openssl/bio.h>
91 #endif
92
93 /* opaque EVP_PKEY object structure */
94 struct Lisp_EVP_PKEY {
95         struct lcrecord_header header;
96         EVP_PKEY *evp_pkey;
97         X509 *x509;
98 };
99 typedef struct Lisp_EVP_PKEY Lisp_EVP_PKEY;
100
101 DECLARE_LRECORD(evp_pkey, Lisp_EVP_PKEY);
102
103 #define XEVPPKEY(x)             XRECORD (x, evp_pkey, Lisp_EVP_PKEY)
104 #define XSETEVPPKEY(x, p)       XSETRECORD (x, p, evp_pkey)
105 #define EVPPKEYP(x)             RECORDP (x, evp_pkey)
106 #define CHECK_EVPPKEY(x)        CHECK_RECORD (x, evp_pkey)
107 #define wrap_evppkey(p)         wrap_object(p)
108
109 /* opaque SSL_CONN object structure
110  * this is just an ssl-ish wrap around the process object
111  */
112 struct Lisp_SSL_CONN {
113         struct lcrecord_header header;
114         SSL_METHOD *ssl_meth;
115         SSL_CTX *ssl_ctx;
116         SSL *ssl_conn;
117         Lisp_Object parent;
118         int infd, outfd;
119         BIO *ssl_bio;
120         int connected_p;
121         int protected_p;
122
123         /* Low level streams used in input and output,
124            backup streams if network stream is proselytised */
125         Lisp_Object pipe_instream;
126         Lisp_Object pipe_outstream;
127 #ifdef FILE_CODING
128         /* Data end streams, decoding and encoding pipe_* streams */
129         Lisp_Object coding_instream;
130         Lisp_Object coding_outstream;
131 #endif  /* FILE_CODING */
132 };
133 typedef struct Lisp_SSL_CONN Lisp_SSL_CONN;
134
135 Lisp_Object make_ssl_conn(Lisp_SSL_CONN *ssl_conn);
136 Lisp_SSL_CONN *allocate_ssl_conn(void);
137 void finalize_ssl_conn(void *header, int for_disksave);
138 Lisp_Object ossl_ssl_handshake(Lisp_Object, Lisp_Object);
139
140 extern Lisp_Object make_ssl_input_stream(SSL*, int);
141 extern Lisp_Object make_ssl_output_stream(SSL*, int);
142 EXFUN(Fset_process_coding_system, 3);
143 extern void ssl_verify_cert_chain(SSL*, void*);
144
145 DECLARE_LRECORD(ssl_conn, Lisp_SSL_CONN);
146
147 #define XSSLCONN(x)             XRECORD (x, ssl_conn, Lisp_SSL_CONN)
148 #define XSETSSLCONN(x, p)       XSETRECORD (x, p, ssl_conn)
149 #define SSLCONNP(x)             RECORDP (x, ssl_conn)
150 #define CHECK_SSLCONN(x)        CHECK_RECORD (x, ssl_conn)
151 #define wrap_sslconn(p)         wrap_object(p)
152
153 #ifdef ALL_DEBUG_FLAGS
154 #undef OSSL_DEBUG_FLAG
155 #define OSSL_DEBUG_FLAG
156 #endif
157
158 #endif /* INCLUDED_openssl_h_ */