Ruby  3.1.0dev(2021-09-10revisionb76ad15ed0da636161de0243c547ee1e6fc95681)
openssl_missing.h
Go to the documentation of this file.
1 /*
2  * 'OpenSSL for Ruby' project
3  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4  * All rights reserved.
5  */
6 /*
7  * This program is licensed under the same licence as Ruby.
8  * (See the file 'LICENCE'.)
9  */
10 #if !defined(_OSSL_OPENSSL_MISSING_H_)
11 #define _OSSL_OPENSSL_MISSING_H_
12 
13 #include "ruby/config.h"
14 
15 /* added in 1.1.0 */
16 #if !defined(HAVE_EVP_MD_CTX_NEW)
17 # define EVP_MD_CTX_new EVP_MD_CTX_create
18 #endif
19 
20 #if !defined(HAVE_EVP_MD_CTX_FREE)
21 # define EVP_MD_CTX_free EVP_MD_CTX_destroy
22 #endif
23 
24 #if !defined(HAVE_EVP_MD_CTX_PKEY_CTX)
25 # define EVP_MD_CTX_pkey_ctx(x) (x)->pctx
26 #endif
27 
28 #if !defined(HAVE_X509_STORE_GET_EX_DATA)
29 # define X509_STORE_get_ex_data(x, idx) \
30  CRYPTO_get_ex_data(&(x)->ex_data, (idx))
31 #endif
32 
33 #if !defined(HAVE_X509_STORE_SET_EX_DATA)
34 # define X509_STORE_set_ex_data(x, idx, data) \
35  CRYPTO_set_ex_data(&(x)->ex_data, (idx), (data))
36 #endif
37 
38 #if !defined(HAVE_X509_STORE_GET_EX_NEW_INDEX) && !defined(X509_STORE_get_ex_new_index)
39 # define X509_STORE_get_ex_new_index(l, p, newf, dupf, freef) \
40  CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE, (l), (p), \
41  (newf), (dupf), (freef))
42 #endif
43 
44 #if !defined(HAVE_X509_CRL_GET0_SIGNATURE)
45 void ossl_X509_CRL_get0_signature(const X509_CRL *, const ASN1_BIT_STRING **, const X509_ALGOR **);
46 # define X509_CRL_get0_signature ossl_X509_CRL_get0_signature
47 #endif
48 
49 #if !defined(HAVE_X509_REQ_GET0_SIGNATURE)
50 void ossl_X509_REQ_get0_signature(const X509_REQ *, const ASN1_BIT_STRING **, const X509_ALGOR **);
51 # define X509_REQ_get0_signature ossl_X509_REQ_get0_signature
52 #endif
53 
54 #if !defined(HAVE_X509_REVOKED_GET0_SERIALNUMBER)
55 # define X509_REVOKED_get0_serialNumber(x) ((x)->serialNumber)
56 #endif
57 
58 #if !defined(HAVE_X509_REVOKED_GET0_REVOCATIONDATE)
59 # define X509_REVOKED_get0_revocationDate(x) ((x)->revocationDate)
60 #endif
61 
62 #if !defined(HAVE_X509_GET0_TBS_SIGALG)
63 # define X509_get0_tbs_sigalg(x) ((x)->cert_info->signature)
64 #endif
65 
66 #if !defined(HAVE_X509_STORE_CTX_GET0_UNTRUSTED)
67 # define X509_STORE_CTX_get0_untrusted(x) ((x)->untrusted)
68 #endif
69 
70 #if !defined(HAVE_X509_STORE_CTX_GET0_CERT)
71 # define X509_STORE_CTX_get0_cert(x) ((x)->cert)
72 #endif
73 
74 #if !defined(HAVE_X509_STORE_CTX_GET0_CHAIN)
75 # define X509_STORE_CTX_get0_chain(ctx) X509_STORE_CTX_get_chain(ctx)
76 #endif
77 
78 #if !defined(HAVE_OCSP_SINGLERESP_GET0_ID)
79 # define OCSP_SINGLERESP_get0_id(s) ((s)->certId)
80 #endif
81 
82 #if !defined(HAVE_SSL_CTX_GET_CIPHERS)
83 # define SSL_CTX_get_ciphers(ctx) ((ctx)->cipher_list)
84 #endif
85 
86 #if !defined(HAVE_X509_UP_REF)
87 # define X509_up_ref(x) \
88  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509)
89 #endif
90 
91 #if !defined(HAVE_X509_CRL_UP_REF)
92 # define X509_CRL_up_ref(x) \
93  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509_CRL);
94 #endif
95 
96 #if !defined(HAVE_X509_STORE_UP_REF)
97 # define X509_STORE_up_ref(x) \
98  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509_STORE);
99 #endif
100 
101 #if !defined(HAVE_SSL_SESSION_UP_REF)
102 # define SSL_SESSION_up_ref(x) \
103  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_SSL_SESSION);
104 #endif
105 
106 #if !defined(HAVE_EVP_PKEY_UP_REF)
107 # define EVP_PKEY_up_ref(x) \
108  CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_EVP_PKEY);
109 #endif
110 
111 #if !defined(HAVE_OPAQUE_OPENSSL)
112 #define IMPL_PKEY_GETTER(_type, _name) \
113 static inline _type *EVP_PKEY_get0_##_type(EVP_PKEY *pkey) { \
114  return pkey->pkey._name; }
115 #define IMPL_KEY_ACCESSOR2(_type, _group, a1, a2, _fail_cond) \
116 static inline void _type##_get0_##_group(const _type *obj, const BIGNUM **a1, const BIGNUM **a2) { \
117  if (a1) *a1 = obj->a1; \
118  if (a2) *a2 = obj->a2; } \
119 static inline int _type##_set0_##_group(_type *obj, BIGNUM *a1, BIGNUM *a2) { \
120  if (_fail_cond) return 0; \
121  BN_clear_free(obj->a1); obj->a1 = a1; \
122  BN_clear_free(obj->a2); obj->a2 = a2; \
123  return 1; }
124 #define IMPL_KEY_ACCESSOR3(_type, _group, a1, a2, a3, _fail_cond) \
125 static inline void _type##_get0_##_group(const _type *obj, const BIGNUM **a1, const BIGNUM **a2, const BIGNUM **a3) { \
126  if (a1) *a1 = obj->a1; \
127  if (a2) *a2 = obj->a2; \
128  if (a3) *a3 = obj->a3; } \
129 static inline int _type##_set0_##_group(_type *obj, BIGNUM *a1, BIGNUM *a2, BIGNUM *a3) { \
130  if (_fail_cond) return 0; \
131  BN_clear_free(obj->a1); obj->a1 = a1; \
132  BN_clear_free(obj->a2); obj->a2 = a2; \
133  BN_clear_free(obj->a3); obj->a3 = a3; \
134  return 1; }
135 
136 #if !defined(OPENSSL_NO_RSA)
137 IMPL_PKEY_GETTER(RSA, rsa)
138 IMPL_KEY_ACCESSOR3(RSA, key, n, e, d, (n == obj->n || e == obj->e || (obj->d && d == obj->d)))
139 IMPL_KEY_ACCESSOR2(RSA, factors, p, q, (p == obj->p || q == obj->q))
140 IMPL_KEY_ACCESSOR3(RSA, crt_params, dmp1, dmq1, iqmp, (dmp1 == obj->dmp1 || dmq1 == obj->dmq1 || iqmp == obj->iqmp))
141 #endif
142 
143 #if !defined(OPENSSL_NO_DSA)
144 IMPL_PKEY_GETTER(DSA, dsa)
146 IMPL_KEY_ACCESSOR3(DSA, pqg, p, q, g, (p == obj->p || q == obj->q || g == obj->g))
147 #endif
148 
149 #if !defined(OPENSSL_NO_DH)
150 IMPL_PKEY_GETTER(DH, dh)
151 IMPL_KEY_ACCESSOR2(DH, key, pub_key, priv_key, (pub_key == obj->pub_key || (obj->priv_key && priv_key == obj->priv_key)))
152 IMPL_KEY_ACCESSOR3(DH, pqg, p, q, g, (p == obj->p || (obj->q && q == obj->q) || g == obj->g))
153 static inline ENGINE *DH_get0_engine(DH *dh) { return dh->engine; }
154 #endif
155 
156 #if !defined(OPENSSL_NO_EC)
157 IMPL_PKEY_GETTER(EC_KEY, ec)
158 #endif
159 
160 #undef IMPL_PKEY_GETTER
161 #undef IMPL_KEY_ACCESSOR2
162 #undef IMPL_KEY_ACCESSOR3
163 #endif /* HAVE_OPAQUE_OPENSSL */
164 
165 #if !defined(EVP_CTRL_AEAD_GET_TAG)
166 # define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG
167 # define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG
168 # define EVP_CTRL_AEAD_SET_IVLEN EVP_CTRL_GCM_SET_IVLEN
169 #endif
170 
171 #if !defined(HAVE_X509_GET0_NOTBEFORE)
172 # define X509_get0_notBefore(x) X509_get_notBefore(x)
173 # define X509_get0_notAfter(x) X509_get_notAfter(x)
174 # define X509_CRL_get0_lastUpdate(x) X509_CRL_get_lastUpdate(x)
175 # define X509_CRL_get0_nextUpdate(x) X509_CRL_get_nextUpdate(x)
176 # define X509_set1_notBefore(x, t) X509_set_notBefore(x, t)
177 # define X509_set1_notAfter(x, t) X509_set_notAfter(x, t)
178 # define X509_CRL_set1_lastUpdate(x, t) X509_CRL_set_lastUpdate(x, t)
179 # define X509_CRL_set1_nextUpdate(x, t) X509_CRL_set_nextUpdate(x, t)
180 #endif
181 
182 #if !defined(HAVE_SSL_SESSION_GET_PROTOCOL_VERSION)
183 # define SSL_SESSION_get_protocol_version(s) ((s)->ssl_version)
184 #endif
185 
186 #if !defined(HAVE_TS_STATUS_INFO_GET0_STATUS)
187 # define TS_STATUS_INFO_get0_status(a) ((a)->status)
188 #endif
189 
190 #if !defined(HAVE_TS_STATUS_INFO_GET0_TEXT)
191 # define TS_STATUS_INFO_get0_text(a) ((a)->text)
192 #endif
193 
194 #if !defined(HAVE_TS_STATUS_INFO_GET0_FAILURE_INFO)
195 # define TS_STATUS_INFO_get0_failure_info(a) ((a)->failure_info)
196 #endif
197 
198 #if !defined(HAVE_TS_VERIFY_CTS_SET_CERTS)
199 # define TS_VERIFY_CTS_set_certs(ctx, crts) ((ctx)->certs=(crts))
200 #endif
201 
202 #if !defined(HAVE_TS_VERIFY_CTX_SET_STORE)
203 # define TS_VERIFY_CTX_set_store(ctx, str) ((ctx)->store=(str))
204 #endif
205 
206 #if !defined(HAVE_TS_VERIFY_CTX_ADD_FLAGS)
207 # define TS_VERIFY_CTX_add_flags(ctx, f) ((ctx)->flags |= (f))
208 #endif
209 
210 #if !defined(HAVE_TS_RESP_CTX_SET_TIME_CB)
211 # define TS_RESP_CTX_set_time_cb(ctx, callback, dta) do { \
212  (ctx)->time_cb = (callback); \
213  (ctx)->time_cb_data = (dta); \
214  } while (0)
215 #endif
216 
217 #endif /* _OSSL_OPENSSL_MISSING_H_ */
priv_key
priv_key
Definition: openssl_missing.h:145
IMPL_KEY_ACCESSOR3
#define IMPL_KEY_ACCESSOR3(_type, _group, a1, a2, a3, _fail_cond)
Definition: openssl_missing.h:124
IMPL_PKEY_GETTER
#define IMPL_PKEY_GETTER(_type, _name)
Definition: openssl_missing.h:112
pub_key
pub_key
Definition: openssl_missing.h:145
ossl_X509_REQ_get0_signature
void ossl_X509_REQ_get0_signature(const X509_REQ *, const ASN1_BIT_STRING **, const X509_ALGOR **)
Definition: openssl_missing.c:35
ossl_X509_CRL_get0_signature
void ossl_X509_CRL_get0_signature(const X509_CRL *, const ASN1_BIT_STRING **, const X509_ALGOR **)
Definition: openssl_missing.c:23
key
key
Definition: openssl_missing.h:145
IMPL_KEY_ACCESSOR2
#define IMPL_KEY_ACCESSOR2(_type, _group, a1, a2, _fail_cond)
Definition: openssl_missing.h:115