summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/x_crl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/x_crl.c')
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index b99f8fc522..11fce96825 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -63,6 +63,8 @@
63 63
64static int X509_REVOKED_cmp(const X509_REVOKED * const *a, 64static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
65 const X509_REVOKED * const *b); 65 const X509_REVOKED * const *b);
66static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
67 const X509_REVOKED * const *b);
66 68
67ASN1_SEQUENCE(X509_REVOKED) = { 69ASN1_SEQUENCE(X509_REVOKED) = {
68 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER), 70 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER),
@@ -70,28 +72,43 @@ ASN1_SEQUENCE(X509_REVOKED) = {
70 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION) 72 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION)
71} ASN1_SEQUENCE_END(X509_REVOKED) 73} ASN1_SEQUENCE_END(X509_REVOKED)
72 74
73/* The X509_CRL_INFO structure needs a bit of customisation. 75/* The X509_CRL_INFO structure needs a bit of customisation. This is actually
74 * Since we cache the original encoding the signature wont be affected by 76 * mirroring the old behaviour: its purpose is to allow the use of
75 * reordering of the revoked field. 77 * sk_X509_REVOKED_find to lookup revoked certificates. Unfortunately
78 * this will zap the original order and the signature so we keep a copy
79 * of the original positions and reorder appropriately before encoding.
80 *
81 * Might want to see if there's a better way of doing this later...
76 */ 82 */
77static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 83static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
78{ 84{
79 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; 85 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
86 int i;
87 int (*old_cmp)(const X509_REVOKED * const *,
88 const X509_REVOKED * const *);
80 89
81 if(!a || !a->revoked) return 1; 90 if(!a || !a->revoked) return 1;
82 switch(operation) { 91 switch(operation) {
83 /* Just set cmp function here. We don't sort because that 92
84 * would affect the output of X509_CRL_print(). 93 /* Save original order */
85 */
86 case ASN1_OP_D2I_POST: 94 case ASN1_OP_D2I_POST:
95 for (i=0; i<sk_X509_REVOKED_num(a->revoked); i++)
96 sk_X509_REVOKED_value(a->revoked,i)->sequence=i;
87 sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); 97 sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
88 break; 98 break;
99
100 /* Restore original order */
101 case ASN1_OP_I2D_PRE:
102 old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
103 sk_X509_REVOKED_sort(a->revoked);
104 sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp);
105 break;
89 } 106 }
90 return 1; 107 return 1;
91} 108}
92 109
93 110
94ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { 111ASN1_SEQUENCE_cb(X509_CRL_INFO, crl_inf_cb) = {
95 ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER), 112 ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER),
96 ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR), 113 ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR),
97 ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME), 114 ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME),
@@ -99,7 +116,7 @@ ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
99 ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME), 116 ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME),
100 ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED), 117 ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED),
101 ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0) 118 ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0)
102} ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO) 119} ASN1_SEQUENCE_END_cb(X509_CRL_INFO, X509_CRL_INFO)
103 120
104ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = { 121ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = {
105 ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), 122 ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO),
@@ -120,6 +137,12 @@ static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
120 (ASN1_STRING *)(*b)->serialNumber)); 137 (ASN1_STRING *)(*b)->serialNumber));
121 } 138 }
122 139
140static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a,
141 const X509_REVOKED * const *b)
142 {
143 return((*a)->sequence-(*b)->sequence);
144 }
145
123int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) 146int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
124{ 147{
125 X509_CRL_INFO *inf; 148 X509_CRL_INFO *inf;
@@ -130,7 +153,6 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
130 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); 153 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
131 return 0; 154 return 0;
132 } 155 }
133 inf->enc.modified = 1;
134 return 1; 156 return 1;
135} 157}
136 158