summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2014-04-18 11:20:32 +0000
committerjsing <>2014-04-18 11:20:32 +0000
commit6d8ab3f51c14ff4e0ce4f0aaafede903671056b3 (patch)
tree80f89d5dfdd4e6eef26aea54fe2399d237045354
parent3a5e199af72e13c8924435aeb9126166854a7c00 (diff)
downloadopenbsd-6d8ab3f51c14ff4e0ce4f0aaafede903671056b3.tar.gz
openbsd-6d8ab3f51c14ff4e0ce4f0aaafede903671056b3.tar.bz2
openbsd-6d8ab3f51c14ff4e0ce4f0aaafede903671056b3.zip
More KNF.
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c26
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c49
-rw-r--r--src/lib/libcrypto/asn1/x_bignum.c69
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c164
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c6
-rw-r--r--src/lib/libcrypto/asn1/x_info.c67
-rw-r--r--src/lib/libcrypto/asn1/x_long.c73
-rw-r--r--src/lib/libcrypto/asn1/x_name.c249
-rw-r--r--src/lib/libcrypto/asn1/x_nx509.c3
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c102
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c154
-rw-r--r--src/lib/libcrypto/asn1/x_req.c23
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c12
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c12
-rw-r--r--src/lib/libcrypto/asn1/x_val.c12
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c71
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c85
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_algor.c26
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_attrib.c49
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_bignum.c69
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_crl.c164
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_exten.c6
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_info.c67
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_long.c73
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_name.c249
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_nx509.c3
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_pkey.c102
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_pubkey.c154
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_req.c23
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_sig.c12
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_spki.c12
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_val.c12
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_x509.c71
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_x509a.c85
34 files changed, 1324 insertions, 1030 deletions
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
index 7ae473485c..65f81e8692 100644
--- a/src/lib/libcrypto/asn1/x_algor.c
+++ b/src/lib/libcrypto/asn1/x_algor.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -66,8 +66,8 @@ ASN1_SEQUENCE(X509_ALGOR) = {
66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY) 66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
67} ASN1_SEQUENCE_END(X509_ALGOR) 67} ASN1_SEQUENCE_END(X509_ALGOR)
68 68
69ASN1_ITEM_TEMPLATE(X509_ALGORS) = 69ASN1_ITEM_TEMPLATE(X509_ALGORS) =
70 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR) 70 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR)
71ASN1_ITEM_TEMPLATE_END(X509_ALGORS) 71ASN1_ITEM_TEMPLATE_END(X509_ALGORS)
72 72
73IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) 73IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
@@ -77,7 +77,8 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
77IMPLEMENT_STACK_OF(X509_ALGOR) 77IMPLEMENT_STACK_OF(X509_ALGOR)
78IMPLEMENT_ASN1_SET_OF(X509_ALGOR) 78IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
79 79
80int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) 80int
81X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
81{ 82{
82 if (!alg) 83 if (!alg)
83 return 0; 84 return 0;
@@ -93,20 +94,20 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
93 alg->algorithm = aobj; 94 alg->algorithm = aobj;
94 } 95 }
95 if (ptype == 0) 96 if (ptype == 0)
96 return 1; 97 return 1;
97 if (ptype == V_ASN1_UNDEF) { 98 if (ptype == V_ASN1_UNDEF) {
98 if (alg->parameter) { 99 if (alg->parameter) {
99 ASN1_TYPE_free(alg->parameter); 100 ASN1_TYPE_free(alg->parameter);
100 alg->parameter = NULL; 101 alg->parameter = NULL;
101 } 102 }
102 } 103 } else
103 else
104 ASN1_TYPE_set(alg->parameter, ptype, pval); 104 ASN1_TYPE_set(alg->parameter, ptype, pval);
105 return 1; 105 return 1;
106} 106}
107 107
108void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, 108void
109 X509_ALGOR *algor) 109X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
110 X509_ALGOR *algor)
110{ 111{
111 if (paobj) 112 if (paobj)
112 *paobj = algor->algorithm; 113 *paobj = algor->algorithm;
@@ -114,8 +115,7 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
114 if (algor->parameter == NULL) { 115 if (algor->parameter == NULL) {
115 *pptype = V_ASN1_UNDEF; 116 *pptype = V_ASN1_UNDEF;
116 return; 117 return;
117 } 118 } else
118 else
119 *pptype = algor->parameter->type; 119 *pptype = algor->parameter->type;
120 if (ppval) 120 if (ppval)
121 *ppval = algor->parameter->value.ptr; 121 *ppval = algor->parameter->value.ptr;
@@ -124,7 +124,8 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
124 124
125/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ 125/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */
126 126
127void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) 127void
128X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)
128{ 129{
129 int param_type; 130 int param_type;
130 131
@@ -134,5 +135,4 @@ void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)
134 param_type = V_ASN1_NULL; 135 param_type = V_ASN1_NULL;
135 136
136 X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); 137 X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);
137
138} 138}
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
index e620e1224e..248a6efa4e 100644
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ b/src/lib/libcrypto/asn1/x_attrib.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -96,23 +96,30 @@ ASN1_SEQUENCE(X509_ATTRIBUTE) = {
96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) 96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) 97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
98 98
99X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) 99X509_ATTRIBUTE *
100X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
100{ 101{
101 X509_ATTRIBUTE *ret=NULL; 102 X509_ATTRIBUTE *ret = NULL;
102 ASN1_TYPE *val=NULL; 103 ASN1_TYPE *val = NULL;
104
105 if ((ret = X509_ATTRIBUTE_new()) == NULL)
106 return (NULL);
107 ret->object = OBJ_nid2obj(nid);
108 ret->single = 0;
109 if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL)
110 goto err;
111 if ((val = ASN1_TYPE_new()) == NULL)
112 goto err;
113 if (!sk_ASN1_TYPE_push(ret->value.set, val))
114 goto err;
103 115
104 if ((ret=X509_ATTRIBUTE_new()) == NULL) 116 ASN1_TYPE_set(val, atrtype, value);
105 return(NULL); 117 return (ret);
106 ret->object=OBJ_nid2obj(nid);
107 ret->single=0;
108 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
109 if ((val=ASN1_TYPE_new()) == NULL) goto err;
110 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
111 118
112 ASN1_TYPE_set(val,atrtype,value);
113 return(ret);
114err: 119err:
115 if (ret != NULL) X509_ATTRIBUTE_free(ret); 120 if (ret != NULL)
116 if (val != NULL) ASN1_TYPE_free(val); 121 X509_ATTRIBUTE_free(ret);
117 return(NULL); 122 if (val != NULL)
123 ASN1_TYPE_free(val);
124 return (NULL);
118} 125}
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c
index 9cf3204a1b..bc74164fdc 100644
--- a/src/lib/libcrypto/asn1/x_bignum.c
+++ b/src/lib/libcrypto/asn1/x_bignum.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -72,11 +72,14 @@
72static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 72static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
73static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 73static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
74 74
75static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 75static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
76static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 76 const ASN1_ITEM *it);
77static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
78 int utype, char *free_cont, const ASN1_ITEM *it);
77 79
78static ASN1_PRIMITIVE_FUNCS bignum_pf = { 80static ASN1_PRIMITIVE_FUNCS bignum_pf = {
79 NULL, 0, 81 NULL,
82 0,
80 bn_new, 83 bn_new,
81 bn_free, 84 bn_free,
82 0, 85 0,
@@ -85,55 +88,69 @@ static ASN1_PRIMITIVE_FUNCS bignum_pf = {
85}; 88};
86 89
87ASN1_ITEM_start(BIGNUM) 90ASN1_ITEM_start(BIGNUM)
88 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM" 91ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
89ASN1_ITEM_end(BIGNUM) 92ASN1_ITEM_end(BIGNUM)
90 93
91ASN1_ITEM_start(CBIGNUM) 94ASN1_ITEM_start(CBIGNUM)
92 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM" 95ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM"
93ASN1_ITEM_end(CBIGNUM) 96ASN1_ITEM_end(CBIGNUM)
94 97
95static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 98static int
99bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
96{ 100{
97 *pval = (ASN1_VALUE *)BN_new(); 101 *pval = (ASN1_VALUE *)BN_new();
98 if(*pval) return 1; 102 if (*pval)
99 else return 0; 103 return 1;
104 else
105 return 0;
100} 106}
101 107
102static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 108static void
109bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
103{ 110{
104 if(!*pval) return; 111 if (!*pval)
105 if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval); 112 return;
106 else BN_free((BIGNUM *)*pval); 113 if (it->size & BN_SENSITIVE)
114 BN_clear_free((BIGNUM *)*pval);
115 else
116 BN_free((BIGNUM *)*pval);
107 *pval = NULL; 117 *pval = NULL;
108} 118}
109 119
110static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) 120static int
121bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
111{ 122{
112 BIGNUM *bn; 123 BIGNUM *bn;
113 int pad; 124 int pad;
114 if(!*pval) return -1; 125
126 if (!*pval)
127 return -1;
115 bn = (BIGNUM *)*pval; 128 bn = (BIGNUM *)*pval;
116 /* If MSB set in an octet we need a padding byte */ 129 /* If MSB set in an octet we need a padding byte */
117 if(BN_num_bits(bn) & 0x7) pad = 0; 130 if (BN_num_bits(bn) & 0x7)
118 else pad = 1; 131 pad = 0;
119 if(cont) { 132 else
120 if(pad) *cont++ = 0; 133 pad = 1;
134 if (cont) {
135 if (pad)
136 *cont++ = 0;
121 BN_bn2bin(bn, cont); 137 BN_bn2bin(bn, cont);
122 } 138 }
123 return pad + BN_num_bytes(bn); 139 return pad + BN_num_bytes(bn);
124} 140}
125 141
126static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 142static int
127 int utype, char *free_cont, const ASN1_ITEM *it) 143bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
144 char *free_cont, const ASN1_ITEM *it)
128{ 145{
129 BIGNUM *bn; 146 BIGNUM *bn;
130 if(!*pval) bn_new(pval, it); 147
131 bn = (BIGNUM *)*pval; 148 if (!*pval)
132 if(!BN_bin2bn(cont, len, bn)) { 149 bn_new(pval, it);
150 bn = (BIGNUM *)*pval;
151 if (!BN_bin2bn(cont, len, bn)) {
133 bn_free(pval, it); 152 bn_free(pval, it);
134 return 0; 153 return 0;
135 } 154 }
136 return 1; 155 return 1;
137} 156}
138
139
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index ea94f026b2..674cca4a1c 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -64,23 +64,23 @@
64#include <openssl/x509v3.h> 64#include <openssl/x509v3.h>
65 65
66static int X509_REVOKED_cmp(const X509_REVOKED * const *a, 66static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
67 const X509_REVOKED * const *b); 67 const X509_REVOKED * const *b);
68static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); 68static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
69 69
70ASN1_SEQUENCE(X509_REVOKED) = { 70ASN1_SEQUENCE(X509_REVOKED) = {
71 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER), 71 ASN1_SIMPLE(X509_REVOKED, serialNumber, ASN1_INTEGER),
72 ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME), 72 ASN1_SIMPLE(X509_REVOKED, revocationDate, ASN1_TIME),
73 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION) 73 ASN1_SEQUENCE_OF_OPT(X509_REVOKED, extensions, X509_EXTENSION)
74} ASN1_SEQUENCE_END(X509_REVOKED) 74} ASN1_SEQUENCE_END(X509_REVOKED)
75 75
76static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r); 76static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r);
77static int def_crl_lookup(X509_CRL *crl, 77static int def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret,
78 X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer); 78 ASN1_INTEGER *serial, X509_NAME *issuer);
79 79
80static X509_CRL_METHOD int_crl_meth = 80static X509_CRL_METHOD int_crl_meth = {
81{ 81 0,
82 0,
82 0, 83 0,
83 0,0,
84 def_crl_lookup, 84 def_crl_lookup,
85 def_crl_verify 85 def_crl_verify
86}; 86};
@@ -91,18 +91,19 @@ static const X509_CRL_METHOD *default_crl_method = &int_crl_meth;
91 * Since we cache the original encoding the signature wont be affected by 91 * Since we cache the original encoding the signature wont be affected by
92 * reordering of the revoked field. 92 * reordering of the revoked field.
93 */ 93 */
94static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 94static int
95 void *exarg) 95crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
96{ 96{
97 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; 97 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
98 98
99 if(!a || !a->revoked) return 1; 99 if (!a || !a->revoked)
100 switch(operation) { 100 return 1;
101 switch (operation) {
101 /* Just set cmp function here. We don't sort because that 102 /* Just set cmp function here. We don't sort because that
102 * would affect the output of X509_CRL_print(). 103 * would affect the output of X509_CRL_print().
103 */ 104 */
104 case ASN1_OP_D2I_POST: 105 case ASN1_OP_D2I_POST:
105 (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); 106 (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp);
106 break; 107 break;
107 } 108 }
108 return 1; 109 return 1;
@@ -123,9 +124,9 @@ ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
123 * Check for unhandled critical CRL entry extensions. 124 * Check for unhandled critical CRL entry extensions.
124 */ 125 */
125 126
126static int crl_set_issuers(X509_CRL *crl) 127static int
128crl_set_issuers(X509_CRL *crl)
127{ 129{
128
129 int i, j; 130 int i, j;
130 GENERAL_NAMES *gens, *gtmp; 131 GENERAL_NAMES *gens, *gtmp;
131 STACK_OF(X509_REVOKED) *revoked; 132 STACK_OF(X509_REVOKED) *revoked;
@@ -138,9 +139,8 @@ static int crl_set_issuers(X509_CRL *crl)
138 STACK_OF(X509_EXTENSION) *exts; 139 STACK_OF(X509_EXTENSION) *exts;
139 ASN1_ENUMERATED *reason; 140 ASN1_ENUMERATED *reason;
140 X509_EXTENSION *ext; 141 X509_EXTENSION *ext;
141 gtmp = X509_REVOKED_get_ext_d2i(rev, 142 gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer,
142 NID_certificate_issuer, 143 &j, NULL);
143 &j, NULL);
144 if (!gtmp && (j != -1)) { 144 if (!gtmp && (j != -1)) {
145 crl->flags |= EXFLAG_INVALID; 145 crl->flags |= EXFLAG_INVALID;
146 return 1; 146 return 1;
@@ -159,7 +159,7 @@ static int crl_set_issuers(X509_CRL *crl)
159 rev->issuer = gens; 159 rev->issuer = gens;
160 160
161 reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, 161 reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
162 &j, NULL); 162 &j, NULL);
163 if (!reason && (j != -1)) { 163 if (!reason && (j != -1)) {
164 crl->flags |= EXFLAG_INVALID; 164 crl->flags |= EXFLAG_INVALID;
165 return 1; 165 return 1;
@@ -169,7 +169,7 @@ static int crl_set_issuers(X509_CRL *crl)
169 rev->reason = ASN1_ENUMERATED_get(reason); 169 rev->reason = ASN1_ENUMERATED_get(reason);
170 ASN1_ENUMERATED_free(reason); 170 ASN1_ENUMERATED_free(reason);
171 } else 171 } else
172 rev->reason = CRL_REASON_NONE; 172 rev->reason = CRL_REASON_NONE;
173 173
174 /* Check for critical CRL entry extensions */ 174 /* Check for critical CRL entry extensions */
175 175
@@ -179,32 +179,29 @@ static int crl_set_issuers(X509_CRL *crl)
179 ext = sk_X509_EXTENSION_value(exts, j); 179 ext = sk_X509_EXTENSION_value(exts, j);
180 if (ext->critical > 0) { 180 if (ext->critical > 0) {
181 if (OBJ_obj2nid(ext->object) == 181 if (OBJ_obj2nid(ext->object) ==
182 NID_certificate_issuer) 182 NID_certificate_issuer)
183 continue; 183 continue;
184 crl->flags |= EXFLAG_CRITICAL; 184 crl->flags |= EXFLAG_CRITICAL;
185 break; 185 break;
186 } 186 }
187 } 187 }
188
189
190 } 188 }
191 189
192 return 1; 190 return 1;
193
194} 191}
195 192
196/* The X509_CRL structure needs a bit of customisation. Cache some extensions 193/* The X509_CRL structure needs a bit of customisation. Cache some extensions
197 * and hash of the whole CRL. 194 * and hash of the whole CRL.
198 */ 195 */
199static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 196static int
200 void *exarg) 197crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
201{ 198{
202 X509_CRL *crl = (X509_CRL *)*pval; 199 X509_CRL *crl = (X509_CRL *)*pval;
203 STACK_OF(X509_EXTENSION) *exts; 200 STACK_OF(X509_EXTENSION) *exts;
204 X509_EXTENSION *ext; 201 X509_EXTENSION *ext;
205 int idx; 202 int idx;
206 203
207 switch(operation) { 204 switch (operation) {
208 case ASN1_OP_NEW_POST: 205 case ASN1_OP_NEW_POST:
209 crl->idp = NULL; 206 crl->idp = NULL;
210 crl->akid = NULL; 207 crl->akid = NULL;
@@ -223,23 +220,23 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
223 X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL); 220 X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
224#endif 221#endif
225 crl->idp = X509_CRL_get_ext_d2i(crl, 222 crl->idp = X509_CRL_get_ext_d2i(crl,
226 NID_issuing_distribution_point, NULL, NULL); 223 NID_issuing_distribution_point, NULL, NULL);
227 if (crl->idp) 224 if (crl->idp)
228 setup_idp(crl, crl->idp); 225 setup_idp(crl, crl->idp);
229 226
230 crl->akid = X509_CRL_get_ext_d2i(crl, 227 crl->akid = X509_CRL_get_ext_d2i(crl,
231 NID_authority_key_identifier, NULL, NULL); 228 NID_authority_key_identifier, NULL, NULL);
232 229
233 crl->crl_number = X509_CRL_get_ext_d2i(crl, 230 crl->crl_number = X509_CRL_get_ext_d2i(crl,
234 NID_crl_number, NULL, NULL); 231 NID_crl_number, NULL, NULL);
235 232
236 crl->base_crl_number = X509_CRL_get_ext_d2i(crl, 233 crl->base_crl_number = X509_CRL_get_ext_d2i(crl,
237 NID_delta_crl, NULL, NULL); 234 NID_delta_crl, NULL, NULL);
238 /* Delta CRLs must have CRL number */ 235 /* Delta CRLs must have CRL number */
239 if (crl->base_crl_number && !crl->crl_number) 236 if (crl->base_crl_number && !crl->crl_number)
240 crl->flags |= EXFLAG_INVALID; 237 crl->flags |= EXFLAG_INVALID;
241 238
242 /* See if we have any unhandled critical CRL extensions and 239 /* See if we have any unhandled critical CRL extensions and
243 * indicate this in a flag. We only currently handle IDP so 240 * indicate this in a flag. We only currently handle IDP so
244 * anything else critical sets the flag. 241 * anything else critical sets the flag.
245 * 242 *
@@ -257,15 +254,14 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
257 crl->flags |= EXFLAG_FRESHEST; 254 crl->flags |= EXFLAG_FRESHEST;
258 if (ext->critical > 0) { 255 if (ext->critical > 0) {
259 /* We handle IDP and deltas */ 256 /* We handle IDP and deltas */
260 if ((nid == NID_issuing_distribution_point) 257 if ((nid == NID_issuing_distribution_point) ||
261 || (nid == NID_delta_crl)) 258 (nid == NID_delta_crl))
262 break;; 259 break;;
263 crl->flags |= EXFLAG_CRITICAL; 260 crl->flags |= EXFLAG_CRITICAL;
264 break; 261 break;
265 } 262 }
266 } 263 }
267 264
268
269 if (!crl_set_issuers(crl)) 265 if (!crl_set_issuers(crl))
270 return 0; 266 return 0;
271 267
@@ -294,9 +290,11 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
294 290
295/* Convert IDP into a more convenient form */ 291/* Convert IDP into a more convenient form */
296 292
297static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) 293static void
294setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
298{ 295{
299 int idp_only = 0; 296 int idp_only = 0;
297
300 /* Set various flags according to IDP */ 298 /* Set various flags according to IDP */
301 crl->idp_flags |= IDP_PRESENT; 299 crl->idp_flags |= IDP_PRESENT;
302 if (idp->onlyuser > 0) { 300 if (idp->onlyuser > 0) {
@@ -324,7 +322,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
324 crl->idp_reasons = idp->onlysomereasons->data[0]; 322 crl->idp_reasons = idp->onlysomereasons->data[0];
325 if (idp->onlysomereasons->length > 1) 323 if (idp->onlysomereasons->length > 1)
326 crl->idp_reasons |= 324 crl->idp_reasons |=
327 (idp->onlysomereasons->data[1] << 8); 325 (idp->onlysomereasons->data[1] << 8);
328 crl->idp_reasons &= CRLDP_ALL_REASONS; 326 crl->idp_reasons &= CRLDP_ALL_REASONS;
329 } 327 }
330 328
@@ -342,60 +340,65 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO)
342IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) 340IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)
343IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) 341IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL)
344 342
345static int X509_REVOKED_cmp(const X509_REVOKED * const *a, 343static int
346 const X509_REVOKED * const *b) 344X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
347{ 345{
348 return(ASN1_STRING_cmp( 346 return(ASN1_STRING_cmp(
349 (ASN1_STRING *)(*a)->serialNumber, 347 (ASN1_STRING *)(*a)->serialNumber,
350 (ASN1_STRING *)(*b)->serialNumber)); 348 (ASN1_STRING *)(*b)->serialNumber));
351} 349}
352 350
353int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) 351int
352X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
354{ 353{
355 X509_CRL_INFO *inf; 354 X509_CRL_INFO *inf;
355
356 inf = crl->crl; 356 inf = crl->crl;
357 if(!inf->revoked) 357 if (!inf->revoked)
358 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); 358 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
359 if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { 359 if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
360 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); 360 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
361 return 0; 361 return 0;
362} 362 }
363 inf->enc.modified = 1; 363 inf->enc.modified = 1;
364 return 1; 364 return 1;
365} 365}
366 366
367int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) 367int
368X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
368{ 369{
369 if (crl->meth->crl_verify) 370 if (crl->meth->crl_verify)
370 return crl->meth->crl_verify(crl, r); 371 return crl->meth->crl_verify(crl, r);
371 return 0; 372 return 0;
372} 373}
373 374
374int X509_CRL_get0_by_serial(X509_CRL *crl, 375int
375 X509_REVOKED **ret, ASN1_INTEGER *serial) 376X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **ret,
377 ASN1_INTEGER *serial)
376{ 378{
377 if (crl->meth->crl_lookup) 379 if (crl->meth->crl_lookup)
378 return crl->meth->crl_lookup(crl, ret, serial, NULL); 380 return crl->meth->crl_lookup(crl, ret, serial, NULL);
379 return 0; 381 return 0;
380} 382}
381 383
382int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) 384int
385X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x)
383{ 386{
384 if (crl->meth->crl_lookup) 387 if (crl->meth->crl_lookup)
385 return crl->meth->crl_lookup(crl, ret, 388 return crl->meth->crl_lookup(crl, ret,
386 X509_get_serialNumber(x), 389 X509_get_serialNumber(x), X509_get_issuer_name(x));
387 X509_get_issuer_name(x));
388 return 0; 390 return 0;
389} 391}
390 392
391static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) 393static int
394def_crl_verify(X509_CRL *crl, EVP_PKEY *r)
392{ 395{
393 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), 396 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
394 crl->sig_alg, crl->signature,crl->crl,r)); 397 crl->sig_alg, crl->signature, crl->crl, r));
395} 398}
396 399
397static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, 400static int
398 X509_REVOKED *rev) 401crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, X509_REVOKED *rev)
399{ 402{
400 int i; 403 int i;
401 404
@@ -421,11 +424,13 @@ static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm,
421 424
422} 425}
423 426
424static int def_crl_lookup(X509_CRL *crl, 427static int
425 X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer) 428def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret, ASN1_INTEGER *serial,
429 X509_NAME *issuer)
426{ 430{
427 X509_REVOKED rtmp, *rev; 431 X509_REVOKED rtmp, *rev;
428 int idx; 432 int idx;
433
429 rtmp.serialNumber = serial; 434 rtmp.serialNumber = serial;
430 /* Sort revoked into serial number order if not already sorted. 435 /* Sort revoked into serial number order if not already sorted.
431 * Do this under a lock to avoid race condition. 436 * Do this under a lock to avoid race condition.
@@ -436,10 +441,10 @@ static int def_crl_lookup(X509_CRL *crl,
436 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); 441 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
437 } 442 }
438 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); 443 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
439 if(idx < 0) 444 if (idx < 0)
440 return 0; 445 return 0;
441 /* Need to look for matching name */ 446 /* Need to look for matching name */
442 for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) { 447 for (; idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) {
443 rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); 448 rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
444 if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) 449 if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
445 return 0; 450 return 0;
@@ -454,22 +459,24 @@ static int def_crl_lookup(X509_CRL *crl,
454 return 0; 459 return 0;
455} 460}
456 461
457void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) 462void
463X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
458{ 464{
459 if (meth == NULL) 465 if (meth == NULL)
460 default_crl_method = &int_crl_meth; 466 default_crl_method = &int_crl_meth;
461 else 467 else
462 default_crl_method = meth; 468 default_crl_method = meth;
463} 469}
464 470
465X509_CRL_METHOD *X509_CRL_METHOD_new( 471X509_CRL_METHOD *
466 int (*crl_init)(X509_CRL *crl), 472X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
467 int (*crl_free)(X509_CRL *crl), 473 int (*crl_free)(X509_CRL *crl),
468 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, 474 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
469 ASN1_INTEGER *ser, X509_NAME *issuer), 475 ASN1_INTEGER *ser, X509_NAME *issuer),
470 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) 476 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk))
471{ 477{
472 X509_CRL_METHOD *m; 478 X509_CRL_METHOD *m;
479
473 m = malloc(sizeof(X509_CRL_METHOD)); 480 m = malloc(sizeof(X509_CRL_METHOD));
474 if (!m) 481 if (!m)
475 return NULL; 482 return NULL;
@@ -481,19 +488,22 @@ X509_CRL_METHOD *X509_CRL_METHOD_new(
481 return m; 488 return m;
482} 489}
483 490
484void X509_CRL_METHOD_free(X509_CRL_METHOD *m) 491void
492X509_CRL_METHOD_free(X509_CRL_METHOD *m)
485{ 493{
486 if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) 494 if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
487 return; 495 return;
488 free(m); 496 free(m);
489} 497}
490 498
491void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) 499void
500X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
492{ 501{
493 crl->meth_data = dat; 502 crl->meth_data = dat;
494} 503}
495 504
496void *X509_CRL_get_meth_data(X509_CRL *crl) 505void *
506X509_CRL_get_meth_data(X509_CRL *crl)
497{ 507{
498 return crl->meth_data; 508 return crl->meth_data;
499} 509}
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
index 3a21239926..5b3f49ed0f 100644
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -67,8 +67,8 @@ ASN1_SEQUENCE(X509_EXTENSION) = {
67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING) 67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
68} ASN1_SEQUENCE_END(X509_EXTENSION) 68} ASN1_SEQUENCE_END(X509_EXTENSION)
69 69
70ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) = 70ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) =
71 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION) 71 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION)
72ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS) 72ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS)
73 73
74IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION) 74IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
index 07ce15dbd7..4d3e2ebd17 100644
--- a/src/lib/libcrypto/asn1/x_info.c
+++ b/src/lib/libcrypto/asn1/x_info.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -62,42 +62,49 @@
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65X509_INFO *X509_INFO_new(void) 65X509_INFO *
66X509_INFO_new(void)
66{ 67{
67 X509_INFO *ret=NULL; 68 X509_INFO *ret = NULL;
68 69
69 ret=(X509_INFO *)malloc(sizeof(X509_INFO)); 70 ret = (X509_INFO *)malloc(sizeof(X509_INFO));
70 if (ret == NULL) { 71 if (ret == NULL) {
71 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); 72 ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE);
72 return(NULL); 73 return (NULL);
73 } 74 }
74 75
75 ret->enc_cipher.cipher=NULL; 76 ret->enc_cipher.cipher = NULL;
76 ret->enc_len=0; 77 ret->enc_len = 0;
77 ret->enc_data=NULL; 78 ret->enc_data = NULL;
78 79
79 ret->references=1; 80 ret->references = 1;
80 ret->x509=NULL; 81 ret->x509 = NULL;
81 ret->crl=NULL; 82 ret->crl = NULL;
82 ret->x_pkey=NULL; 83 ret->x_pkey = NULL;
83 return(ret); 84 return (ret);
84} 85}
85 86
86void X509_INFO_free(X509_INFO *x) 87void
88X509_INFO_free(X509_INFO *x)
87{ 89{
88 int i; 90 int i;
89 91
90 if (x == NULL) return; 92 if (x == NULL)
93 return;
91 94
92 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO); 95 i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
93 if (i > 0) return; 96 if (i > 0)
97 return;
94 98
95 if (x->x509 != NULL) X509_free(x->x509); 99 if (x->x509 != NULL)
96 if (x->crl != NULL) X509_CRL_free(x->crl); 100 X509_free(x->x509);
97 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); 101 if (x->crl != NULL)
98 if (x->enc_data != NULL) free(x->enc_data); 102 X509_CRL_free(x->crl);
103 if (x->x_pkey != NULL)
104 X509_PKEY_free(x->x_pkey);
105 if (x->enc_data != NULL)
106 free(x->enc_data);
99 free(x); 107 free(x);
100} 108}
101 109
102IMPLEMENT_STACK_OF(X509_INFO) 110IMPLEMENT_STACK_OF(X509_INFO)
103
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
index 1417284d3c..81dcc4fc29 100644
--- a/src/lib/libcrypto/asn1/x_long.c
+++ b/src/lib/libcrypto/asn1/x_long.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -84,25 +84,29 @@ static ASN1_PRIMITIVE_FUNCS long_pf = {
84}; 84};
85 85
86ASN1_ITEM_start(LONG) 86ASN1_ITEM_start(LONG)
87 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG" 87ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG"
88ASN1_ITEM_end(LONG) 88ASN1_ITEM_end(LONG)
89 89
90ASN1_ITEM_start(ZLONG) 90ASN1_ITEM_start(ZLONG)
91 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG" 91ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG"
92ASN1_ITEM_end(ZLONG) 92ASN1_ITEM_end(ZLONG)
93 93
94static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 94static int
95long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
95{ 96{
96 *(long *)pval = it->size; 97 *(long *)pval = it->size;
97 return 1; 98 return 1;
98} 99}
99 100
100static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 101static void
102long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
101{ 103{
102 *(long *)pval = it->size; 104 *(long *)pval = it->size;
103} 105}
104 106
105static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) 107static int
108long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
109 const ASN1_ITEM *it)
106{ 110{
107 long ltmp; 111 long ltmp;
108 unsigned long utmp; 112 unsigned long utmp;
@@ -113,58 +117,70 @@ static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const A
113 /* use memcpy, because we may not be long aligned */ 117 /* use memcpy, because we may not be long aligned */
114 memcpy(&ltmp, cp, sizeof(long)); 118 memcpy(&ltmp, cp, sizeof(long));
115 119
116 if(ltmp == it->size) return -1; 120 if (ltmp == it->size)
121 return -1;
117 /* Convert the long to positive: we subtract one if negative so 122 /* Convert the long to positive: we subtract one if negative so
118 * we can cleanly handle the padding if only the MSB of the leading 123 * we can cleanly handle the padding if only the MSB of the leading
119 * octet is set. 124 * octet is set.
120 */ 125 */
121 if(ltmp < 0) utmp = -ltmp - 1; 126 if (ltmp < 0)
122 else utmp = ltmp; 127 utmp = -ltmp - 1;
128 else
129 utmp = ltmp;
123 clen = BN_num_bits_word(utmp); 130 clen = BN_num_bits_word(utmp);
124 /* If MSB of leading octet set we need to pad */ 131 /* If MSB of leading octet set we need to pad */
125 if(!(clen & 0x7)) pad = 1; 132 if (!(clen & 0x7))
126 else pad = 0; 133 pad = 1;
134 else
135 pad = 0;
127 136
128 /* Convert number of bits to number of octets */ 137 /* Convert number of bits to number of octets */
129 clen = (clen + 7) >> 3; 138 clen = (clen + 7) >> 3;
130 139
131 if(cont) { 140 if (cont) {
132 if(pad) *cont++ = (ltmp < 0) ? 0xff : 0; 141 if (pad)
133 for(i = clen - 1; i >= 0; i--) { 142 *cont++ = (ltmp < 0) ? 0xff : 0;
143 for (i = clen - 1; i >= 0; i--) {
134 cont[i] = (unsigned char)(utmp & 0xff); 144 cont[i] = (unsigned char)(utmp & 0xff);
135 if(ltmp < 0) cont[i] ^= 0xff; 145 if (ltmp < 0)
146 cont[i] ^= 0xff;
136 utmp >>= 8; 147 utmp >>= 8;
137 } 148 }
138 } 149 }
139 return clen + pad; 150 return clen + pad;
140} 151}
141 152
142static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 153static int
143 int utype, char *free_cont, const ASN1_ITEM *it) 154long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
155 char *free_cont, const ASN1_ITEM *it)
144{ 156{
145 int neg, i; 157 int neg, i;
146 long ltmp; 158 long ltmp;
147 unsigned long utmp = 0; 159 unsigned long utmp = 0;
148 char *cp = (char *)pval; 160 char *cp = (char *)pval;
149 if(len > (int)sizeof(long)) { 161 if (len > (int)sizeof(long)) {
150 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 162 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
151 return 0; 163 return 0;
152 } 164 }
153 /* Is it negative? */ 165 /* Is it negative? */
154 if(len && (cont[0] & 0x80)) neg = 1; 166 if (len && (cont[0] & 0x80))
155 else neg = 0; 167 neg = 1;
168 else
169 neg = 0;
156 utmp = 0; 170 utmp = 0;
157 for(i = 0; i < len; i++) { 171 for (i = 0; i < len; i++) {
158 utmp <<= 8; 172 utmp <<= 8;
159 if(neg) utmp |= cont[i] ^ 0xff; 173 if (neg)
160 else utmp |= cont[i]; 174 utmp |= cont[i] ^ 0xff;
175 else
176 utmp |= cont[i];
161 } 177 }
162 ltmp = (long)utmp; 178 ltmp = (long)utmp;
163 if(neg) { 179 if (neg) {
164 ltmp++; 180 ltmp++;
165 ltmp = -ltmp; 181 ltmp = -ltmp;
166 } 182 }
167 if(ltmp == it->size) { 183 if (ltmp == it->size) {
168 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 184 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
169 return 0; 185 return 0;
170 } 186 }
@@ -172,8 +188,9 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
172 return 1; 188 return 1;
173} 189}
174 190
175static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, 191static int
176 int indent, const ASN1_PCTX *pctx) 192long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent,
193 const ASN1_PCTX *pctx)
177{ 194{
178 return BIO_printf(out, "%ld\n", *(long *)pval); 195 return BIO_printf(out, "%ld\n", *(long *)pval);
179} 196}
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index d10ac5acd1..70459babc4 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -66,13 +66,12 @@
66typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; 66typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
67DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY) 67DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
68 68
69static int x509_name_ex_d2i(ASN1_VALUE **val, 69static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
70 const unsigned char **in, long len, 70 long len, const ASN1_ITEM *it, int tag, int aclass, char opt,
71 const ASN1_ITEM *it, 71 ASN1_TLC *ctx);
72 int tag, int aclass, char opt, ASN1_TLC *ctx);
73 72
74static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, 73static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out,
75 const ASN1_ITEM *it, int tag, int aclass); 74 const ASN1_ITEM *it, int tag, int aclass);
76static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it); 75static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);
77static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); 76static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);
78 77
@@ -80,13 +79,10 @@ static int x509_name_encode(X509_NAME *a);
80static int x509_name_canon(X509_NAME *a); 79static int x509_name_canon(X509_NAME *a);
81static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in); 80static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in);
82static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname, 81static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname,
83 unsigned char **in); 82 unsigned char **in);
84 83
85 84static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent,
86static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, 85 const char *fname, const ASN1_PCTX *pctx);
87 int indent,
88 const char *fname,
89 const ASN1_PCTX *pctx);
90 86
91ASN1_SEQUENCE(X509_NAME_ENTRY) = { 87ASN1_SEQUENCE(X509_NAME_ENTRY) = {
92 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT), 88 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),
@@ -101,11 +97,11 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY)
101 */ 97 */
102 98
103ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) = 99ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) =
104 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY) 100 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY)
105ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES) 101ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES)
106 102
107ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) = 103ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) =
108 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES) 104 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES)
109ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL) 105ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL)
110 106
111/* Normally that's where it would end: we'd have two nested STACK structures 107/* Normally that's where it would end: we'd have two nested STACK structures
@@ -124,26 +120,30 @@ const ASN1_EXTERN_FUNCS x509_name_ff = {
124 x509_name_ex_print 120 x509_name_ex_print
125}; 121};
126 122
127IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff) 123IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff)
128 124
129IMPLEMENT_ASN1_FUNCTIONS(X509_NAME) 125IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)
130IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME) 126IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
131 127
132static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) 128static int
129x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
133{ 130{
134 X509_NAME *ret = NULL; 131 X509_NAME *ret = NULL;
132
135 ret = malloc(sizeof(X509_NAME)); 133 ret = malloc(sizeof(X509_NAME));
136 if(!ret) goto memerr; 134 if (!ret)
137 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL) 135 goto memerr;
136 if ((ret->entries = sk_X509_NAME_ENTRY_new_null()) == NULL)
137 goto memerr;
138 if ((ret->bytes = BUF_MEM_new()) == NULL)
138 goto memerr; 139 goto memerr;
139 if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr;
140 ret->canon_enc = NULL; 140 ret->canon_enc = NULL;
141 ret->canon_enclen = 0; 141 ret->canon_enclen = 0;
142 ret->modified=1; 142 ret->modified = 1;
143 *val = (ASN1_VALUE *)ret; 143 *val = (ASN1_VALUE *)ret;
144 return 1; 144 return 1;
145 145
146 memerr: 146memerr:
147 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); 147 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE);
148 if (ret) { 148 if (ret) {
149 if (ret->entries) 149 if (ret->entries)
@@ -153,54 +153,64 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
153 return 0; 153 return 0;
154} 154}
155 155
156static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 156static void
157x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
157{ 158{
158 X509_NAME *a; 159 X509_NAME *a;
159 if(!pval || !*pval) 160
160 return; 161 if (!pval || !*pval)
162 return;
161 a = (X509_NAME *)*pval; 163 a = (X509_NAME *)*pval;
162 164
163 BUF_MEM_free(a->bytes); 165 BUF_MEM_free(a->bytes);
164 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free); 166 sk_X509_NAME_ENTRY_pop_free(a->entries, X509_NAME_ENTRY_free);
165 if (a->canon_enc) 167 if (a->canon_enc)
166 free(a->canon_enc); 168 free(a->canon_enc);
167 free(a); 169 free(a);
168 *pval = NULL; 170 *pval = NULL;
169} 171}
170 172
171static int x509_name_ex_d2i(ASN1_VALUE **val, 173static int
172 const unsigned char **in, long len, const ASN1_ITEM *it, 174x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
173 int tag, int aclass, char opt, ASN1_TLC *ctx) 175 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
174{ 176{
175 const unsigned char *p = *in, *q; 177 const unsigned char *p = *in, *q;
176 union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; 178 union {
177 ASN1_VALUE *a; } intname = {NULL}; 179 STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
178 union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL}; 180 ASN1_VALUE *a;
181 } intname = {NULL};
182 union {
183 X509_NAME *x;
184 ASN1_VALUE *a;
185 } nm = {NULL};
179 int i, j, ret; 186 int i, j, ret;
180 STACK_OF(X509_NAME_ENTRY) *entries; 187 STACK_OF(X509_NAME_ENTRY) *entries;
181 X509_NAME_ENTRY *entry; 188 X509_NAME_ENTRY *entry;
182 q = p; 189 q = p;
183 190
184 /* Get internal representation of Name */ 191 /* Get internal representation of Name */
185 ret = ASN1_item_ex_d2i(&intname.a, 192 ret = ASN1_item_ex_d2i(&intname.a, &p, len,
186 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), 193 ASN1_ITEM_rptr(X509_NAME_INTERNAL), tag, aclass, opt, ctx);
187 tag, aclass, opt, ctx); 194
188 195 if (ret <= 0)
189 if(ret <= 0) return ret; 196 return ret;
190 197
191 if(*val) x509_name_ex_free(val, NULL); 198 if (*val)
192 if(!x509_name_ex_new(&nm.a, NULL)) goto err; 199 x509_name_ex_free(val, NULL);
200 if (!x509_name_ex_new(&nm.a, NULL))
201 goto err;
193 /* We've decoded it: now cache encoding */ 202 /* We've decoded it: now cache encoding */
194 if(!BUF_MEM_grow(nm.x->bytes, p - q)) goto err; 203 if (!BUF_MEM_grow(nm.x->bytes, p - q))
204 goto err;
195 memcpy(nm.x->bytes->data, q, p - q); 205 memcpy(nm.x->bytes->data, q, p - q);
196 206
197 /* Convert internal representation to X509_NAME structure */ 207 /* Convert internal representation to X509_NAME structure */
198 for(i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) { 208 for (i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) {
199 entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i); 209 entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i);
200 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { 210 for (j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
201 entry = sk_X509_NAME_ENTRY_value(entries, j); 211 entry = sk_X509_NAME_ENTRY_value(entries, j);
202 entry->set = i; 212 entry->set = i;
203 if(!sk_X509_NAME_ENTRY_push(nm.x->entries, entry)) 213 if (!sk_X509_NAME_ENTRY_push(nm.x->entries, entry))
204 goto err; 214 goto err;
205 } 215 }
206 sk_X509_NAME_ENTRY_free(entries); 216 sk_X509_NAME_ENTRY_free(entries);
@@ -213,90 +223,104 @@ static int x509_name_ex_d2i(ASN1_VALUE **val,
213 *val = nm.a; 223 *val = nm.a;
214 *in = p; 224 *in = p;
215 return ret; 225 return ret;
226
216err: 227err:
217 if (nm.x != NULL) 228 if (nm.x != NULL)
218 X509_NAME_free(nm.x); 229 X509_NAME_free(nm.x);
219 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR); 230 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
220 return 0; 231 return 0;
221} 232}
222 233
223static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) 234static int
235x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it,
236 int tag, int aclass)
224{ 237{
225 int ret; 238 int ret;
226 X509_NAME *a = (X509_NAME *)*val; 239 X509_NAME *a = (X509_NAME *)*val;
227 if(a->modified) { 240
241 if (a->modified) {
228 ret = x509_name_encode(a); 242 ret = x509_name_encode(a);
229 if(ret < 0) 243 if (ret < 0)
230 return ret; 244 return ret;
231 ret = x509_name_canon(a); 245 ret = x509_name_canon(a);
232 if(ret < 0) 246 if (ret < 0)
233 return ret; 247 return ret;
234 } 248 }
235 ret = a->bytes->length; 249 ret = a->bytes->length;
236 if(out != NULL) { 250 if (out != NULL) {
237 memcpy(*out,a->bytes->data,ret); 251 memcpy(*out, a->bytes->data, ret);
238 *out+=ret; 252 *out += ret;
239 } 253 }
240 return ret; 254 return ret;
241} 255}
242 256
243static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne) 257static void
258local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne)
244{ 259{
245 sk_X509_NAME_ENTRY_free(ne); 260 sk_X509_NAME_ENTRY_free(ne);
246} 261}
247 262
248static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne) 263static void
264local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne)
249{ 265{
250 sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free); 266 sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free);
251} 267}
252 268
253static int x509_name_encode(X509_NAME *a) 269static int
270x509_name_encode(X509_NAME *a)
254{ 271{
255 union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; 272 union {
256 ASN1_VALUE *a; } intname = {NULL}; 273 STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
274 ASN1_VALUE *a;
275 } intname = {NULL};
257 int len; 276 int len;
258 unsigned char *p; 277 unsigned char *p;
259 STACK_OF(X509_NAME_ENTRY) *entries = NULL; 278 STACK_OF(X509_NAME_ENTRY) *entries = NULL;
260 X509_NAME_ENTRY *entry; 279 X509_NAME_ENTRY *entry;
261 int i, set = -1; 280 int i, set = -1;
281
262 intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null(); 282 intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
263 if(!intname.s) goto memerr; 283 if (!intname.s)
264 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { 284 goto memerr;
285 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
265 entry = sk_X509_NAME_ENTRY_value(a->entries, i); 286 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
266 if(entry->set != set) { 287 if (entry->set != set) {
267 entries = sk_X509_NAME_ENTRY_new_null(); 288 entries = sk_X509_NAME_ENTRY_new_null();
268 if(!entries) goto memerr; 289 if (!entries)
269 if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, 290 goto memerr;
270 entries)) 291 if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s,
292 entries))
271 goto memerr; 293 goto memerr;
272 set = entry->set; 294 set = entry->set;
273 } 295 }
274 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; 296 if (!sk_X509_NAME_ENTRY_push(entries, entry))
297 goto memerr;
275 } 298 }
276 len = ASN1_item_ex_i2d(&intname.a, NULL, 299 len = ASN1_item_ex_i2d(&intname.a, NULL,
277 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); 300 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
278 if (!BUF_MEM_grow(a->bytes,len)) goto memerr; 301 if (!BUF_MEM_grow(a->bytes, len))
279 p=(unsigned char *)a->bytes->data; 302 goto memerr;
280 ASN1_item_ex_i2d(&intname.a, 303 p = (unsigned char *)a->bytes->data;
281 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); 304 ASN1_item_ex_i2d(&intname.a, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
305 -1, -1);
282 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, 306 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
283 local_sk_X509_NAME_ENTRY_free); 307 local_sk_X509_NAME_ENTRY_free);
284 a->modified = 0; 308 a->modified = 0;
285 return len; 309 return len;
310
286memerr: 311memerr:
287 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, 312 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
288 local_sk_X509_NAME_ENTRY_free); 313 local_sk_X509_NAME_ENTRY_free);
289 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); 314 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);
290 return -1; 315 return -1;
291} 316}
292 317
293static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, 318static int
294 int indent, 319x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent, const char *fname,
295 const char *fname, 320 const ASN1_PCTX *pctx)
296 const ASN1_PCTX *pctx)
297{ 321{
298 if (X509_NAME_print_ex(out, (X509_NAME *)*pval, 322 if (X509_NAME_print_ex(out, (X509_NAME *)*pval, indent,
299 indent, pctx->nm_flags) <= 0) 323 pctx->nm_flags) <= 0)
300 return 0; 324 return 0;
301 return 2; 325 return 2;
302} 326}
@@ -314,7 +338,8 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,
314 * dirName can also be checked with a simple memcmp(). 338 * dirName can also be checked with a simple memcmp().
315 */ 339 */
316 340
317static int x509_name_canon(X509_NAME *a) 341static int
342x509_name_canon(X509_NAME *a)
318{ 343{
319 unsigned char *p; 344 unsigned char *p;
320 STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL; 345 STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
@@ -325,22 +350,22 @@ static int x509_name_canon(X509_NAME *a)
325 if (a->canon_enc) { 350 if (a->canon_enc) {
326 free(a->canon_enc); 351 free(a->canon_enc);
327 a->canon_enc = NULL; 352 a->canon_enc = NULL;
328 } 353 }
329 /* Special case: empty X509_NAME => null encoding */ 354 /* Special case: empty X509_NAME => null encoding */
330 if (sk_X509_NAME_ENTRY_num(a->entries) == 0) { 355 if (sk_X509_NAME_ENTRY_num(a->entries) == 0) {
331 a->canon_enclen = 0; 356 a->canon_enclen = 0;
332 return 1; 357 return 1;
333 } 358 }
334 intname = sk_STACK_OF_X509_NAME_ENTRY_new_null(); 359 intname = sk_STACK_OF_X509_NAME_ENTRY_new_null();
335 if(!intname) 360 if (!intname)
336 goto err; 361 goto err;
337 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { 362 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
338 entry = sk_X509_NAME_ENTRY_value(a->entries, i); 363 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
339 if(entry->set != set) { 364 if (entry->set != set) {
340 entries = sk_X509_NAME_ENTRY_new_null(); 365 entries = sk_X509_NAME_ENTRY_new_null();
341 if(!entries) 366 if (!entries)
342 goto err; 367 goto err;
343 if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) 368 if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries))
344 goto err; 369 goto err;
345 set = entry->set; 370 set = entry->set;
346 } 371 }
@@ -348,33 +373,27 @@ static int x509_name_canon(X509_NAME *a)
348 tmpentry->object = OBJ_dup(entry->object); 373 tmpentry->object = OBJ_dup(entry->object);
349 if (!asn1_string_canon(tmpentry->value, entry->value)) 374 if (!asn1_string_canon(tmpentry->value, entry->value))
350 goto err; 375 goto err;
351 if(!sk_X509_NAME_ENTRY_push(entries, tmpentry)) 376 if (!sk_X509_NAME_ENTRY_push(entries, tmpentry))
352 goto err; 377 goto err;
353 tmpentry = NULL; 378 tmpentry = NULL;
354 } 379 }
355 380
356 /* Finally generate encoding */ 381 /* Finally generate encoding */
357
358 a->canon_enclen = i2d_name_canon(intname, NULL); 382 a->canon_enclen = i2d_name_canon(intname, NULL);
359
360 p = malloc(a->canon_enclen); 383 p = malloc(a->canon_enclen);
361
362 if (!p) 384 if (!p)
363 goto err; 385 goto err;
364
365 a->canon_enc = p; 386 a->canon_enc = p;
366
367 i2d_name_canon(intname, &p); 387 i2d_name_canon(intname, &p);
368
369 ret = 1; 388 ret = 1;
370 389
371 err: 390err:
372 391
373 if (tmpentry) 392 if (tmpentry)
374 X509_NAME_ENTRY_free(tmpentry); 393 X509_NAME_ENTRY_free(tmpentry);
375 if (intname) 394 if (intname)
376 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, 395 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
377 local_sk_X509_NAME_ENTRY_pop_free); 396 local_sk_X509_NAME_ENTRY_pop_free);
378 return ret; 397 return ret;
379} 398}
380 399
@@ -384,9 +403,10 @@ static int x509_name_canon(X509_NAME *a)
384 (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \ 403 (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \
385 | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \ 404 | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \
386 | B_ASN1_VISIBLESTRING) 405 | B_ASN1_VISIBLESTRING)
387
388 406
389static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) 407
408static int
409asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
390{ 410{
391 unsigned char *to, *from; 411 unsigned char *to, *from;
392 int len, i; 412 int len, i;
@@ -415,7 +435,7 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
415 */ 435 */
416 436
417 /* Ignore leading spaces */ 437 /* Ignore leading spaces */
418 while((len > 0) && !(*from & 0x80) && isspace(*from)) { 438 while ((len > 0) && !(*from & 0x80) && isspace(*from)) {
419 from++; 439 from++;
420 len--; 440 len--;
421 } 441 }
@@ -431,24 +451,24 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
431 to = out->data; 451 to = out->data;
432 452
433 i = 0; 453 i = 0;
434 while(i < len) { 454 while (i < len) {
435 /* If MSB set just copy across */ 455 /* If MSB set just copy across */
436 if (*from & 0x80) { 456 if (*from & 0x80) {
437 *to++ = *from++; 457 *to++ = *from++;
438 i++; 458 i++;
439 } 459 }
440 /* Collapse multiple spaces */ 460 /* Collapse multiple spaces */
441 else if (isspace(*from)) { 461 else if (isspace(*from)) {
442 /* Copy one space across */ 462 /* Copy one space across */
443 *to++ = ' '; 463 *to++ = ' ';
444 /* Ignore subsequent spaces. Note: don't need to 464 /* Ignore subsequent spaces. Note: don't need to
445 * check len here because we know the last 465 * check len here because we know the last
446 * character is a non-space so we can't overflow. 466 * character is a non-space so we can't overflow.
447 */ 467 */
448 do { 468 do {
449 from++; 469 from++;
450 i++; 470 i++;
451 } while(!(*from & 0x80) && isspace(*from)); 471 } while (!(*from & 0x80) && isspace(*from));
452 } else { 472 } else {
453 *to++ = tolower(*from); 473 *to++ = tolower(*from);
454 from++; 474 from++;
@@ -459,11 +479,10 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
459 out->length = to - out->data; 479 out->length = to - out->data;
460 480
461 return 1; 481 return 1;
462
463} 482}
464 483
465static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, 484static int
466 unsigned char **in) 485i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, unsigned char **in)
467{ 486{
468 int i, len, ltmp; 487 int i, len, ltmp;
469 ASN1_VALUE *v; 488 ASN1_VALUE *v;
@@ -473,7 +492,7 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
473 for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) { 492 for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) {
474 v = sk_ASN1_VALUE_value(intname, i); 493 v = sk_ASN1_VALUE_value(intname, i);
475 ltmp = ASN1_item_ex_i2d(&v, in, 494 ltmp = ASN1_item_ex_i2d(&v, in,
476 ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1); 495 ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1);
477 if (ltmp < 0) 496 if (ltmp < 0)
478 return ltmp; 497 return ltmp;
479 len += ltmp; 498 len += ltmp;
@@ -481,21 +500,23 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
481 return len; 500 return len;
482} 501}
483 502
484int X509_NAME_set(X509_NAME **xn, X509_NAME *name) 503int
504X509_NAME_set(X509_NAME **xn, X509_NAME *name)
485{ 505{
486 X509_NAME *in; 506 X509_NAME *in;
487 507
488 if (!xn || !name) return(0); 508 if (!xn || !name)
509 return (0);
489 510
490 if (*xn != name) { 511 if (*xn != name) {
491 in=X509_NAME_dup(name); 512 in = X509_NAME_dup(name);
492 if (in != NULL) { 513 if (in != NULL) {
493 X509_NAME_free(*xn); 514 X509_NAME_free(*xn);
494 *xn=in; 515 *xn = in;
495 } 516 }
496 } 517 }
497 return(*xn != NULL); 518 return (*xn != NULL);
498} 519}
499 520
500IMPLEMENT_STACK_OF(X509_NAME_ENTRY) 521IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
501IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) 522IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_nx509.c b/src/lib/libcrypto/asn1/x_nx509.c
index fbd9a22db3..538a9f95eb 100644
--- a/src/lib/libcrypto/asn1/x_nx509.c
+++ b/src/lib/libcrypto/asn1/x_nx509.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -69,4 +69,3 @@ ASN1_SEQUENCE(NETSCAPE_X509) = {
69} ASN1_SEQUENCE_END(NETSCAPE_X509) 69} ASN1_SEQUENCE_END(NETSCAPE_X509)
70 70
71IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509) 71IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509)
72
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index eac134a1ee..d18b8f6f5e 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -64,75 +64,85 @@
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66/* need to implement */ 66/* need to implement */
67int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) 67int
68i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
68{ 69{
69 return(0); 70 return (0);
70} 71}
71 72
72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) 73X509_PKEY *
74d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length)
73{ 75{
74 int i; 76 int i;
75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); 77 M_ASN1_D2I_vars(a, X509_PKEY *, X509_PKEY_new);
76 78
77 M_ASN1_D2I_Init(); 79 M_ASN1_D2I_Init();
78 M_ASN1_D2I_start_sequence(); 80 M_ASN1_D2I_start_sequence();
79 M_ASN1_D2I_get_x(X509_ALGOR,ret->enc_algor,d2i_X509_ALGOR); 81 M_ASN1_D2I_get_x(X509_ALGOR, ret->enc_algor, d2i_X509_ALGOR);
80 M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->enc_pkey,d2i_ASN1_OCTET_STRING); 82 M_ASN1_D2I_get_x(ASN1_OCTET_STRING, ret->enc_pkey,
83 d2i_ASN1_OCTET_STRING);
81 84
82 ret->cipher.cipher=EVP_get_cipherbyname( 85 ret->cipher.cipher = EVP_get_cipherbyname(
83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); 86 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
84 if (ret->cipher.cipher == NULL) { 87 if (ret->cipher.cipher == NULL) {
85 c.error=ASN1_R_UNSUPPORTED_CIPHER; 88 c.error = ASN1_R_UNSUPPORTED_CIPHER;
86 c.line=__LINE__; 89 c.line = __LINE__;
87 goto err; 90 goto err;
88 } 91 }
89 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) { 92 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) {
90 i=ret->enc_algor->parameter->value.octet_string->length; 93 i = ret->enc_algor->parameter->value.octet_string->length;
91 if (i > EVP_MAX_IV_LENGTH) { 94 if (i > EVP_MAX_IV_LENGTH) {
92 c.error=ASN1_R_IV_TOO_LARGE; 95 c.error = ASN1_R_IV_TOO_LARGE;
93 c.line=__LINE__; 96 c.line = __LINE__;
94 goto err; 97 goto err;
95 } 98 }
96 memcpy(ret->cipher.iv, 99 memcpy(ret->cipher.iv,
97 ret->enc_algor->parameter->value.octet_string->data,i); 100 ret->enc_algor->parameter->value.octet_string->data, i);
98 } 101 } else
99 else 102 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
100 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); 103 M_ASN1_D2I_Finish(a, X509_PKEY_free, ASN1_F_D2I_X509_PKEY);
101 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
102} 104}
103 105
104X509_PKEY *X509_PKEY_new(void) 106X509_PKEY *
107X509_PKEY_new(void)
105{ 108{
106 X509_PKEY *ret=NULL; 109 X509_PKEY *ret = NULL;
107 ASN1_CTX c; 110 ASN1_CTX c;
108 111
109 M_ASN1_New_Malloc(ret,X509_PKEY); 112 M_ASN1_New_Malloc(ret, X509_PKEY);
110 ret->version=0; 113 ret->version = 0;
111 M_ASN1_New(ret->enc_algor,X509_ALGOR_new); 114 M_ASN1_New(ret->enc_algor, X509_ALGOR_new);
112 M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new); 115 M_ASN1_New(ret->enc_pkey, M_ASN1_OCTET_STRING_new);
113 ret->dec_pkey=NULL; 116 ret->dec_pkey = NULL;
114 ret->key_length=0; 117 ret->key_length = 0;
115 ret->key_data=NULL; 118 ret->key_data = NULL;
116 ret->key_free=0; 119 ret->key_free = 0;
117 ret->cipher.cipher=NULL; 120 ret->cipher.cipher = NULL;
118 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); 121 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
119 ret->references=1; 122 ret->references = 1;
120 return(ret); 123 return (ret);
121 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); 124 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
122} 125}
123 126
124void X509_PKEY_free(X509_PKEY *x) 127void
128X509_PKEY_free(X509_PKEY *x)
125{ 129{
126 int i; 130 int i;
127 131
128 if (x == NULL) return; 132 if (x == NULL)
133 return;
129 134
130 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY); 135 i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY);
131 if (i > 0) return; 136 if (i > 0)
137 return;
132 138
133 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); 139 if (x->enc_algor != NULL)
134 if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey); 140 X509_ALGOR_free(x->enc_algor);
135 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); 141 if (x->enc_pkey != NULL)
136 if ((x->key_data != NULL) && (x->key_free)) free(x->key_data); 142 M_ASN1_OCTET_STRING_free(x->enc_pkey);
143 if (x->dec_pkey != NULL)
144 EVP_PKEY_free(x->dec_pkey);
145 if ((x->key_data != NULL) && (x->key_free))
146 free(x->key_data);
137 free(x); 147 free(x);
138} 148}
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index 1d6ab6580a..df915e2dfd 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -69,8 +69,8 @@
69#endif 69#endif
70 70
71/* Minor tweak to operation: free up EVP_PKEY */ 71/* Minor tweak to operation: free up EVP_PKEY */
72static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 72static int
73 void *exarg) 73pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
74{ 74{
75 if (operation == ASN1_OP_FREE_POST) { 75 if (operation == ASN1_OP_FREE_POST) {
76 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; 76 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
@@ -86,54 +86,61 @@ ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
86 86
87IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) 87IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
88 88
89int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) 89int
90X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
90{ 91{
91 X509_PUBKEY *pk=NULL; 92 X509_PUBKEY *pk = NULL;
92 93
93 if (x == NULL) return(0); 94 if (x == NULL)
94 95 return (0);
95 if ((pk=X509_PUBKEY_new()) == NULL) goto error; 96 if ((pk = X509_PUBKEY_new()) == NULL)
97 goto error;
96 98
97 if (pkey->ameth) { 99 if (pkey->ameth) {
98 if (pkey->ameth->pub_encode) { 100 if (pkey->ameth->pub_encode) {
99 if (!pkey->ameth->pub_encode(pk, pkey)) { 101 if (!pkey->ameth->pub_encode(pk, pkey)) {
100 X509err(X509_F_X509_PUBKEY_SET, 102 X509err(X509_F_X509_PUBKEY_SET,
101 X509_R_PUBLIC_KEY_ENCODE_ERROR); 103 X509_R_PUBLIC_KEY_ENCODE_ERROR);
102 goto error; 104 goto error;
103 } 105 }
104 } else { 106 } else {
105 X509err(X509_F_X509_PUBKEY_SET, 107 X509err(X509_F_X509_PUBKEY_SET,
106 X509_R_METHOD_NOT_SUPPORTED); 108 X509_R_METHOD_NOT_SUPPORTED);
107 goto error; 109 goto error;
108 } 110 }
109 } else { 111 } else {
110 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); 112 X509err(X509_F_X509_PUBKEY_SET, X509_R_UNSUPPORTED_ALGORITHM);
111 goto error; 113 goto error;
112 } 114 }
113 115
114 if (*x != NULL) 116 if (*x != NULL)
115 X509_PUBKEY_free(*x); 117 X509_PUBKEY_free(*x);
116 118
117 *x=pk; 119 *x = pk;
118 120
119 return 1; 121 return 1;
122
120error: 123error:
121 if (pk != NULL) X509_PUBKEY_free(pk); 124 if (pk != NULL)
125 X509_PUBKEY_free(pk);
122 return 0; 126 return 0;
123} 127}
124 128
125EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) 129EVP_PKEY *
130X509_PUBKEY_get(X509_PUBKEY *key)
126{ 131{
127 EVP_PKEY *ret=NULL; 132 EVP_PKEY *ret = NULL;
128 133
129 if (key == NULL) goto error; 134 if (key == NULL)
135 goto error;
130 136
131 if (key->pkey != NULL) { 137 if (key->pkey != NULL) {
132 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); 138 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
133 return key->pkey; 139 return key->pkey;
134 } 140 }
135 141
136 if (key->public_key == NULL) goto error; 142 if (key->public_key == NULL)
143 goto error;
137 144
138 if ((ret = EVP_PKEY_new()) == NULL) { 145 if ((ret = EVP_PKEY_new()) == NULL) {
139 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); 146 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
@@ -141,14 +148,14 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
141 } 148 }
142 149
143 if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) { 150 if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {
144 X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); 151 X509err(X509_F_X509_PUBKEY_GET, X509_R_UNSUPPORTED_ALGORITHM);
145 goto error; 152 goto error;
146 } 153 }
147 154
148 if (ret->ameth->pub_decode) { 155 if (ret->ameth->pub_decode) {
149 if (!ret->ameth->pub_decode(ret, key)) { 156 if (!ret->ameth->pub_decode(ret, key)) {
150 X509err(X509_F_X509_PUBKEY_GET, 157 X509err(X509_F_X509_PUBKEY_GET,
151 X509_R_PUBLIC_KEY_DECODE_ERROR); 158 X509_R_PUBLIC_KEY_DECODE_ERROR);
152 goto error; 159 goto error;
153 } 160 }
154 } else { 161 } else {
@@ -170,39 +177,44 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
170 177
171 return ret; 178 return ret;
172 179
173 error: 180error:
174 if (ret != NULL) 181 if (ret != NULL)
175 EVP_PKEY_free(ret); 182 EVP_PKEY_free(ret);
176 return(NULL); 183 return (NULL);
177} 184}
178 185
179/* Now two pseudo ASN1 routines that take an EVP_PKEY structure 186/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
180 * and encode or decode as X509_PUBKEY 187 * and encode or decode as X509_PUBKEY
181 */ 188 */
182 189
183EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, 190EVP_PKEY *
184 long length) 191d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length)
185{ 192{
186 X509_PUBKEY *xpk; 193 X509_PUBKEY *xpk;
187 EVP_PKEY *pktmp; 194 EVP_PKEY *pktmp;
188 xpk = d2i_X509_PUBKEY(NULL, pp, length); 195 xpk = d2i_X509_PUBKEY(NULL, pp, length);
189 if(!xpk) return NULL; 196 if (!xpk)
197 return NULL;
190 pktmp = X509_PUBKEY_get(xpk); 198 pktmp = X509_PUBKEY_get(xpk);
191 X509_PUBKEY_free(xpk); 199 X509_PUBKEY_free(xpk);
192 if(!pktmp) return NULL; 200 if (!pktmp)
193 if(a) { 201 return NULL;
202 if (a) {
194 EVP_PKEY_free(*a); 203 EVP_PKEY_free(*a);
195 *a = pktmp; 204 *a = pktmp;
196 } 205 }
197 return pktmp; 206 return pktmp;
198} 207}
199 208
200int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) 209int
210i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
201{ 211{
202 X509_PUBKEY *xpk=NULL; 212 X509_PUBKEY *xpk = NULL;
203 int ret; 213 int ret;
204 if(!a) return 0; 214 if (!a)
205 if(!X509_PUBKEY_set(&xpk, a)) return 0; 215 return 0;
216 if (!X509_PUBKEY_set(&xpk, a))
217 return 0;
206 ret = i2d_X509_PUBKEY(xpk, pp); 218 ret = i2d_X509_PUBKEY(xpk, pp);
207 X509_PUBKEY_free(xpk); 219 X509_PUBKEY_free(xpk);
208 return ret; 220 return ret;
@@ -212,18 +224,20 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
212 * keys 224 * keys
213 */ 225 */
214#ifndef OPENSSL_NO_RSA 226#ifndef OPENSSL_NO_RSA
215RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, 227RSA *
216 long length) 228d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length)
217{ 229{
218 EVP_PKEY *pkey; 230 EVP_PKEY *pkey;
219 RSA *key; 231 RSA *key;
220 const unsigned char *q; 232 const unsigned char *q;
221 q = *pp; 233 q = *pp;
222 pkey = d2i_PUBKEY(NULL, &q, length); 234 pkey = d2i_PUBKEY(NULL, &q, length);
223 if (!pkey) return NULL; 235 if (!pkey)
236 return NULL;
224 key = EVP_PKEY_get1_RSA(pkey); 237 key = EVP_PKEY_get1_RSA(pkey);
225 EVP_PKEY_free(pkey); 238 EVP_PKEY_free(pkey);
226 if (!key) return NULL; 239 if (!key)
240 return NULL;
227 *pp = q; 241 *pp = q;
228 if (a) { 242 if (a) {
229 RSA_free(*a); 243 RSA_free(*a);
@@ -232,11 +246,13 @@ RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp,
232 return key; 246 return key;
233} 247}
234 248
235int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) 249int
250i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
236{ 251{
237 EVP_PKEY *pktmp; 252 EVP_PKEY *pktmp;
238 int ret; 253 int ret;
239 if (!a) return 0; 254 if (!a)
255 return 0;
240 pktmp = EVP_PKEY_new(); 256 pktmp = EVP_PKEY_new();
241 if (!pktmp) { 257 if (!pktmp) {
242 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); 258 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
@@ -250,18 +266,20 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
250#endif 266#endif
251 267
252#ifndef OPENSSL_NO_DSA 268#ifndef OPENSSL_NO_DSA
253DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, 269DSA *
254 long length) 270d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length)
255{ 271{
256 EVP_PKEY *pkey; 272 EVP_PKEY *pkey;
257 DSA *key; 273 DSA *key;
258 const unsigned char *q; 274 const unsigned char *q;
259 q = *pp; 275 q = *pp;
260 pkey = d2i_PUBKEY(NULL, &q, length); 276 pkey = d2i_PUBKEY(NULL, &q, length);
261 if (!pkey) return NULL; 277 if (!pkey)
278 return NULL;
262 key = EVP_PKEY_get1_DSA(pkey); 279 key = EVP_PKEY_get1_DSA(pkey);
263 EVP_PKEY_free(pkey); 280 EVP_PKEY_free(pkey);
264 if (!key) return NULL; 281 if (!key)
282 return NULL;
265 *pp = q; 283 *pp = q;
266 if (a) { 284 if (a) {
267 DSA_free(*a); 285 DSA_free(*a);
@@ -270,13 +288,15 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp,
270 return key; 288 return key;
271} 289}
272 290
273int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) 291int
292i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
274{ 293{
275 EVP_PKEY *pktmp; 294 EVP_PKEY *pktmp;
276 int ret; 295 int ret;
277 if(!a) return 0; 296 if (!a)
297 return 0;
278 pktmp = EVP_PKEY_new(); 298 pktmp = EVP_PKEY_new();
279 if(!pktmp) { 299 if (!pktmp) {
280 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); 300 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
281 return 0; 301 return 0;
282 } 302 }
@@ -288,44 +308,49 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
288#endif 308#endif
289 309
290#ifndef OPENSSL_NO_EC 310#ifndef OPENSSL_NO_EC
291EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) 311EC_KEY *
312d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length)
292{ 313{
293 EVP_PKEY *pkey; 314 EVP_PKEY *pkey;
294 EC_KEY *key; 315 EC_KEY *key;
295 const unsigned char *q; 316 const unsigned char *q;
296 q = *pp; 317 q = *pp;
297 pkey = d2i_PUBKEY(NULL, &q, length); 318 pkey = d2i_PUBKEY(NULL, &q, length);
298 if (!pkey) return(NULL); 319 if (!pkey)
320 return (NULL);
299 key = EVP_PKEY_get1_EC_KEY(pkey); 321 key = EVP_PKEY_get1_EC_KEY(pkey);
300 EVP_PKEY_free(pkey); 322 EVP_PKEY_free(pkey);
301 if (!key) return(NULL); 323 if (!key)
324 return (NULL);
302 *pp = q; 325 *pp = q;
303 if (a) { 326 if (a) {
304 EC_KEY_free(*a); 327 EC_KEY_free(*a);
305 *a = key; 328 *a = key;
306 } 329 }
307 return(key); 330 return (key);
308} 331}
309 332
310int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) 333int
334i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
311{ 335{
312 EVP_PKEY *pktmp; 336 EVP_PKEY *pktmp;
313 int ret; 337 int ret;
314 if (!a) return(0); 338 if (!a)
339 return (0);
315 if ((pktmp = EVP_PKEY_new()) == NULL) { 340 if ((pktmp = EVP_PKEY_new()) == NULL) {
316 ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); 341 ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
317 return(0); 342 return (0);
318 } 343 }
319 EVP_PKEY_set1_EC_KEY(pktmp, a); 344 EVP_PKEY_set1_EC_KEY(pktmp, a);
320 ret = i2d_PUBKEY(pktmp, pp); 345 ret = i2d_PUBKEY(pktmp, pp);
321 EVP_PKEY_free(pktmp); 346 EVP_PKEY_free(pktmp);
322 return(ret); 347 return (ret);
323} 348}
324#endif 349#endif
325 350
326int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, 351int
327 int ptype, void *pval, 352X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, int ptype,
328 unsigned char *penc, int penclen) 353 void *pval, unsigned char *penc, int penclen)
329{ 354{
330 if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) 355 if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
331 return 0; 356 return 0;
@@ -334,17 +359,16 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
334 free(pub->public_key->data); 359 free(pub->public_key->data);
335 pub->public_key->data = penc; 360 pub->public_key->data = penc;
336 pub->public_key->length = penclen; 361 pub->public_key->length = penclen;
337 /* Set number of unused bits to zero */ 362 /* Set number of unused bits to zero */
338 pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); 363 pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
339 pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; 364 pub->public_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
340 } 365 }
341 return 1; 366 return 1;
342} 367}
343 368
344int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, 369int
345 const unsigned char **pk, int *ppklen, 370X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, const unsigned char **pk,
346 X509_ALGOR **pa, 371 int *ppklen, X509_ALGOR **pa, X509_PUBKEY *pub)
347 X509_PUBKEY *pub)
348{ 372{
349 if (ppkalg) 373 if (ppkalg)
350 *ppkalg = pub->algor->algorithm; 374 *ppkalg = pub->algor->algorithm;
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
index d57555827c..442f56a144 100644
--- a/src/lib/libcrypto/asn1/x_req.c
+++ b/src/lib/libcrypto/asn1/x_req.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -66,7 +66,7 @@
66 * encode the attributes field if it is empty. This is in 66 * encode the attributes field if it is empty. This is in
67 * violation of PKCS#10 but we need to tolerate it. We do 67 * violation of PKCS#10 but we need to tolerate it. We do
68 * this by making the attributes field OPTIONAL then using 68 * this by making the attributes field OPTIONAL then using
69 * the callback to initialise it to an empty STACK. 69 * the callback to initialise it to an empty STACK.
70 * 70 *
71 * This means that the field will be correctly encoded unless 71 * This means that the field will be correctly encoded unless
72 * we NULL out the field. 72 * we NULL out the field.
@@ -79,14 +79,15 @@
79 * 79 *
80 */ 80 */
81 81
82static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 82static int
83 void *exarg) 83rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
84{ 84{
85 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval; 85 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
86 86
87 if(operation == ASN1_OP_NEW_POST) { 87 if (operation == ASN1_OP_NEW_POST) {
88 rinf->attributes = sk_X509_ATTRIBUTE_new_null(); 88 rinf->attributes = sk_X509_ATTRIBUTE_new_null();
89 if(!rinf->attributes) return 0; 89 if (!rinf->attributes)
90 return 0;
90 } 91 }
91 return 1; 92 return 1;
92} 93}
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c
index 42efa86c1c..5c9aef0365 100644
--- a/src/lib/libcrypto/asn1/x_sig.c
+++ b/src/lib/libcrypto/asn1/x_sig.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c
index 2aece077c5..34fe81443c 100644
--- a/src/lib/libcrypto/asn1/x_spki.c
+++ b/src/lib/libcrypto/asn1/x_spki.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c
index dc17c67758..6436f0cb55 100644
--- a/src/lib/libcrypto/asn1/x_val.c
+++ b/src/lib/libcrypto/asn1/x_val.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
index 20448a8e3b..e7d613e20f 100644
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -81,15 +81,15 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
81 81
82extern void policy_cache_free(X509_POLICY_CACHE *cache); 82extern void policy_cache_free(X509_POLICY_CACHE *cache);
83 83
84static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 84static int
85 void *exarg) 85x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
86{ 86{
87 X509 *ret = (X509 *)*pval; 87 X509 *ret = (X509 *)*pval;
88 88
89 switch(operation) { 89 switch (operation) {
90 90
91 case ASN1_OP_NEW_POST: 91 case ASN1_OP_NEW_POST:
92 ret->valid=0; 92 ret->valid = 0;
93 ret->name = NULL; 93 ret->name = NULL;
94 ret->ex_flags = 0; 94 ret->ex_flags = 0;
95 ret->ex_pathlen = -1; 95 ret->ex_pathlen = -1;
@@ -105,8 +105,9 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
105 break; 105 break;
106 106
107 case ASN1_OP_D2I_POST: 107 case ASN1_OP_D2I_POST:
108 if (ret->name != NULL) free(ret->name); 108 if (ret->name != NULL)
109 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); 109 free(ret->name);
110 ret->name = X509_NAME_oneline(ret->cert_info->subject, NULL, 0);
110 break; 111 break;
111 112
112 case ASN1_OP_FREE_POST: 113 case ASN1_OP_FREE_POST:
@@ -122,14 +123,12 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
122 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free); 123 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
123 ASIdentifiers_free(ret->rfc3779_asid); 124 ASIdentifiers_free(ret->rfc3779_asid);
124#endif 125#endif
125 126 if (ret->name != NULL)
126 if (ret->name != NULL) free(ret->name); 127 free(ret->name);
127 break; 128 break;
128
129 } 129 }
130 130
131 return 1; 131 return 1;
132
133} 132}
134 133
135ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { 134ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
@@ -141,21 +140,24 @@ ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
141IMPLEMENT_ASN1_FUNCTIONS(X509) 140IMPLEMENT_ASN1_FUNCTIONS(X509)
142IMPLEMENT_ASN1_DUP_FUNCTION(X509) 141IMPLEMENT_ASN1_DUP_FUNCTION(X509)
143 142
144int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 143int
145 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 144X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
145 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
146{ 146{
147 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,
148 new_func, dup_func, free_func); 148 new_func, dup_func, free_func);
149} 149}
150 150
151int X509_set_ex_data(X509 *r, int idx, void *arg) 151int
152X509_set_ex_data(X509 *r, int idx, void *arg)
152{ 153{
153 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); 154 return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
154} 155}
155 156
156void *X509_get_ex_data(X509 *r, int idx) 157void *
158X509_get_ex_data(X509 *r, int idx)
157{ 159{
158 return(CRYPTO_get_ex_data(&r->ex_data,idx)); 160 return (CRYPTO_get_ex_data(&r->ex_data, idx));
159} 161}
160 162
161/* X509_AUX ASN1 routines. X509_AUX is the name given to 163/* X509_AUX ASN1 routines. X509_AUX is the name given to
@@ -166,29 +168,38 @@ void *X509_get_ex_data(X509 *r, int idx)
166 * 168 *
167 */ 169 */
168 170
169X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length) 171X509 *
172d2i_X509_AUX(X509 **a, const unsigned char **pp, long length)
170{ 173{
171 const unsigned char *q; 174 const unsigned char *q;
172 X509 *ret; 175 X509 *ret;
176
173 /* Save start position */ 177 /* Save start position */
174 q = *pp; 178 q = *pp;
175 ret = d2i_X509(a, pp, length); 179 ret = d2i_X509(a, pp, length);
176 /* If certificate unreadable then forget it */ 180 /* If certificate unreadable then forget it */
177 if(!ret) return NULL; 181 if (!ret)
182 return NULL;
178 /* update length */ 183 /* update length */
179 length -= *pp - q; 184 length -= *pp - q;
180 if(!length) return ret; 185 if (!length)
181 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err; 186 return ret;
187 if (!d2i_X509_CERT_AUX(&ret->aux, pp, length))
188 goto err;
182 return ret; 189 return ret;
183 err: 190
191err:
184 X509_free(ret); 192 X509_free(ret);
185 return NULL; 193 return NULL;
186} 194}
187 195
188int i2d_X509_AUX(X509 *a, unsigned char **pp) 196int
197i2d_X509_AUX(X509 *a, unsigned char **pp)
189{ 198{
190 int length; 199 int length;
200
191 length = i2d_X509(a, pp); 201 length = i2d_X509(a, pp);
192 if(a) length += i2d_X509_CERT_AUX(a->aux, pp); 202 if (a)
203 length += i2d_X509_CERT_AUX(a->aux, pp);
193 return length; 204 return length;
194} 205}
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
index 287d780830..69ea725709 100644
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ b/src/lib/libcrypto/asn1/x_x509a.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -66,7 +66,7 @@
66 * user modifiable data about a certificate. This data is 66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines 67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines 68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data. 69 * will simply ignore the extra data.
70 */ 70 */
71 71
72static X509_CERT_AUX *aux_get(X509 *x); 72static X509_CERT_AUX *aux_get(X509 *x);
@@ -81,14 +81,18 @@ ASN1_SEQUENCE(X509_CERT_AUX) = {
81 81
82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX) 82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
83 83
84static X509_CERT_AUX *aux_get(X509 *x) 84static X509_CERT_AUX *
85aux_get(X509 *x)
85{ 86{
86 if(!x) return NULL; 87 if (!x)
87 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL; 88 return NULL;
89 if (!x->aux && !(x->aux = X509_CERT_AUX_new()))
90 return NULL;
88 return x->aux; 91 return x->aux;
89} 92}
90 93
91int X509_alias_set1(X509 *x, unsigned char *name, int len) 94int
95X509_alias_set1(X509 *x, unsigned char *name, int len)
92{ 96{
93 X509_CERT_AUX *aux; 97 X509_CERT_AUX *aux;
94 if (!name) { 98 if (!name) {
@@ -98,12 +102,15 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len)
98 x->aux->alias = NULL; 102 x->aux->alias = NULL;
99 return 1; 103 return 1;
100 } 104 }
101 if(!(aux = aux_get(x))) return 0; 105 if (!(aux = aux_get(x)))
102 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; 106 return 0;
107 if (!aux->alias && !(aux->alias = ASN1_UTF8STRING_new()))
108 return 0;
103 return ASN1_STRING_set(aux->alias, name, len); 109 return ASN1_STRING_set(aux->alias, name, len);
104} 110}
105 111
106int X509_keyid_set1(X509 *x, unsigned char *id, int len) 112int
113X509_keyid_set1(X509 *x, unsigned char *id, int len)
107{ 114{
108 X509_CERT_AUX *aux; 115 X509_CERT_AUX *aux;
109 if (!id) { 116 if (!id) {
@@ -113,58 +120,74 @@ int X509_keyid_set1(X509 *x, unsigned char *id, int len)
113 x->aux->keyid = NULL; 120 x->aux->keyid = NULL;
114 return 1; 121 return 1;
115 } 122 }
116 if(!(aux = aux_get(x))) return 0; 123 if (!(aux = aux_get(x)))
117 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; 124 return 0;
125 if (!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new()))
126 return 0;
118 return ASN1_STRING_set(aux->keyid, id, len); 127 return ASN1_STRING_set(aux->keyid, id, len);
119} 128}
120 129
121unsigned char *X509_alias_get0(X509 *x, int *len) 130unsigned char *
131X509_alias_get0(X509 *x, int *len)
122{ 132{
123 if(!x->aux || !x->aux->alias) return NULL; 133 if (!x->aux || !x->aux->alias)
124 if(len) *len = x->aux->alias->length; 134 return NULL;
135 if (len)
136 *len = x->aux->alias->length;
125 return x->aux->alias->data; 137 return x->aux->alias->data;
126} 138}
127 139
128unsigned char *X509_keyid_get0(X509 *x, int *len) 140unsigned char *
141X509_keyid_get0(X509 *x, int *len)
129{ 142{
130 if(!x->aux || !x->aux->keyid) return NULL; 143 if (!x->aux || !x->aux->keyid)
131 if(len) *len = x->aux->keyid->length; 144 return NULL;
145 if (len)
146 *len = x->aux->keyid->length;
132 return x->aux->keyid->data; 147 return x->aux->keyid->data;
133} 148}
134 149
135int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj) 150int
151X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
136{ 152{
137 X509_CERT_AUX *aux; 153 X509_CERT_AUX *aux;
138 ASN1_OBJECT *objtmp; 154 ASN1_OBJECT *objtmp;
139 if(!(objtmp = OBJ_dup(obj))) return 0; 155 if (!(objtmp = OBJ_dup(obj)))
140 if(!(aux = aux_get(x))) return 0; 156 return 0;
141 if(!aux->trust 157 if (!(aux = aux_get(x)))
142 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0; 158 return 0;
159 if (!aux->trust && !(aux->trust = sk_ASN1_OBJECT_new_null()))
160 return 0;
143 return sk_ASN1_OBJECT_push(aux->trust, objtmp); 161 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
144} 162}
145 163
146int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj) 164int
165X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
147{ 166{
148 X509_CERT_AUX *aux; 167 X509_CERT_AUX *aux;
149 ASN1_OBJECT *objtmp; 168 ASN1_OBJECT *objtmp;
150 if(!(objtmp = OBJ_dup(obj))) return 0; 169 if (!(objtmp = OBJ_dup(obj)))
151 if(!(aux = aux_get(x))) return 0; 170 return 0;
152 if(!aux->reject 171 if (!(aux = aux_get(x)))
153 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0; 172 return 0;
173 if (!aux->reject && !(aux->reject = sk_ASN1_OBJECT_new_null()))
174 return 0;
154 return sk_ASN1_OBJECT_push(aux->reject, objtmp); 175 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
155} 176}
156 177
157void X509_trust_clear(X509 *x) 178void
179X509_trust_clear(X509 *x)
158{ 180{
159 if(x->aux && x->aux->trust) { 181 if (x->aux && x->aux->trust) {
160 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free); 182 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
161 x->aux->trust = NULL; 183 x->aux->trust = NULL;
162 } 184 }
163} 185}
164 186
165void X509_reject_clear(X509 *x) 187void
188X509_reject_clear(X509 *x)
166{ 189{
167 if(x->aux && x->aux->reject) { 190 if (x->aux && x->aux->reject) {
168 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free); 191 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
169 x->aux->reject = NULL; 192 x->aux->reject = NULL;
170 } 193 }
diff --git a/src/lib/libssl/src/crypto/asn1/x_algor.c b/src/lib/libssl/src/crypto/asn1/x_algor.c
index 7ae473485c..65f81e8692 100644
--- a/src/lib/libssl/src/crypto/asn1/x_algor.c
+++ b/src/lib/libssl/src/crypto/asn1/x_algor.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -66,8 +66,8 @@ ASN1_SEQUENCE(X509_ALGOR) = {
66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY) 66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
67} ASN1_SEQUENCE_END(X509_ALGOR) 67} ASN1_SEQUENCE_END(X509_ALGOR)
68 68
69ASN1_ITEM_TEMPLATE(X509_ALGORS) = 69ASN1_ITEM_TEMPLATE(X509_ALGORS) =
70 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR) 70 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR)
71ASN1_ITEM_TEMPLATE_END(X509_ALGORS) 71ASN1_ITEM_TEMPLATE_END(X509_ALGORS)
72 72
73IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) 73IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
@@ -77,7 +77,8 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
77IMPLEMENT_STACK_OF(X509_ALGOR) 77IMPLEMENT_STACK_OF(X509_ALGOR)
78IMPLEMENT_ASN1_SET_OF(X509_ALGOR) 78IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
79 79
80int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) 80int
81X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
81{ 82{
82 if (!alg) 83 if (!alg)
83 return 0; 84 return 0;
@@ -93,20 +94,20 @@ int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
93 alg->algorithm = aobj; 94 alg->algorithm = aobj;
94 } 95 }
95 if (ptype == 0) 96 if (ptype == 0)
96 return 1; 97 return 1;
97 if (ptype == V_ASN1_UNDEF) { 98 if (ptype == V_ASN1_UNDEF) {
98 if (alg->parameter) { 99 if (alg->parameter) {
99 ASN1_TYPE_free(alg->parameter); 100 ASN1_TYPE_free(alg->parameter);
100 alg->parameter = NULL; 101 alg->parameter = NULL;
101 } 102 }
102 } 103 } else
103 else
104 ASN1_TYPE_set(alg->parameter, ptype, pval); 104 ASN1_TYPE_set(alg->parameter, ptype, pval);
105 return 1; 105 return 1;
106} 106}
107 107
108void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, 108void
109 X509_ALGOR *algor) 109X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
110 X509_ALGOR *algor)
110{ 111{
111 if (paobj) 112 if (paobj)
112 *paobj = algor->algorithm; 113 *paobj = algor->algorithm;
@@ -114,8 +115,7 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
114 if (algor->parameter == NULL) { 115 if (algor->parameter == NULL) {
115 *pptype = V_ASN1_UNDEF; 116 *pptype = V_ASN1_UNDEF;
116 return; 117 return;
117 } 118 } else
118 else
119 *pptype = algor->parameter->type; 119 *pptype = algor->parameter->type;
120 if (ppval) 120 if (ppval)
121 *ppval = algor->parameter->value.ptr; 121 *ppval = algor->parameter->value.ptr;
@@ -124,7 +124,8 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
124 124
125/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */ 125/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */
126 126
127void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md) 127void
128X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)
128{ 129{
129 int param_type; 130 int param_type;
130 131
@@ -134,5 +135,4 @@ void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md)
134 param_type = V_ASN1_NULL; 135 param_type = V_ASN1_NULL;
135 136
136 X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL); 137 X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);
137
138} 138}
diff --git a/src/lib/libssl/src/crypto/asn1/x_attrib.c b/src/lib/libssl/src/crypto/asn1/x_attrib.c
index e620e1224e..248a6efa4e 100644
--- a/src/lib/libssl/src/crypto/asn1/x_attrib.c
+++ b/src/lib/libssl/src/crypto/asn1/x_attrib.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -96,23 +96,30 @@ ASN1_SEQUENCE(X509_ATTRIBUTE) = {
96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) 96IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) 97IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
98 98
99X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) 99X509_ATTRIBUTE *
100X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
100{ 101{
101 X509_ATTRIBUTE *ret=NULL; 102 X509_ATTRIBUTE *ret = NULL;
102 ASN1_TYPE *val=NULL; 103 ASN1_TYPE *val = NULL;
104
105 if ((ret = X509_ATTRIBUTE_new()) == NULL)
106 return (NULL);
107 ret->object = OBJ_nid2obj(nid);
108 ret->single = 0;
109 if ((ret->value.set = sk_ASN1_TYPE_new_null()) == NULL)
110 goto err;
111 if ((val = ASN1_TYPE_new()) == NULL)
112 goto err;
113 if (!sk_ASN1_TYPE_push(ret->value.set, val))
114 goto err;
103 115
104 if ((ret=X509_ATTRIBUTE_new()) == NULL) 116 ASN1_TYPE_set(val, atrtype, value);
105 return(NULL); 117 return (ret);
106 ret->object=OBJ_nid2obj(nid);
107 ret->single=0;
108 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
109 if ((val=ASN1_TYPE_new()) == NULL) goto err;
110 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
111 118
112 ASN1_TYPE_set(val,atrtype,value);
113 return(ret);
114err: 119err:
115 if (ret != NULL) X509_ATTRIBUTE_free(ret); 120 if (ret != NULL)
116 if (val != NULL) ASN1_TYPE_free(val); 121 X509_ATTRIBUTE_free(ret);
117 return(NULL); 122 if (val != NULL)
123 ASN1_TYPE_free(val);
124 return (NULL);
118} 125}
diff --git a/src/lib/libssl/src/crypto/asn1/x_bignum.c b/src/lib/libssl/src/crypto/asn1/x_bignum.c
index 9cf3204a1b..bc74164fdc 100644
--- a/src/lib/libssl/src/crypto/asn1/x_bignum.c
+++ b/src/lib/libssl/src/crypto/asn1/x_bignum.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -72,11 +72,14 @@
72static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 72static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
73static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 73static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
74 74
75static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 75static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
76static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 76 const ASN1_ITEM *it);
77static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
78 int utype, char *free_cont, const ASN1_ITEM *it);
77 79
78static ASN1_PRIMITIVE_FUNCS bignum_pf = { 80static ASN1_PRIMITIVE_FUNCS bignum_pf = {
79 NULL, 0, 81 NULL,
82 0,
80 bn_new, 83 bn_new,
81 bn_free, 84 bn_free,
82 0, 85 0,
@@ -85,55 +88,69 @@ static ASN1_PRIMITIVE_FUNCS bignum_pf = {
85}; 88};
86 89
87ASN1_ITEM_start(BIGNUM) 90ASN1_ITEM_start(BIGNUM)
88 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM" 91ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM"
89ASN1_ITEM_end(BIGNUM) 92ASN1_ITEM_end(BIGNUM)
90 93
91ASN1_ITEM_start(CBIGNUM) 94ASN1_ITEM_start(CBIGNUM)
92 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM" 95ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM"
93ASN1_ITEM_end(CBIGNUM) 96ASN1_ITEM_end(CBIGNUM)
94 97
95static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 98static int
99bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
96{ 100{
97 *pval = (ASN1_VALUE *)BN_new(); 101 *pval = (ASN1_VALUE *)BN_new();
98 if(*pval) return 1; 102 if (*pval)
99 else return 0; 103 return 1;
104 else
105 return 0;
100} 106}
101 107
102static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 108static void
109bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
103{ 110{
104 if(!*pval) return; 111 if (!*pval)
105 if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval); 112 return;
106 else BN_free((BIGNUM *)*pval); 113 if (it->size & BN_SENSITIVE)
114 BN_clear_free((BIGNUM *)*pval);
115 else
116 BN_free((BIGNUM *)*pval);
107 *pval = NULL; 117 *pval = NULL;
108} 118}
109 119
110static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) 120static int
121bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)
111{ 122{
112 BIGNUM *bn; 123 BIGNUM *bn;
113 int pad; 124 int pad;
114 if(!*pval) return -1; 125
126 if (!*pval)
127 return -1;
115 bn = (BIGNUM *)*pval; 128 bn = (BIGNUM *)*pval;
116 /* If MSB set in an octet we need a padding byte */ 129 /* If MSB set in an octet we need a padding byte */
117 if(BN_num_bits(bn) & 0x7) pad = 0; 130 if (BN_num_bits(bn) & 0x7)
118 else pad = 1; 131 pad = 0;
119 if(cont) { 132 else
120 if(pad) *cont++ = 0; 133 pad = 1;
134 if (cont) {
135 if (pad)
136 *cont++ = 0;
121 BN_bn2bin(bn, cont); 137 BN_bn2bin(bn, cont);
122 } 138 }
123 return pad + BN_num_bytes(bn); 139 return pad + BN_num_bytes(bn);
124} 140}
125 141
126static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 142static int
127 int utype, char *free_cont, const ASN1_ITEM *it) 143bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
144 char *free_cont, const ASN1_ITEM *it)
128{ 145{
129 BIGNUM *bn; 146 BIGNUM *bn;
130 if(!*pval) bn_new(pval, it); 147
131 bn = (BIGNUM *)*pval; 148 if (!*pval)
132 if(!BN_bin2bn(cont, len, bn)) { 149 bn_new(pval, it);
150 bn = (BIGNUM *)*pval;
151 if (!BN_bin2bn(cont, len, bn)) {
133 bn_free(pval, it); 152 bn_free(pval, it);
134 return 0; 153 return 0;
135 } 154 }
136 return 1; 155 return 1;
137} 156}
138
139
diff --git a/src/lib/libssl/src/crypto/asn1/x_crl.c b/src/lib/libssl/src/crypto/asn1/x_crl.c
index ea94f026b2..674cca4a1c 100644
--- a/src/lib/libssl/src/crypto/asn1/x_crl.c
+++ b/src/lib/libssl/src/crypto/asn1/x_crl.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -64,23 +64,23 @@
64#include <openssl/x509v3.h> 64#include <openssl/x509v3.h>
65 65
66static int X509_REVOKED_cmp(const X509_REVOKED * const *a, 66static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
67 const X509_REVOKED * const *b); 67 const X509_REVOKED * const *b);
68static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); 68static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
69 69
70ASN1_SEQUENCE(X509_REVOKED) = { 70ASN1_SEQUENCE(X509_REVOKED) = {
71 ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER), 71 ASN1_SIMPLE(X509_REVOKED, serialNumber, ASN1_INTEGER),
72 ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME), 72 ASN1_SIMPLE(X509_REVOKED, revocationDate, ASN1_TIME),
73 ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION) 73 ASN1_SEQUENCE_OF_OPT(X509_REVOKED, extensions, X509_EXTENSION)
74} ASN1_SEQUENCE_END(X509_REVOKED) 74} ASN1_SEQUENCE_END(X509_REVOKED)
75 75
76static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r); 76static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r);
77static int def_crl_lookup(X509_CRL *crl, 77static int def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret,
78 X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer); 78 ASN1_INTEGER *serial, X509_NAME *issuer);
79 79
80static X509_CRL_METHOD int_crl_meth = 80static X509_CRL_METHOD int_crl_meth = {
81{ 81 0,
82 0,
82 0, 83 0,
83 0,0,
84 def_crl_lookup, 84 def_crl_lookup,
85 def_crl_verify 85 def_crl_verify
86}; 86};
@@ -91,18 +91,19 @@ static const X509_CRL_METHOD *default_crl_method = &int_crl_meth;
91 * Since we cache the original encoding the signature wont be affected by 91 * Since we cache the original encoding the signature wont be affected by
92 * reordering of the revoked field. 92 * reordering of the revoked field.
93 */ 93 */
94static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 94static int
95 void *exarg) 95crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
96{ 96{
97 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; 97 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
98 98
99 if(!a || !a->revoked) return 1; 99 if (!a || !a->revoked)
100 switch(operation) { 100 return 1;
101 switch (operation) {
101 /* Just set cmp function here. We don't sort because that 102 /* Just set cmp function here. We don't sort because that
102 * would affect the output of X509_CRL_print(). 103 * would affect the output of X509_CRL_print().
103 */ 104 */
104 case ASN1_OP_D2I_POST: 105 case ASN1_OP_D2I_POST:
105 (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); 106 (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp);
106 break; 107 break;
107 } 108 }
108 return 1; 109 return 1;
@@ -123,9 +124,9 @@ ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
123 * Check for unhandled critical CRL entry extensions. 124 * Check for unhandled critical CRL entry extensions.
124 */ 125 */
125 126
126static int crl_set_issuers(X509_CRL *crl) 127static int
128crl_set_issuers(X509_CRL *crl)
127{ 129{
128
129 int i, j; 130 int i, j;
130 GENERAL_NAMES *gens, *gtmp; 131 GENERAL_NAMES *gens, *gtmp;
131 STACK_OF(X509_REVOKED) *revoked; 132 STACK_OF(X509_REVOKED) *revoked;
@@ -138,9 +139,8 @@ static int crl_set_issuers(X509_CRL *crl)
138 STACK_OF(X509_EXTENSION) *exts; 139 STACK_OF(X509_EXTENSION) *exts;
139 ASN1_ENUMERATED *reason; 140 ASN1_ENUMERATED *reason;
140 X509_EXTENSION *ext; 141 X509_EXTENSION *ext;
141 gtmp = X509_REVOKED_get_ext_d2i(rev, 142 gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer,
142 NID_certificate_issuer, 143 &j, NULL);
143 &j, NULL);
144 if (!gtmp && (j != -1)) { 144 if (!gtmp && (j != -1)) {
145 crl->flags |= EXFLAG_INVALID; 145 crl->flags |= EXFLAG_INVALID;
146 return 1; 146 return 1;
@@ -159,7 +159,7 @@ static int crl_set_issuers(X509_CRL *crl)
159 rev->issuer = gens; 159 rev->issuer = gens;
160 160
161 reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, 161 reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
162 &j, NULL); 162 &j, NULL);
163 if (!reason && (j != -1)) { 163 if (!reason && (j != -1)) {
164 crl->flags |= EXFLAG_INVALID; 164 crl->flags |= EXFLAG_INVALID;
165 return 1; 165 return 1;
@@ -169,7 +169,7 @@ static int crl_set_issuers(X509_CRL *crl)
169 rev->reason = ASN1_ENUMERATED_get(reason); 169 rev->reason = ASN1_ENUMERATED_get(reason);
170 ASN1_ENUMERATED_free(reason); 170 ASN1_ENUMERATED_free(reason);
171 } else 171 } else
172 rev->reason = CRL_REASON_NONE; 172 rev->reason = CRL_REASON_NONE;
173 173
174 /* Check for critical CRL entry extensions */ 174 /* Check for critical CRL entry extensions */
175 175
@@ -179,32 +179,29 @@ static int crl_set_issuers(X509_CRL *crl)
179 ext = sk_X509_EXTENSION_value(exts, j); 179 ext = sk_X509_EXTENSION_value(exts, j);
180 if (ext->critical > 0) { 180 if (ext->critical > 0) {
181 if (OBJ_obj2nid(ext->object) == 181 if (OBJ_obj2nid(ext->object) ==
182 NID_certificate_issuer) 182 NID_certificate_issuer)
183 continue; 183 continue;
184 crl->flags |= EXFLAG_CRITICAL; 184 crl->flags |= EXFLAG_CRITICAL;
185 break; 185 break;
186 } 186 }
187 } 187 }
188
189
190 } 188 }
191 189
192 return 1; 190 return 1;
193
194} 191}
195 192
196/* The X509_CRL structure needs a bit of customisation. Cache some extensions 193/* The X509_CRL structure needs a bit of customisation. Cache some extensions
197 * and hash of the whole CRL. 194 * and hash of the whole CRL.
198 */ 195 */
199static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 196static int
200 void *exarg) 197crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
201{ 198{
202 X509_CRL *crl = (X509_CRL *)*pval; 199 X509_CRL *crl = (X509_CRL *)*pval;
203 STACK_OF(X509_EXTENSION) *exts; 200 STACK_OF(X509_EXTENSION) *exts;
204 X509_EXTENSION *ext; 201 X509_EXTENSION *ext;
205 int idx; 202 int idx;
206 203
207 switch(operation) { 204 switch (operation) {
208 case ASN1_OP_NEW_POST: 205 case ASN1_OP_NEW_POST:
209 crl->idp = NULL; 206 crl->idp = NULL;
210 crl->akid = NULL; 207 crl->akid = NULL;
@@ -223,23 +220,23 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
223 X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL); 220 X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
224#endif 221#endif
225 crl->idp = X509_CRL_get_ext_d2i(crl, 222 crl->idp = X509_CRL_get_ext_d2i(crl,
226 NID_issuing_distribution_point, NULL, NULL); 223 NID_issuing_distribution_point, NULL, NULL);
227 if (crl->idp) 224 if (crl->idp)
228 setup_idp(crl, crl->idp); 225 setup_idp(crl, crl->idp);
229 226
230 crl->akid = X509_CRL_get_ext_d2i(crl, 227 crl->akid = X509_CRL_get_ext_d2i(crl,
231 NID_authority_key_identifier, NULL, NULL); 228 NID_authority_key_identifier, NULL, NULL);
232 229
233 crl->crl_number = X509_CRL_get_ext_d2i(crl, 230 crl->crl_number = X509_CRL_get_ext_d2i(crl,
234 NID_crl_number, NULL, NULL); 231 NID_crl_number, NULL, NULL);
235 232
236 crl->base_crl_number = X509_CRL_get_ext_d2i(crl, 233 crl->base_crl_number = X509_CRL_get_ext_d2i(crl,
237 NID_delta_crl, NULL, NULL); 234 NID_delta_crl, NULL, NULL);
238 /* Delta CRLs must have CRL number */ 235 /* Delta CRLs must have CRL number */
239 if (crl->base_crl_number && !crl->crl_number) 236 if (crl->base_crl_number && !crl->crl_number)
240 crl->flags |= EXFLAG_INVALID; 237 crl->flags |= EXFLAG_INVALID;
241 238
242 /* See if we have any unhandled critical CRL extensions and 239 /* See if we have any unhandled critical CRL extensions and
243 * indicate this in a flag. We only currently handle IDP so 240 * indicate this in a flag. We only currently handle IDP so
244 * anything else critical sets the flag. 241 * anything else critical sets the flag.
245 * 242 *
@@ -257,15 +254,14 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
257 crl->flags |= EXFLAG_FRESHEST; 254 crl->flags |= EXFLAG_FRESHEST;
258 if (ext->critical > 0) { 255 if (ext->critical > 0) {
259 /* We handle IDP and deltas */ 256 /* We handle IDP and deltas */
260 if ((nid == NID_issuing_distribution_point) 257 if ((nid == NID_issuing_distribution_point) ||
261 || (nid == NID_delta_crl)) 258 (nid == NID_delta_crl))
262 break;; 259 break;;
263 crl->flags |= EXFLAG_CRITICAL; 260 crl->flags |= EXFLAG_CRITICAL;
264 break; 261 break;
265 } 262 }
266 } 263 }
267 264
268
269 if (!crl_set_issuers(crl)) 265 if (!crl_set_issuers(crl))
270 return 0; 266 return 0;
271 267
@@ -294,9 +290,11 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
294 290
295/* Convert IDP into a more convenient form */ 291/* Convert IDP into a more convenient form */
296 292
297static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) 293static void
294setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
298{ 295{
299 int idp_only = 0; 296 int idp_only = 0;
297
300 /* Set various flags according to IDP */ 298 /* Set various flags according to IDP */
301 crl->idp_flags |= IDP_PRESENT; 299 crl->idp_flags |= IDP_PRESENT;
302 if (idp->onlyuser > 0) { 300 if (idp->onlyuser > 0) {
@@ -324,7 +322,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
324 crl->idp_reasons = idp->onlysomereasons->data[0]; 322 crl->idp_reasons = idp->onlysomereasons->data[0];
325 if (idp->onlysomereasons->length > 1) 323 if (idp->onlysomereasons->length > 1)
326 crl->idp_reasons |= 324 crl->idp_reasons |=
327 (idp->onlysomereasons->data[1] << 8); 325 (idp->onlysomereasons->data[1] << 8);
328 crl->idp_reasons &= CRLDP_ALL_REASONS; 326 crl->idp_reasons &= CRLDP_ALL_REASONS;
329 } 327 }
330 328
@@ -342,60 +340,65 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO)
342IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) 340IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)
343IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) 341IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL)
344 342
345static int X509_REVOKED_cmp(const X509_REVOKED * const *a, 343static int
346 const X509_REVOKED * const *b) 344X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
347{ 345{
348 return(ASN1_STRING_cmp( 346 return(ASN1_STRING_cmp(
349 (ASN1_STRING *)(*a)->serialNumber, 347 (ASN1_STRING *)(*a)->serialNumber,
350 (ASN1_STRING *)(*b)->serialNumber)); 348 (ASN1_STRING *)(*b)->serialNumber));
351} 349}
352 350
353int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) 351int
352X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
354{ 353{
355 X509_CRL_INFO *inf; 354 X509_CRL_INFO *inf;
355
356 inf = crl->crl; 356 inf = crl->crl;
357 if(!inf->revoked) 357 if (!inf->revoked)
358 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); 358 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
359 if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { 359 if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
360 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); 360 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
361 return 0; 361 return 0;
362} 362 }
363 inf->enc.modified = 1; 363 inf->enc.modified = 1;
364 return 1; 364 return 1;
365} 365}
366 366
367int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) 367int
368X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
368{ 369{
369 if (crl->meth->crl_verify) 370 if (crl->meth->crl_verify)
370 return crl->meth->crl_verify(crl, r); 371 return crl->meth->crl_verify(crl, r);
371 return 0; 372 return 0;
372} 373}
373 374
374int X509_CRL_get0_by_serial(X509_CRL *crl, 375int
375 X509_REVOKED **ret, ASN1_INTEGER *serial) 376X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **ret,
377 ASN1_INTEGER *serial)
376{ 378{
377 if (crl->meth->crl_lookup) 379 if (crl->meth->crl_lookup)
378 return crl->meth->crl_lookup(crl, ret, serial, NULL); 380 return crl->meth->crl_lookup(crl, ret, serial, NULL);
379 return 0; 381 return 0;
380} 382}
381 383
382int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) 384int
385X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x)
383{ 386{
384 if (crl->meth->crl_lookup) 387 if (crl->meth->crl_lookup)
385 return crl->meth->crl_lookup(crl, ret, 388 return crl->meth->crl_lookup(crl, ret,
386 X509_get_serialNumber(x), 389 X509_get_serialNumber(x), X509_get_issuer_name(x));
387 X509_get_issuer_name(x));
388 return 0; 390 return 0;
389} 391}
390 392
391static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) 393static int
394def_crl_verify(X509_CRL *crl, EVP_PKEY *r)
392{ 395{
393 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO), 396 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
394 crl->sig_alg, crl->signature,crl->crl,r)); 397 crl->sig_alg, crl->signature, crl->crl, r));
395} 398}
396 399
397static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, 400static int
398 X509_REVOKED *rev) 401crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, X509_REVOKED *rev)
399{ 402{
400 int i; 403 int i;
401 404
@@ -421,11 +424,13 @@ static int crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm,
421 424
422} 425}
423 426
424static int def_crl_lookup(X509_CRL *crl, 427static int
425 X509_REVOKED **ret, ASN1_INTEGER *serial, X509_NAME *issuer) 428def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret, ASN1_INTEGER *serial,
429 X509_NAME *issuer)
426{ 430{
427 X509_REVOKED rtmp, *rev; 431 X509_REVOKED rtmp, *rev;
428 int idx; 432 int idx;
433
429 rtmp.serialNumber = serial; 434 rtmp.serialNumber = serial;
430 /* Sort revoked into serial number order if not already sorted. 435 /* Sort revoked into serial number order if not already sorted.
431 * Do this under a lock to avoid race condition. 436 * Do this under a lock to avoid race condition.
@@ -436,10 +441,10 @@ static int def_crl_lookup(X509_CRL *crl,
436 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); 441 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
437 } 442 }
438 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); 443 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
439 if(idx < 0) 444 if (idx < 0)
440 return 0; 445 return 0;
441 /* Need to look for matching name */ 446 /* Need to look for matching name */
442 for(;idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) { 447 for (; idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) {
443 rev = sk_X509_REVOKED_value(crl->crl->revoked, idx); 448 rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
444 if (ASN1_INTEGER_cmp(rev->serialNumber, serial)) 449 if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
445 return 0; 450 return 0;
@@ -454,22 +459,24 @@ static int def_crl_lookup(X509_CRL *crl,
454 return 0; 459 return 0;
455} 460}
456 461
457void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) 462void
463X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
458{ 464{
459 if (meth == NULL) 465 if (meth == NULL)
460 default_crl_method = &int_crl_meth; 466 default_crl_method = &int_crl_meth;
461 else 467 else
462 default_crl_method = meth; 468 default_crl_method = meth;
463} 469}
464 470
465X509_CRL_METHOD *X509_CRL_METHOD_new( 471X509_CRL_METHOD *
466 int (*crl_init)(X509_CRL *crl), 472X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
467 int (*crl_free)(X509_CRL *crl), 473 int (*crl_free)(X509_CRL *crl),
468 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, 474 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
469 ASN1_INTEGER *ser, X509_NAME *issuer), 475 ASN1_INTEGER *ser, X509_NAME *issuer),
470 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) 476 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk))
471{ 477{
472 X509_CRL_METHOD *m; 478 X509_CRL_METHOD *m;
479
473 m = malloc(sizeof(X509_CRL_METHOD)); 480 m = malloc(sizeof(X509_CRL_METHOD));
474 if (!m) 481 if (!m)
475 return NULL; 482 return NULL;
@@ -481,19 +488,22 @@ X509_CRL_METHOD *X509_CRL_METHOD_new(
481 return m; 488 return m;
482} 489}
483 490
484void X509_CRL_METHOD_free(X509_CRL_METHOD *m) 491void
492X509_CRL_METHOD_free(X509_CRL_METHOD *m)
485{ 493{
486 if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) 494 if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
487 return; 495 return;
488 free(m); 496 free(m);
489} 497}
490 498
491void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) 499void
500X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
492{ 501{
493 crl->meth_data = dat; 502 crl->meth_data = dat;
494} 503}
495 504
496void *X509_CRL_get_meth_data(X509_CRL *crl) 505void *
506X509_CRL_get_meth_data(X509_CRL *crl)
497{ 507{
498 return crl->meth_data; 508 return crl->meth_data;
499} 509}
diff --git a/src/lib/libssl/src/crypto/asn1/x_exten.c b/src/lib/libssl/src/crypto/asn1/x_exten.c
index 3a21239926..5b3f49ed0f 100644
--- a/src/lib/libssl/src/crypto/asn1/x_exten.c
+++ b/src/lib/libssl/src/crypto/asn1/x_exten.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -67,8 +67,8 @@ ASN1_SEQUENCE(X509_EXTENSION) = {
67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING) 67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
68} ASN1_SEQUENCE_END(X509_EXTENSION) 68} ASN1_SEQUENCE_END(X509_EXTENSION)
69 69
70ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) = 70ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) =
71 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION) 71 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION)
72ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS) 72ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS)
73 73
74IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION) 74IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
diff --git a/src/lib/libssl/src/crypto/asn1/x_info.c b/src/lib/libssl/src/crypto/asn1/x_info.c
index 07ce15dbd7..4d3e2ebd17 100644
--- a/src/lib/libssl/src/crypto/asn1/x_info.c
+++ b/src/lib/libssl/src/crypto/asn1/x_info.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -62,42 +62,49 @@
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65X509_INFO *X509_INFO_new(void) 65X509_INFO *
66X509_INFO_new(void)
66{ 67{
67 X509_INFO *ret=NULL; 68 X509_INFO *ret = NULL;
68 69
69 ret=(X509_INFO *)malloc(sizeof(X509_INFO)); 70 ret = (X509_INFO *)malloc(sizeof(X509_INFO));
70 if (ret == NULL) { 71 if (ret == NULL) {
71 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); 72 ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE);
72 return(NULL); 73 return (NULL);
73 } 74 }
74 75
75 ret->enc_cipher.cipher=NULL; 76 ret->enc_cipher.cipher = NULL;
76 ret->enc_len=0; 77 ret->enc_len = 0;
77 ret->enc_data=NULL; 78 ret->enc_data = NULL;
78 79
79 ret->references=1; 80 ret->references = 1;
80 ret->x509=NULL; 81 ret->x509 = NULL;
81 ret->crl=NULL; 82 ret->crl = NULL;
82 ret->x_pkey=NULL; 83 ret->x_pkey = NULL;
83 return(ret); 84 return (ret);
84} 85}
85 86
86void X509_INFO_free(X509_INFO *x) 87void
88X509_INFO_free(X509_INFO *x)
87{ 89{
88 int i; 90 int i;
89 91
90 if (x == NULL) return; 92 if (x == NULL)
93 return;
91 94
92 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO); 95 i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
93 if (i > 0) return; 96 if (i > 0)
97 return;
94 98
95 if (x->x509 != NULL) X509_free(x->x509); 99 if (x->x509 != NULL)
96 if (x->crl != NULL) X509_CRL_free(x->crl); 100 X509_free(x->x509);
97 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); 101 if (x->crl != NULL)
98 if (x->enc_data != NULL) free(x->enc_data); 102 X509_CRL_free(x->crl);
103 if (x->x_pkey != NULL)
104 X509_PKEY_free(x->x_pkey);
105 if (x->enc_data != NULL)
106 free(x->enc_data);
99 free(x); 107 free(x);
100} 108}
101 109
102IMPLEMENT_STACK_OF(X509_INFO) 110IMPLEMENT_STACK_OF(X509_INFO)
103
diff --git a/src/lib/libssl/src/crypto/asn1/x_long.c b/src/lib/libssl/src/crypto/asn1/x_long.c
index 1417284d3c..81dcc4fc29 100644
--- a/src/lib/libssl/src/crypto/asn1/x_long.c
+++ b/src/lib/libssl/src/crypto/asn1/x_long.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -84,25 +84,29 @@ static ASN1_PRIMITIVE_FUNCS long_pf = {
84}; 84};
85 85
86ASN1_ITEM_start(LONG) 86ASN1_ITEM_start(LONG)
87 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG" 87ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG"
88ASN1_ITEM_end(LONG) 88ASN1_ITEM_end(LONG)
89 89
90ASN1_ITEM_start(ZLONG) 90ASN1_ITEM_start(ZLONG)
91 ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG" 91ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG"
92ASN1_ITEM_end(ZLONG) 92ASN1_ITEM_end(ZLONG)
93 93
94static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 94static int
95long_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
95{ 96{
96 *(long *)pval = it->size; 97 *(long *)pval = it->size;
97 return 1; 98 return 1;
98} 99}
99 100
100static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 101static void
102long_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
101{ 103{
102 *(long *)pval = it->size; 104 *(long *)pval = it->size;
103} 105}
104 106
105static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) 107static int
108long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype,
109 const ASN1_ITEM *it)
106{ 110{
107 long ltmp; 111 long ltmp;
108 unsigned long utmp; 112 unsigned long utmp;
@@ -113,58 +117,70 @@ static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const A
113 /* use memcpy, because we may not be long aligned */ 117 /* use memcpy, because we may not be long aligned */
114 memcpy(&ltmp, cp, sizeof(long)); 118 memcpy(&ltmp, cp, sizeof(long));
115 119
116 if(ltmp == it->size) return -1; 120 if (ltmp == it->size)
121 return -1;
117 /* Convert the long to positive: we subtract one if negative so 122 /* Convert the long to positive: we subtract one if negative so
118 * we can cleanly handle the padding if only the MSB of the leading 123 * we can cleanly handle the padding if only the MSB of the leading
119 * octet is set. 124 * octet is set.
120 */ 125 */
121 if(ltmp < 0) utmp = -ltmp - 1; 126 if (ltmp < 0)
122 else utmp = ltmp; 127 utmp = -ltmp - 1;
128 else
129 utmp = ltmp;
123 clen = BN_num_bits_word(utmp); 130 clen = BN_num_bits_word(utmp);
124 /* If MSB of leading octet set we need to pad */ 131 /* If MSB of leading octet set we need to pad */
125 if(!(clen & 0x7)) pad = 1; 132 if (!(clen & 0x7))
126 else pad = 0; 133 pad = 1;
134 else
135 pad = 0;
127 136
128 /* Convert number of bits to number of octets */ 137 /* Convert number of bits to number of octets */
129 clen = (clen + 7) >> 3; 138 clen = (clen + 7) >> 3;
130 139
131 if(cont) { 140 if (cont) {
132 if(pad) *cont++ = (ltmp < 0) ? 0xff : 0; 141 if (pad)
133 for(i = clen - 1; i >= 0; i--) { 142 *cont++ = (ltmp < 0) ? 0xff : 0;
143 for (i = clen - 1; i >= 0; i--) {
134 cont[i] = (unsigned char)(utmp & 0xff); 144 cont[i] = (unsigned char)(utmp & 0xff);
135 if(ltmp < 0) cont[i] ^= 0xff; 145 if (ltmp < 0)
146 cont[i] ^= 0xff;
136 utmp >>= 8; 147 utmp >>= 8;
137 } 148 }
138 } 149 }
139 return clen + pad; 150 return clen + pad;
140} 151}
141 152
142static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 153static int
143 int utype, char *free_cont, const ASN1_ITEM *it) 154long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
155 char *free_cont, const ASN1_ITEM *it)
144{ 156{
145 int neg, i; 157 int neg, i;
146 long ltmp; 158 long ltmp;
147 unsigned long utmp = 0; 159 unsigned long utmp = 0;
148 char *cp = (char *)pval; 160 char *cp = (char *)pval;
149 if(len > (int)sizeof(long)) { 161 if (len > (int)sizeof(long)) {
150 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 162 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
151 return 0; 163 return 0;
152 } 164 }
153 /* Is it negative? */ 165 /* Is it negative? */
154 if(len && (cont[0] & 0x80)) neg = 1; 166 if (len && (cont[0] & 0x80))
155 else neg = 0; 167 neg = 1;
168 else
169 neg = 0;
156 utmp = 0; 170 utmp = 0;
157 for(i = 0; i < len; i++) { 171 for (i = 0; i < len; i++) {
158 utmp <<= 8; 172 utmp <<= 8;
159 if(neg) utmp |= cont[i] ^ 0xff; 173 if (neg)
160 else utmp |= cont[i]; 174 utmp |= cont[i] ^ 0xff;
175 else
176 utmp |= cont[i];
161 } 177 }
162 ltmp = (long)utmp; 178 ltmp = (long)utmp;
163 if(neg) { 179 if (neg) {
164 ltmp++; 180 ltmp++;
165 ltmp = -ltmp; 181 ltmp = -ltmp;
166 } 182 }
167 if(ltmp == it->size) { 183 if (ltmp == it->size) {
168 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 184 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
169 return 0; 185 return 0;
170 } 186 }
@@ -172,8 +188,9 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
172 return 1; 188 return 1;
173} 189}
174 190
175static int long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, 191static int
176 int indent, const ASN1_PCTX *pctx) 192long_print(BIO *out, ASN1_VALUE **pval, const ASN1_ITEM *it, int indent,
193 const ASN1_PCTX *pctx)
177{ 194{
178 return BIO_printf(out, "%ld\n", *(long *)pval); 195 return BIO_printf(out, "%ld\n", *(long *)pval);
179} 196}
diff --git a/src/lib/libssl/src/crypto/asn1/x_name.c b/src/lib/libssl/src/crypto/asn1/x_name.c
index d10ac5acd1..70459babc4 100644
--- a/src/lib/libssl/src/crypto/asn1/x_name.c
+++ b/src/lib/libssl/src/crypto/asn1/x_name.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -66,13 +66,12 @@
66typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; 66typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
67DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY) 67DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
68 68
69static int x509_name_ex_d2i(ASN1_VALUE **val, 69static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
70 const unsigned char **in, long len, 70 long len, const ASN1_ITEM *it, int tag, int aclass, char opt,
71 const ASN1_ITEM *it, 71 ASN1_TLC *ctx);
72 int tag, int aclass, char opt, ASN1_TLC *ctx);
73 72
74static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, 73static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out,
75 const ASN1_ITEM *it, int tag, int aclass); 74 const ASN1_ITEM *it, int tag, int aclass);
76static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it); 75static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);
77static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); 76static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);
78 77
@@ -80,13 +79,10 @@ static int x509_name_encode(X509_NAME *a);
80static int x509_name_canon(X509_NAME *a); 79static int x509_name_canon(X509_NAME *a);
81static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in); 80static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in);
82static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname, 81static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname,
83 unsigned char **in); 82 unsigned char **in);
84 83
85 84static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent,
86static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, 85 const char *fname, const ASN1_PCTX *pctx);
87 int indent,
88 const char *fname,
89 const ASN1_PCTX *pctx);
90 86
91ASN1_SEQUENCE(X509_NAME_ENTRY) = { 87ASN1_SEQUENCE(X509_NAME_ENTRY) = {
92 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT), 88 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),
@@ -101,11 +97,11 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY)
101 */ 97 */
102 98
103ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) = 99ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) =
104 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY) 100 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY)
105ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES) 101ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES)
106 102
107ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) = 103ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) =
108 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES) 104 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES)
109ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL) 105ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL)
110 106
111/* Normally that's where it would end: we'd have two nested STACK structures 107/* Normally that's where it would end: we'd have two nested STACK structures
@@ -124,26 +120,30 @@ const ASN1_EXTERN_FUNCS x509_name_ff = {
124 x509_name_ex_print 120 x509_name_ex_print
125}; 121};
126 122
127IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff) 123IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff)
128 124
129IMPLEMENT_ASN1_FUNCTIONS(X509_NAME) 125IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)
130IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME) 126IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
131 127
132static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) 128static int
129x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
133{ 130{
134 X509_NAME *ret = NULL; 131 X509_NAME *ret = NULL;
132
135 ret = malloc(sizeof(X509_NAME)); 133 ret = malloc(sizeof(X509_NAME));
136 if(!ret) goto memerr; 134 if (!ret)
137 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL) 135 goto memerr;
136 if ((ret->entries = sk_X509_NAME_ENTRY_new_null()) == NULL)
137 goto memerr;
138 if ((ret->bytes = BUF_MEM_new()) == NULL)
138 goto memerr; 139 goto memerr;
139 if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr;
140 ret->canon_enc = NULL; 140 ret->canon_enc = NULL;
141 ret->canon_enclen = 0; 141 ret->canon_enclen = 0;
142 ret->modified=1; 142 ret->modified = 1;
143 *val = (ASN1_VALUE *)ret; 143 *val = (ASN1_VALUE *)ret;
144 return 1; 144 return 1;
145 145
146 memerr: 146memerr:
147 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); 147 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE);
148 if (ret) { 148 if (ret) {
149 if (ret->entries) 149 if (ret->entries)
@@ -153,54 +153,64 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
153 return 0; 153 return 0;
154} 154}
155 155
156static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 156static void
157x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
157{ 158{
158 X509_NAME *a; 159 X509_NAME *a;
159 if(!pval || !*pval) 160
160 return; 161 if (!pval || !*pval)
162 return;
161 a = (X509_NAME *)*pval; 163 a = (X509_NAME *)*pval;
162 164
163 BUF_MEM_free(a->bytes); 165 BUF_MEM_free(a->bytes);
164 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free); 166 sk_X509_NAME_ENTRY_pop_free(a->entries, X509_NAME_ENTRY_free);
165 if (a->canon_enc) 167 if (a->canon_enc)
166 free(a->canon_enc); 168 free(a->canon_enc);
167 free(a); 169 free(a);
168 *pval = NULL; 170 *pval = NULL;
169} 171}
170 172
171static int x509_name_ex_d2i(ASN1_VALUE **val, 173static int
172 const unsigned char **in, long len, const ASN1_ITEM *it, 174x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
173 int tag, int aclass, char opt, ASN1_TLC *ctx) 175 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
174{ 176{
175 const unsigned char *p = *in, *q; 177 const unsigned char *p = *in, *q;
176 union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; 178 union {
177 ASN1_VALUE *a; } intname = {NULL}; 179 STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
178 union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL}; 180 ASN1_VALUE *a;
181 } intname = {NULL};
182 union {
183 X509_NAME *x;
184 ASN1_VALUE *a;
185 } nm = {NULL};
179 int i, j, ret; 186 int i, j, ret;
180 STACK_OF(X509_NAME_ENTRY) *entries; 187 STACK_OF(X509_NAME_ENTRY) *entries;
181 X509_NAME_ENTRY *entry; 188 X509_NAME_ENTRY *entry;
182 q = p; 189 q = p;
183 190
184 /* Get internal representation of Name */ 191 /* Get internal representation of Name */
185 ret = ASN1_item_ex_d2i(&intname.a, 192 ret = ASN1_item_ex_d2i(&intname.a, &p, len,
186 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), 193 ASN1_ITEM_rptr(X509_NAME_INTERNAL), tag, aclass, opt, ctx);
187 tag, aclass, opt, ctx); 194
188 195 if (ret <= 0)
189 if(ret <= 0) return ret; 196 return ret;
190 197
191 if(*val) x509_name_ex_free(val, NULL); 198 if (*val)
192 if(!x509_name_ex_new(&nm.a, NULL)) goto err; 199 x509_name_ex_free(val, NULL);
200 if (!x509_name_ex_new(&nm.a, NULL))
201 goto err;
193 /* We've decoded it: now cache encoding */ 202 /* We've decoded it: now cache encoding */
194 if(!BUF_MEM_grow(nm.x->bytes, p - q)) goto err; 203 if (!BUF_MEM_grow(nm.x->bytes, p - q))
204 goto err;
195 memcpy(nm.x->bytes->data, q, p - q); 205 memcpy(nm.x->bytes->data, q, p - q);
196 206
197 /* Convert internal representation to X509_NAME structure */ 207 /* Convert internal representation to X509_NAME structure */
198 for(i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) { 208 for (i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) {
199 entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i); 209 entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i);
200 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { 210 for (j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
201 entry = sk_X509_NAME_ENTRY_value(entries, j); 211 entry = sk_X509_NAME_ENTRY_value(entries, j);
202 entry->set = i; 212 entry->set = i;
203 if(!sk_X509_NAME_ENTRY_push(nm.x->entries, entry)) 213 if (!sk_X509_NAME_ENTRY_push(nm.x->entries, entry))
204 goto err; 214 goto err;
205 } 215 }
206 sk_X509_NAME_ENTRY_free(entries); 216 sk_X509_NAME_ENTRY_free(entries);
@@ -213,90 +223,104 @@ static int x509_name_ex_d2i(ASN1_VALUE **val,
213 *val = nm.a; 223 *val = nm.a;
214 *in = p; 224 *in = p;
215 return ret; 225 return ret;
226
216err: 227err:
217 if (nm.x != NULL) 228 if (nm.x != NULL)
218 X509_NAME_free(nm.x); 229 X509_NAME_free(nm.x);
219 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR); 230 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
220 return 0; 231 return 0;
221} 232}
222 233
223static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) 234static int
235x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it,
236 int tag, int aclass)
224{ 237{
225 int ret; 238 int ret;
226 X509_NAME *a = (X509_NAME *)*val; 239 X509_NAME *a = (X509_NAME *)*val;
227 if(a->modified) { 240
241 if (a->modified) {
228 ret = x509_name_encode(a); 242 ret = x509_name_encode(a);
229 if(ret < 0) 243 if (ret < 0)
230 return ret; 244 return ret;
231 ret = x509_name_canon(a); 245 ret = x509_name_canon(a);
232 if(ret < 0) 246 if (ret < 0)
233 return ret; 247 return ret;
234 } 248 }
235 ret = a->bytes->length; 249 ret = a->bytes->length;
236 if(out != NULL) { 250 if (out != NULL) {
237 memcpy(*out,a->bytes->data,ret); 251 memcpy(*out, a->bytes->data, ret);
238 *out+=ret; 252 *out += ret;
239 } 253 }
240 return ret; 254 return ret;
241} 255}
242 256
243static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne) 257static void
258local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne)
244{ 259{
245 sk_X509_NAME_ENTRY_free(ne); 260 sk_X509_NAME_ENTRY_free(ne);
246} 261}
247 262
248static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne) 263static void
264local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne)
249{ 265{
250 sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free); 266 sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free);
251} 267}
252 268
253static int x509_name_encode(X509_NAME *a) 269static int
270x509_name_encode(X509_NAME *a)
254{ 271{
255 union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; 272 union {
256 ASN1_VALUE *a; } intname = {NULL}; 273 STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;
274 ASN1_VALUE *a;
275 } intname = {NULL};
257 int len; 276 int len;
258 unsigned char *p; 277 unsigned char *p;
259 STACK_OF(X509_NAME_ENTRY) *entries = NULL; 278 STACK_OF(X509_NAME_ENTRY) *entries = NULL;
260 X509_NAME_ENTRY *entry; 279 X509_NAME_ENTRY *entry;
261 int i, set = -1; 280 int i, set = -1;
281
262 intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null(); 282 intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();
263 if(!intname.s) goto memerr; 283 if (!intname.s)
264 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { 284 goto memerr;
285 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
265 entry = sk_X509_NAME_ENTRY_value(a->entries, i); 286 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
266 if(entry->set != set) { 287 if (entry->set != set) {
267 entries = sk_X509_NAME_ENTRY_new_null(); 288 entries = sk_X509_NAME_ENTRY_new_null();
268 if(!entries) goto memerr; 289 if (!entries)
269 if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, 290 goto memerr;
270 entries)) 291 if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s,
292 entries))
271 goto memerr; 293 goto memerr;
272 set = entry->set; 294 set = entry->set;
273 } 295 }
274 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; 296 if (!sk_X509_NAME_ENTRY_push(entries, entry))
297 goto memerr;
275 } 298 }
276 len = ASN1_item_ex_i2d(&intname.a, NULL, 299 len = ASN1_item_ex_i2d(&intname.a, NULL,
277 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); 300 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
278 if (!BUF_MEM_grow(a->bytes,len)) goto memerr; 301 if (!BUF_MEM_grow(a->bytes, len))
279 p=(unsigned char *)a->bytes->data; 302 goto memerr;
280 ASN1_item_ex_i2d(&intname.a, 303 p = (unsigned char *)a->bytes->data;
281 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); 304 ASN1_item_ex_i2d(&intname.a, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
305 -1, -1);
282 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, 306 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
283 local_sk_X509_NAME_ENTRY_free); 307 local_sk_X509_NAME_ENTRY_free);
284 a->modified = 0; 308 a->modified = 0;
285 return len; 309 return len;
310
286memerr: 311memerr:
287 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, 312 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
288 local_sk_X509_NAME_ENTRY_free); 313 local_sk_X509_NAME_ENTRY_free);
289 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); 314 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);
290 return -1; 315 return -1;
291} 316}
292 317
293static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, 318static int
294 int indent, 319x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent, const char *fname,
295 const char *fname, 320 const ASN1_PCTX *pctx)
296 const ASN1_PCTX *pctx)
297{ 321{
298 if (X509_NAME_print_ex(out, (X509_NAME *)*pval, 322 if (X509_NAME_print_ex(out, (X509_NAME *)*pval, indent,
299 indent, pctx->nm_flags) <= 0) 323 pctx->nm_flags) <= 0)
300 return 0; 324 return 0;
301 return 2; 325 return 2;
302} 326}
@@ -314,7 +338,8 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,
314 * dirName can also be checked with a simple memcmp(). 338 * dirName can also be checked with a simple memcmp().
315 */ 339 */
316 340
317static int x509_name_canon(X509_NAME *a) 341static int
342x509_name_canon(X509_NAME *a)
318{ 343{
319 unsigned char *p; 344 unsigned char *p;
320 STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL; 345 STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL;
@@ -325,22 +350,22 @@ static int x509_name_canon(X509_NAME *a)
325 if (a->canon_enc) { 350 if (a->canon_enc) {
326 free(a->canon_enc); 351 free(a->canon_enc);
327 a->canon_enc = NULL; 352 a->canon_enc = NULL;
328 } 353 }
329 /* Special case: empty X509_NAME => null encoding */ 354 /* Special case: empty X509_NAME => null encoding */
330 if (sk_X509_NAME_ENTRY_num(a->entries) == 0) { 355 if (sk_X509_NAME_ENTRY_num(a->entries) == 0) {
331 a->canon_enclen = 0; 356 a->canon_enclen = 0;
332 return 1; 357 return 1;
333 } 358 }
334 intname = sk_STACK_OF_X509_NAME_ENTRY_new_null(); 359 intname = sk_STACK_OF_X509_NAME_ENTRY_new_null();
335 if(!intname) 360 if (!intname)
336 goto err; 361 goto err;
337 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { 362 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
338 entry = sk_X509_NAME_ENTRY_value(a->entries, i); 363 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
339 if(entry->set != set) { 364 if (entry->set != set) {
340 entries = sk_X509_NAME_ENTRY_new_null(); 365 entries = sk_X509_NAME_ENTRY_new_null();
341 if(!entries) 366 if (!entries)
342 goto err; 367 goto err;
343 if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) 368 if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries))
344 goto err; 369 goto err;
345 set = entry->set; 370 set = entry->set;
346 } 371 }
@@ -348,33 +373,27 @@ static int x509_name_canon(X509_NAME *a)
348 tmpentry->object = OBJ_dup(entry->object); 373 tmpentry->object = OBJ_dup(entry->object);
349 if (!asn1_string_canon(tmpentry->value, entry->value)) 374 if (!asn1_string_canon(tmpentry->value, entry->value))
350 goto err; 375 goto err;
351 if(!sk_X509_NAME_ENTRY_push(entries, tmpentry)) 376 if (!sk_X509_NAME_ENTRY_push(entries, tmpentry))
352 goto err; 377 goto err;
353 tmpentry = NULL; 378 tmpentry = NULL;
354 } 379 }
355 380
356 /* Finally generate encoding */ 381 /* Finally generate encoding */
357
358 a->canon_enclen = i2d_name_canon(intname, NULL); 382 a->canon_enclen = i2d_name_canon(intname, NULL);
359
360 p = malloc(a->canon_enclen); 383 p = malloc(a->canon_enclen);
361
362 if (!p) 384 if (!p)
363 goto err; 385 goto err;
364
365 a->canon_enc = p; 386 a->canon_enc = p;
366
367 i2d_name_canon(intname, &p); 387 i2d_name_canon(intname, &p);
368
369 ret = 1; 388 ret = 1;
370 389
371 err: 390err:
372 391
373 if (tmpentry) 392 if (tmpentry)
374 X509_NAME_ENTRY_free(tmpentry); 393 X509_NAME_ENTRY_free(tmpentry);
375 if (intname) 394 if (intname)
376 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, 395 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,
377 local_sk_X509_NAME_ENTRY_pop_free); 396 local_sk_X509_NAME_ENTRY_pop_free);
378 return ret; 397 return ret;
379} 398}
380 399
@@ -384,9 +403,10 @@ static int x509_name_canon(X509_NAME *a)
384 (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \ 403 (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \
385 | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \ 404 | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \
386 | B_ASN1_VISIBLESTRING) 405 | B_ASN1_VISIBLESTRING)
387
388 406
389static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) 407
408static int
409asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
390{ 410{
391 unsigned char *to, *from; 411 unsigned char *to, *from;
392 int len, i; 412 int len, i;
@@ -415,7 +435,7 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
415 */ 435 */
416 436
417 /* Ignore leading spaces */ 437 /* Ignore leading spaces */
418 while((len > 0) && !(*from & 0x80) && isspace(*from)) { 438 while ((len > 0) && !(*from & 0x80) && isspace(*from)) {
419 from++; 439 from++;
420 len--; 440 len--;
421 } 441 }
@@ -431,24 +451,24 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
431 to = out->data; 451 to = out->data;
432 452
433 i = 0; 453 i = 0;
434 while(i < len) { 454 while (i < len) {
435 /* If MSB set just copy across */ 455 /* If MSB set just copy across */
436 if (*from & 0x80) { 456 if (*from & 0x80) {
437 *to++ = *from++; 457 *to++ = *from++;
438 i++; 458 i++;
439 } 459 }
440 /* Collapse multiple spaces */ 460 /* Collapse multiple spaces */
441 else if (isspace(*from)) { 461 else if (isspace(*from)) {
442 /* Copy one space across */ 462 /* Copy one space across */
443 *to++ = ' '; 463 *to++ = ' ';
444 /* Ignore subsequent spaces. Note: don't need to 464 /* Ignore subsequent spaces. Note: don't need to
445 * check len here because we know the last 465 * check len here because we know the last
446 * character is a non-space so we can't overflow. 466 * character is a non-space so we can't overflow.
447 */ 467 */
448 do { 468 do {
449 from++; 469 from++;
450 i++; 470 i++;
451 } while(!(*from & 0x80) && isspace(*from)); 471 } while (!(*from & 0x80) && isspace(*from));
452 } else { 472 } else {
453 *to++ = tolower(*from); 473 *to++ = tolower(*from);
454 from++; 474 from++;
@@ -459,11 +479,10 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in)
459 out->length = to - out->data; 479 out->length = to - out->data;
460 480
461 return 1; 481 return 1;
462
463} 482}
464 483
465static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, 484static int
466 unsigned char **in) 485i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, unsigned char **in)
467{ 486{
468 int i, len, ltmp; 487 int i, len, ltmp;
469 ASN1_VALUE *v; 488 ASN1_VALUE *v;
@@ -473,7 +492,7 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
473 for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) { 492 for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) {
474 v = sk_ASN1_VALUE_value(intname, i); 493 v = sk_ASN1_VALUE_value(intname, i);
475 ltmp = ASN1_item_ex_i2d(&v, in, 494 ltmp = ASN1_item_ex_i2d(&v, in,
476 ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1); 495 ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1);
477 if (ltmp < 0) 496 if (ltmp < 0)
478 return ltmp; 497 return ltmp;
479 len += ltmp; 498 len += ltmp;
@@ -481,21 +500,23 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname,
481 return len; 500 return len;
482} 501}
483 502
484int X509_NAME_set(X509_NAME **xn, X509_NAME *name) 503int
504X509_NAME_set(X509_NAME **xn, X509_NAME *name)
485{ 505{
486 X509_NAME *in; 506 X509_NAME *in;
487 507
488 if (!xn || !name) return(0); 508 if (!xn || !name)
509 return (0);
489 510
490 if (*xn != name) { 511 if (*xn != name) {
491 in=X509_NAME_dup(name); 512 in = X509_NAME_dup(name);
492 if (in != NULL) { 513 if (in != NULL) {
493 X509_NAME_free(*xn); 514 X509_NAME_free(*xn);
494 *xn=in; 515 *xn = in;
495 } 516 }
496 } 517 }
497 return(*xn != NULL); 518 return (*xn != NULL);
498} 519}
499 520
500IMPLEMENT_STACK_OF(X509_NAME_ENTRY) 521IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
501IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) 522IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libssl/src/crypto/asn1/x_nx509.c b/src/lib/libssl/src/crypto/asn1/x_nx509.c
index fbd9a22db3..538a9f95eb 100644
--- a/src/lib/libssl/src/crypto/asn1/x_nx509.c
+++ b/src/lib/libssl/src/crypto/asn1/x_nx509.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -69,4 +69,3 @@ ASN1_SEQUENCE(NETSCAPE_X509) = {
69} ASN1_SEQUENCE_END(NETSCAPE_X509) 69} ASN1_SEQUENCE_END(NETSCAPE_X509)
70 70
71IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509) 71IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_X509)
72
diff --git a/src/lib/libssl/src/crypto/asn1/x_pkey.c b/src/lib/libssl/src/crypto/asn1/x_pkey.c
index eac134a1ee..d18b8f6f5e 100644
--- a/src/lib/libssl/src/crypto/asn1/x_pkey.c
+++ b/src/lib/libssl/src/crypto/asn1/x_pkey.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -64,75 +64,85 @@
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66/* need to implement */ 66/* need to implement */
67int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) 67int
68i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
68{ 69{
69 return(0); 70 return (0);
70} 71}
71 72
72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) 73X509_PKEY *
74d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length)
73{ 75{
74 int i; 76 int i;
75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); 77 M_ASN1_D2I_vars(a, X509_PKEY *, X509_PKEY_new);
76 78
77 M_ASN1_D2I_Init(); 79 M_ASN1_D2I_Init();
78 M_ASN1_D2I_start_sequence(); 80 M_ASN1_D2I_start_sequence();
79 M_ASN1_D2I_get_x(X509_ALGOR,ret->enc_algor,d2i_X509_ALGOR); 81 M_ASN1_D2I_get_x(X509_ALGOR, ret->enc_algor, d2i_X509_ALGOR);
80 M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->enc_pkey,d2i_ASN1_OCTET_STRING); 82 M_ASN1_D2I_get_x(ASN1_OCTET_STRING, ret->enc_pkey,
83 d2i_ASN1_OCTET_STRING);
81 84
82 ret->cipher.cipher=EVP_get_cipherbyname( 85 ret->cipher.cipher = EVP_get_cipherbyname(
83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); 86 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
84 if (ret->cipher.cipher == NULL) { 87 if (ret->cipher.cipher == NULL) {
85 c.error=ASN1_R_UNSUPPORTED_CIPHER; 88 c.error = ASN1_R_UNSUPPORTED_CIPHER;
86 c.line=__LINE__; 89 c.line = __LINE__;
87 goto err; 90 goto err;
88 } 91 }
89 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) { 92 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) {
90 i=ret->enc_algor->parameter->value.octet_string->length; 93 i = ret->enc_algor->parameter->value.octet_string->length;
91 if (i > EVP_MAX_IV_LENGTH) { 94 if (i > EVP_MAX_IV_LENGTH) {
92 c.error=ASN1_R_IV_TOO_LARGE; 95 c.error = ASN1_R_IV_TOO_LARGE;
93 c.line=__LINE__; 96 c.line = __LINE__;
94 goto err; 97 goto err;
95 } 98 }
96 memcpy(ret->cipher.iv, 99 memcpy(ret->cipher.iv,
97 ret->enc_algor->parameter->value.octet_string->data,i); 100 ret->enc_algor->parameter->value.octet_string->data, i);
98 } 101 } else
99 else 102 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
100 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); 103 M_ASN1_D2I_Finish(a, X509_PKEY_free, ASN1_F_D2I_X509_PKEY);
101 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
102} 104}
103 105
104X509_PKEY *X509_PKEY_new(void) 106X509_PKEY *
107X509_PKEY_new(void)
105{ 108{
106 X509_PKEY *ret=NULL; 109 X509_PKEY *ret = NULL;
107 ASN1_CTX c; 110 ASN1_CTX c;
108 111
109 M_ASN1_New_Malloc(ret,X509_PKEY); 112 M_ASN1_New_Malloc(ret, X509_PKEY);
110 ret->version=0; 113 ret->version = 0;
111 M_ASN1_New(ret->enc_algor,X509_ALGOR_new); 114 M_ASN1_New(ret->enc_algor, X509_ALGOR_new);
112 M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new); 115 M_ASN1_New(ret->enc_pkey, M_ASN1_OCTET_STRING_new);
113 ret->dec_pkey=NULL; 116 ret->dec_pkey = NULL;
114 ret->key_length=0; 117 ret->key_length = 0;
115 ret->key_data=NULL; 118 ret->key_data = NULL;
116 ret->key_free=0; 119 ret->key_free = 0;
117 ret->cipher.cipher=NULL; 120 ret->cipher.cipher = NULL;
118 memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); 121 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
119 ret->references=1; 122 ret->references = 1;
120 return(ret); 123 return (ret);
121 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); 124 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
122} 125}
123 126
124void X509_PKEY_free(X509_PKEY *x) 127void
128X509_PKEY_free(X509_PKEY *x)
125{ 129{
126 int i; 130 int i;
127 131
128 if (x == NULL) return; 132 if (x == NULL)
133 return;
129 134
130 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY); 135 i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY);
131 if (i > 0) return; 136 if (i > 0)
137 return;
132 138
133 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); 139 if (x->enc_algor != NULL)
134 if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey); 140 X509_ALGOR_free(x->enc_algor);
135 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); 141 if (x->enc_pkey != NULL)
136 if ((x->key_data != NULL) && (x->key_free)) free(x->key_data); 142 M_ASN1_OCTET_STRING_free(x->enc_pkey);
143 if (x->dec_pkey != NULL)
144 EVP_PKEY_free(x->dec_pkey);
145 if ((x->key_data != NULL) && (x->key_free))
146 free(x->key_data);
137 free(x); 147 free(x);
138} 148}
diff --git a/src/lib/libssl/src/crypto/asn1/x_pubkey.c b/src/lib/libssl/src/crypto/asn1/x_pubkey.c
index 1d6ab6580a..df915e2dfd 100644
--- a/src/lib/libssl/src/crypto/asn1/x_pubkey.c
+++ b/src/lib/libssl/src/crypto/asn1/x_pubkey.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -69,8 +69,8 @@
69#endif 69#endif
70 70
71/* Minor tweak to operation: free up EVP_PKEY */ 71/* Minor tweak to operation: free up EVP_PKEY */
72static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 72static int
73 void *exarg) 73pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
74{ 74{
75 if (operation == ASN1_OP_FREE_POST) { 75 if (operation == ASN1_OP_FREE_POST) {
76 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; 76 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
@@ -86,54 +86,61 @@ ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
86 86
87IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) 87IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
88 88
89int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) 89int
90X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
90{ 91{
91 X509_PUBKEY *pk=NULL; 92 X509_PUBKEY *pk = NULL;
92 93
93 if (x == NULL) return(0); 94 if (x == NULL)
94 95 return (0);
95 if ((pk=X509_PUBKEY_new()) == NULL) goto error; 96 if ((pk = X509_PUBKEY_new()) == NULL)
97 goto error;
96 98
97 if (pkey->ameth) { 99 if (pkey->ameth) {
98 if (pkey->ameth->pub_encode) { 100 if (pkey->ameth->pub_encode) {
99 if (!pkey->ameth->pub_encode(pk, pkey)) { 101 if (!pkey->ameth->pub_encode(pk, pkey)) {
100 X509err(X509_F_X509_PUBKEY_SET, 102 X509err(X509_F_X509_PUBKEY_SET,
101 X509_R_PUBLIC_KEY_ENCODE_ERROR); 103 X509_R_PUBLIC_KEY_ENCODE_ERROR);
102 goto error; 104 goto error;
103 } 105 }
104 } else { 106 } else {
105 X509err(X509_F_X509_PUBKEY_SET, 107 X509err(X509_F_X509_PUBKEY_SET,
106 X509_R_METHOD_NOT_SUPPORTED); 108 X509_R_METHOD_NOT_SUPPORTED);
107 goto error; 109 goto error;
108 } 110 }
109 } else { 111 } else {
110 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); 112 X509err(X509_F_X509_PUBKEY_SET, X509_R_UNSUPPORTED_ALGORITHM);
111 goto error; 113 goto error;
112 } 114 }
113 115
114 if (*x != NULL) 116 if (*x != NULL)
115 X509_PUBKEY_free(*x); 117 X509_PUBKEY_free(*x);
116 118
117 *x=pk; 119 *x = pk;
118 120
119 return 1; 121 return 1;
122
120error: 123error:
121 if (pk != NULL) X509_PUBKEY_free(pk); 124 if (pk != NULL)
125 X509_PUBKEY_free(pk);
122 return 0; 126 return 0;
123} 127}
124 128
125EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) 129EVP_PKEY *
130X509_PUBKEY_get(X509_PUBKEY *key)
126{ 131{
127 EVP_PKEY *ret=NULL; 132 EVP_PKEY *ret = NULL;
128 133
129 if (key == NULL) goto error; 134 if (key == NULL)
135 goto error;
130 136
131 if (key->pkey != NULL) { 137 if (key->pkey != NULL) {
132 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); 138 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
133 return key->pkey; 139 return key->pkey;
134 } 140 }
135 141
136 if (key->public_key == NULL) goto error; 142 if (key->public_key == NULL)
143 goto error;
137 144
138 if ((ret = EVP_PKEY_new()) == NULL) { 145 if ((ret = EVP_PKEY_new()) == NULL) {
139 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); 146 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
@@ -141,14 +148,14 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
141 } 148 }
142 149
143 if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) { 150 if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {
144 X509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM); 151 X509err(X509_F_X509_PUBKEY_GET, X509_R_UNSUPPORTED_ALGORITHM);
145 goto error; 152 goto error;
146 } 153 }
147 154
148 if (ret->ameth->pub_decode) { 155 if (ret->ameth->pub_decode) {
149 if (!ret->ameth->pub_decode(ret, key)) { 156 if (!ret->ameth->pub_decode(ret, key)) {
150 X509err(X509_F_X509_PUBKEY_GET, 157 X509err(X509_F_X509_PUBKEY_GET,
151 X509_R_PUBLIC_KEY_DECODE_ERROR); 158 X509_R_PUBLIC_KEY_DECODE_ERROR);
152 goto error; 159 goto error;
153 } 160 }
154 } else { 161 } else {
@@ -170,39 +177,44 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
170 177
171 return ret; 178 return ret;
172 179
173 error: 180error:
174 if (ret != NULL) 181 if (ret != NULL)
175 EVP_PKEY_free(ret); 182 EVP_PKEY_free(ret);
176 return(NULL); 183 return (NULL);
177} 184}
178 185
179/* Now two pseudo ASN1 routines that take an EVP_PKEY structure 186/* Now two pseudo ASN1 routines that take an EVP_PKEY structure
180 * and encode or decode as X509_PUBKEY 187 * and encode or decode as X509_PUBKEY
181 */ 188 */
182 189
183EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, 190EVP_PKEY *
184 long length) 191d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length)
185{ 192{
186 X509_PUBKEY *xpk; 193 X509_PUBKEY *xpk;
187 EVP_PKEY *pktmp; 194 EVP_PKEY *pktmp;
188 xpk = d2i_X509_PUBKEY(NULL, pp, length); 195 xpk = d2i_X509_PUBKEY(NULL, pp, length);
189 if(!xpk) return NULL; 196 if (!xpk)
197 return NULL;
190 pktmp = X509_PUBKEY_get(xpk); 198 pktmp = X509_PUBKEY_get(xpk);
191 X509_PUBKEY_free(xpk); 199 X509_PUBKEY_free(xpk);
192 if(!pktmp) return NULL; 200 if (!pktmp)
193 if(a) { 201 return NULL;
202 if (a) {
194 EVP_PKEY_free(*a); 203 EVP_PKEY_free(*a);
195 *a = pktmp; 204 *a = pktmp;
196 } 205 }
197 return pktmp; 206 return pktmp;
198} 207}
199 208
200int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) 209int
210i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
201{ 211{
202 X509_PUBKEY *xpk=NULL; 212 X509_PUBKEY *xpk = NULL;
203 int ret; 213 int ret;
204 if(!a) return 0; 214 if (!a)
205 if(!X509_PUBKEY_set(&xpk, a)) return 0; 215 return 0;
216 if (!X509_PUBKEY_set(&xpk, a))
217 return 0;
206 ret = i2d_X509_PUBKEY(xpk, pp); 218 ret = i2d_X509_PUBKEY(xpk, pp);
207 X509_PUBKEY_free(xpk); 219 X509_PUBKEY_free(xpk);
208 return ret; 220 return ret;
@@ -212,18 +224,20 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
212 * keys 224 * keys
213 */ 225 */
214#ifndef OPENSSL_NO_RSA 226#ifndef OPENSSL_NO_RSA
215RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, 227RSA *
216 long length) 228d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length)
217{ 229{
218 EVP_PKEY *pkey; 230 EVP_PKEY *pkey;
219 RSA *key; 231 RSA *key;
220 const unsigned char *q; 232 const unsigned char *q;
221 q = *pp; 233 q = *pp;
222 pkey = d2i_PUBKEY(NULL, &q, length); 234 pkey = d2i_PUBKEY(NULL, &q, length);
223 if (!pkey) return NULL; 235 if (!pkey)
236 return NULL;
224 key = EVP_PKEY_get1_RSA(pkey); 237 key = EVP_PKEY_get1_RSA(pkey);
225 EVP_PKEY_free(pkey); 238 EVP_PKEY_free(pkey);
226 if (!key) return NULL; 239 if (!key)
240 return NULL;
227 *pp = q; 241 *pp = q;
228 if (a) { 242 if (a) {
229 RSA_free(*a); 243 RSA_free(*a);
@@ -232,11 +246,13 @@ RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp,
232 return key; 246 return key;
233} 247}
234 248
235int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) 249int
250i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
236{ 251{
237 EVP_PKEY *pktmp; 252 EVP_PKEY *pktmp;
238 int ret; 253 int ret;
239 if (!a) return 0; 254 if (!a)
255 return 0;
240 pktmp = EVP_PKEY_new(); 256 pktmp = EVP_PKEY_new();
241 if (!pktmp) { 257 if (!pktmp) {
242 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); 258 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
@@ -250,18 +266,20 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
250#endif 266#endif
251 267
252#ifndef OPENSSL_NO_DSA 268#ifndef OPENSSL_NO_DSA
253DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, 269DSA *
254 long length) 270d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length)
255{ 271{
256 EVP_PKEY *pkey; 272 EVP_PKEY *pkey;
257 DSA *key; 273 DSA *key;
258 const unsigned char *q; 274 const unsigned char *q;
259 q = *pp; 275 q = *pp;
260 pkey = d2i_PUBKEY(NULL, &q, length); 276 pkey = d2i_PUBKEY(NULL, &q, length);
261 if (!pkey) return NULL; 277 if (!pkey)
278 return NULL;
262 key = EVP_PKEY_get1_DSA(pkey); 279 key = EVP_PKEY_get1_DSA(pkey);
263 EVP_PKEY_free(pkey); 280 EVP_PKEY_free(pkey);
264 if (!key) return NULL; 281 if (!key)
282 return NULL;
265 *pp = q; 283 *pp = q;
266 if (a) { 284 if (a) {
267 DSA_free(*a); 285 DSA_free(*a);
@@ -270,13 +288,15 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp,
270 return key; 288 return key;
271} 289}
272 290
273int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) 291int
292i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
274{ 293{
275 EVP_PKEY *pktmp; 294 EVP_PKEY *pktmp;
276 int ret; 295 int ret;
277 if(!a) return 0; 296 if (!a)
297 return 0;
278 pktmp = EVP_PKEY_new(); 298 pktmp = EVP_PKEY_new();
279 if(!pktmp) { 299 if (!pktmp) {
280 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); 300 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
281 return 0; 301 return 0;
282 } 302 }
@@ -288,44 +308,49 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
288#endif 308#endif
289 309
290#ifndef OPENSSL_NO_EC 310#ifndef OPENSSL_NO_EC
291EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length) 311EC_KEY *
312d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length)
292{ 313{
293 EVP_PKEY *pkey; 314 EVP_PKEY *pkey;
294 EC_KEY *key; 315 EC_KEY *key;
295 const unsigned char *q; 316 const unsigned char *q;
296 q = *pp; 317 q = *pp;
297 pkey = d2i_PUBKEY(NULL, &q, length); 318 pkey = d2i_PUBKEY(NULL, &q, length);
298 if (!pkey) return(NULL); 319 if (!pkey)
320 return (NULL);
299 key = EVP_PKEY_get1_EC_KEY(pkey); 321 key = EVP_PKEY_get1_EC_KEY(pkey);
300 EVP_PKEY_free(pkey); 322 EVP_PKEY_free(pkey);
301 if (!key) return(NULL); 323 if (!key)
324 return (NULL);
302 *pp = q; 325 *pp = q;
303 if (a) { 326 if (a) {
304 EC_KEY_free(*a); 327 EC_KEY_free(*a);
305 *a = key; 328 *a = key;
306 } 329 }
307 return(key); 330 return (key);
308} 331}
309 332
310int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp) 333int
334i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
311{ 335{
312 EVP_PKEY *pktmp; 336 EVP_PKEY *pktmp;
313 int ret; 337 int ret;
314 if (!a) return(0); 338 if (!a)
339 return (0);
315 if ((pktmp = EVP_PKEY_new()) == NULL) { 340 if ((pktmp = EVP_PKEY_new()) == NULL) {
316 ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); 341 ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
317 return(0); 342 return (0);
318 } 343 }
319 EVP_PKEY_set1_EC_KEY(pktmp, a); 344 EVP_PKEY_set1_EC_KEY(pktmp, a);
320 ret = i2d_PUBKEY(pktmp, pp); 345 ret = i2d_PUBKEY(pktmp, pp);
321 EVP_PKEY_free(pktmp); 346 EVP_PKEY_free(pktmp);
322 return(ret); 347 return (ret);
323} 348}
324#endif 349#endif
325 350
326int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, 351int
327 int ptype, void *pval, 352X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, int ptype,
328 unsigned char *penc, int penclen) 353 void *pval, unsigned char *penc, int penclen)
329{ 354{
330 if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval)) 355 if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
331 return 0; 356 return 0;
@@ -334,17 +359,16 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
334 free(pub->public_key->data); 359 free(pub->public_key->data);
335 pub->public_key->data = penc; 360 pub->public_key->data = penc;
336 pub->public_key->length = penclen; 361 pub->public_key->length = penclen;
337 /* Set number of unused bits to zero */ 362 /* Set number of unused bits to zero */
338 pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); 363 pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
339 pub->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; 364 pub->public_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
340 } 365 }
341 return 1; 366 return 1;
342} 367}
343 368
344int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, 369int
345 const unsigned char **pk, int *ppklen, 370X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, const unsigned char **pk,
346 X509_ALGOR **pa, 371 int *ppklen, X509_ALGOR **pa, X509_PUBKEY *pub)
347 X509_PUBKEY *pub)
348{ 372{
349 if (ppkalg) 373 if (ppkalg)
350 *ppkalg = pub->algor->algorithm; 374 *ppkalg = pub->algor->algorithm;
diff --git a/src/lib/libssl/src/crypto/asn1/x_req.c b/src/lib/libssl/src/crypto/asn1/x_req.c
index d57555827c..442f56a144 100644
--- a/src/lib/libssl/src/crypto/asn1/x_req.c
+++ b/src/lib/libssl/src/crypto/asn1/x_req.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -66,7 +66,7 @@
66 * encode the attributes field if it is empty. This is in 66 * encode the attributes field if it is empty. This is in
67 * violation of PKCS#10 but we need to tolerate it. We do 67 * violation of PKCS#10 but we need to tolerate it. We do
68 * this by making the attributes field OPTIONAL then using 68 * this by making the attributes field OPTIONAL then using
69 * the callback to initialise it to an empty STACK. 69 * the callback to initialise it to an empty STACK.
70 * 70 *
71 * This means that the field will be correctly encoded unless 71 * This means that the field will be correctly encoded unless
72 * we NULL out the field. 72 * we NULL out the field.
@@ -79,14 +79,15 @@
79 * 79 *
80 */ 80 */
81 81
82static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 82static int
83 void *exarg) 83rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
84{ 84{
85 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval; 85 X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval;
86 86
87 if(operation == ASN1_OP_NEW_POST) { 87 if (operation == ASN1_OP_NEW_POST) {
88 rinf->attributes = sk_X509_ATTRIBUTE_new_null(); 88 rinf->attributes = sk_X509_ATTRIBUTE_new_null();
89 if(!rinf->attributes) return 0; 89 if (!rinf->attributes)
90 return 0;
90 } 91 }
91 return 1; 92 return 1;
92} 93}
diff --git a/src/lib/libssl/src/crypto/asn1/x_sig.c b/src/lib/libssl/src/crypto/asn1/x_sig.c
index 42efa86c1c..5c9aef0365 100644
--- a/src/lib/libssl/src/crypto/asn1/x_sig.c
+++ b/src/lib/libssl/src/crypto/asn1/x_sig.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
diff --git a/src/lib/libssl/src/crypto/asn1/x_spki.c b/src/lib/libssl/src/crypto/asn1/x_spki.c
index 2aece077c5..34fe81443c 100644
--- a/src/lib/libssl/src/crypto/asn1/x_spki.c
+++ b/src/lib/libssl/src/crypto/asn1/x_spki.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
diff --git a/src/lib/libssl/src/crypto/asn1/x_val.c b/src/lib/libssl/src/crypto/asn1/x_val.c
index dc17c67758..6436f0cb55 100644
--- a/src/lib/libssl/src/crypto/asn1/x_val.c
+++ b/src/lib/libssl/src/crypto/asn1/x_val.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509.c b/src/lib/libssl/src/crypto/asn1/x_x509.c
index 20448a8e3b..e7d613e20f 100644
--- a/src/lib/libssl/src/crypto/asn1/x_x509.c
+++ b/src/lib/libssl/src/crypto/asn1/x_x509.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -81,15 +81,15 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
81 81
82extern void policy_cache_free(X509_POLICY_CACHE *cache); 82extern void policy_cache_free(X509_POLICY_CACHE *cache);
83 83
84static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, 84static int
85 void *exarg) 85x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
86{ 86{
87 X509 *ret = (X509 *)*pval; 87 X509 *ret = (X509 *)*pval;
88 88
89 switch(operation) { 89 switch (operation) {
90 90
91 case ASN1_OP_NEW_POST: 91 case ASN1_OP_NEW_POST:
92 ret->valid=0; 92 ret->valid = 0;
93 ret->name = NULL; 93 ret->name = NULL;
94 ret->ex_flags = 0; 94 ret->ex_flags = 0;
95 ret->ex_pathlen = -1; 95 ret->ex_pathlen = -1;
@@ -105,8 +105,9 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
105 break; 105 break;
106 106
107 case ASN1_OP_D2I_POST: 107 case ASN1_OP_D2I_POST:
108 if (ret->name != NULL) free(ret->name); 108 if (ret->name != NULL)
109 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); 109 free(ret->name);
110 ret->name = X509_NAME_oneline(ret->cert_info->subject, NULL, 0);
110 break; 111 break;
111 112
112 case ASN1_OP_FREE_POST: 113 case ASN1_OP_FREE_POST:
@@ -122,14 +123,12 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
122 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free); 123 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
123 ASIdentifiers_free(ret->rfc3779_asid); 124 ASIdentifiers_free(ret->rfc3779_asid);
124#endif 125#endif
125 126 if (ret->name != NULL)
126 if (ret->name != NULL) free(ret->name); 127 free(ret->name);
127 break; 128 break;
128
129 } 129 }
130 130
131 return 1; 131 return 1;
132
133} 132}
134 133
135ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { 134ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
@@ -141,21 +140,24 @@ ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
141IMPLEMENT_ASN1_FUNCTIONS(X509) 140IMPLEMENT_ASN1_FUNCTIONS(X509)
142IMPLEMENT_ASN1_DUP_FUNCTION(X509) 141IMPLEMENT_ASN1_DUP_FUNCTION(X509)
143 142
144int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 143int
145 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 144X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
145 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
146{ 146{
147 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,
148 new_func, dup_func, free_func); 148 new_func, dup_func, free_func);
149} 149}
150 150
151int X509_set_ex_data(X509 *r, int idx, void *arg) 151int
152X509_set_ex_data(X509 *r, int idx, void *arg)
152{ 153{
153 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); 154 return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
154} 155}
155 156
156void *X509_get_ex_data(X509 *r, int idx) 157void *
158X509_get_ex_data(X509 *r, int idx)
157{ 159{
158 return(CRYPTO_get_ex_data(&r->ex_data,idx)); 160 return (CRYPTO_get_ex_data(&r->ex_data, idx));
159} 161}
160 162
161/* X509_AUX ASN1 routines. X509_AUX is the name given to 163/* X509_AUX ASN1 routines. X509_AUX is the name given to
@@ -166,29 +168,38 @@ void *X509_get_ex_data(X509 *r, int idx)
166 * 168 *
167 */ 169 */
168 170
169X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length) 171X509 *
172d2i_X509_AUX(X509 **a, const unsigned char **pp, long length)
170{ 173{
171 const unsigned char *q; 174 const unsigned char *q;
172 X509 *ret; 175 X509 *ret;
176
173 /* Save start position */ 177 /* Save start position */
174 q = *pp; 178 q = *pp;
175 ret = d2i_X509(a, pp, length); 179 ret = d2i_X509(a, pp, length);
176 /* If certificate unreadable then forget it */ 180 /* If certificate unreadable then forget it */
177 if(!ret) return NULL; 181 if (!ret)
182 return NULL;
178 /* update length */ 183 /* update length */
179 length -= *pp - q; 184 length -= *pp - q;
180 if(!length) return ret; 185 if (!length)
181 if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err; 186 return ret;
187 if (!d2i_X509_CERT_AUX(&ret->aux, pp, length))
188 goto err;
182 return ret; 189 return ret;
183 err: 190
191err:
184 X509_free(ret); 192 X509_free(ret);
185 return NULL; 193 return NULL;
186} 194}
187 195
188int i2d_X509_AUX(X509 *a, unsigned char **pp) 196int
197i2d_X509_AUX(X509 *a, unsigned char **pp)
189{ 198{
190 int length; 199 int length;
200
191 length = i2d_X509(a, pp); 201 length = i2d_X509(a, pp);
192 if(a) length += i2d_X509_CERT_AUX(a->aux, pp); 202 if (a)
203 length += i2d_X509_CERT_AUX(a->aux, pp);
193 return length; 204 return length;
194} 205}
diff --git a/src/lib/libssl/src/crypto/asn1/x_x509a.c b/src/lib/libssl/src/crypto/asn1/x_x509a.c
index 287d780830..69ea725709 100644
--- a/src/lib/libssl/src/crypto/asn1/x_x509a.c
+++ b/src/lib/libssl/src/crypto/asn1/x_x509a.c
@@ -10,7 +10,7 @@
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 14 *
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in 16 * notice, this list of conditions and the following disclaimer in
@@ -66,7 +66,7 @@
66 * user modifiable data about a certificate. This data is 66 * user modifiable data about a certificate. This data is
67 * appended to the X509 encoding when the *_X509_AUX routines 67 * appended to the X509 encoding when the *_X509_AUX routines
68 * are used. This means that the "traditional" X509 routines 68 * are used. This means that the "traditional" X509 routines
69 * will simply ignore the extra data. 69 * will simply ignore the extra data.
70 */ 70 */
71 71
72static X509_CERT_AUX *aux_get(X509 *x); 72static X509_CERT_AUX *aux_get(X509 *x);
@@ -81,14 +81,18 @@ ASN1_SEQUENCE(X509_CERT_AUX) = {
81 81
82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX) 82IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
83 83
84static X509_CERT_AUX *aux_get(X509 *x) 84static X509_CERT_AUX *
85aux_get(X509 *x)
85{ 86{
86 if(!x) return NULL; 87 if (!x)
87 if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL; 88 return NULL;
89 if (!x->aux && !(x->aux = X509_CERT_AUX_new()))
90 return NULL;
88 return x->aux; 91 return x->aux;
89} 92}
90 93
91int X509_alias_set1(X509 *x, unsigned char *name, int len) 94int
95X509_alias_set1(X509 *x, unsigned char *name, int len)
92{ 96{
93 X509_CERT_AUX *aux; 97 X509_CERT_AUX *aux;
94 if (!name) { 98 if (!name) {
@@ -98,12 +102,15 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len)
98 x->aux->alias = NULL; 102 x->aux->alias = NULL;
99 return 1; 103 return 1;
100 } 104 }
101 if(!(aux = aux_get(x))) return 0; 105 if (!(aux = aux_get(x)))
102 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; 106 return 0;
107 if (!aux->alias && !(aux->alias = ASN1_UTF8STRING_new()))
108 return 0;
103 return ASN1_STRING_set(aux->alias, name, len); 109 return ASN1_STRING_set(aux->alias, name, len);
104} 110}
105 111
106int X509_keyid_set1(X509 *x, unsigned char *id, int len) 112int
113X509_keyid_set1(X509 *x, unsigned char *id, int len)
107{ 114{
108 X509_CERT_AUX *aux; 115 X509_CERT_AUX *aux;
109 if (!id) { 116 if (!id) {
@@ -113,58 +120,74 @@ int X509_keyid_set1(X509 *x, unsigned char *id, int len)
113 x->aux->keyid = NULL; 120 x->aux->keyid = NULL;
114 return 1; 121 return 1;
115 } 122 }
116 if(!(aux = aux_get(x))) return 0; 123 if (!(aux = aux_get(x)))
117 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; 124 return 0;
125 if (!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new()))
126 return 0;
118 return ASN1_STRING_set(aux->keyid, id, len); 127 return ASN1_STRING_set(aux->keyid, id, len);
119} 128}
120 129
121unsigned char *X509_alias_get0(X509 *x, int *len) 130unsigned char *
131X509_alias_get0(X509 *x, int *len)
122{ 132{
123 if(!x->aux || !x->aux->alias) return NULL; 133 if (!x->aux || !x->aux->alias)
124 if(len) *len = x->aux->alias->length; 134 return NULL;
135 if (len)
136 *len = x->aux->alias->length;
125 return x->aux->alias->data; 137 return x->aux->alias->data;
126} 138}
127 139
128unsigned char *X509_keyid_get0(X509 *x, int *len) 140unsigned char *
141X509_keyid_get0(X509 *x, int *len)
129{ 142{
130 if(!x->aux || !x->aux->keyid) return NULL; 143 if (!x->aux || !x->aux->keyid)
131 if(len) *len = x->aux->keyid->length; 144 return NULL;
145 if (len)
146 *len = x->aux->keyid->length;
132 return x->aux->keyid->data; 147 return x->aux->keyid->data;
133} 148}
134 149
135int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj) 150int
151X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
136{ 152{
137 X509_CERT_AUX *aux; 153 X509_CERT_AUX *aux;
138 ASN1_OBJECT *objtmp; 154 ASN1_OBJECT *objtmp;
139 if(!(objtmp = OBJ_dup(obj))) return 0; 155 if (!(objtmp = OBJ_dup(obj)))
140 if(!(aux = aux_get(x))) return 0; 156 return 0;
141 if(!aux->trust 157 if (!(aux = aux_get(x)))
142 && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0; 158 return 0;
159 if (!aux->trust && !(aux->trust = sk_ASN1_OBJECT_new_null()))
160 return 0;
143 return sk_ASN1_OBJECT_push(aux->trust, objtmp); 161 return sk_ASN1_OBJECT_push(aux->trust, objtmp);
144} 162}
145 163
146int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj) 164int
165X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj)
147{ 166{
148 X509_CERT_AUX *aux; 167 X509_CERT_AUX *aux;
149 ASN1_OBJECT *objtmp; 168 ASN1_OBJECT *objtmp;
150 if(!(objtmp = OBJ_dup(obj))) return 0; 169 if (!(objtmp = OBJ_dup(obj)))
151 if(!(aux = aux_get(x))) return 0; 170 return 0;
152 if(!aux->reject 171 if (!(aux = aux_get(x)))
153 && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0; 172 return 0;
173 if (!aux->reject && !(aux->reject = sk_ASN1_OBJECT_new_null()))
174 return 0;
154 return sk_ASN1_OBJECT_push(aux->reject, objtmp); 175 return sk_ASN1_OBJECT_push(aux->reject, objtmp);
155} 176}
156 177
157void X509_trust_clear(X509 *x) 178void
179X509_trust_clear(X509 *x)
158{ 180{
159 if(x->aux && x->aux->trust) { 181 if (x->aux && x->aux->trust) {
160 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free); 182 sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free);
161 x->aux->trust = NULL; 183 x->aux->trust = NULL;
162 } 184 }
163} 185}
164 186
165void X509_reject_clear(X509 *x) 187void
188X509_reject_clear(X509 *x)
166{ 189{
167 if(x->aux && x->aux->reject) { 190 if (x->aux && x->aux->reject) {
168 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free); 191 sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free);
169 x->aux->reject = NULL; 192 x->aux->reject = NULL;
170 } 193 }