diff options
author | jsing <> | 2014-04-20 16:24:15 +0000 |
---|---|---|
committer | jsing <> | 2014-04-20 16:24:15 +0000 |
commit | 9ac91f6b64d9ad9f95056ff3e49b351c73df88ce (patch) | |
tree | aa6c8f4f4d7d3ac687ec98451a6ee5e763c06c30 /src/lib | |
parent | fc9997e7e4ee7815dbe22f29e57d61727e20ad10 (diff) | |
download | openbsd-9ac91f6b64d9ad9f95056ff3e49b351c73df88ce.tar.gz openbsd-9ac91f6b64d9ad9f95056ff3e49b351c73df88ce.tar.bz2 openbsd-9ac91f6b64d9ad9f95056ff3e49b351c73df88ce.zip |
KNF.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/x509/x509cset.c | 89 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509name.c | 324 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509rset.c | 37 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509spki.c | 33 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509type.c | 60 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509cset.c | 89 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509name.c | 324 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509rset.c | 37 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509spki.c | 33 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509type.c | 60 |
10 files changed, 610 insertions, 476 deletions
diff --git a/src/lib/libcrypto/x509/x509cset.c b/src/lib/libcrypto/x509/x509cset.c index bb39cf4e04..ee405d6e9f 100644 --- a/src/lib/libcrypto/x509/x509cset.c +++ b/src/lib/libcrypto/x509/x509cset.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 |
@@ -63,98 +63,111 @@ | |||
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | 65 | ||
66 | int X509_CRL_set_version(X509_CRL *x, long version) | 66 | int |
67 | X509_CRL_set_version(X509_CRL *x, long version) | ||
67 | { | 68 | { |
68 | if (x == NULL) return(0); | 69 | if (x == NULL) |
70 | return (0); | ||
69 | if (x->crl->version == NULL) { | 71 | if (x->crl->version == NULL) { |
70 | if ((x->crl->version=M_ASN1_INTEGER_new()) == NULL) | 72 | if ((x->crl->version = M_ASN1_INTEGER_new()) == NULL) |
71 | return(0); | 73 | return (0); |
72 | } | 74 | } |
73 | return(ASN1_INTEGER_set(x->crl->version,version)); | 75 | return (ASN1_INTEGER_set(x->crl->version, version)); |
74 | } | 76 | } |
75 | 77 | ||
76 | int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) | 78 | int |
79 | X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) | ||
77 | { | 80 | { |
78 | if ((x == NULL) || (x->crl == NULL)) return(0); | 81 | if ((x == NULL) || (x->crl == NULL)) |
79 | return(X509_NAME_set(&x->crl->issuer,name)); | 82 | return (0); |
83 | return (X509_NAME_set(&x->crl->issuer, name)); | ||
80 | } | 84 | } |
81 | 85 | ||
82 | 86 | int | |
83 | int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) | 87 | X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) |
84 | { | 88 | { |
85 | ASN1_TIME *in; | 89 | ASN1_TIME *in; |
86 | 90 | ||
87 | if (x == NULL) return(0); | 91 | if (x == NULL) |
88 | in=x->crl->lastUpdate; | 92 | return (0); |
93 | in = x->crl->lastUpdate; | ||
89 | if (in != tm) { | 94 | if (in != tm) { |
90 | in=M_ASN1_TIME_dup(tm); | 95 | in = M_ASN1_TIME_dup(tm); |
91 | if (in != NULL) { | 96 | if (in != NULL) { |
92 | M_ASN1_TIME_free(x->crl->lastUpdate); | 97 | M_ASN1_TIME_free(x->crl->lastUpdate); |
93 | x->crl->lastUpdate=in; | 98 | x->crl->lastUpdate = in; |
94 | } | 99 | } |
95 | } | 100 | } |
96 | return(in != NULL); | 101 | return (in != NULL); |
97 | } | 102 | } |
98 | 103 | ||
99 | int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) | 104 | int |
105 | X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) | ||
100 | { | 106 | { |
101 | ASN1_TIME *in; | 107 | ASN1_TIME *in; |
102 | 108 | ||
103 | if (x == NULL) return(0); | 109 | if (x == NULL) |
104 | in=x->crl->nextUpdate; | 110 | return (0); |
111 | in = x->crl->nextUpdate; | ||
105 | if (in != tm) { | 112 | if (in != tm) { |
106 | in=M_ASN1_TIME_dup(tm); | 113 | in = M_ASN1_TIME_dup(tm); |
107 | if (in != NULL) { | 114 | if (in != NULL) { |
108 | M_ASN1_TIME_free(x->crl->nextUpdate); | 115 | M_ASN1_TIME_free(x->crl->nextUpdate); |
109 | x->crl->nextUpdate=in; | 116 | x->crl->nextUpdate = in; |
110 | } | 117 | } |
111 | } | 118 | } |
112 | return(in != NULL); | 119 | return (in != NULL); |
113 | } | 120 | } |
114 | 121 | ||
115 | int X509_CRL_sort(X509_CRL *c) | 122 | int |
123 | X509_CRL_sort(X509_CRL *c) | ||
116 | { | 124 | { |
117 | int i; | 125 | int i; |
118 | X509_REVOKED *r; | 126 | X509_REVOKED *r; |
127 | |||
119 | /* sort the data so it will be written in serial | 128 | /* sort the data so it will be written in serial |
120 | * number order */ | 129 | * number order */ |
121 | sk_X509_REVOKED_sort(c->crl->revoked); | 130 | sk_X509_REVOKED_sort(c->crl->revoked); |
122 | for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++) { | 131 | for (i = 0; i < sk_X509_REVOKED_num(c->crl->revoked); i++) { |
123 | r=sk_X509_REVOKED_value(c->crl->revoked,i); | 132 | r = sk_X509_REVOKED_value(c->crl->revoked, i); |
124 | r->sequence=i; | 133 | r->sequence = i; |
125 | } | 134 | } |
126 | c->crl->enc.modified = 1; | 135 | c->crl->enc.modified = 1; |
127 | return 1; | 136 | return 1; |
128 | } | 137 | } |
129 | 138 | ||
130 | int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) | 139 | int |
140 | X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) | ||
131 | { | 141 | { |
132 | ASN1_TIME *in; | 142 | ASN1_TIME *in; |
133 | 143 | ||
134 | if (x == NULL) return(0); | 144 | if (x == NULL) |
135 | in=x->revocationDate; | 145 | return (0); |
146 | in = x->revocationDate; | ||
136 | if (in != tm) { | 147 | if (in != tm) { |
137 | in=M_ASN1_TIME_dup(tm); | 148 | in = M_ASN1_TIME_dup(tm); |
138 | if (in != NULL) { | 149 | if (in != NULL) { |
139 | M_ASN1_TIME_free(x->revocationDate); | 150 | M_ASN1_TIME_free(x->revocationDate); |
140 | x->revocationDate=in; | 151 | x->revocationDate = in; |
141 | } | 152 | } |
142 | } | 153 | } |
143 | return(in != NULL); | 154 | return (in != NULL); |
144 | } | 155 | } |
145 | 156 | ||
146 | int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) | 157 | int |
158 | X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) | ||
147 | { | 159 | { |
148 | ASN1_INTEGER *in; | 160 | ASN1_INTEGER *in; |
149 | 161 | ||
150 | if (x == NULL) return(0); | 162 | if (x == NULL) |
151 | in=x->serialNumber; | 163 | return (0); |
164 | in = x->serialNumber; | ||
152 | if (in != serial) { | 165 | if (in != serial) { |
153 | in=M_ASN1_INTEGER_dup(serial); | 166 | in = M_ASN1_INTEGER_dup(serial); |
154 | if (in != NULL) { | 167 | if (in != NULL) { |
155 | M_ASN1_INTEGER_free(x->serialNumber); | 168 | M_ASN1_INTEGER_free(x->serialNumber); |
156 | x->serialNumber=in; | 169 | x->serialNumber = in; |
157 | } | 170 | } |
158 | } | 171 | } |
159 | return(in != NULL); | 172 | return (in != NULL); |
160 | } | 173 | } |
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c index 729fb060f8..3d90fd67fe 100644 --- a/src/lib/libcrypto/x509/x509name.c +++ b/src/lib/libcrypto/x509/x509name.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,97 +64,110 @@ | |||
64 | #include <openssl/evp.h> | 64 | #include <openssl/evp.h> |
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) | 67 | int |
68 | X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) | ||
68 | { | 69 | { |
69 | ASN1_OBJECT *obj; | 70 | ASN1_OBJECT *obj; |
70 | 71 | ||
71 | obj=OBJ_nid2obj(nid); | 72 | obj = OBJ_nid2obj(nid); |
72 | if (obj == NULL) return(-1); | 73 | if (obj == NULL) |
73 | return(X509_NAME_get_text_by_OBJ(name,obj,buf,len)); | 74 | return (-1); |
75 | return (X509_NAME_get_text_by_OBJ(name, obj, buf, len)); | ||
74 | } | 76 | } |
75 | 77 | ||
76 | int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, | 78 | int |
77 | int len) | 79 | X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, |
80 | int len) | ||
78 | { | 81 | { |
79 | int i; | 82 | int i; |
80 | ASN1_STRING *data; | 83 | ASN1_STRING *data; |
81 | 84 | ||
82 | i=X509_NAME_get_index_by_OBJ(name,obj,-1); | 85 | i = X509_NAME_get_index_by_OBJ(name, obj, -1); |
83 | if (i < 0) return(-1); | 86 | if (i < 0) |
84 | data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i)); | 87 | return (-1); |
85 | i=(data->length > (len-1))?(len-1):data->length; | 88 | data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); |
86 | if (buf == NULL) return(data->length); | 89 | i = (data->length > (len - 1)) ? (len - 1) : data->length; |
87 | memcpy(buf,data->data,i); | 90 | if (buf == NULL) |
88 | buf[i]='\0'; | 91 | return (data->length); |
89 | return(i); | 92 | memcpy(buf, data->data, i); |
93 | buf[i] = '\0'; | ||
94 | return (i); | ||
90 | } | 95 | } |
91 | 96 | ||
92 | int X509_NAME_entry_count(X509_NAME *name) | 97 | int |
98 | X509_NAME_entry_count(X509_NAME *name) | ||
93 | { | 99 | { |
94 | if (name == NULL) return(0); | 100 | if (name == NULL) |
95 | return(sk_X509_NAME_ENTRY_num(name->entries)); | 101 | return (0); |
102 | return (sk_X509_NAME_ENTRY_num(name->entries)); | ||
96 | } | 103 | } |
97 | 104 | ||
98 | int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) | 105 | int |
106 | X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) | ||
99 | { | 107 | { |
100 | ASN1_OBJECT *obj; | 108 | ASN1_OBJECT *obj; |
101 | 109 | ||
102 | obj=OBJ_nid2obj(nid); | 110 | obj = OBJ_nid2obj(nid); |
103 | if (obj == NULL) return(-2); | 111 | if (obj == NULL) |
104 | return(X509_NAME_get_index_by_OBJ(name,obj,lastpos)); | 112 | return (-2); |
113 | return (X509_NAME_get_index_by_OBJ(name, obj, lastpos)); | ||
105 | } | 114 | } |
106 | 115 | ||
107 | /* NOTE: you should be passsing -1, not 0 as lastpos */ | 116 | /* NOTE: you should be passsing -1, not 0 as lastpos */ |
108 | int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, | 117 | int |
109 | int lastpos) | 118 | X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int lastpos) |
110 | { | 119 | { |
111 | int n; | 120 | int n; |
112 | X509_NAME_ENTRY *ne; | 121 | X509_NAME_ENTRY *ne; |
113 | STACK_OF(X509_NAME_ENTRY) *sk; | 122 | STACK_OF(X509_NAME_ENTRY) *sk; |
114 | 123 | ||
115 | if (name == NULL) return(-1); | 124 | if (name == NULL) |
125 | return (-1); | ||
116 | if (lastpos < 0) | 126 | if (lastpos < 0) |
117 | lastpos= -1; | 127 | lastpos = -1; |
118 | sk=name->entries; | 128 | sk = name->entries; |
119 | n=sk_X509_NAME_ENTRY_num(sk); | 129 | n = sk_X509_NAME_ENTRY_num(sk); |
120 | for (lastpos++; lastpos < n; lastpos++) { | 130 | for (lastpos++; lastpos < n; lastpos++) { |
121 | ne=sk_X509_NAME_ENTRY_value(sk,lastpos); | 131 | ne = sk_X509_NAME_ENTRY_value(sk, lastpos); |
122 | if (OBJ_cmp(ne->object,obj) == 0) | 132 | if (OBJ_cmp(ne->object, obj) == 0) |
123 | return(lastpos); | 133 | return (lastpos); |
124 | } | 134 | } |
125 | return(-1); | 135 | return (-1); |
126 | } | 136 | } |
127 | 137 | ||
128 | X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc) | 138 | X509_NAME_ENTRY * |
139 | X509_NAME_get_entry(X509_NAME *name, int loc) | ||
129 | { | 140 | { |
130 | if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc | 141 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc || |
131 | || loc < 0) | 142 | loc < 0) |
132 | return(NULL); | 143 | return (NULL); |
133 | else | 144 | else |
134 | return(sk_X509_NAME_ENTRY_value(name->entries,loc)); | 145 | return (sk_X509_NAME_ENTRY_value(name->entries, loc)); |
135 | } | 146 | } |
136 | 147 | ||
137 | X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) | 148 | X509_NAME_ENTRY * |
149 | X509_NAME_delete_entry(X509_NAME *name, int loc) | ||
138 | { | 150 | { |
139 | X509_NAME_ENTRY *ret; | 151 | X509_NAME_ENTRY *ret; |
140 | int i,n,set_prev,set_next; | 152 | int i, n, set_prev, set_next; |
141 | STACK_OF(X509_NAME_ENTRY) *sk; | 153 | STACK_OF(X509_NAME_ENTRY) *sk; |
142 | 154 | ||
143 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc | 155 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc || |
144 | || loc < 0) | 156 | loc < 0) |
145 | return(NULL); | 157 | return (NULL); |
146 | sk=name->entries; | 158 | sk = name->entries; |
147 | ret=sk_X509_NAME_ENTRY_delete(sk,loc); | 159 | ret = sk_X509_NAME_ENTRY_delete(sk, loc); |
148 | n=sk_X509_NAME_ENTRY_num(sk); | 160 | n = sk_X509_NAME_ENTRY_num(sk); |
149 | name->modified=1; | 161 | name->modified = 1; |
150 | if (loc == n) return(ret); | 162 | if (loc == n) |
163 | return (ret); | ||
151 | 164 | ||
152 | /* else we need to fixup the set field */ | 165 | /* else we need to fixup the set field */ |
153 | if (loc != 0) | 166 | if (loc != 0) |
154 | set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set; | 167 | set_prev = (sk_X509_NAME_ENTRY_value(sk, loc - 1))->set; |
155 | else | 168 | else |
156 | set_prev=ret->set-1; | 169 | set_prev = ret->set - 1; |
157 | set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set; | 170 | set_next = sk_X509_NAME_ENTRY_value(sk, loc)->set; |
158 | 171 | ||
159 | /* set_prev is the previous set | 172 | /* set_prev is the previous set |
160 | * set is the current set | 173 | * set is the current set |
@@ -164,43 +177,52 @@ X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) | |||
164 | * next 1 1 2 2 2 2 3 2 | 177 | * next 1 1 2 2 2 2 3 2 |
165 | * so basically only if prev and next differ by 2, then | 178 | * so basically only if prev and next differ by 2, then |
166 | * re-number down by 1 */ | 179 | * re-number down by 1 */ |
167 | if (set_prev+1 < set_next) | 180 | if (set_prev + 1 < set_next) |
168 | for (i=loc; i<n; i++) | 181 | for (i = loc; i < n; i++) |
169 | sk_X509_NAME_ENTRY_value(sk,i)->set--; | 182 | sk_X509_NAME_ENTRY_value(sk, i)->set--; |
170 | return(ret); | 183 | return (ret); |
171 | } | 184 | } |
172 | 185 | ||
173 | int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, | 186 | int |
174 | unsigned char *bytes, int len, int loc, int set) | 187 | X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, |
188 | unsigned char *bytes, int len, int loc, int set) | ||
175 | { | 189 | { |
176 | X509_NAME_ENTRY *ne; | 190 | X509_NAME_ENTRY *ne; |
177 | int ret; | 191 | int ret; |
192 | |||
178 | ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); | 193 | ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); |
179 | if(!ne) return 0; | 194 | if (!ne) |
195 | return 0; | ||
180 | ret = X509_NAME_add_entry(name, ne, loc, set); | 196 | ret = X509_NAME_add_entry(name, ne, loc, set); |
181 | X509_NAME_ENTRY_free(ne); | 197 | X509_NAME_ENTRY_free(ne); |
182 | return ret; | 198 | return ret; |
183 | } | 199 | } |
184 | 200 | ||
185 | int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, | 201 | int |
186 | unsigned char *bytes, int len, int loc, int set) | 202 | X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, |
203 | unsigned char *bytes, int len, int loc, int set) | ||
187 | { | 204 | { |
188 | X509_NAME_ENTRY *ne; | 205 | X509_NAME_ENTRY *ne; |
189 | int ret; | 206 | int ret; |
207 | |||
190 | ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); | 208 | ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); |
191 | if(!ne) return 0; | 209 | if (!ne) |
210 | return 0; | ||
192 | ret = X509_NAME_add_entry(name, ne, loc, set); | 211 | ret = X509_NAME_add_entry(name, ne, loc, set); |
193 | X509_NAME_ENTRY_free(ne); | 212 | X509_NAME_ENTRY_free(ne); |
194 | return ret; | 213 | return ret; |
195 | } | 214 | } |
196 | 215 | ||
197 | int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, | 216 | int |
198 | const unsigned char *bytes, int len, int loc, int set) | 217 | X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, |
218 | const unsigned char *bytes, int len, int loc, int set) | ||
199 | { | 219 | { |
200 | X509_NAME_ENTRY *ne; | 220 | X509_NAME_ENTRY *ne; |
201 | int ret; | 221 | int ret; |
222 | |||
202 | ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); | 223 | ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); |
203 | if(!ne) return 0; | 224 | if (!ne) |
225 | return 0; | ||
204 | ret = X509_NAME_add_entry(name, ne, loc, set); | 226 | ret = X509_NAME_add_entry(name, ne, loc, set); |
205 | X509_NAME_ENTRY_free(ne); | 227 | X509_NAME_ENTRY_free(ne); |
206 | return ret; | 228 | return ret; |
@@ -208,159 +230,177 @@ int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, | |||
208 | 230 | ||
209 | /* if set is -1, append to previous set, 0 'a new one', and 1, | 231 | /* if set is -1, append to previous set, 0 'a new one', and 1, |
210 | * prepend to the guy we are about to stomp on. */ | 232 | * prepend to the guy we are about to stomp on. */ |
211 | int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, | 233 | int |
212 | int set) | 234 | X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, int set) |
213 | { | 235 | { |
214 | X509_NAME_ENTRY *new_name=NULL; | 236 | X509_NAME_ENTRY *new_name = NULL; |
215 | int n,i,inc; | 237 | int n, i, inc; |
216 | STACK_OF(X509_NAME_ENTRY) *sk; | 238 | STACK_OF(X509_NAME_ENTRY) *sk; |
217 | 239 | ||
218 | if (name == NULL) return(0); | 240 | if (name == NULL) |
219 | sk=name->entries; | 241 | return (0); |
220 | n=sk_X509_NAME_ENTRY_num(sk); | 242 | sk = name->entries; |
221 | if (loc > n) loc=n; | 243 | n = sk_X509_NAME_ENTRY_num(sk); |
222 | else if (loc < 0) loc=n; | 244 | if (loc > n) |
245 | loc = n; | ||
246 | else if (loc < 0) | ||
247 | loc = n; | ||
223 | 248 | ||
224 | name->modified=1; | 249 | name->modified = 1; |
225 | 250 | ||
226 | if (set == -1) { | 251 | if (set == -1) { |
227 | if (loc == 0) { | 252 | if (loc == 0) { |
228 | set=0; | 253 | set = 0; |
229 | inc=1; | 254 | inc = 1; |
230 | } else { | 255 | } else { |
231 | set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set; | 256 | set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set; |
232 | inc=0; | 257 | inc = 0; |
233 | } | 258 | } |
234 | } else /* if (set >= 0) */ { | 259 | } else /* if (set >= 0) */ { |
235 | if (loc >= n) { | 260 | if (loc >= n) { |
236 | if (loc != 0) | 261 | if (loc != 0) |
237 | set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1; | 262 | set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set + 1; |
238 | else | 263 | else |
239 | set=0; | 264 | set = 0; |
240 | } else | 265 | } else |
241 | set=sk_X509_NAME_ENTRY_value(sk,loc)->set; | 266 | set = sk_X509_NAME_ENTRY_value(sk, loc)->set; |
242 | inc=(set == 0)?1:0; | 267 | inc = (set == 0) ? 1 : 0; |
243 | } | 268 | } |
244 | 269 | ||
245 | if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL) | 270 | if ((new_name = X509_NAME_ENTRY_dup(ne)) == NULL) |
246 | goto err; | 271 | goto err; |
247 | new_name->set=set; | 272 | new_name->set = set; |
248 | if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc)) { | 273 | if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) { |
249 | X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE); | 274 | X509err(X509_F_X509_NAME_ADD_ENTRY, ERR_R_MALLOC_FAILURE); |
250 | goto err; | 275 | goto err; |
251 | } | 276 | } |
252 | if (inc) { | 277 | if (inc) { |
253 | n=sk_X509_NAME_ENTRY_num(sk); | 278 | n = sk_X509_NAME_ENTRY_num(sk); |
254 | for (i=loc+1; i<n; i++) | 279 | for (i = loc + 1; i < n; i++) |
255 | sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1; | 280 | sk_X509_NAME_ENTRY_value(sk, i - 1)->set += 1; |
256 | } | 281 | } |
257 | return(1); | 282 | return (1); |
283 | |||
258 | err: | 284 | err: |
259 | if (new_name != NULL) | 285 | if (new_name != NULL) |
260 | X509_NAME_ENTRY_free(new_name); | 286 | X509_NAME_ENTRY_free(new_name); |
261 | return(0); | 287 | return (0); |
262 | } | 288 | } |
263 | 289 | ||
264 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, | 290 | X509_NAME_ENTRY * |
265 | const char *field, int type, const unsigned char *bytes, int len) | 291 | X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, |
292 | const char *field, int type, const unsigned char *bytes, int len) | ||
266 | { | 293 | { |
267 | ASN1_OBJECT *obj; | 294 | ASN1_OBJECT *obj; |
268 | X509_NAME_ENTRY *nentry; | 295 | X509_NAME_ENTRY *nentry; |
269 | 296 | ||
270 | obj=OBJ_txt2obj(field, 0); | 297 | obj = OBJ_txt2obj(field, 0); |
271 | if (obj == NULL) { | 298 | if (obj == NULL) { |
272 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, | 299 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, |
273 | X509_R_INVALID_FIELD_NAME); | 300 | X509_R_INVALID_FIELD_NAME); |
274 | ERR_add_error_data(2, "name=", field); | 301 | ERR_add_error_data(2, "name=", field); |
275 | return(NULL); | 302 | return (NULL); |
276 | } | 303 | } |
277 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len); | 304 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); |
278 | ASN1_OBJECT_free(obj); | 305 | ASN1_OBJECT_free(obj); |
279 | return nentry; | 306 | return nentry; |
280 | } | 307 | } |
281 | 308 | ||
282 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, | 309 | X509_NAME_ENTRY * |
283 | int type, unsigned char *bytes, int len) | 310 | X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type, |
311 | unsigned char *bytes, int len) | ||
284 | { | 312 | { |
285 | ASN1_OBJECT *obj; | 313 | ASN1_OBJECT *obj; |
286 | X509_NAME_ENTRY *nentry; | 314 | X509_NAME_ENTRY *nentry; |
287 | 315 | ||
288 | obj=OBJ_nid2obj(nid); | 316 | obj = OBJ_nid2obj(nid); |
289 | if (obj == NULL) { | 317 | if (obj == NULL) { |
290 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID); | 318 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID, |
291 | return(NULL); | 319 | X509_R_UNKNOWN_NID); |
320 | return (NULL); | ||
292 | } | 321 | } |
293 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len); | 322 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); |
294 | ASN1_OBJECT_free(obj); | 323 | ASN1_OBJECT_free(obj); |
295 | return nentry; | 324 | return nentry; |
296 | } | 325 | } |
297 | 326 | ||
298 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, | 327 | X509_NAME_ENTRY * |
299 | ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len) | 328 | X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, |
329 | const unsigned char *bytes, int len) | ||
300 | { | 330 | { |
301 | X509_NAME_ENTRY *ret; | 331 | X509_NAME_ENTRY *ret; |
302 | 332 | ||
303 | if ((ne == NULL) || (*ne == NULL)) { | 333 | if ((ne == NULL) || (*ne == NULL)) { |
304 | if ((ret=X509_NAME_ENTRY_new()) == NULL) | 334 | if ((ret = X509_NAME_ENTRY_new()) == NULL) |
305 | return(NULL); | 335 | return (NULL); |
306 | } else | 336 | } else |
307 | ret= *ne; | 337 | ret= *ne; |
308 | 338 | ||
309 | if (!X509_NAME_ENTRY_set_object(ret,obj)) | 339 | if (!X509_NAME_ENTRY_set_object(ret, obj)) |
310 | goto err; | 340 | goto err; |
311 | if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len)) | 341 | if (!X509_NAME_ENTRY_set_data(ret, type, bytes, len)) |
312 | goto err; | 342 | goto err; |
313 | 343 | ||
314 | if ((ne != NULL) && (*ne == NULL)) *ne=ret; | 344 | if ((ne != NULL) && (*ne == NULL)) |
315 | return(ret); | 345 | *ne = ret; |
346 | return (ret); | ||
347 | |||
316 | err: | 348 | err: |
317 | if ((ne == NULL) || (ret != *ne)) | 349 | if ((ne == NULL) || (ret != *ne)) |
318 | X509_NAME_ENTRY_free(ret); | 350 | X509_NAME_ENTRY_free(ret); |
319 | return(NULL); | 351 | return (NULL); |
320 | } | 352 | } |
321 | 353 | ||
322 | int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) | 354 | int |
355 | X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) | ||
323 | { | 356 | { |
324 | if ((ne == NULL) || (obj == NULL)) { | 357 | if ((ne == NULL) || (obj == NULL)) { |
325 | X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER); | 358 | X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT, |
326 | return(0); | 359 | ERR_R_PASSED_NULL_PARAMETER); |
360 | return (0); | ||
327 | } | 361 | } |
328 | ASN1_OBJECT_free(ne->object); | 362 | ASN1_OBJECT_free(ne->object); |
329 | ne->object=OBJ_dup(obj); | 363 | ne->object = OBJ_dup(obj); |
330 | return((ne->object == NULL)?0:1); | 364 | return ((ne->object == NULL) ? 0 : 1); |
331 | } | 365 | } |
332 | 366 | ||
333 | int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, | 367 | int |
334 | const unsigned char *bytes, int len) | 368 | X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, |
369 | const unsigned char *bytes, int len) | ||
335 | { | 370 | { |
336 | int i; | 371 | int i; |
337 | 372 | ||
338 | if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0); | 373 | if ((ne == NULL) || ((bytes == NULL) && (len != 0))) |
339 | if((type > 0) && (type & MBSTRING_FLAG)) | 374 | return (0); |
340 | return ASN1_STRING_set_by_NID(&ne->value, bytes, | 375 | if ((type > 0) && (type & MBSTRING_FLAG)) |
341 | len, type, | 376 | return ASN1_STRING_set_by_NID(&ne->value, bytes, len, type, |
342 | OBJ_obj2nid(ne->object)) ? 1 : 0; | 377 | OBJ_obj2nid(ne->object)) ? 1 : 0; |
343 | if (len < 0) len=strlen((const char *)bytes); | 378 | if (len < 0) |
344 | i=ASN1_STRING_set(ne->value,bytes,len); | 379 | len = strlen((const char *)bytes); |
345 | if (!i) return(0); | 380 | i = ASN1_STRING_set(ne->value, bytes, len); |
381 | if (!i) | ||
382 | return (0); | ||
346 | if (type != V_ASN1_UNDEF) { | 383 | if (type != V_ASN1_UNDEF) { |
347 | if (type == V_ASN1_APP_CHOOSE) | 384 | if (type == V_ASN1_APP_CHOOSE) |
348 | ne->value->type=ASN1_PRINTABLE_type(bytes,len); | 385 | ne->value->type = ASN1_PRINTABLE_type(bytes, len); |
349 | else | 386 | else |
350 | ne->value->type=type; | 387 | ne->value->type = type; |
351 | } | 388 | } |
352 | return(1); | 389 | return (1); |
353 | } | 390 | } |
354 | 391 | ||
355 | ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) | 392 | ASN1_OBJECT * |
393 | X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) | ||
356 | { | 394 | { |
357 | if (ne == NULL) return(NULL); | 395 | if (ne == NULL) |
358 | return(ne->object); | 396 | return (NULL); |
397 | return (ne->object); | ||
359 | } | 398 | } |
360 | 399 | ||
361 | ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) | 400 | ASN1_STRING * |
401 | X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) | ||
362 | { | 402 | { |
363 | if (ne == NULL) return(NULL); | 403 | if (ne == NULL) |
364 | return(ne->value); | 404 | return (NULL); |
405 | return (ne->value); | ||
365 | } | 406 | } |
366 | |||
diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c index fab93cce97..791b7916b8 100644 --- a/src/lib/libcrypto/x509/x509rset.c +++ b/src/lib/libcrypto/x509/x509rset.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 |
@@ -63,21 +63,26 @@ | |||
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | 65 | ||
66 | int X509_REQ_set_version(X509_REQ *x, long version) | 66 | int |
67 | X509_REQ_set_version(X509_REQ *x, long version) | ||
67 | { | 68 | { |
68 | if (x == NULL) return(0); | 69 | if (x == NULL) |
69 | return(ASN1_INTEGER_set(x->req_info->version,version)); | 70 | return (0); |
71 | return (ASN1_INTEGER_set(x->req_info->version, version)); | ||
70 | } | 72 | } |
71 | 73 | ||
72 | int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) | 74 | int |
75 | X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) | ||
73 | { | 76 | { |
74 | if ((x == NULL) || (x->req_info == NULL)) return(0); | 77 | if ((x == NULL) || (x->req_info == NULL)) |
75 | return(X509_NAME_set(&x->req_info->subject,name)); | 78 | return (0); |
79 | return (X509_NAME_set(&x->req_info->subject, name)); | ||
76 | } | 80 | } |
77 | 81 | ||
78 | int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) | 82 | int |
83 | X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) | ||
79 | { | 84 | { |
80 | if ((x == NULL) || (x->req_info == NULL)) return(0); | 85 | if ((x == NULL) || (x->req_info == NULL)) |
81 | return(X509_PUBKEY_set(&x->req_info->pubkey,pkey)); | 86 | return (0); |
87 | return (X509_PUBKEY_set(&x->req_info->pubkey, pkey)); | ||
82 | } | 88 | } |
83 | |||
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c index 9f0fbd39e3..b5f67b5a97 100644 --- a/src/lib/libcrypto/x509/x509spki.c +++ b/src/lib/libcrypto/x509/x509spki.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 |
@@ -60,36 +60,42 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/x509.h> | 61 | #include <openssl/x509.h> |
62 | 62 | ||
63 | int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) | 63 | int |
64 | NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) | ||
64 | { | 65 | { |
65 | if ((x == NULL) || (x->spkac == NULL)) return(0); | 66 | if ((x == NULL) || (x->spkac == NULL)) |
66 | return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey)); | 67 | return (0); |
68 | return (X509_PUBKEY_set(&(x->spkac->pubkey), pkey)); | ||
67 | } | 69 | } |
68 | 70 | ||
69 | EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x) | 71 | EVP_PKEY * |
72 | NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x) | ||
70 | { | 73 | { |
71 | if ((x == NULL) || (x->spkac == NULL)) | 74 | if ((x == NULL) || (x->spkac == NULL)) |
72 | return(NULL); | 75 | return (NULL); |
73 | return(X509_PUBKEY_get(x->spkac->pubkey)); | 76 | return (X509_PUBKEY_get(x->spkac->pubkey)); |
74 | } | 77 | } |
75 | 78 | ||
76 | /* Load a Netscape SPKI from a base64 encoded string */ | 79 | /* Load a Netscape SPKI from a base64 encoded string */ |
77 | 80 | ||
78 | NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len) | 81 | NETSCAPE_SPKI * |
82 | NETSCAPE_SPKI_b64_decode(const char *str, int len) | ||
79 | { | 83 | { |
80 | unsigned char *spki_der; | 84 | unsigned char *spki_der; |
81 | const unsigned char *p; | 85 | const unsigned char *p; |
82 | int spki_len; | 86 | int spki_len; |
83 | NETSCAPE_SPKI *spki; | 87 | NETSCAPE_SPKI *spki; |
84 | if(len <= 0) len = strlen(str); | 88 | |
89 | if (len <= 0) | ||
90 | len = strlen(str); | ||
85 | if (!(spki_der = malloc(len + 1))) { | 91 | if (!(spki_der = malloc(len + 1))) { |
86 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); | 92 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); |
87 | return NULL; | 93 | return NULL; |
88 | } | 94 | } |
89 | spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len); | 95 | spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len); |
90 | if(spki_len < 0) { | 96 | if (spki_len < 0) { |
91 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, | 97 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, |
92 | X509_R_BASE64_DECODE_ERROR); | 98 | X509_R_BASE64_DECODE_ERROR); |
93 | free(spki_der); | 99 | free(spki_der); |
94 | return NULL; | 100 | return NULL; |
95 | } | 101 | } |
@@ -101,7 +107,8 @@ NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len) | |||
101 | 107 | ||
102 | /* Generate a base64 encoded string from an SPKI */ | 108 | /* Generate a base64 encoded string from an SPKI */ |
103 | 109 | ||
104 | char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | 110 | char * |
111 | NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | ||
105 | { | 112 | { |
106 | unsigned char *der_spki, *p; | 113 | unsigned char *der_spki, *p; |
107 | char *b64_str; | 114 | char *b64_str; |
@@ -109,7 +116,7 @@ char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | |||
109 | der_len = i2d_NETSCAPE_SPKI(spki, NULL); | 116 | der_len = i2d_NETSCAPE_SPKI(spki, NULL); |
110 | der_spki = malloc(der_len); | 117 | der_spki = malloc(der_len); |
111 | b64_str = malloc(der_len * 2); | 118 | b64_str = malloc(der_len * 2); |
112 | if(!der_spki || !b64_str) { | 119 | if (!der_spki || !b64_str) { |
113 | X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); | 120 | X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); |
114 | free(der_spki); | 121 | free(der_spki); |
115 | free(b64_str); | 122 | free(b64_str); |
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c index ff06cfcab9..b85363f37e 100644 --- a/src/lib/libcrypto/x509/x509type.c +++ b/src/lib/libcrypto/x509/x509type.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,57 +62,59 @@ | |||
62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | int X509_certificate_type(X509 *x, EVP_PKEY *pkey) | 65 | int |
66 | X509_certificate_type(X509 *x, EVP_PKEY *pkey) | ||
66 | { | 67 | { |
67 | EVP_PKEY *pk; | 68 | EVP_PKEY *pk; |
68 | int ret=0,i; | 69 | int ret = 0, i; |
69 | 70 | ||
70 | if (x == NULL) return(0); | 71 | if (x == NULL) |
72 | return (0); | ||
71 | 73 | ||
72 | if (pkey == NULL) | 74 | if (pkey == NULL) |
73 | pk=X509_get_pubkey(x); | 75 | pk = X509_get_pubkey(x); |
74 | else | 76 | else |
75 | pk=pkey; | 77 | pk = pkey; |
76 | 78 | ||
77 | if (pk == NULL) return(0); | 79 | if (pk == NULL) |
80 | return (0); | ||
78 | 81 | ||
79 | switch (pk->type) { | 82 | switch (pk->type) { |
80 | case EVP_PKEY_RSA: | 83 | case EVP_PKEY_RSA: |
81 | ret=EVP_PK_RSA|EVP_PKT_SIGN; | 84 | ret = EVP_PK_RSA|EVP_PKT_SIGN; |
82 | /* if (!sign only extension) */ | 85 | /* if (!sign only extension) */ |
83 | ret|=EVP_PKT_ENC; | 86 | ret |= EVP_PKT_ENC; |
84 | break; | 87 | break; |
85 | case EVP_PKEY_DSA: | 88 | case EVP_PKEY_DSA: |
86 | ret=EVP_PK_DSA|EVP_PKT_SIGN; | 89 | ret = EVP_PK_DSA|EVP_PKT_SIGN; |
87 | break; | 90 | break; |
88 | case EVP_PKEY_EC: | 91 | case EVP_PKEY_EC: |
89 | ret=EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH; | 92 | ret = EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH; |
90 | break; | 93 | break; |
91 | case EVP_PKEY_DH: | 94 | case EVP_PKEY_DH: |
92 | ret=EVP_PK_DH|EVP_PKT_EXCH; | 95 | ret = EVP_PK_DH|EVP_PKT_EXCH; |
93 | break; | 96 | break; |
94 | case NID_id_GostR3410_94: | 97 | case NID_id_GostR3410_94: |
95 | case NID_id_GostR3410_2001: | 98 | case NID_id_GostR3410_2001: |
96 | ret=EVP_PKT_EXCH|EVP_PKT_SIGN; | 99 | ret = EVP_PKT_EXCH|EVP_PKT_SIGN; |
97 | break; | 100 | break; |
98 | default: | 101 | default: |
99 | break; | 102 | break; |
100 | } | 103 | } |
101 | 104 | ||
102 | i=OBJ_obj2nid(x->sig_alg->algorithm); | 105 | i = OBJ_obj2nid(x->sig_alg->algorithm); |
103 | if (i && OBJ_find_sigid_algs(i, NULL, &i)) { | 106 | if (i && OBJ_find_sigid_algs(i, NULL, &i)) { |
104 | |||
105 | switch (i) { | 107 | switch (i) { |
106 | case NID_rsaEncryption: | 108 | case NID_rsaEncryption: |
107 | case NID_rsa: | 109 | case NID_rsa: |
108 | ret|=EVP_PKS_RSA; | 110 | ret |= EVP_PKS_RSA; |
109 | break; | 111 | break; |
110 | case NID_dsa: | 112 | case NID_dsa: |
111 | case NID_dsa_2: | 113 | case NID_dsa_2: |
112 | ret|=EVP_PKS_DSA; | 114 | ret |= EVP_PKS_DSA; |
113 | break; | 115 | break; |
114 | case NID_X9_62_id_ecPublicKey: | 116 | case NID_X9_62_id_ecPublicKey: |
115 | ret|=EVP_PKS_EC; | 117 | ret |= EVP_PKS_EC; |
116 | break; | 118 | break; |
117 | default: | 119 | default: |
118 | break; | 120 | break; |
@@ -121,8 +123,8 @@ int X509_certificate_type(X509 *x, EVP_PKEY *pkey) | |||
121 | 123 | ||
122 | if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look | 124 | if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look |
123 | for, not bytes */ | 125 | for, not bytes */ |
124 | ret|=EVP_PKT_EXP; | 126 | ret |= EVP_PKT_EXP; |
125 | if(pkey==NULL) EVP_PKEY_free(pk); | 127 | if (pkey == NULL) |
126 | return(ret); | 128 | EVP_PKEY_free(pk); |
129 | return (ret); | ||
127 | } | 130 | } |
128 | |||
diff --git a/src/lib/libssl/src/crypto/x509/x509cset.c b/src/lib/libssl/src/crypto/x509/x509cset.c index bb39cf4e04..ee405d6e9f 100644 --- a/src/lib/libssl/src/crypto/x509/x509cset.c +++ b/src/lib/libssl/src/crypto/x509/x509cset.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 |
@@ -63,98 +63,111 @@ | |||
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | 65 | ||
66 | int X509_CRL_set_version(X509_CRL *x, long version) | 66 | int |
67 | X509_CRL_set_version(X509_CRL *x, long version) | ||
67 | { | 68 | { |
68 | if (x == NULL) return(0); | 69 | if (x == NULL) |
70 | return (0); | ||
69 | if (x->crl->version == NULL) { | 71 | if (x->crl->version == NULL) { |
70 | if ((x->crl->version=M_ASN1_INTEGER_new()) == NULL) | 72 | if ((x->crl->version = M_ASN1_INTEGER_new()) == NULL) |
71 | return(0); | 73 | return (0); |
72 | } | 74 | } |
73 | return(ASN1_INTEGER_set(x->crl->version,version)); | 75 | return (ASN1_INTEGER_set(x->crl->version, version)); |
74 | } | 76 | } |
75 | 77 | ||
76 | int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) | 78 | int |
79 | X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) | ||
77 | { | 80 | { |
78 | if ((x == NULL) || (x->crl == NULL)) return(0); | 81 | if ((x == NULL) || (x->crl == NULL)) |
79 | return(X509_NAME_set(&x->crl->issuer,name)); | 82 | return (0); |
83 | return (X509_NAME_set(&x->crl->issuer, name)); | ||
80 | } | 84 | } |
81 | 85 | ||
82 | 86 | int | |
83 | int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) | 87 | X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) |
84 | { | 88 | { |
85 | ASN1_TIME *in; | 89 | ASN1_TIME *in; |
86 | 90 | ||
87 | if (x == NULL) return(0); | 91 | if (x == NULL) |
88 | in=x->crl->lastUpdate; | 92 | return (0); |
93 | in = x->crl->lastUpdate; | ||
89 | if (in != tm) { | 94 | if (in != tm) { |
90 | in=M_ASN1_TIME_dup(tm); | 95 | in = M_ASN1_TIME_dup(tm); |
91 | if (in != NULL) { | 96 | if (in != NULL) { |
92 | M_ASN1_TIME_free(x->crl->lastUpdate); | 97 | M_ASN1_TIME_free(x->crl->lastUpdate); |
93 | x->crl->lastUpdate=in; | 98 | x->crl->lastUpdate = in; |
94 | } | 99 | } |
95 | } | 100 | } |
96 | return(in != NULL); | 101 | return (in != NULL); |
97 | } | 102 | } |
98 | 103 | ||
99 | int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) | 104 | int |
105 | X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) | ||
100 | { | 106 | { |
101 | ASN1_TIME *in; | 107 | ASN1_TIME *in; |
102 | 108 | ||
103 | if (x == NULL) return(0); | 109 | if (x == NULL) |
104 | in=x->crl->nextUpdate; | 110 | return (0); |
111 | in = x->crl->nextUpdate; | ||
105 | if (in != tm) { | 112 | if (in != tm) { |
106 | in=M_ASN1_TIME_dup(tm); | 113 | in = M_ASN1_TIME_dup(tm); |
107 | if (in != NULL) { | 114 | if (in != NULL) { |
108 | M_ASN1_TIME_free(x->crl->nextUpdate); | 115 | M_ASN1_TIME_free(x->crl->nextUpdate); |
109 | x->crl->nextUpdate=in; | 116 | x->crl->nextUpdate = in; |
110 | } | 117 | } |
111 | } | 118 | } |
112 | return(in != NULL); | 119 | return (in != NULL); |
113 | } | 120 | } |
114 | 121 | ||
115 | int X509_CRL_sort(X509_CRL *c) | 122 | int |
123 | X509_CRL_sort(X509_CRL *c) | ||
116 | { | 124 | { |
117 | int i; | 125 | int i; |
118 | X509_REVOKED *r; | 126 | X509_REVOKED *r; |
127 | |||
119 | /* sort the data so it will be written in serial | 128 | /* sort the data so it will be written in serial |
120 | * number order */ | 129 | * number order */ |
121 | sk_X509_REVOKED_sort(c->crl->revoked); | 130 | sk_X509_REVOKED_sort(c->crl->revoked); |
122 | for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++) { | 131 | for (i = 0; i < sk_X509_REVOKED_num(c->crl->revoked); i++) { |
123 | r=sk_X509_REVOKED_value(c->crl->revoked,i); | 132 | r = sk_X509_REVOKED_value(c->crl->revoked, i); |
124 | r->sequence=i; | 133 | r->sequence = i; |
125 | } | 134 | } |
126 | c->crl->enc.modified = 1; | 135 | c->crl->enc.modified = 1; |
127 | return 1; | 136 | return 1; |
128 | } | 137 | } |
129 | 138 | ||
130 | int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) | 139 | int |
140 | X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) | ||
131 | { | 141 | { |
132 | ASN1_TIME *in; | 142 | ASN1_TIME *in; |
133 | 143 | ||
134 | if (x == NULL) return(0); | 144 | if (x == NULL) |
135 | in=x->revocationDate; | 145 | return (0); |
146 | in = x->revocationDate; | ||
136 | if (in != tm) { | 147 | if (in != tm) { |
137 | in=M_ASN1_TIME_dup(tm); | 148 | in = M_ASN1_TIME_dup(tm); |
138 | if (in != NULL) { | 149 | if (in != NULL) { |
139 | M_ASN1_TIME_free(x->revocationDate); | 150 | M_ASN1_TIME_free(x->revocationDate); |
140 | x->revocationDate=in; | 151 | x->revocationDate = in; |
141 | } | 152 | } |
142 | } | 153 | } |
143 | return(in != NULL); | 154 | return (in != NULL); |
144 | } | 155 | } |
145 | 156 | ||
146 | int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) | 157 | int |
158 | X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) | ||
147 | { | 159 | { |
148 | ASN1_INTEGER *in; | 160 | ASN1_INTEGER *in; |
149 | 161 | ||
150 | if (x == NULL) return(0); | 162 | if (x == NULL) |
151 | in=x->serialNumber; | 163 | return (0); |
164 | in = x->serialNumber; | ||
152 | if (in != serial) { | 165 | if (in != serial) { |
153 | in=M_ASN1_INTEGER_dup(serial); | 166 | in = M_ASN1_INTEGER_dup(serial); |
154 | if (in != NULL) { | 167 | if (in != NULL) { |
155 | M_ASN1_INTEGER_free(x->serialNumber); | 168 | M_ASN1_INTEGER_free(x->serialNumber); |
156 | x->serialNumber=in; | 169 | x->serialNumber = in; |
157 | } | 170 | } |
158 | } | 171 | } |
159 | return(in != NULL); | 172 | return (in != NULL); |
160 | } | 173 | } |
diff --git a/src/lib/libssl/src/crypto/x509/x509name.c b/src/lib/libssl/src/crypto/x509/x509name.c index 729fb060f8..3d90fd67fe 100644 --- a/src/lib/libssl/src/crypto/x509/x509name.c +++ b/src/lib/libssl/src/crypto/x509/x509name.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,97 +64,110 @@ | |||
64 | #include <openssl/evp.h> | 64 | #include <openssl/evp.h> |
65 | #include <openssl/x509.h> | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) | 67 | int |
68 | X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) | ||
68 | { | 69 | { |
69 | ASN1_OBJECT *obj; | 70 | ASN1_OBJECT *obj; |
70 | 71 | ||
71 | obj=OBJ_nid2obj(nid); | 72 | obj = OBJ_nid2obj(nid); |
72 | if (obj == NULL) return(-1); | 73 | if (obj == NULL) |
73 | return(X509_NAME_get_text_by_OBJ(name,obj,buf,len)); | 74 | return (-1); |
75 | return (X509_NAME_get_text_by_OBJ(name, obj, buf, len)); | ||
74 | } | 76 | } |
75 | 77 | ||
76 | int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, | 78 | int |
77 | int len) | 79 | X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, |
80 | int len) | ||
78 | { | 81 | { |
79 | int i; | 82 | int i; |
80 | ASN1_STRING *data; | 83 | ASN1_STRING *data; |
81 | 84 | ||
82 | i=X509_NAME_get_index_by_OBJ(name,obj,-1); | 85 | i = X509_NAME_get_index_by_OBJ(name, obj, -1); |
83 | if (i < 0) return(-1); | 86 | if (i < 0) |
84 | data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i)); | 87 | return (-1); |
85 | i=(data->length > (len-1))?(len-1):data->length; | 88 | data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); |
86 | if (buf == NULL) return(data->length); | 89 | i = (data->length > (len - 1)) ? (len - 1) : data->length; |
87 | memcpy(buf,data->data,i); | 90 | if (buf == NULL) |
88 | buf[i]='\0'; | 91 | return (data->length); |
89 | return(i); | 92 | memcpy(buf, data->data, i); |
93 | buf[i] = '\0'; | ||
94 | return (i); | ||
90 | } | 95 | } |
91 | 96 | ||
92 | int X509_NAME_entry_count(X509_NAME *name) | 97 | int |
98 | X509_NAME_entry_count(X509_NAME *name) | ||
93 | { | 99 | { |
94 | if (name == NULL) return(0); | 100 | if (name == NULL) |
95 | return(sk_X509_NAME_ENTRY_num(name->entries)); | 101 | return (0); |
102 | return (sk_X509_NAME_ENTRY_num(name->entries)); | ||
96 | } | 103 | } |
97 | 104 | ||
98 | int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) | 105 | int |
106 | X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) | ||
99 | { | 107 | { |
100 | ASN1_OBJECT *obj; | 108 | ASN1_OBJECT *obj; |
101 | 109 | ||
102 | obj=OBJ_nid2obj(nid); | 110 | obj = OBJ_nid2obj(nid); |
103 | if (obj == NULL) return(-2); | 111 | if (obj == NULL) |
104 | return(X509_NAME_get_index_by_OBJ(name,obj,lastpos)); | 112 | return (-2); |
113 | return (X509_NAME_get_index_by_OBJ(name, obj, lastpos)); | ||
105 | } | 114 | } |
106 | 115 | ||
107 | /* NOTE: you should be passsing -1, not 0 as lastpos */ | 116 | /* NOTE: you should be passsing -1, not 0 as lastpos */ |
108 | int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, | 117 | int |
109 | int lastpos) | 118 | X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int lastpos) |
110 | { | 119 | { |
111 | int n; | 120 | int n; |
112 | X509_NAME_ENTRY *ne; | 121 | X509_NAME_ENTRY *ne; |
113 | STACK_OF(X509_NAME_ENTRY) *sk; | 122 | STACK_OF(X509_NAME_ENTRY) *sk; |
114 | 123 | ||
115 | if (name == NULL) return(-1); | 124 | if (name == NULL) |
125 | return (-1); | ||
116 | if (lastpos < 0) | 126 | if (lastpos < 0) |
117 | lastpos= -1; | 127 | lastpos = -1; |
118 | sk=name->entries; | 128 | sk = name->entries; |
119 | n=sk_X509_NAME_ENTRY_num(sk); | 129 | n = sk_X509_NAME_ENTRY_num(sk); |
120 | for (lastpos++; lastpos < n; lastpos++) { | 130 | for (lastpos++; lastpos < n; lastpos++) { |
121 | ne=sk_X509_NAME_ENTRY_value(sk,lastpos); | 131 | ne = sk_X509_NAME_ENTRY_value(sk, lastpos); |
122 | if (OBJ_cmp(ne->object,obj) == 0) | 132 | if (OBJ_cmp(ne->object, obj) == 0) |
123 | return(lastpos); | 133 | return (lastpos); |
124 | } | 134 | } |
125 | return(-1); | 135 | return (-1); |
126 | } | 136 | } |
127 | 137 | ||
128 | X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc) | 138 | X509_NAME_ENTRY * |
139 | X509_NAME_get_entry(X509_NAME *name, int loc) | ||
129 | { | 140 | { |
130 | if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc | 141 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc || |
131 | || loc < 0) | 142 | loc < 0) |
132 | return(NULL); | 143 | return (NULL); |
133 | else | 144 | else |
134 | return(sk_X509_NAME_ENTRY_value(name->entries,loc)); | 145 | return (sk_X509_NAME_ENTRY_value(name->entries, loc)); |
135 | } | 146 | } |
136 | 147 | ||
137 | X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) | 148 | X509_NAME_ENTRY * |
149 | X509_NAME_delete_entry(X509_NAME *name, int loc) | ||
138 | { | 150 | { |
139 | X509_NAME_ENTRY *ret; | 151 | X509_NAME_ENTRY *ret; |
140 | int i,n,set_prev,set_next; | 152 | int i, n, set_prev, set_next; |
141 | STACK_OF(X509_NAME_ENTRY) *sk; | 153 | STACK_OF(X509_NAME_ENTRY) *sk; |
142 | 154 | ||
143 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc | 155 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc || |
144 | || loc < 0) | 156 | loc < 0) |
145 | return(NULL); | 157 | return (NULL); |
146 | sk=name->entries; | 158 | sk = name->entries; |
147 | ret=sk_X509_NAME_ENTRY_delete(sk,loc); | 159 | ret = sk_X509_NAME_ENTRY_delete(sk, loc); |
148 | n=sk_X509_NAME_ENTRY_num(sk); | 160 | n = sk_X509_NAME_ENTRY_num(sk); |
149 | name->modified=1; | 161 | name->modified = 1; |
150 | if (loc == n) return(ret); | 162 | if (loc == n) |
163 | return (ret); | ||
151 | 164 | ||
152 | /* else we need to fixup the set field */ | 165 | /* else we need to fixup the set field */ |
153 | if (loc != 0) | 166 | if (loc != 0) |
154 | set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set; | 167 | set_prev = (sk_X509_NAME_ENTRY_value(sk, loc - 1))->set; |
155 | else | 168 | else |
156 | set_prev=ret->set-1; | 169 | set_prev = ret->set - 1; |
157 | set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set; | 170 | set_next = sk_X509_NAME_ENTRY_value(sk, loc)->set; |
158 | 171 | ||
159 | /* set_prev is the previous set | 172 | /* set_prev is the previous set |
160 | * set is the current set | 173 | * set is the current set |
@@ -164,43 +177,52 @@ X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) | |||
164 | * next 1 1 2 2 2 2 3 2 | 177 | * next 1 1 2 2 2 2 3 2 |
165 | * so basically only if prev and next differ by 2, then | 178 | * so basically only if prev and next differ by 2, then |
166 | * re-number down by 1 */ | 179 | * re-number down by 1 */ |
167 | if (set_prev+1 < set_next) | 180 | if (set_prev + 1 < set_next) |
168 | for (i=loc; i<n; i++) | 181 | for (i = loc; i < n; i++) |
169 | sk_X509_NAME_ENTRY_value(sk,i)->set--; | 182 | sk_X509_NAME_ENTRY_value(sk, i)->set--; |
170 | return(ret); | 183 | return (ret); |
171 | } | 184 | } |
172 | 185 | ||
173 | int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, | 186 | int |
174 | unsigned char *bytes, int len, int loc, int set) | 187 | X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, |
188 | unsigned char *bytes, int len, int loc, int set) | ||
175 | { | 189 | { |
176 | X509_NAME_ENTRY *ne; | 190 | X509_NAME_ENTRY *ne; |
177 | int ret; | 191 | int ret; |
192 | |||
178 | ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); | 193 | ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); |
179 | if(!ne) return 0; | 194 | if (!ne) |
195 | return 0; | ||
180 | ret = X509_NAME_add_entry(name, ne, loc, set); | 196 | ret = X509_NAME_add_entry(name, ne, loc, set); |
181 | X509_NAME_ENTRY_free(ne); | 197 | X509_NAME_ENTRY_free(ne); |
182 | return ret; | 198 | return ret; |
183 | } | 199 | } |
184 | 200 | ||
185 | int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, | 201 | int |
186 | unsigned char *bytes, int len, int loc, int set) | 202 | X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, |
203 | unsigned char *bytes, int len, int loc, int set) | ||
187 | { | 204 | { |
188 | X509_NAME_ENTRY *ne; | 205 | X509_NAME_ENTRY *ne; |
189 | int ret; | 206 | int ret; |
207 | |||
190 | ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); | 208 | ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); |
191 | if(!ne) return 0; | 209 | if (!ne) |
210 | return 0; | ||
192 | ret = X509_NAME_add_entry(name, ne, loc, set); | 211 | ret = X509_NAME_add_entry(name, ne, loc, set); |
193 | X509_NAME_ENTRY_free(ne); | 212 | X509_NAME_ENTRY_free(ne); |
194 | return ret; | 213 | return ret; |
195 | } | 214 | } |
196 | 215 | ||
197 | int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, | 216 | int |
198 | const unsigned char *bytes, int len, int loc, int set) | 217 | X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, |
218 | const unsigned char *bytes, int len, int loc, int set) | ||
199 | { | 219 | { |
200 | X509_NAME_ENTRY *ne; | 220 | X509_NAME_ENTRY *ne; |
201 | int ret; | 221 | int ret; |
222 | |||
202 | ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); | 223 | ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); |
203 | if(!ne) return 0; | 224 | if (!ne) |
225 | return 0; | ||
204 | ret = X509_NAME_add_entry(name, ne, loc, set); | 226 | ret = X509_NAME_add_entry(name, ne, loc, set); |
205 | X509_NAME_ENTRY_free(ne); | 227 | X509_NAME_ENTRY_free(ne); |
206 | return ret; | 228 | return ret; |
@@ -208,159 +230,177 @@ int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, | |||
208 | 230 | ||
209 | /* if set is -1, append to previous set, 0 'a new one', and 1, | 231 | /* if set is -1, append to previous set, 0 'a new one', and 1, |
210 | * prepend to the guy we are about to stomp on. */ | 232 | * prepend to the guy we are about to stomp on. */ |
211 | int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, | 233 | int |
212 | int set) | 234 | X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, int set) |
213 | { | 235 | { |
214 | X509_NAME_ENTRY *new_name=NULL; | 236 | X509_NAME_ENTRY *new_name = NULL; |
215 | int n,i,inc; | 237 | int n, i, inc; |
216 | STACK_OF(X509_NAME_ENTRY) *sk; | 238 | STACK_OF(X509_NAME_ENTRY) *sk; |
217 | 239 | ||
218 | if (name == NULL) return(0); | 240 | if (name == NULL) |
219 | sk=name->entries; | 241 | return (0); |
220 | n=sk_X509_NAME_ENTRY_num(sk); | 242 | sk = name->entries; |
221 | if (loc > n) loc=n; | 243 | n = sk_X509_NAME_ENTRY_num(sk); |
222 | else if (loc < 0) loc=n; | 244 | if (loc > n) |
245 | loc = n; | ||
246 | else if (loc < 0) | ||
247 | loc = n; | ||
223 | 248 | ||
224 | name->modified=1; | 249 | name->modified = 1; |
225 | 250 | ||
226 | if (set == -1) { | 251 | if (set == -1) { |
227 | if (loc == 0) { | 252 | if (loc == 0) { |
228 | set=0; | 253 | set = 0; |
229 | inc=1; | 254 | inc = 1; |
230 | } else { | 255 | } else { |
231 | set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set; | 256 | set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set; |
232 | inc=0; | 257 | inc = 0; |
233 | } | 258 | } |
234 | } else /* if (set >= 0) */ { | 259 | } else /* if (set >= 0) */ { |
235 | if (loc >= n) { | 260 | if (loc >= n) { |
236 | if (loc != 0) | 261 | if (loc != 0) |
237 | set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1; | 262 | set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set + 1; |
238 | else | 263 | else |
239 | set=0; | 264 | set = 0; |
240 | } else | 265 | } else |
241 | set=sk_X509_NAME_ENTRY_value(sk,loc)->set; | 266 | set = sk_X509_NAME_ENTRY_value(sk, loc)->set; |
242 | inc=(set == 0)?1:0; | 267 | inc = (set == 0) ? 1 : 0; |
243 | } | 268 | } |
244 | 269 | ||
245 | if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL) | 270 | if ((new_name = X509_NAME_ENTRY_dup(ne)) == NULL) |
246 | goto err; | 271 | goto err; |
247 | new_name->set=set; | 272 | new_name->set = set; |
248 | if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc)) { | 273 | if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) { |
249 | X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE); | 274 | X509err(X509_F_X509_NAME_ADD_ENTRY, ERR_R_MALLOC_FAILURE); |
250 | goto err; | 275 | goto err; |
251 | } | 276 | } |
252 | if (inc) { | 277 | if (inc) { |
253 | n=sk_X509_NAME_ENTRY_num(sk); | 278 | n = sk_X509_NAME_ENTRY_num(sk); |
254 | for (i=loc+1; i<n; i++) | 279 | for (i = loc + 1; i < n; i++) |
255 | sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1; | 280 | sk_X509_NAME_ENTRY_value(sk, i - 1)->set += 1; |
256 | } | 281 | } |
257 | return(1); | 282 | return (1); |
283 | |||
258 | err: | 284 | err: |
259 | if (new_name != NULL) | 285 | if (new_name != NULL) |
260 | X509_NAME_ENTRY_free(new_name); | 286 | X509_NAME_ENTRY_free(new_name); |
261 | return(0); | 287 | return (0); |
262 | } | 288 | } |
263 | 289 | ||
264 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, | 290 | X509_NAME_ENTRY * |
265 | const char *field, int type, const unsigned char *bytes, int len) | 291 | X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, |
292 | const char *field, int type, const unsigned char *bytes, int len) | ||
266 | { | 293 | { |
267 | ASN1_OBJECT *obj; | 294 | ASN1_OBJECT *obj; |
268 | X509_NAME_ENTRY *nentry; | 295 | X509_NAME_ENTRY *nentry; |
269 | 296 | ||
270 | obj=OBJ_txt2obj(field, 0); | 297 | obj = OBJ_txt2obj(field, 0); |
271 | if (obj == NULL) { | 298 | if (obj == NULL) { |
272 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, | 299 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, |
273 | X509_R_INVALID_FIELD_NAME); | 300 | X509_R_INVALID_FIELD_NAME); |
274 | ERR_add_error_data(2, "name=", field); | 301 | ERR_add_error_data(2, "name=", field); |
275 | return(NULL); | 302 | return (NULL); |
276 | } | 303 | } |
277 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len); | 304 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); |
278 | ASN1_OBJECT_free(obj); | 305 | ASN1_OBJECT_free(obj); |
279 | return nentry; | 306 | return nentry; |
280 | } | 307 | } |
281 | 308 | ||
282 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, | 309 | X509_NAME_ENTRY * |
283 | int type, unsigned char *bytes, int len) | 310 | X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type, |
311 | unsigned char *bytes, int len) | ||
284 | { | 312 | { |
285 | ASN1_OBJECT *obj; | 313 | ASN1_OBJECT *obj; |
286 | X509_NAME_ENTRY *nentry; | 314 | X509_NAME_ENTRY *nentry; |
287 | 315 | ||
288 | obj=OBJ_nid2obj(nid); | 316 | obj = OBJ_nid2obj(nid); |
289 | if (obj == NULL) { | 317 | if (obj == NULL) { |
290 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID); | 318 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID, |
291 | return(NULL); | 319 | X509_R_UNKNOWN_NID); |
320 | return (NULL); | ||
292 | } | 321 | } |
293 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len); | 322 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); |
294 | ASN1_OBJECT_free(obj); | 323 | ASN1_OBJECT_free(obj); |
295 | return nentry; | 324 | return nentry; |
296 | } | 325 | } |
297 | 326 | ||
298 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, | 327 | X509_NAME_ENTRY * |
299 | ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len) | 328 | X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, |
329 | const unsigned char *bytes, int len) | ||
300 | { | 330 | { |
301 | X509_NAME_ENTRY *ret; | 331 | X509_NAME_ENTRY *ret; |
302 | 332 | ||
303 | if ((ne == NULL) || (*ne == NULL)) { | 333 | if ((ne == NULL) || (*ne == NULL)) { |
304 | if ((ret=X509_NAME_ENTRY_new()) == NULL) | 334 | if ((ret = X509_NAME_ENTRY_new()) == NULL) |
305 | return(NULL); | 335 | return (NULL); |
306 | } else | 336 | } else |
307 | ret= *ne; | 337 | ret= *ne; |
308 | 338 | ||
309 | if (!X509_NAME_ENTRY_set_object(ret,obj)) | 339 | if (!X509_NAME_ENTRY_set_object(ret, obj)) |
310 | goto err; | 340 | goto err; |
311 | if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len)) | 341 | if (!X509_NAME_ENTRY_set_data(ret, type, bytes, len)) |
312 | goto err; | 342 | goto err; |
313 | 343 | ||
314 | if ((ne != NULL) && (*ne == NULL)) *ne=ret; | 344 | if ((ne != NULL) && (*ne == NULL)) |
315 | return(ret); | 345 | *ne = ret; |
346 | return (ret); | ||
347 | |||
316 | err: | 348 | err: |
317 | if ((ne == NULL) || (ret != *ne)) | 349 | if ((ne == NULL) || (ret != *ne)) |
318 | X509_NAME_ENTRY_free(ret); | 350 | X509_NAME_ENTRY_free(ret); |
319 | return(NULL); | 351 | return (NULL); |
320 | } | 352 | } |
321 | 353 | ||
322 | int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) | 354 | int |
355 | X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) | ||
323 | { | 356 | { |
324 | if ((ne == NULL) || (obj == NULL)) { | 357 | if ((ne == NULL) || (obj == NULL)) { |
325 | X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER); | 358 | X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT, |
326 | return(0); | 359 | ERR_R_PASSED_NULL_PARAMETER); |
360 | return (0); | ||
327 | } | 361 | } |
328 | ASN1_OBJECT_free(ne->object); | 362 | ASN1_OBJECT_free(ne->object); |
329 | ne->object=OBJ_dup(obj); | 363 | ne->object = OBJ_dup(obj); |
330 | return((ne->object == NULL)?0:1); | 364 | return ((ne->object == NULL) ? 0 : 1); |
331 | } | 365 | } |
332 | 366 | ||
333 | int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, | 367 | int |
334 | const unsigned char *bytes, int len) | 368 | X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, |
369 | const unsigned char *bytes, int len) | ||
335 | { | 370 | { |
336 | int i; | 371 | int i; |
337 | 372 | ||
338 | if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0); | 373 | if ((ne == NULL) || ((bytes == NULL) && (len != 0))) |
339 | if((type > 0) && (type & MBSTRING_FLAG)) | 374 | return (0); |
340 | return ASN1_STRING_set_by_NID(&ne->value, bytes, | 375 | if ((type > 0) && (type & MBSTRING_FLAG)) |
341 | len, type, | 376 | return ASN1_STRING_set_by_NID(&ne->value, bytes, len, type, |
342 | OBJ_obj2nid(ne->object)) ? 1 : 0; | 377 | OBJ_obj2nid(ne->object)) ? 1 : 0; |
343 | if (len < 0) len=strlen((const char *)bytes); | 378 | if (len < 0) |
344 | i=ASN1_STRING_set(ne->value,bytes,len); | 379 | len = strlen((const char *)bytes); |
345 | if (!i) return(0); | 380 | i = ASN1_STRING_set(ne->value, bytes, len); |
381 | if (!i) | ||
382 | return (0); | ||
346 | if (type != V_ASN1_UNDEF) { | 383 | if (type != V_ASN1_UNDEF) { |
347 | if (type == V_ASN1_APP_CHOOSE) | 384 | if (type == V_ASN1_APP_CHOOSE) |
348 | ne->value->type=ASN1_PRINTABLE_type(bytes,len); | 385 | ne->value->type = ASN1_PRINTABLE_type(bytes, len); |
349 | else | 386 | else |
350 | ne->value->type=type; | 387 | ne->value->type = type; |
351 | } | 388 | } |
352 | return(1); | 389 | return (1); |
353 | } | 390 | } |
354 | 391 | ||
355 | ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) | 392 | ASN1_OBJECT * |
393 | X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) | ||
356 | { | 394 | { |
357 | if (ne == NULL) return(NULL); | 395 | if (ne == NULL) |
358 | return(ne->object); | 396 | return (NULL); |
397 | return (ne->object); | ||
359 | } | 398 | } |
360 | 399 | ||
361 | ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) | 400 | ASN1_STRING * |
401 | X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) | ||
362 | { | 402 | { |
363 | if (ne == NULL) return(NULL); | 403 | if (ne == NULL) |
364 | return(ne->value); | 404 | return (NULL); |
405 | return (ne->value); | ||
365 | } | 406 | } |
366 | |||
diff --git a/src/lib/libssl/src/crypto/x509/x509rset.c b/src/lib/libssl/src/crypto/x509/x509rset.c index fab93cce97..791b7916b8 100644 --- a/src/lib/libssl/src/crypto/x509/x509rset.c +++ b/src/lib/libssl/src/crypto/x509/x509rset.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 |
@@ -63,21 +63,26 @@ | |||
63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | 65 | ||
66 | int X509_REQ_set_version(X509_REQ *x, long version) | 66 | int |
67 | X509_REQ_set_version(X509_REQ *x, long version) | ||
67 | { | 68 | { |
68 | if (x == NULL) return(0); | 69 | if (x == NULL) |
69 | return(ASN1_INTEGER_set(x->req_info->version,version)); | 70 | return (0); |
71 | return (ASN1_INTEGER_set(x->req_info->version, version)); | ||
70 | } | 72 | } |
71 | 73 | ||
72 | int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) | 74 | int |
75 | X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) | ||
73 | { | 76 | { |
74 | if ((x == NULL) || (x->req_info == NULL)) return(0); | 77 | if ((x == NULL) || (x->req_info == NULL)) |
75 | return(X509_NAME_set(&x->req_info->subject,name)); | 78 | return (0); |
79 | return (X509_NAME_set(&x->req_info->subject, name)); | ||
76 | } | 80 | } |
77 | 81 | ||
78 | int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) | 82 | int |
83 | X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) | ||
79 | { | 84 | { |
80 | if ((x == NULL) || (x->req_info == NULL)) return(0); | 85 | if ((x == NULL) || (x->req_info == NULL)) |
81 | return(X509_PUBKEY_set(&x->req_info->pubkey,pkey)); | 86 | return (0); |
87 | return (X509_PUBKEY_set(&x->req_info->pubkey, pkey)); | ||
82 | } | 88 | } |
83 | |||
diff --git a/src/lib/libssl/src/crypto/x509/x509spki.c b/src/lib/libssl/src/crypto/x509/x509spki.c index 9f0fbd39e3..b5f67b5a97 100644 --- a/src/lib/libssl/src/crypto/x509/x509spki.c +++ b/src/lib/libssl/src/crypto/x509/x509spki.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 |
@@ -60,36 +60,42 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/x509.h> | 61 | #include <openssl/x509.h> |
62 | 62 | ||
63 | int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) | 63 | int |
64 | NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) | ||
64 | { | 65 | { |
65 | if ((x == NULL) || (x->spkac == NULL)) return(0); | 66 | if ((x == NULL) || (x->spkac == NULL)) |
66 | return(X509_PUBKEY_set(&(x->spkac->pubkey),pkey)); | 67 | return (0); |
68 | return (X509_PUBKEY_set(&(x->spkac->pubkey), pkey)); | ||
67 | } | 69 | } |
68 | 70 | ||
69 | EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x) | 71 | EVP_PKEY * |
72 | NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x) | ||
70 | { | 73 | { |
71 | if ((x == NULL) || (x->spkac == NULL)) | 74 | if ((x == NULL) || (x->spkac == NULL)) |
72 | return(NULL); | 75 | return (NULL); |
73 | return(X509_PUBKEY_get(x->spkac->pubkey)); | 76 | return (X509_PUBKEY_get(x->spkac->pubkey)); |
74 | } | 77 | } |
75 | 78 | ||
76 | /* Load a Netscape SPKI from a base64 encoded string */ | 79 | /* Load a Netscape SPKI from a base64 encoded string */ |
77 | 80 | ||
78 | NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len) | 81 | NETSCAPE_SPKI * |
82 | NETSCAPE_SPKI_b64_decode(const char *str, int len) | ||
79 | { | 83 | { |
80 | unsigned char *spki_der; | 84 | unsigned char *spki_der; |
81 | const unsigned char *p; | 85 | const unsigned char *p; |
82 | int spki_len; | 86 | int spki_len; |
83 | NETSCAPE_SPKI *spki; | 87 | NETSCAPE_SPKI *spki; |
84 | if(len <= 0) len = strlen(str); | 88 | |
89 | if (len <= 0) | ||
90 | len = strlen(str); | ||
85 | if (!(spki_der = malloc(len + 1))) { | 91 | if (!(spki_der = malloc(len + 1))) { |
86 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); | 92 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); |
87 | return NULL; | 93 | return NULL; |
88 | } | 94 | } |
89 | spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len); | 95 | spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len); |
90 | if(spki_len < 0) { | 96 | if (spki_len < 0) { |
91 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, | 97 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, |
92 | X509_R_BASE64_DECODE_ERROR); | 98 | X509_R_BASE64_DECODE_ERROR); |
93 | free(spki_der); | 99 | free(spki_der); |
94 | return NULL; | 100 | return NULL; |
95 | } | 101 | } |
@@ -101,7 +107,8 @@ NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len) | |||
101 | 107 | ||
102 | /* Generate a base64 encoded string from an SPKI */ | 108 | /* Generate a base64 encoded string from an SPKI */ |
103 | 109 | ||
104 | char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | 110 | char * |
111 | NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | ||
105 | { | 112 | { |
106 | unsigned char *der_spki, *p; | 113 | unsigned char *der_spki, *p; |
107 | char *b64_str; | 114 | char *b64_str; |
@@ -109,7 +116,7 @@ char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | |||
109 | der_len = i2d_NETSCAPE_SPKI(spki, NULL); | 116 | der_len = i2d_NETSCAPE_SPKI(spki, NULL); |
110 | der_spki = malloc(der_len); | 117 | der_spki = malloc(der_len); |
111 | b64_str = malloc(der_len * 2); | 118 | b64_str = malloc(der_len * 2); |
112 | if(!der_spki || !b64_str) { | 119 | if (!der_spki || !b64_str) { |
113 | X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); | 120 | X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); |
114 | free(der_spki); | 121 | free(der_spki); |
115 | free(b64_str); | 122 | free(b64_str); |
diff --git a/src/lib/libssl/src/crypto/x509/x509type.c b/src/lib/libssl/src/crypto/x509/x509type.c index ff06cfcab9..b85363f37e 100644 --- a/src/lib/libssl/src/crypto/x509/x509type.c +++ b/src/lib/libssl/src/crypto/x509/x509type.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,57 +62,59 @@ | |||
62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | int X509_certificate_type(X509 *x, EVP_PKEY *pkey) | 65 | int |
66 | X509_certificate_type(X509 *x, EVP_PKEY *pkey) | ||
66 | { | 67 | { |
67 | EVP_PKEY *pk; | 68 | EVP_PKEY *pk; |
68 | int ret=0,i; | 69 | int ret = 0, i; |
69 | 70 | ||
70 | if (x == NULL) return(0); | 71 | if (x == NULL) |
72 | return (0); | ||
71 | 73 | ||
72 | if (pkey == NULL) | 74 | if (pkey == NULL) |
73 | pk=X509_get_pubkey(x); | 75 | pk = X509_get_pubkey(x); |
74 | else | 76 | else |
75 | pk=pkey; | 77 | pk = pkey; |
76 | 78 | ||
77 | if (pk == NULL) return(0); | 79 | if (pk == NULL) |
80 | return (0); | ||
78 | 81 | ||
79 | switch (pk->type) { | 82 | switch (pk->type) { |
80 | case EVP_PKEY_RSA: | 83 | case EVP_PKEY_RSA: |
81 | ret=EVP_PK_RSA|EVP_PKT_SIGN; | 84 | ret = EVP_PK_RSA|EVP_PKT_SIGN; |
82 | /* if (!sign only extension) */ | 85 | /* if (!sign only extension) */ |
83 | ret|=EVP_PKT_ENC; | 86 | ret |= EVP_PKT_ENC; |
84 | break; | 87 | break; |
85 | case EVP_PKEY_DSA: | 88 | case EVP_PKEY_DSA: |
86 | ret=EVP_PK_DSA|EVP_PKT_SIGN; | 89 | ret = EVP_PK_DSA|EVP_PKT_SIGN; |
87 | break; | 90 | break; |
88 | case EVP_PKEY_EC: | 91 | case EVP_PKEY_EC: |
89 | ret=EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH; | 92 | ret = EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH; |
90 | break; | 93 | break; |
91 | case EVP_PKEY_DH: | 94 | case EVP_PKEY_DH: |
92 | ret=EVP_PK_DH|EVP_PKT_EXCH; | 95 | ret = EVP_PK_DH|EVP_PKT_EXCH; |
93 | break; | 96 | break; |
94 | case NID_id_GostR3410_94: | 97 | case NID_id_GostR3410_94: |
95 | case NID_id_GostR3410_2001: | 98 | case NID_id_GostR3410_2001: |
96 | ret=EVP_PKT_EXCH|EVP_PKT_SIGN; | 99 | ret = EVP_PKT_EXCH|EVP_PKT_SIGN; |
97 | break; | 100 | break; |
98 | default: | 101 | default: |
99 | break; | 102 | break; |
100 | } | 103 | } |
101 | 104 | ||
102 | i=OBJ_obj2nid(x->sig_alg->algorithm); | 105 | i = OBJ_obj2nid(x->sig_alg->algorithm); |
103 | if (i && OBJ_find_sigid_algs(i, NULL, &i)) { | 106 | if (i && OBJ_find_sigid_algs(i, NULL, &i)) { |
104 | |||
105 | switch (i) { | 107 | switch (i) { |
106 | case NID_rsaEncryption: | 108 | case NID_rsaEncryption: |
107 | case NID_rsa: | 109 | case NID_rsa: |
108 | ret|=EVP_PKS_RSA; | 110 | ret |= EVP_PKS_RSA; |
109 | break; | 111 | break; |
110 | case NID_dsa: | 112 | case NID_dsa: |
111 | case NID_dsa_2: | 113 | case NID_dsa_2: |
112 | ret|=EVP_PKS_DSA; | 114 | ret |= EVP_PKS_DSA; |
113 | break; | 115 | break; |
114 | case NID_X9_62_id_ecPublicKey: | 116 | case NID_X9_62_id_ecPublicKey: |
115 | ret|=EVP_PKS_EC; | 117 | ret |= EVP_PKS_EC; |
116 | break; | 118 | break; |
117 | default: | 119 | default: |
118 | break; | 120 | break; |
@@ -121,8 +123,8 @@ int X509_certificate_type(X509 *x, EVP_PKEY *pkey) | |||
121 | 123 | ||
122 | if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look | 124 | if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look |
123 | for, not bytes */ | 125 | for, not bytes */ |
124 | ret|=EVP_PKT_EXP; | 126 | ret |= EVP_PKT_EXP; |
125 | if(pkey==NULL) EVP_PKEY_free(pk); | 127 | if (pkey == NULL) |
126 | return(ret); | 128 | EVP_PKEY_free(pk); |
129 | return (ret); | ||
127 | } | 130 | } |
128 | |||