| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
| 2 | // Copyright (C) 2014 BlackBerry Limited. All rights reserved. |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | |
| 5 | /**************************************************************************** |
| 6 | ** |
| 7 | ** In addition, as a special exception, the copyright holders listed above give |
| 8 | ** permission to link the code of its release of Qt with the OpenSSL project's |
| 9 | ** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the |
| 10 | ** same license as the original version), and distribute the linked executables. |
| 11 | ** |
| 12 | ** You must comply with the GNU General Public License version 2 in all |
| 13 | ** respects for all of the code used other than the "OpenSSL" code. If you |
| 14 | ** modify this file, you may extend this exception to your version of the file, |
| 15 | ** but you are not obligated to do so. If you do not wish to do so, delete |
| 16 | ** this exception statement from your version of this file. |
| 17 | ** |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | #ifndef OPENSSL_SYMBOLS_P_H |
| 21 | #define OPENSSL_SYMBOLS_P_H |
| 22 | |
| 23 | #include <openssl/asn1.h> |
| 24 | #include <openssl/bio.h> |
| 25 | #include <openssl/bn.h> |
| 26 | #include <openssl/err.h> |
| 27 | #include <openssl/evp.h> |
| 28 | #include <openssl/pem.h> |
| 29 | #include <openssl/pkcs12.h> |
| 30 | #include <openssl/pkcs7.h> |
| 31 | #include <openssl/rand.h> |
| 32 | #include <openssl/ssl.h> |
| 33 | #include <openssl/stack.h> |
| 34 | #include <openssl/x509.h> |
| 35 | #include <openssl/x509v3.h> |
| 36 | #include <openssl/x509_vfy.h> |
| 37 | #include <openssl/dsa.h> |
| 38 | #include <openssl/rsa.h> |
| 39 | #include <openssl/crypto.h> |
| 40 | #include <openssl/tls1.h> |
| 41 | |
| 42 | // |
| 43 | // W A R N I N G |
| 44 | // ------------- |
| 45 | // |
| 46 | // This file is not part of the Qt API. It exists purely as an |
| 47 | // implementation detail. This header file may change from version to |
| 48 | // version without notice, or even be removed. |
| 49 | // |
| 50 | // We mean it. |
| 51 | // |
| 52 | |
| 53 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
| 54 | #include <QtCore/QLoggingCategory> |
| 55 | |
| 56 | #ifdef Q_OS_WIN |
| 57 | #include <qt_windows.h> |
| 58 | #if defined(X509_NAME) |
| 59 | #undef X509_NAME |
| 60 | #endif |
| 61 | #endif // Q_OS_WIN |
| 62 | |
| 63 | #include <QtCore/qglobal.h> |
| 64 | |
| 65 | QT_BEGIN_NAMESPACE |
| 66 | |
| 67 | Q_DECLARE_LOGGING_CATEGORY(lcSsl) |
| 68 | |
| 69 | #define DUMMYARG |
| 70 | |
| 71 | #if !defined QT_LINKED_OPENSSL |
| 72 | // **************** Shared declarations ****************** |
| 73 | // ret func(arg) |
| 74 | |
| 75 | # define DEFINEFUNC(ret, func, arg, a, err, funcret) \ |
| 76 | typedef ret (*_q_PTR_##func)(arg); \ |
| 77 | static _q_PTR_##func _q_##func = 0; \ |
| 78 | ret q_##func(arg) { \ |
| 79 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 80 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 81 | err; \ |
| 82 | } \ |
| 83 | funcret _q_##func(a); \ |
| 84 | } |
| 85 | |
| 86 | // ret func(arg1, arg2) |
| 87 | # define DEFINEFUNC2(ret, func, arg1, a, arg2, b, err, funcret) \ |
| 88 | typedef ret (*_q_PTR_##func)(arg1, arg2); \ |
| 89 | static _q_PTR_##func _q_##func = 0; \ |
| 90 | ret q_##func(arg1, arg2) { \ |
| 91 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 92 | qsslSocketUnresolvedSymbolWarning(#func);\ |
| 93 | err; \ |
| 94 | } \ |
| 95 | funcret _q_##func(a, b); \ |
| 96 | } |
| 97 | |
| 98 | // ret func(arg1, arg2, arg3) |
| 99 | # define DEFINEFUNC3(ret, func, arg1, a, arg2, b, arg3, c, err, funcret) \ |
| 100 | typedef ret (*_q_PTR_##func)(arg1, arg2, arg3); \ |
| 101 | static _q_PTR_##func _q_##func = 0; \ |
| 102 | ret q_##func(arg1, arg2, arg3) { \ |
| 103 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 104 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 105 | err; \ |
| 106 | } \ |
| 107 | funcret _q_##func(a, b, c); \ |
| 108 | } |
| 109 | |
| 110 | // ret func(arg1, arg2, arg3, arg4) |
| 111 | # define DEFINEFUNC4(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, err, funcret) \ |
| 112 | typedef ret (*_q_PTR_##func)(arg1, arg2, arg3, arg4); \ |
| 113 | static _q_PTR_##func _q_##func = 0; \ |
| 114 | ret q_##func(arg1, arg2, arg3, arg4) { \ |
| 115 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 116 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 117 | err; \ |
| 118 | } \ |
| 119 | funcret _q_##func(a, b, c, d); \ |
| 120 | } |
| 121 | |
| 122 | // ret func(arg1, arg2, arg3, arg4, arg5) |
| 123 | # define DEFINEFUNC5(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, err, funcret) \ |
| 124 | typedef ret (*_q_PTR_##func)(arg1, arg2, arg3, arg4, arg5); \ |
| 125 | static _q_PTR_##func _q_##func = 0; \ |
| 126 | ret q_##func(arg1, arg2, arg3, arg4, arg5) { \ |
| 127 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 128 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 129 | err; \ |
| 130 | } \ |
| 131 | funcret _q_##func(a, b, c, d, e); \ |
| 132 | } |
| 133 | |
| 134 | // ret func(arg1, arg2, arg3, arg4, arg6) |
| 135 | # define DEFINEFUNC6(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, err, funcret) \ |
| 136 | typedef ret (*_q_PTR_##func)(arg1, arg2, arg3, arg4, arg5, arg6); \ |
| 137 | static _q_PTR_##func _q_##func = 0; \ |
| 138 | ret q_##func(arg1, arg2, arg3, arg4, arg5, arg6) { \ |
| 139 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 140 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 141 | err; \ |
| 142 | } \ |
| 143 | funcret _q_##func(a, b, c, d, e, f); \ |
| 144 | } |
| 145 | |
| 146 | // ret func(arg1, arg2, arg3, arg4, arg6, arg7) |
| 147 | # define DEFINEFUNC7(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, arg7, g, err, funcret) \ |
| 148 | typedef ret (*_q_PTR_##func)(arg1, arg2, arg3, arg4, arg5, arg6, arg7); \ |
| 149 | static _q_PTR_##func _q_##func = 0; \ |
| 150 | ret q_##func(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { \ |
| 151 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 152 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 153 | err; \ |
| 154 | } \ |
| 155 | funcret _q_##func(a, b, c, d, e, f, g); \ |
| 156 | } |
| 157 | |
| 158 | // ret func(arg1, arg2, arg3, arg4, arg6, arg7, arg8, arg9) |
| 159 | # define DEFINEFUNC9(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, arg7, g, arg8, h, arg9, i, err, funcret) \ |
| 160 | typedef ret (*_q_PTR_##func)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); \ |
| 161 | static _q_PTR_##func _q_##func = 0; \ |
| 162 | ret q_##func(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { \ |
| 163 | if (Q_UNLIKELY(!_q_##func)) { \ |
| 164 | qsslSocketUnresolvedSymbolWarning(#func); \ |
| 165 | err; \ |
| 166 | } \ |
| 167 | funcret _q_##func(a, b, c, d, e, f, g, h, i); \ |
| 168 | } |
| 169 | // **************** Shared declarations ****************** |
| 170 | |
| 171 | #else // !defined QT_LINKED_OPENSSL |
| 172 | |
| 173 | // **************** Static declarations ****************** |
| 174 | |
| 175 | // ret func(arg) |
| 176 | # define DEFINEFUNC(ret, func, arg, a, err, funcret) \ |
| 177 | ret q_##func(arg) { funcret func(a); } |
| 178 | |
| 179 | // ret func(arg1, arg2) |
| 180 | # define DEFINEFUNC2(ret, func, arg1, a, arg2, b, err, funcret) \ |
| 181 | ret q_##func(arg1, arg2) { funcret func(a, b); } |
| 182 | |
| 183 | // ret func(arg1, arg2, arg3) |
| 184 | # define DEFINEFUNC3(ret, func, arg1, a, arg2, b, arg3, c, err, funcret) \ |
| 185 | ret q_##func(arg1, arg2, arg3) { funcret func(a, b, c); } |
| 186 | |
| 187 | // ret func(arg1, arg2, arg3, arg4) |
| 188 | # define DEFINEFUNC4(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, err, funcret) \ |
| 189 | ret q_##func(arg1, arg2, arg3, arg4) { funcret func(a, b, c, d); } |
| 190 | |
| 191 | // ret func(arg1, arg2, arg3, arg4, arg5) |
| 192 | # define DEFINEFUNC5(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, err, funcret) \ |
| 193 | ret q_##func(arg1, arg2, arg3, arg4, arg5) { funcret func(a, b, c, d, e); } |
| 194 | |
| 195 | // ret func(arg1, arg2, arg3, arg4, arg6) |
| 196 | # define DEFINEFUNC6(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, err, funcret) \ |
| 197 | ret q_##func(arg1, arg2, arg3, arg4, arg5, arg6) { funcret func(a, b, c, d, e, f); } |
| 198 | |
| 199 | // ret func(arg1, arg2, arg3, arg4, arg6, arg7) |
| 200 | # define DEFINEFUNC7(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, arg7, g, err, funcret) \ |
| 201 | ret q_##func(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { funcret func(a, b, c, d, e, f, g); } |
| 202 | |
| 203 | // ret func(arg1, arg2, arg3, arg4, arg6, arg7, arg8, arg9) |
| 204 | # define DEFINEFUNC9(ret, func, arg1, a, arg2, b, arg3, c, arg4, d, arg5, e, arg6, f, arg7, g, arg8, h, arg9, i, err, funcret) \ |
| 205 | ret q_##func(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { funcret func(a, b, c, d, e, f, g, h, i); } |
| 206 | |
| 207 | // **************** Static declarations ****************** |
| 208 | |
| 209 | #endif // !defined QT_LINKED_OPENSSL |
| 210 | |
| 211 | BIO *q_BIO_new(const BIO_METHOD *a); |
| 212 | const BIO_METHOD *q_BIO_s_mem(); |
| 213 | |
| 214 | int q_EVP_PKEY_get_base_id(const EVP_PKEY *pkey); |
| 215 | #define q_EVP_PKEY_base_id q_EVP_PKEY_get_base_id |
| 216 | |
| 217 | void q_OPENSSL_sk_pop_free(OPENSSL_STACK *a, void (*b)(void *)); |
| 218 | void q_OPENSSL_sk_push(OPENSSL_STACK *st, void *data); |
| 219 | ASN1_TIME *q_X509_getm_notBefore(X509 *a); |
| 220 | ASN1_TIME *q_X509_getm_notAfter(X509 *a); |
| 221 | |
| 222 | // We resolve q_sk_ functions, but use q_OPENSSL_sk_ macros in code to reduce |
| 223 | // the amount of #ifdefs and for confusing developers. |
| 224 | OPENSSL_STACK *q_sk_new_null(); |
| 225 | #define q_OPENSSL_sk_new_null() q_sk_new_null() |
| 226 | #define q_sk_X509_EXTENSION_new_null() \ |
| 227 | ((OPENSSL_STACK *)q_sk_new_null()) |
| 228 | #define q_sk_X509_EXTENSION_push(st, val) \ |
| 229 | q_OPENSSL_sk_push((st), (val)) |
| 230 | #define q_sk_X509_EXTENSION_pop_free(st, free_func) \ |
| 231 | q_OPENSSL_sk_pop_free((st), (free_func)) |
| 232 | |
| 233 | int q_OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings); |
| 234 | EVP_PKEY_CTX* q_EVP_PKEY_CTX_new_id(int id, ENGINE *e); |
| 235 | void q_EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); |
| 236 | int q_EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx); |
| 237 | |
| 238 | int q_RSA_pkey_ctx_ctrl(EVP_PKEY_CTX *ctx, int optype, int cmd, int p1, void *p2); |
| 239 | #define q_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) \ |
| 240 | q_RSA_pkey_ctx_ctrl(ctx, EVP_PKEY_OP_KEYGEN, \ |
| 241 | EVP_PKEY_CTRL_RSA_KEYGEN_BITS, bits, NULL) |
| 242 | |
| 243 | int q_EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **pkey); |
| 244 | bool q_resolveOpenSslSymbols(); |
| 245 | |
| 246 | long q_BIO_ctrl(BIO *a, int b, long c, void *d); |
| 247 | void q_BIO_free_all(BIO *a); |
| 248 | BIO *q_BIO_new_mem_buf(void *a, int b); |
| 249 | void q_ERR_error_string_n(unsigned long e, char *buf, size_t len); |
| 250 | unsigned long q_ERR_get_error(); |
| 251 | X509_REQ *q_X509_REQ_new(); |
| 252 | void q_X509_REQ_free(X509_REQ *req); |
| 253 | int q_PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x); |
| 254 | int q_X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts); |
| 255 | void q_X509_EXTENSION_free(X509_EXTENSION *ext); |
| 256 | int q_X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); |
| 257 | ASN1_INTEGER *q_ASN1_INTEGER_dup(const ASN1_INTEGER *x); |
| 258 | |
| 259 | X509_NAME *q_X509_REQ_get_subject_name(X509_REQ *req); |
| 260 | #define q_ERR_load_crypto_strings() \ |
| 261 | q_OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL) |
| 262 | |
| 263 | int q_X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len, int loc, int set); |
| 264 | ASN1_OBJECT *q_OBJ_txt2obj(const char *s, int no_name); |
| 265 | int q_X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); |
| 266 | int q_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); |
| 267 | int q_X509_REQ_set_version(X509_REQ *x, long version); |
| 268 | X509_EXTENSION *q_X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, int ext_nid, char *value); |
| 269 | |
| 270 | const EVP_CIPHER *q_EVP_aes_128_cbc(); |
| 271 | const EVP_MD *q_EVP_sha1(); |
| 272 | const EVP_MD *q_EVP_sha256(); |
| 273 | void q_EVP_PKEY_free(EVP_PKEY *a); |
| 274 | EVP_PKEY *q_PEM_read_bio_PrivateKey(BIO *a, EVP_PKEY **b, pem_password_cb *c, void *d); |
| 275 | int q_PEM_write_bio_PKCS8PrivateKey(BIO *a, EVP_PKEY *b, const EVP_CIPHER *c, char *d, |
| 276 | int e, pem_password_cb *f, void *g); |
| 277 | EVP_PKEY *q_PEM_read_bio_PUBKEY(BIO *a, EVP_PKEY **b, pem_password_cb *c, void *d); |
| 278 | int q_PEM_write_bio_PUBKEY(BIO *a, EVP_PKEY *b); |
| 279 | |
| 280 | void q_X509_free(X509 *a); |
| 281 | ASN1_TIME *q_X509_gmtime_adj(ASN1_TIME *s, long adj); |
| 282 | void *q_X509_get_ext_d2i(X509 *a, int b, int *c, int *d); |
| 283 | void q_AUTHORITY_KEYID_free(AUTHORITY_KEYID *a); |
| 284 | X509_NAME *q_X509_get_issuer_name(X509 *a); |
| 285 | X509_NAME *q_X509_get_subject_name(X509 *a); |
| 286 | ASN1_INTEGER *q_X509_get_serialNumber(X509 *a); |
| 287 | int q_PEM_write_bio_X509(BIO *bp, X509 *x); |
| 288 | X509 *q_X509_new(); |
| 289 | int q_X509_set_pubkey(X509 *x, EVP_PKEY *key); |
| 290 | int q_X509_sign(X509 *x, EVP_PKEY *key, const EVP_MD *md); |
| 291 | int q_X509_add_ext(X509 *x, X509_EXTENSION *ex, int location); |
| 292 | int q_X509_set_version(X509 *x, long version); |
| 293 | ASN1_OCTET_STRING *q_ASN1_OCTET_STRING_new(); |
| 294 | int q_X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, unsigned int *len); |
| 295 | int q_ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len); |
| 296 | int q_X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, unsigned long flags); |
| 297 | void q_ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *a); |
| 298 | int q_X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, unsigned int *len); |
| 299 | ASN1_INTEGER *q_ASN1_INTEGER_new(); |
| 300 | GENERAL_NAMES *q_GENERAL_NAMES_new(); |
| 301 | GENERAL_NAME *q_GENERAL_NAME_new(); |
| 302 | X509_NAME *q_X509_NAME_dup(X509_NAME *xn); |
| 303 | int q_X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); |
| 304 | AUTHORITY_KEYID *q_AUTHORITY_KEYID_new(); |
| 305 | void q_ASN1_INTEGER_free(ASN1_INTEGER *a); |
| 306 | int q_i2d_X509_REQ_bio(BIO *bp, X509_REQ *req); |
| 307 | int q_i2d_X509_bio(BIO *bp, X509 *x509); |
| 308 | |
| 309 | #define q_BIO_get_mem_data(b, pp) (int)q_BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) |
| 310 | #define q_sk_GENERAL_NAME_push(st, val) q_OPENSSL_sk_push((st), (val)) |
| 311 | |
| 312 | QT_END_NAMESPACE |
| 313 | |
| 314 | #endif |
| 315 | |