1212
1313#include "ruby/config.h"
1414
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_X509_STORE_GET_EX_DATA )
25- # define X509_STORE_get_ex_data (x , idx ) \
26- CRYPTO_get_ex_data(&(x)->ex_data, (idx))
27- #endif
28-
29- #if !defined(HAVE_X509_STORE_SET_EX_DATA )
30- # define X509_STORE_set_ex_data (x , idx , data ) \
31- CRYPTO_set_ex_data(&(x)->ex_data, (idx), (data))
32- #endif
33-
34- #if !defined(HAVE_X509_STORE_GET_EX_NEW_INDEX ) && !defined(X509_STORE_get_ex_new_index )
35- # define X509_STORE_get_ex_new_index (l , p , newf , dupf , freef ) \
36- CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE, (l), (p), \
37- (newf), (dupf), (freef))
38- #endif
39-
40- #if !defined(HAVE_X509_CRL_GET0_SIGNATURE )
41- void ossl_X509_CRL_get0_signature (const X509_CRL * , const ASN1_BIT_STRING * * , const X509_ALGOR * * );
42- # define X509_CRL_get0_signature ossl_X509_CRL_get0_signature
43- #endif
44-
45- #if !defined(HAVE_X509_REQ_GET0_SIGNATURE )
46- void ossl_X509_REQ_get0_signature (const X509_REQ * , const ASN1_BIT_STRING * * , const X509_ALGOR * * );
47- # define X509_REQ_get0_signature ossl_X509_REQ_get0_signature
48- #endif
49-
50- #if !defined(HAVE_X509_REVOKED_GET0_SERIALNUMBER )
51- # define X509_REVOKED_get0_serialNumber (x ) ((x)->serialNumber)
52- #endif
53-
54- #if !defined(HAVE_X509_REVOKED_GET0_REVOCATIONDATE )
55- # define X509_REVOKED_get0_revocationDate (x ) ((x)->revocationDate)
56- #endif
57-
58- #if !defined(HAVE_X509_GET0_TBS_SIGALG )
59- # define X509_get0_tbs_sigalg (x ) ((x)->cert_info->signature)
60- #endif
61-
62- #if !defined(HAVE_X509_STORE_CTX_GET0_UNTRUSTED )
63- # define X509_STORE_CTX_get0_untrusted (x ) ((x)->untrusted)
64- #endif
65-
66- #if !defined(HAVE_X509_STORE_CTX_GET0_CERT )
67- # define X509_STORE_CTX_get0_cert (x ) ((x)->cert)
68- #endif
69-
70- #if !defined(HAVE_X509_STORE_CTX_GET0_CHAIN )
71- # define X509_STORE_CTX_get0_chain (ctx ) X509_STORE_CTX_get_chain(ctx)
72- #endif
73-
74- #if !defined(HAVE_OCSP_SINGLERESP_GET0_ID )
75- # define OCSP_SINGLERESP_get0_id (s ) ((s)->certId)
76- #endif
77-
78- #if !defined(HAVE_SSL_CTX_GET_CIPHERS )
79- # define SSL_CTX_get_ciphers (ctx ) ((ctx)->cipher_list)
80- #endif
81-
82- #if !defined(HAVE_X509_UP_REF )
83- # define X509_up_ref (x ) \
84- CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509)
85- #endif
86-
87- #if !defined(HAVE_X509_CRL_UP_REF )
88- # define X509_CRL_up_ref (x ) \
89- CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509_CRL);
90- #endif
91-
92- #if !defined(HAVE_X509_STORE_UP_REF )
93- # define X509_STORE_up_ref (x ) \
94- CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_X509_STORE);
95- #endif
96-
97- #if !defined(HAVE_SSL_SESSION_UP_REF )
98- # define SSL_SESSION_up_ref (x ) \
99- CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_SSL_SESSION);
100- #endif
101-
102- #if !defined(HAVE_EVP_PKEY_UP_REF )
103- # define EVP_PKEY_up_ref (x ) \
104- CRYPTO_add(&(x)->references, 1, CRYPTO_LOCK_EVP_PKEY);
105- #endif
106-
107- #if !defined(HAVE_OPAQUE_OPENSSL )
108- #define IMPL_PKEY_GETTER (_type , _name ) \
109- static inline _type *EVP_PKEY_get0_##_type(EVP_PKEY *pkey) { \
110- return pkey->pkey._name; }
111- #define IMPL_KEY_ACCESSOR2 (_type , _group , a1 , a2 , _fail_cond ) \
112- static inline void _type##_get0_##_group(const _type *obj, const BIGNUM **a1, const BIGNUM **a2) { \
113- if (a1) *a1 = obj->a1; \
114- if (a2) *a2 = obj->a2; } \
115- static inline int _type##_set0_##_group(_type *obj, BIGNUM *a1, BIGNUM *a2) { \
116- if (_fail_cond) return 0; \
117- BN_clear_free(obj->a1); obj->a1 = a1; \
118- BN_clear_free(obj->a2); obj->a2 = a2; \
119- return 1; }
120- #define IMPL_KEY_ACCESSOR3 (_type , _group , a1 , a2 , a3 , _fail_cond ) \
121- static inline void _type##_get0_##_group(const _type *obj, const BIGNUM **a1, const BIGNUM **a2, const BIGNUM **a3) { \
122- if (a1) *a1 = obj->a1; \
123- if (a2) *a2 = obj->a2; \
124- if (a3) *a3 = obj->a3; } \
125- static inline int _type##_set0_##_group(_type *obj, BIGNUM *a1, BIGNUM *a2, BIGNUM *a3) { \
126- if (_fail_cond) return 0; \
127- BN_clear_free(obj->a1); obj->a1 = a1; \
128- BN_clear_free(obj->a2); obj->a2 = a2; \
129- BN_clear_free(obj->a3); obj->a3 = a3; \
130- return 1; }
131-
132- #if !defined(OPENSSL_NO_RSA )
133- IMPL_PKEY_GETTER (RSA , rsa )
134- IMPL_KEY_ACCESSOR3 (RSA , key , n , e , d , (n == obj -> n || e == obj -> e || (obj -> d && d == obj -> d )))
135- IMPL_KEY_ACCESSOR2 (RSA , factors , p , q , (p == obj -> p || q == obj -> q ))
136- IMPL_KEY_ACCESSOR3 (RSA , crt_params , dmp1 , dmq1 , iqmp , (dmp1 == obj -> dmp1 || dmq1 == obj -> dmq1 || iqmp == obj -> iqmp ))
137- #endif
138-
139- #if !defined(OPENSSL_NO_DSA )
140- IMPL_PKEY_GETTER (DSA , dsa )
141- IMPL_KEY_ACCESSOR2 (DSA , key , pub_key , priv_key , (pub_key == obj -> pub_key || (obj -> priv_key && priv_key == obj -> priv_key )))
142- IMPL_KEY_ACCESSOR3 (DSA , pqg , p , q , g , (p == obj -> p || q == obj -> q || g == obj -> g ))
143- #endif
144-
145- #if !defined(OPENSSL_NO_DH )
146- IMPL_PKEY_GETTER (DH , dh )
147- IMPL_KEY_ACCESSOR2 (DH , key , pub_key , priv_key , (pub_key == obj -> pub_key || (obj -> priv_key && priv_key == obj -> priv_key )))
148- IMPL_KEY_ACCESSOR3 (DH , pqg , p , q , g , (p == obj -> p || (obj -> q && q == obj -> q ) || g == obj -> g ))
149- static inline ENGINE * DH_get0_engine (DH * dh ) { return dh -> engine ; }
150- #endif
151-
152- #if !defined(OPENSSL_NO_EC )
153- IMPL_PKEY_GETTER (EC_KEY , ec )
154- #endif
155-
156- #undef IMPL_PKEY_GETTER
157- #undef IMPL_KEY_ACCESSOR2
158- #undef IMPL_KEY_ACCESSOR3
159- #endif /* HAVE_OPAQUE_OPENSSL */
160-
161- #if !defined(EVP_CTRL_AEAD_GET_TAG )
162- # define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG
163- # define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG
164- # define EVP_CTRL_AEAD_SET_IVLEN EVP_CTRL_GCM_SET_IVLEN
165- #endif
166-
167- #if !defined(HAVE_X509_GET0_NOTBEFORE )
168- # define X509_get0_notBefore (x ) X509_get_notBefore(x)
169- # define X509_get0_notAfter (x ) X509_get_notAfter(x)
170- # define X509_CRL_get0_lastUpdate (x ) X509_CRL_get_lastUpdate(x)
171- # define X509_CRL_get0_nextUpdate (x ) X509_CRL_get_nextUpdate(x)
172- # define X509_set1_notBefore (x , t ) X509_set_notBefore(x, t)
173- # define X509_set1_notAfter (x , t ) X509_set_notAfter(x, t)
174- # define X509_CRL_set1_lastUpdate (x , t ) X509_CRL_set_lastUpdate(x, t)
175- # define X509_CRL_set1_nextUpdate (x , t ) X509_CRL_set_nextUpdate(x, t)
176- #endif
177-
178- #if !defined(HAVE_SSL_SESSION_GET_PROTOCOL_VERSION )
179- # define SSL_SESSION_get_protocol_version (s ) ((s)->ssl_version)
180- #endif
181-
182- #if !defined(HAVE_TS_STATUS_INFO_GET0_STATUS )
183- # define TS_STATUS_INFO_get0_status (a ) ((a)->status)
184- #endif
185-
186- #if !defined(HAVE_TS_STATUS_INFO_GET0_TEXT )
187- # define TS_STATUS_INFO_get0_text (a ) ((a)->text)
188- #endif
189-
190- #if !defined(HAVE_TS_STATUS_INFO_GET0_FAILURE_INFO )
191- # define TS_STATUS_INFO_get0_failure_info (a ) ((a)->failure_info)
192- #endif
193-
194- #if !defined(HAVE_TS_VERIFY_CTS_SET_CERTS )
195- # define TS_VERIFY_CTS_set_certs (ctx , crts ) ((ctx)->certs=(crts))
196- #endif
197-
198- #if !defined(HAVE_TS_VERIFY_CTX_SET_STORE )
199- # define TS_VERIFY_CTX_set_store (ctx , str ) ((ctx)->store=(str))
200- #endif
201-
202- #if !defined(HAVE_TS_VERIFY_CTX_ADD_FLAGS )
203- # define TS_VERIFY_CTX_add_flags (ctx , f ) ((ctx)->flags |= (f))
204- #endif
205-
206- #if !defined(HAVE_TS_RESP_CTX_SET_TIME_CB )
207- # define TS_RESP_CTX_set_time_cb (ctx , callback , dta ) do { \
208- (ctx)->time_cb = (callback); \
209- (ctx)->time_cb_data = (dta); \
210- } while (0)
211- #endif
212-
21315/* added in 3.0.0 */
21416#if !defined(HAVE_TS_VERIFY_CTX_SET_CERTS )
21517# define TS_VERIFY_CTX_set_certs (ctx , crts ) TS_VERIFY_CTS_set_certs(ctx, crts)
@@ -224,11 +26,7 @@ IMPL_PKEY_GETTER(EC_KEY, ec)
22426 * EVP_MD_CTX_get_pkey_ctx(x) in OpenSSL 3.0.
22527 */
22628#ifndef HAVE_EVP_MD_CTX_GET_PKEY_CTX
227- # ifdef HAVE_EVP_MD_CTX_PKEY_CTX
22829# define EVP_MD_CTX_get_pkey_ctx (x ) EVP_MD_CTX_pkey_ctx(x)
229- # else
230- # define EVP_MD_CTX_get_pkey_ctx (x ) (x)->pctx
231- # endif
23230#endif
23331
23432#ifndef HAVE_EVP_PKEY_EQ
0 commit comments