| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
|
| 7 |
INCLUDES = """ |
| 8 |
#include <openssl/ocsp.h> |
| 9 |
""" |
| 10 |
|
| 11 |
TYPES = """ |
| 12 |
typedef ... OCSP_REQUEST; |
| 13 |
typedef ... OCSP_ONEREQ; |
| 14 |
typedef ... OCSP_RESPONSE; |
| 15 |
typedef ... OCSP_BASICRESP; |
| 16 |
typedef ... OCSP_SINGLERESP; |
| 17 |
typedef ... OCSP_CERTID; |
| 18 |
typedef ... OCSP_RESPDATA; |
| 19 |
static const long OCSP_NOCERTS; |
| 20 |
static const long OCSP_RESPID_KEY; |
| 21 |
""" |
| 22 |
|
| 23 |
FUNCTIONS = """ |
| 24 |
int OCSP_response_status(OCSP_RESPONSE *); |
| 25 |
OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *); |
| 26 |
int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *); |
| 27 |
const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *); |
| 28 |
const Cryptography_STACK_OF_X509 *OCSP_resp_get0_certs(const OCSP_BASICRESP *); |
| 29 |
const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at( |
| 30 |
const OCSP_BASICRESP *); |
| 31 |
const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *); |
| 32 |
int OCSP_resp_get0_id(const OCSP_BASICRESP *, const ASN1_OCTET_STRING **, |
| 33 |
const X509_NAME **); |
| 34 |
const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *); |
| 35 |
const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *); |
| 36 |
X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *, int); |
| 37 |
int OCSP_resp_count(OCSP_BASICRESP *); |
| 38 |
OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *, int); |
| 39 |
int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *); |
| 40 |
X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *, int); |
| 41 |
|
| 42 |
int OCSP_single_get0_status(OCSP_SINGLERESP *, int *, ASN1_GENERALIZEDTIME **, |
| 43 |
ASN1_GENERALIZEDTIME **, ASN1_GENERALIZEDTIME **); |
| 44 |
|
| 45 |
int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *); |
| 46 |
X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *, int); |
| 47 |
int OCSP_request_onereq_count(OCSP_REQUEST *); |
| 48 |
OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *, int); |
| 49 |
int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *); |
| 50 |
X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *, int); |
| 51 |
OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *); |
| 52 |
OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *, OCSP_CERTID *); |
| 53 |
OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *, const X509 *, const X509 *); |
| 54 |
void OCSP_CERTID_free(OCSP_CERTID *); |
| 55 |
|
| 56 |
|
| 57 |
OCSP_BASICRESP *OCSP_BASICRESP_new(void); |
| 58 |
void OCSP_BASICRESP_free(OCSP_BASICRESP *); |
| 59 |
OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *, OCSP_CERTID *, int, |
| 60 |
int, ASN1_TIME *, ASN1_TIME *, |
| 61 |
ASN1_TIME *); |
| 62 |
int OCSP_basic_add1_nonce(OCSP_BASICRESP *, unsigned char *, int); |
| 63 |
int OCSP_basic_add1_cert(OCSP_BASICRESP *, X509 *); |
| 64 |
int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *, X509_EXTENSION *, int); |
| 65 |
int OCSP_basic_sign(OCSP_BASICRESP *, X509 *, EVP_PKEY *, const EVP_MD *, |
| 66 |
Cryptography_STACK_OF_X509 *, unsigned long); |
| 67 |
OCSP_RESPONSE *OCSP_response_create(int, OCSP_BASICRESP *); |
| 68 |
void OCSP_RESPONSE_free(OCSP_RESPONSE *); |
| 69 |
|
| 70 |
OCSP_REQUEST *OCSP_REQUEST_new(void); |
| 71 |
void OCSP_REQUEST_free(OCSP_REQUEST *); |
| 72 |
int OCSP_request_add1_nonce(OCSP_REQUEST *, unsigned char *, int); |
| 73 |
int OCSP_REQUEST_add_ext(OCSP_REQUEST *, X509_EXTENSION *, int); |
| 74 |
int OCSP_id_get0_info(ASN1_OCTET_STRING **, ASN1_OBJECT **, |
| 75 |
ASN1_OCTET_STRING **, ASN1_INTEGER **, OCSP_CERTID *); |
| 76 |
OCSP_REQUEST *d2i_OCSP_REQUEST_bio(BIO *, OCSP_REQUEST **); |
| 77 |
OCSP_RESPONSE *d2i_OCSP_RESPONSE_bio(BIO *, OCSP_RESPONSE **); |
| 78 |
int i2d_OCSP_REQUEST_bio(BIO *, OCSP_REQUEST *); |
| 79 |
int i2d_OCSP_RESPONSE_bio(BIO *, OCSP_RESPONSE *); |
| 80 |
int i2d_OCSP_RESPDATA(OCSP_RESPDATA *, unsigned char **); |
| 81 |
""" |
| 82 |
|
| 83 |
CUSTOMIZATIONS = """ |
| 84 |
#if ( \ |
| 85 |
CRYPTOGRAPHY_OPENSSL_110_OR_GREATER && \ |
| 86 |
CRYPTOGRAPHY_OPENSSL_LESS_THAN_110J \ |
| 87 |
) |
| 88 |
/* These structs come from ocsp_lcl.h and are needed to de-opaque the struct |
| 89 |
for the getters in OpenSSL 1.1.0 through 1.1.0i */ |
| 90 |
struct ocsp_responder_id_st { |
| 91 |
int type; |
| 92 |
union { |
| 93 |
X509_NAME *byName; |
| 94 |
ASN1_OCTET_STRING *byKey; |
| 95 |
} value; |
| 96 |
}; |
| 97 |
struct ocsp_response_data_st { |
| 98 |
ASN1_INTEGER *version; |
| 99 |
OCSP_RESPID responderId; |
| 100 |
ASN1_GENERALIZEDTIME *producedAt; |
| 101 |
STACK_OF(OCSP_SINGLERESP) *responses; |
| 102 |
STACK_OF(X509_EXTENSION) *responseExtensions; |
| 103 |
}; |
| 104 |
struct ocsp_basic_response_st { |
| 105 |
OCSP_RESPDATA tbsResponseData; |
| 106 |
X509_ALGOR signatureAlgorithm; |
| 107 |
ASN1_BIT_STRING *signature; |
| 108 |
STACK_OF(X509) *certs; |
| 109 |
}; |
| 110 |
#endif |
| 111 |
|
| 112 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 |
| 113 |
/* These functions are all taken from ocsp_cl.c in OpenSSL 1.1.0 */ |
| 114 |
const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *single) |
| 115 |
{ |
| 116 |
return single->certId; |
| 117 |
} |
| 118 |
const Cryptography_STACK_OF_X509 *OCSP_resp_get0_certs( |
| 119 |
const OCSP_BASICRESP *bs) |
| 120 |
{ |
| 121 |
return bs->certs; |
| 122 |
} |
| 123 |
int OCSP_resp_get0_id(const OCSP_BASICRESP *bs, |
| 124 |
const ASN1_OCTET_STRING **pid, |
| 125 |
const X509_NAME **pname) |
| 126 |
{ |
| 127 |
const OCSP_RESPID *rid = bs->tbsResponseData->responderId; |
| 128 |
|
| 129 |
if (rid->type == V_OCSP_RESPID_NAME) { |
| 130 |
*pname = rid->value.byName; |
| 131 |
*pid = NULL; |
| 132 |
} else if (rid->type == V_OCSP_RESPID_KEY) { |
| 133 |
*pid = rid->value.byKey; |
| 134 |
*pname = NULL; |
| 135 |
} else { |
| 136 |
return 0; |
| 137 |
} |
| 138 |
return 1; |
| 139 |
} |
| 140 |
const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at( |
| 141 |
const OCSP_BASICRESP* bs) |
| 142 |
{ |
| 143 |
return bs->tbsResponseData->producedAt; |
| 144 |
} |
| 145 |
const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs) |
| 146 |
{ |
| 147 |
return bs->signature; |
| 148 |
} |
| 149 |
#endif |
| 150 |
|
| 151 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110J |
| 152 |
const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs) |
| 153 |
{ |
| 154 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 |
| 155 |
return bs->signatureAlgorithm; |
| 156 |
#else |
| 157 |
return &bs->signatureAlgorithm; |
| 158 |
#endif |
| 159 |
} |
| 160 |
|
| 161 |
const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs) |
| 162 |
{ |
| 163 |
#if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 |
| 164 |
return bs->tbsResponseData; |
| 165 |
#else |
| 166 |
return &bs->tbsResponseData; |
| 167 |
#endif |
| 168 |
} |
| 169 |
#endif |
| 170 |
""" |