diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/x_x509.c')
-rw-r--r-- | src/lib/libcrypto/asn1/x_x509.c | 155 |
1 files changed, 64 insertions, 91 deletions
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c index 61ba856b17..b50167ce43 100644 --- a/src/lib/libcrypto/asn1/x_x509.c +++ b/src/lib/libcrypto/asn1/x_x509.c | |||
@@ -59,12 +59,71 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1t.h> |
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | #include <openssl/x509v3.h> | 64 | #include <openssl/x509v3.h> |
65 | 65 | ||
66 | static int x509_meth_num = 0; | 66 | ASN1_SEQUENCE(X509_CINF) = { |
67 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_meth = NULL; | 67 | ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), |
68 | ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER), | ||
69 | ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR), | ||
70 | ASN1_SIMPLE(X509_CINF, issuer, X509_NAME), | ||
71 | ASN1_SIMPLE(X509_CINF, validity, X509_VAL), | ||
72 | ASN1_SIMPLE(X509_CINF, subject, X509_NAME), | ||
73 | ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY), | ||
74 | ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1), | ||
75 | ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2), | ||
76 | ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3) | ||
77 | } ASN1_SEQUENCE_END(X509_CINF) | ||
78 | |||
79 | IMPLEMENT_ASN1_FUNCTIONS(X509_CINF) | ||
80 | /* X509 top level structure needs a bit of customisation */ | ||
81 | |||
82 | static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
83 | { | ||
84 | X509 *ret = (X509 *)*pval; | ||
85 | |||
86 | switch(operation) { | ||
87 | |||
88 | case ASN1_OP_NEW_POST: | ||
89 | ret->valid=0; | ||
90 | ret->name = NULL; | ||
91 | ret->ex_flags = 0; | ||
92 | ret->ex_pathlen = -1; | ||
93 | ret->skid = NULL; | ||
94 | ret->akid = NULL; | ||
95 | ret->aux = NULL; | ||
96 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | ||
97 | break; | ||
98 | |||
99 | case ASN1_OP_D2I_POST: | ||
100 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
101 | ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); | ||
102 | break; | ||
103 | |||
104 | case ASN1_OP_FREE_POST: | ||
105 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | ||
106 | X509_CERT_AUX_free(ret->aux); | ||
107 | ASN1_OCTET_STRING_free(ret->skid); | ||
108 | AUTHORITY_KEYID_free(ret->akid); | ||
109 | |||
110 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
111 | break; | ||
112 | |||
113 | } | ||
114 | |||
115 | return 1; | ||
116 | |||
117 | } | ||
118 | |||
119 | ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { | ||
120 | ASN1_SIMPLE(X509, cert_info, X509_CINF), | ||
121 | ASN1_SIMPLE(X509, sig_alg, X509_ALGOR), | ||
122 | ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING) | ||
123 | } ASN1_SEQUENCE_END_ref(X509, X509) | ||
124 | |||
125 | IMPLEMENT_ASN1_FUNCTIONS(X509) | ||
126 | IMPLEMENT_ASN1_DUP_FUNCTION(X509) | ||
68 | 127 | ||
69 | static ASN1_METHOD meth={ | 128 | static ASN1_METHOD meth={ |
70 | (int (*)()) i2d_X509, | 129 | (int (*)()) i2d_X509, |
@@ -77,97 +136,11 @@ ASN1_METHOD *X509_asn1_meth(void) | |||
77 | return(&meth); | 136 | return(&meth); |
78 | } | 137 | } |
79 | 138 | ||
80 | int i2d_X509(X509 *a, unsigned char **pp) | ||
81 | { | ||
82 | M_ASN1_I2D_vars(a); | ||
83 | |||
84 | M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF); | ||
85 | M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); | ||
86 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
87 | |||
88 | M_ASN1_I2D_seq_total(); | ||
89 | |||
90 | M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF); | ||
91 | M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); | ||
92 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
93 | |||
94 | M_ASN1_I2D_finish(); | ||
95 | } | ||
96 | |||
97 | X509 *d2i_X509(X509 **a, unsigned char **pp, long length) | ||
98 | { | ||
99 | M_ASN1_D2I_vars(a,X509 *,X509_new); | ||
100 | |||
101 | M_ASN1_D2I_Init(); | ||
102 | M_ASN1_D2I_start_sequence(); | ||
103 | M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); | ||
104 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
105 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
106 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
107 | ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); | ||
108 | |||
109 | M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); | ||
110 | } | ||
111 | |||
112 | X509 *X509_new(void) | ||
113 | { | ||
114 | X509 *ret=NULL; | ||
115 | ASN1_CTX c; | ||
116 | |||
117 | M_ASN1_New_Malloc(ret,X509); | ||
118 | ret->valid=0; | ||
119 | ret->references=1; | ||
120 | ret->name = NULL; | ||
121 | ret->ex_flags = 0; | ||
122 | ret->ex_pathlen = -1; | ||
123 | ret->skid = NULL; | ||
124 | ret->akid = NULL; | ||
125 | ret->aux = NULL; | ||
126 | M_ASN1_New(ret->cert_info,X509_CINF_new); | ||
127 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
128 | M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new); | ||
129 | CRYPTO_new_ex_data(x509_meth, ret, &ret->ex_data); | ||
130 | return(ret); | ||
131 | M_ASN1_New_Error(ASN1_F_X509_NEW); | ||
132 | } | ||
133 | |||
134 | void X509_free(X509 *a) | ||
135 | { | ||
136 | int i; | ||
137 | |||
138 | if (a == NULL) return; | ||
139 | |||
140 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509); | ||
141 | #ifdef REF_PRINT | ||
142 | REF_PRINT("X509",a); | ||
143 | #endif | ||
144 | if (i > 0) return; | ||
145 | #ifdef REF_CHECK | ||
146 | if (i < 0) | ||
147 | { | ||
148 | fprintf(stderr,"X509_free, bad reference count\n"); | ||
149 | abort(); | ||
150 | } | ||
151 | #endif | ||
152 | |||
153 | CRYPTO_free_ex_data(x509_meth,a,&a->ex_data); | ||
154 | X509_CINF_free(a->cert_info); | ||
155 | X509_ALGOR_free(a->sig_alg); | ||
156 | M_ASN1_BIT_STRING_free(a->signature); | ||
157 | X509_CERT_AUX_free(a->aux); | ||
158 | ASN1_OCTET_STRING_free(a->skid); | ||
159 | AUTHORITY_KEYID_free(a->akid); | ||
160 | |||
161 | if (a->name != NULL) OPENSSL_free(a->name); | ||
162 | OPENSSL_free(a); | ||
163 | } | ||
164 | |||
165 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 139 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
166 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 140 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
167 | { | 141 | { |
168 | x509_meth_num++; | 142 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, |
169 | return(CRYPTO_get_ex_new_index(x509_meth_num-1, | 143 | new_func, dup_func, free_func); |
170 | &x509_meth,argl,argp,new_func,dup_func,free_func)); | ||
171 | } | 144 | } |
172 | 145 | ||
173 | int X509_set_ex_data(X509 *r, int idx, void *arg) | 146 | int X509_set_ex_data(X509 *r, int idx, void *arg) |