php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_openssl.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Stig Venaas <venaas@php.net> |
14 | Wez Furlong <wez@thebrainroom.com |
15 +----------------------------------------------------------------------+
16 */
17
18#ifndef PHP_OPENSSL_H
19#define PHP_OPENSSL_H
20
21#ifdef HAVE_OPENSSL_EXT
23#define phpext_openssl_ptr &openssl_module_entry
24
25#include "php_version.h"
26#define PHP_OPENSSL_VERSION PHP_VERSION
27
28#include <openssl/opensslv.h>
29#ifdef LIBRESSL_VERSION_NUMBER
30/* LibreSSL version check */
31#if LIBRESSL_VERSION_NUMBER < 0x20700000L
32#define PHP_OPENSSL_API_VERSION 0x10001
33#else
34#define PHP_OPENSSL_API_VERSION 0x10100
35#endif
36#else
37/* OpenSSL version check */
38#if OPENSSL_VERSION_NUMBER < 0x30000000L
39#define PHP_OPENSSL_API_VERSION 0x10100
40#elif OPENSSL_VERSION_NUMBER < 0x30200000L
41#define PHP_OPENSSL_API_VERSION 0x30000
42#else
43#define PHP_OPENSSL_API_VERSION 0x30200
44#endif
45#endif
46
47#define OPENSSL_RAW_DATA 1
48#define OPENSSL_ZERO_PADDING 2
49#define OPENSSL_DONT_ZERO_PAD_KEY 4
50
51#define OPENSSL_ERROR_X509_PRIVATE_KEY_VALUES_MISMATCH 0x0B080074
52
53/* Used for client-initiated handshake renegotiation DoS protection*/
54#define OPENSSL_DEFAULT_RENEG_LIMIT 2
55#define OPENSSL_DEFAULT_RENEG_WINDOW 300
56#define OPENSSL_DEFAULT_STREAM_VERIFY_DEPTH 9
57#define OPENSSL_DEFAULT_STREAM_CIPHERS "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:" \
58 "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:" \
59 "DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:" \
60 "ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:" \
61 "ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:" \
62 "DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:" \
63 "AES256-GCM-SHA384:AES128:AES256:HIGH:!SSLv2:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!RC4:!ADH"
64
65#include <openssl/err.h>
66
67#ifdef PHP_WIN32
68# define PHP_OPENSSL_API __declspec(dllexport)
69#elif defined(__GNUC__) && __GNUC__ >= 4
70# define PHP_OPENSSL_API __attribute__((visibility("default")))
71#else
72# define PHP_OPENSSL_API
73#endif
74
75struct php_openssl_errors {
76 int buffer[ERR_NUM_ERRORS];
77 int top;
78 int bottom;
79};
80
82 struct php_openssl_errors *errors;
83 struct php_openssl_errors *errors_mark;
85
86#define OPENSSL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(openssl, v)
87
88#if defined(ZTS) && defined(COMPILE_DL_OPENSSL)
90#endif
91
93
95
96/* openssl file path extra */
98 const char *file_path, size_t file_path_len, char *real_path, uint32_t arg_num,
99 bool contains_file_protocol, bool is_from_array, const char *option_name);
100
101/* openssl file path check */
102static inline bool php_openssl_check_path(
103 const char *file_path, size_t file_path_len, char *real_path, uint32_t arg_num)
104{
106 file_path, file_path_len, real_path, arg_num, false, false, NULL);
107}
108
109/* openssl file path extra check with zend string */
110static inline bool php_openssl_check_path_str_ex(
111 zend_string *file_path, char *real_path, uint32_t arg_num,
112 bool contains_file_protocol, bool is_from_array, const char *option_name)
113{
115 ZSTR_VAL(file_path), ZSTR_LEN(file_path), real_path, arg_num, contains_file_protocol,
116 is_from_array, option_name);
117}
118
119/* openssl file path check with zend string */
120static inline bool php_openssl_check_path_str(
121 zend_string *file_path, char *real_path, uint32_t arg_num)
122{
123 return php_openssl_check_path_str_ex(file_path, real_path, arg_num, true, false, NULL);
124}
125
126PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length(const char *method);
127PHP_OPENSSL_API zend_long php_openssl_cipher_key_length(const char *method);
129PHP_OPENSSL_API zend_string* php_openssl_encrypt(
130 const char *data, size_t data_len,
131 const char *method, size_t method_len,
132 const char *password, size_t password_len,
134 const char *iv, size_t iv_len,
135 zval *tag, zend_long tag_len,
136 const char *aad, size_t aad_len);
137PHP_OPENSSL_API zend_string* php_openssl_decrypt(
138 const char *data, size_t data_len,
139 const char *method, size_t method_len,
140 const char *password, size_t password_len,
142 const char *iv, size_t iv_len,
143 const char *tag, zend_long tag_len,
144 const char *aad, size_t aad_len);
145
146/* OpenSSLCertificate class */
147
148typedef struct _php_openssl_certificate_object {
149 X509 *x509;
150 zend_object std;
151} php_openssl_certificate_object;
152
154
155static inline php_openssl_certificate_object *php_openssl_certificate_from_obj(zend_object *obj) {
156 return (php_openssl_certificate_object *)((char *)(obj) - XtOffsetOf(php_openssl_certificate_object, std));
157}
158
159#define Z_OPENSSL_CERTIFICATE_P(zv) php_openssl_certificate_from_obj(Z_OBJ_P(zv))
160
161#if defined(HAVE_OPENSSL_ARGON2)
162
169#if defined(PHP_PASSWORD_ARGON2_MEMORY_COST)
170#define PHP_OPENSSL_PWHASH_MEMLIMIT PHP_PASSWORD_ARGON2_MEMORY_COST
171#else
172#define PHP_OPENSSL_PWHASH_MEMLIMIT (64 << 10)
173#endif
174#if defined(PHP_PASSWORD_ARGON2_TIME_COST)
175#define PHP_OPENSSL_PWHASH_ITERLIMIT PHP_PASSWORD_ARGON2_TIME_COST
176#else
177#define PHP_OPENSSL_PWHASH_ITERLIMIT 4
178#endif
179#if defined(PHP_PASSWORD_ARGON2_THREADS)
180#define PHP_OPENSSL_PWHASH_THREADS PHP_PASSWORD_ARGON2_THREADS
181#else
182#define PHP_OPENSSL_PWHASH_THREADS 1
183#endif
184
185#endif
186
187PHP_MINIT_FUNCTION(openssl);
189PHP_MINFO_FUNCTION(openssl);
190PHP_GINIT_FUNCTION(openssl);
192#if defined(HAVE_OPENSSL_ARGON2)
193PHP_MINIT_FUNCTION(openssl_pwhash);
194#endif
195
196#ifdef PHP_WIN32
197#define PHP_OPENSSL_BIO_MODE_R(flags) (((flags) & PKCS7_BINARY) ? "rb" : "r")
198#define PHP_OPENSSL_BIO_MODE_W(flags) (((flags) & PKCS7_BINARY) ? "wb" : "w")
199#else
200#define PHP_OPENSSL_BIO_MODE_R(flags) "r"
201#define PHP_OPENSSL_BIO_MODE_W(flags) "w"
202#endif
203
204#else
205
206#define phpext_openssl_ptr NULL
207
208#endif
209
210
211#endif
#define NULL
Definition gdcache.h:45
PHP_OPENSSL_API zend_string * php_openssl_encrypt(const char *data, size_t data_len, const char *method, size_t method_len, const char *password, size_t password_len, zend_long options, const char *iv, size_t iv_len, zval *tag, zend_long tag_len, const char *aad, size_t aad_len)
Definition openssl.c:7855
PHP_OPENSSL_API zend_string * php_openssl_random_pseudo_bytes(zend_long buffer_length)
Definition openssl.c:8144
PHP_OPENSSL_API zend_long php_openssl_cipher_key_length(const char *method)
Definition openssl.c:8115
void php_openssl_store_errors(void)
Definition openssl.c:479
zend_module_entry openssl_module_entry
Definition openssl.c:280
PHP_OPENSSL_API zend_string * php_openssl_decrypt(const char *data, size_t data_len, const char *method, size_t method_len, const char *password, size_t password_len, zend_long options, const char *iv, size_t iv_len, const char *tag, zend_long tag_len, const char *aad, size_t aad_len)
Definition openssl.c:7968
zend_class_entry * php_openssl_certificate_ce
Definition openssl.c:161
PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length(const char *method)
Definition openssl.c:8086
bool php_openssl_check_path_ex(const char *file_path, size_t file_path_len, char *real_path, uint32_t arg_num, bool contains_file_protocol, bool is_from_array, const char *option_name)
Definition openssl.c:554
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_GINIT_FUNCTION
Definition php.h:405
#define PHP_GSHUTDOWN_FUNCTION
Definition php.h:406
PHP_JSON_API size_t int options
Definition php_json.h:102
php_stream * php_stream_transport_factory_func(const char *proto, size_t protolen, const char *resourcename, size_t resourcenamelen, const char *persistent_id, int options, int flags, struct timeval *timeout, php_stream_context *context STREAMS_DC)
char * buffer
Definition phpdbg.h:296
zend_constant * data
original_stack top
php_stream * php_openssl_ssl_socket_factory(const char *proto, size_t protolen, const char *resourcename, size_t resourcenamelen, const char *persistent_id, int options, int flags, struct timeval *timeout, php_stream_context *context STREAMS_DC)
Definition xp_ssl.c:2770
#define ZEND_TSRMLS_CACHE_EXTERN()
Definition zend.h:67
#define ZEND_END_MODULE_GLOBALS(module_name)
Definition zend_API.h:248
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
Definition zend_API.h:246
struct _zval_struct zval
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
struct _zend_module_entry zend_module_entry
#define XtOffsetOf(s_type, field)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define ZSTR_LEN(zstr)
Definition zend_string.h:69
uint32_t arg_num