| OLD | NEW |
| 1 /* crypto/asn1/x_x509.c */ | 1 /* crypto/asn1/x_x509.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
| 6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
| 7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
| 8 * | 8 * |
| 9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
| 10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
| 57 */ | 57 */ |
| 58 | 58 |
| 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/asn1t.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 ASN1_SEQUENCE(X509_CINF) = { | 66 ASN1_SEQUENCE_enc(X509_CINF, enc, 0) = { |
| 67 ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), | 67 ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), |
| 68 ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER), | 68 ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER), |
| 69 ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR), | 69 ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR), |
| 70 ASN1_SIMPLE(X509_CINF, issuer, X509_NAME), | 70 ASN1_SIMPLE(X509_CINF, issuer, X509_NAME), |
| 71 ASN1_SIMPLE(X509_CINF, validity, X509_VAL), | 71 ASN1_SIMPLE(X509_CINF, validity, X509_VAL), |
| 72 ASN1_SIMPLE(X509_CINF, subject, X509_NAME), | 72 ASN1_SIMPLE(X509_CINF, subject, X509_NAME), |
| 73 ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY), | 73 ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY), |
| 74 ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1), | 74 ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1), |
| 75 ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2), | 75 ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2), |
| 76 ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3) | 76 ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3) |
| 77 } ASN1_SEQUENCE_END(X509_CINF) | 77 } ASN1_SEQUENCE_END_enc(X509_CINF, X509_CINF) |
| 78 | 78 |
| 79 IMPLEMENT_ASN1_FUNCTIONS(X509_CINF) | 79 IMPLEMENT_ASN1_FUNCTIONS(X509_CINF) |
| 80 /* X509 top level structure needs a bit of customisation */ | 80 /* X509 top level structure needs a bit of customisation */ |
| 81 | 81 |
| 82 extern void policy_cache_free(X509_POLICY_CACHE *cache); | 82 extern void policy_cache_free(X509_POLICY_CACHE *cache); |
| 83 | 83 |
| 84 static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | 84 static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
| 85 » » » » » » » » void *exarg) |
| 85 { | 86 { |
| 86 X509 *ret = (X509 *)*pval; | 87 X509 *ret = (X509 *)*pval; |
| 87 | 88 |
| 88 switch(operation) { | 89 switch(operation) { |
| 89 | 90 |
| 90 case ASN1_OP_NEW_POST: | 91 case ASN1_OP_NEW_POST: |
| 91 ret->valid=0; | 92 ret->valid=0; |
| 92 ret->name = NULL; | 93 ret->name = NULL; |
| 93 ret->ex_flags = 0; | 94 ret->ex_flags = 0; |
| 94 ret->ex_pathlen = -1; | 95 ret->ex_pathlen = -1; |
| 95 ret->skid = NULL; | 96 ret->skid = NULL; |
| 96 ret->akid = NULL; | 97 ret->akid = NULL; |
| 97 #ifndef OPENSSL_NO_RFC3779 | 98 #ifndef OPENSSL_NO_RFC3779 |
| 98 ret->rfc3779_addr = NULL; | 99 ret->rfc3779_addr = NULL; |
| 99 ret->rfc3779_asid = NULL; | 100 ret->rfc3779_asid = NULL; |
| 100 #endif | 101 #endif |
| 101 ret->aux = NULL; | 102 ret->aux = NULL; |
| 103 ret->crldp = NULL; |
| 102 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | 104 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); |
| 103 break; | 105 break; |
| 104 | 106 |
| 105 case ASN1_OP_D2I_POST: | 107 case ASN1_OP_D2I_POST: |
| 106 if (ret->name != NULL) OPENSSL_free(ret->name); | 108 if (ret->name != NULL) OPENSSL_free(ret->name); |
| 107 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); | 109 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); |
| 108 break; | 110 break; |
| 109 | 111 |
| 110 case ASN1_OP_FREE_POST: | 112 case ASN1_OP_FREE_POST: |
| 111 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | 113 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); |
| 112 X509_CERT_AUX_free(ret->aux); | 114 X509_CERT_AUX_free(ret->aux); |
| 113 ASN1_OCTET_STRING_free(ret->skid); | 115 ASN1_OCTET_STRING_free(ret->skid); |
| 114 AUTHORITY_KEYID_free(ret->akid); | 116 AUTHORITY_KEYID_free(ret->akid); |
| 117 CRL_DIST_POINTS_free(ret->crldp); |
| 115 policy_cache_free(ret->policy_cache); | 118 policy_cache_free(ret->policy_cache); |
| 119 GENERAL_NAMES_free(ret->altname); |
| 120 NAME_CONSTRAINTS_free(ret->nc); |
| 116 #ifndef OPENSSL_NO_RFC3779 | 121 #ifndef OPENSSL_NO_RFC3779 |
| 117 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_f
ree); | 122 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_f
ree); |
| 118 ASIdentifiers_free(ret->rfc3779_asid); | 123 ASIdentifiers_free(ret->rfc3779_asid); |
| 119 #endif | 124 #endif |
| 120 | 125 |
| 121 if (ret->name != NULL) OPENSSL_free(ret->name); | 126 if (ret->name != NULL) OPENSSL_free(ret->name); |
| 122 break; | 127 break; |
| 123 | 128 |
| 124 } | 129 } |
| 125 | 130 |
| 126 return 1; | 131 return 1; |
| 127 | 132 |
| 128 } | 133 } |
| 129 | 134 |
| 130 ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { | 135 ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { |
| 131 ASN1_SIMPLE(X509, cert_info, X509_CINF), | 136 ASN1_SIMPLE(X509, cert_info, X509_CINF), |
| 132 ASN1_SIMPLE(X509, sig_alg, X509_ALGOR), | 137 ASN1_SIMPLE(X509, sig_alg, X509_ALGOR), |
| 133 ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING) | 138 ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING) |
| 134 } ASN1_SEQUENCE_END_ref(X509, X509) | 139 } ASN1_SEQUENCE_END_ref(X509, X509) |
| 135 | 140 |
| 136 IMPLEMENT_ASN1_FUNCTIONS(X509) | 141 IMPLEMENT_ASN1_FUNCTIONS(X509) |
| 137 IMPLEMENT_ASN1_DUP_FUNCTION(X509) | 142 IMPLEMENT_ASN1_DUP_FUNCTION(X509) |
| 138 | 143 |
| 139 static ASN1_METHOD meth= | |
| 140 { | |
| 141 (I2D_OF(void)) i2d_X509, | |
| 142 (D2I_OF(void)) d2i_X509, | |
| 143 (void *(*)(void))X509_new, | |
| 144 (void (*)(void *)) X509_free | |
| 145 }; | |
| 146 | |
| 147 ASN1_METHOD *X509_asn1_meth(void) | |
| 148 { | |
| 149 return(&meth); | |
| 150 } | |
| 151 | |
| 152 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 144 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
| 153 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 145 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) |
| 154 { | 146 { |
| 155 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, | 147 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, |
| 156 new_func, dup_func, free_func); | 148 new_func, dup_func, free_func); |
| 157 } | 149 } |
| 158 | 150 |
| 159 int X509_set_ex_data(X509 *r, int idx, void *arg) | 151 int X509_set_ex_data(X509 *r, int idx, void *arg) |
| 160 { | 152 { |
| 161 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | 153 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return NULL; | 185 return NULL; |
| 194 } | 186 } |
| 195 | 187 |
| 196 int i2d_X509_AUX(X509 *a, unsigned char **pp) | 188 int i2d_X509_AUX(X509 *a, unsigned char **pp) |
| 197 { | 189 { |
| 198 int length; | 190 int length; |
| 199 length = i2d_X509(a, pp); | 191 length = i2d_X509(a, pp); |
| 200 if(a) length += i2d_X509_CERT_AUX(a->aux, pp); | 192 if(a) length += i2d_X509_CERT_AUX(a->aux, pp); |
| 201 return length; | 193 return length; |
| 202 } | 194 } |
| OLD | NEW |