xref: /PHP-7.2/ext/openssl/php_openssl.h (revision 68c3d09c)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Stig Venaas <venaas@php.net>                                |
16    |          Wez Furlong <wez@thebrainroom.com                           |
17    +----------------------------------------------------------------------+
18  */
19 
20 /* $Id$ */
21 
22 #ifndef PHP_OPENSSL_H
23 #define PHP_OPENSSL_H
24 /* HAVE_OPENSSL would include SSL MySQL stuff */
25 #ifdef HAVE_OPENSSL_EXT
26 extern zend_module_entry openssl_module_entry;
27 #define phpext_openssl_ptr &openssl_module_entry
28 
29 #include "php_version.h"
30 #define PHP_OPENSSL_VERSION PHP_VERSION
31 
32 #include <openssl/opensslv.h>
33 #if defined(LIBRESSL_VERSION_NUMBER)
34 /* LibreSSL version check */
35 #if LIBRESSL_VERSION_NUMBER < 0x20700000L
36 #define PHP_OPENSSL_API_VERSION 0x10001
37 #else
38 #define PHP_OPENSSL_API_VERSION 0x10100
39 #endif
40 #else
41 /* OpenSSL version check */
42 #if OPENSSL_VERSION_NUMBER < 0x10002000L
43 #define PHP_OPENSSL_API_VERSION 0x10001
44 #elif OPENSSL_VERSION_NUMBER < 0x10100000L
45 #define PHP_OPENSSL_API_VERSION 0x10002
46 #else
47 #define PHP_OPENSSL_API_VERSION 0x10100
48 #endif
49 #endif
50 
51 #define OPENSSL_RAW_DATA 1
52 #define OPENSSL_ZERO_PADDING 2
53 #define OPENSSL_DONT_ZERO_PAD_KEY 4
54 
55 #define OPENSSL_ERROR_X509_PRIVATE_KEY_VALUES_MISMATCH 0x0B080074
56 
57 /* Used for client-initiated handshake renegotiation DoS protection*/
58 #define OPENSSL_DEFAULT_RENEG_LIMIT 2
59 #define OPENSSL_DEFAULT_RENEG_WINDOW 300
60 #define OPENSSL_DEFAULT_STREAM_VERIFY_DEPTH 9
61 #define OPENSSL_DEFAULT_STREAM_CIPHERS "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:" \
62 	"ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:" \
63 	"DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:" \
64 	"ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:" \
65 	"ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:" \
66 	"DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:" \
67 	"AES256-GCM-SHA384:AES128:AES256:HIGH:!SSLv2:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!RC4:!ADH"
68 
69 #include <openssl/err.h>
70 
71 struct php_openssl_errors {
72 	int buffer[ERR_NUM_ERRORS];
73 	int top;
74 	int bottom;
75 };
76 
77 ZEND_BEGIN_MODULE_GLOBALS(openssl)
78 	struct php_openssl_errors *errors;
79 ZEND_END_MODULE_GLOBALS(openssl)
80 
81 #define OPENSSL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(openssl, v)
82 
83 #if defined(ZTS) && defined(COMPILE_DL_OPENSSL)
84 ZEND_TSRMLS_CACHE_EXTERN();
85 #endif
86 
87 php_stream_transport_factory_func php_openssl_ssl_socket_factory;
88 
89 void php_openssl_store_errors();
90 
91 PHP_MINIT_FUNCTION(openssl);
92 PHP_MSHUTDOWN_FUNCTION(openssl);
93 PHP_MINFO_FUNCTION(openssl);
94 PHP_GINIT_FUNCTION(openssl);
95 PHP_GSHUTDOWN_FUNCTION(openssl);
96 
97 PHP_FUNCTION(openssl_pkey_get_private);
98 PHP_FUNCTION(openssl_pkey_get_public);
99 PHP_FUNCTION(openssl_pkey_free);
100 PHP_FUNCTION(openssl_pkey_new);
101 PHP_FUNCTION(openssl_pkey_export);
102 PHP_FUNCTION(openssl_pkey_export_to_file);
103 PHP_FUNCTION(openssl_pkey_get_details);
104 
105 PHP_FUNCTION(openssl_sign);
106 PHP_FUNCTION(openssl_verify);
107 PHP_FUNCTION(openssl_seal);
108 PHP_FUNCTION(openssl_open);
109 PHP_FUNCTION(openssl_private_encrypt);
110 PHP_FUNCTION(openssl_private_decrypt);
111 PHP_FUNCTION(openssl_public_encrypt);
112 PHP_FUNCTION(openssl_public_decrypt);
113 
114 PHP_FUNCTION(openssl_pbkdf2);
115 
116 PHP_FUNCTION(openssl_pkcs7_verify);
117 PHP_FUNCTION(openssl_pkcs7_decrypt);
118 PHP_FUNCTION(openssl_pkcs7_sign);
119 PHP_FUNCTION(openssl_pkcs7_encrypt);
120 PHP_FUNCTION(openssl_pkcs7_read);
121 
122 PHP_FUNCTION(openssl_error_string);
123 
124 PHP_FUNCTION(openssl_x509_read);
125 PHP_FUNCTION(openssl_x509_free);
126 PHP_FUNCTION(openssl_x509_parse);
127 PHP_FUNCTION(openssl_x509_checkpurpose);
128 PHP_FUNCTION(openssl_x509_export);
129 PHP_FUNCTION(openssl_x509_fingerprint);
130 PHP_FUNCTION(openssl_x509_export_to_file);
131 PHP_FUNCTION(openssl_x509_check_private_key);
132 
133 PHP_FUNCTION(openssl_pkcs12_export);
134 PHP_FUNCTION(openssl_pkcs12_export_to_file);
135 PHP_FUNCTION(openssl_pkcs12_read);
136 
137 PHP_FUNCTION(openssl_csr_new);
138 PHP_FUNCTION(openssl_csr_export);
139 PHP_FUNCTION(openssl_csr_export_to_file);
140 PHP_FUNCTION(openssl_csr_sign);
141 PHP_FUNCTION(openssl_csr_get_subject);
142 PHP_FUNCTION(openssl_csr_get_public_key);
143 
144 PHP_FUNCTION(openssl_spki_new);
145 PHP_FUNCTION(openssl_spki_verify);
146 PHP_FUNCTION(openssl_spki_export);
147 PHP_FUNCTION(openssl_spki_export_challenge);
148 
149 PHP_FUNCTION(openssl_get_cert_locations);
150 
151 #ifdef PHP_WIN32
152 #define PHP_OPENSSL_BIO_MODE_R(flags) (((flags) & PKCS7_BINARY) ? "rb" : "r")
153 #define PHP_OPENSSL_BIO_MODE_W(flags) (((flags) & PKCS7_BINARY) ? "wb" : "w")
154 #else
155 #define PHP_OPENSSL_BIO_MODE_R(flags) "r"
156 #define PHP_OPENSSL_BIO_MODE_W(flags) "w"
157 #endif
158 
159 #else
160 
161 #define phpext_openssl_ptr NULL
162 
163 #endif
164 
165 
166 #endif
167 
168 /*
169  * Local variables:
170  * tab-width: 4
171  * c-basic-offset: 4
172  * End:
173  */
174