blob: 17b491f36e1843be9c825a2afc3b0c5d75be588e [file] [log] [blame]
Dirkjan Bussink1866d6d2016-08-29 13:26:37 +02001#ifndef _PROTO_OPENSSL_COMPAT_H
2#define _PROTO_OPENSSL_COMPAT_H
3#include <openssl/crypto.h>
4#include <openssl/ssl.h>
5#include <openssl/x509.h>
6#include <openssl/x509v3.h>
7#include <openssl/x509.h>
8#include <openssl/err.h>
9#include <openssl/rand.h>
10#if (defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB && !defined OPENSSL_NO_OCSP)
11#include <openssl/ocsp.h>
12#endif
13#ifndef OPENSSL_NO_DH
14#include <openssl/dh.h>
15#endif
16
17#if (OPENSSL_VERSION_NUMBER < 0x1000000fL)
18/*
19 * Functions introduced in OpenSSL 1.0.1
20 */
21static inline int SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx, unsigned int sid_ctx_len)
22{
23 s->sid_ctx_length = sid_ctx_len;
24 memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
25 return 1;
26}
27
28static inline int EVP_PKEY_base_id(const EVP_PKEY *pkey)
29{
30 return EVP_PKEY_type(pkey->type);
31}
32
33static inline const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *sess, unsigned int *sid_length)
34{
35 *sid_length = sess->session_id_length;
36 return sess->session_id;
37}
38
39static inline X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc)
40{
41 return sk_X509_NAME_ENTRY_value(name->entries, loc);
42}
43
44static inline ASN1_OBJECT *X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne)
45{
46 return ne->object;
47}
48
49static inline ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne)
50{
51 return ne->value;
52}
53
54static inline int ASN1_STRING_length(const ASN1_STRING *x)
55{
56 return x->length;
57}
58
59static inline int X509_NAME_entry_count(X509_NAME *name)
60{
61 return sk_X509_NAME_ENTRY_num(name->entries)
62}
63
64int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, const unsigned char **pk, int *ppklen, X509_ALGOR **pa, X509_PUBKEY *pub)
65{
66 *ppkalg = pub->algor->algorithm;
67 return 1;
68}
69
70static inline void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, const void **ppval, const X509_ALGOR *algor)
71{
72 *paobj = algor->algorithm;
73}
74
75#ifndef X509_get_X509_PUBKEY
76#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key
77#endif
78
79#endif
80
81#if (OPENSSL_VERSION_NUMBER < 0x1010000fL)
82/*
83 * Functions introduced in OpenSSL 1.1.0
84 */
85
86static inline const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *sess, unsigned int *sid_ctx_length)
87{
88 *sid_ctx_length = sess->sid_ctx_length;
89 return sess->sid_ctx;
90}
91
92static inline int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid, unsigned int sid_len)
93{
94 s->session_id_length = sid_len;
95 memcpy(s->session_id, sid, sid_len);
96 return 1;
97}
98
99static inline const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *single)
100{
101 return single->certId;
102}
103
104static inline pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx)
105{
106 return ctx->default_passwd_callback;
107}
108
109static inline void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx)
110{
111 return ctx->default_passwd_callback_userdata;
112}
113
114#ifndef OPENSSL_NO_DH
115static inline int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
116{
117 /* Implements only the bare necessities for HAProxy */
118 dh->p = p;
119 dh->g = g;
120 return 1;
121}
122#endif
123
124static inline const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *x)
125{
126 return x->data;
127}
128
129static inline X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x)
130{
131 return x->cert_info->signature;
132}
133
134#endif
135
136#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
137#define __OPENSSL_110_CONST__ const
138#else
139#define __OPENSSL_110_CONST__
140#endif
141
142#endif /* _PROTO_OPENSSL_COMPAT_H */