summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509_v3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/x509/x509_v3.c')
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c94
1 files changed, 43 insertions, 51 deletions
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
index 42e6f0ab05..f41fab3367 100644
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -66,24 +66,24 @@
66#include <openssl/x509v3.h> 66#include <openssl/x509v3.h>
67 67
68int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) 68int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
69 { 69{
70 if (x == NULL) return(0); 70 if (x == NULL) return(0);
71 return(sk_X509_EXTENSION_num(x)); 71 return(sk_X509_EXTENSION_num(x));
72 } 72}
73 73
74int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid, 74int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid,
75 int lastpos) 75 int lastpos)
76 { 76{
77 ASN1_OBJECT *obj; 77 ASN1_OBJECT *obj;
78 78
79 obj=OBJ_nid2obj(nid); 79 obj=OBJ_nid2obj(nid);
80 if (obj == NULL) return(-2); 80 if (obj == NULL) return(-2);
81 return(X509v3_get_ext_by_OBJ(x,obj,lastpos)); 81 return(X509v3_get_ext_by_OBJ(x,obj,lastpos));
82 } 82}
83 83
84int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj, 84int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj,
85 int lastpos) 85 int lastpos)
86 { 86{
87 int n; 87 int n;
88 X509_EXTENSION *ex; 88 X509_EXTENSION *ex;
89 89
@@ -92,18 +92,17 @@ int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj,
92 if (lastpos < 0) 92 if (lastpos < 0)
93 lastpos=0; 93 lastpos=0;
94 n=sk_X509_EXTENSION_num(sk); 94 n=sk_X509_EXTENSION_num(sk);
95 for ( ; lastpos < n; lastpos++) 95 for ( ; lastpos < n; lastpos++) {
96 {
97 ex=sk_X509_EXTENSION_value(sk,lastpos); 96 ex=sk_X509_EXTENSION_value(sk,lastpos);
98 if (OBJ_cmp(ex->object,obj) == 0) 97 if (OBJ_cmp(ex->object,obj) == 0)
99 return(lastpos); 98 return(lastpos);
100 }
101 return(-1);
102 } 99 }
100 return(-1);
101}
103 102
104int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit, 103int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
105 int lastpos) 104 int lastpos)
106 { 105{
107 int n; 106 int n;
108 X509_EXTENSION *ex; 107 X509_EXTENSION *ex;
109 108
@@ -112,53 +111,49 @@ int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
112 if (lastpos < 0) 111 if (lastpos < 0)
113 lastpos=0; 112 lastpos=0;
114 n=sk_X509_EXTENSION_num(sk); 113 n=sk_X509_EXTENSION_num(sk);
115 for ( ; lastpos < n; lastpos++) 114 for ( ; lastpos < n; lastpos++) {
116 {
117 ex=sk_X509_EXTENSION_value(sk,lastpos); 115 ex=sk_X509_EXTENSION_value(sk,lastpos);
118 if ( ((ex->critical > 0) && crit) || 116 if ( ((ex->critical > 0) && crit) ||
119 ((ex->critical <= 0) && !crit)) 117 ((ex->critical <= 0) && !crit))
120 return(lastpos); 118 return(lastpos);
121 }
122 return(-1);
123 } 119 }
120 return(-1);
121}
124 122
125X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc) 123X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc)
126 { 124{
127 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) 125 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
128 return NULL; 126 return NULL;
129 else 127 else
130 return sk_X509_EXTENSION_value(x,loc); 128 return sk_X509_EXTENSION_value(x,loc);
131 } 129}
132 130
133X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc) 131X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)
134 { 132{
135 X509_EXTENSION *ret; 133 X509_EXTENSION *ret;
136 134
137 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) 135 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
138 return(NULL); 136 return(NULL);
139 ret=sk_X509_EXTENSION_delete(x,loc); 137 ret=sk_X509_EXTENSION_delete(x,loc);
140 return(ret); 138 return(ret);
141 } 139}
142 140
143STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, 141STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
144 X509_EXTENSION *ex, int loc) 142 X509_EXTENSION *ex, int loc)
145 { 143{
146 X509_EXTENSION *new_ex=NULL; 144 X509_EXTENSION *new_ex=NULL;
147 int n; 145 int n;
148 STACK_OF(X509_EXTENSION) *sk=NULL; 146 STACK_OF(X509_EXTENSION) *sk=NULL;
149 147
150 if (x == NULL) 148 if (x == NULL) {
151 {
152 X509err(X509_F_X509V3_ADD_EXT,ERR_R_PASSED_NULL_PARAMETER); 149 X509err(X509_F_X509V3_ADD_EXT,ERR_R_PASSED_NULL_PARAMETER);
153 goto err2; 150 goto err2;
154 } 151 }
155 152
156 if (*x == NULL) 153 if (*x == NULL) {
157 {
158 if ((sk=sk_X509_EXTENSION_new_null()) == NULL) 154 if ((sk=sk_X509_EXTENSION_new_null()) == NULL)
159 goto err; 155 goto err;
160 } 156 } else
161 else
162 sk= *x; 157 sk= *x;
163 158
164 n=sk_X509_EXTENSION_num(sk); 159 n=sk_X509_EXTENSION_num(sk);
@@ -178,39 +173,36 @@ err2:
178 if (new_ex != NULL) X509_EXTENSION_free(new_ex); 173 if (new_ex != NULL) X509_EXTENSION_free(new_ex);
179 if (sk != NULL) sk_X509_EXTENSION_free(sk); 174 if (sk != NULL) sk_X509_EXTENSION_free(sk);
180 return(NULL); 175 return(NULL);
181 } 176}
182 177
183X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, 178X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
184 int crit, ASN1_OCTET_STRING *data) 179 int crit, ASN1_OCTET_STRING *data)
185 { 180{
186 ASN1_OBJECT *obj; 181 ASN1_OBJECT *obj;
187 X509_EXTENSION *ret; 182 X509_EXTENSION *ret;
188 183
189 obj=OBJ_nid2obj(nid); 184 obj=OBJ_nid2obj(nid);
190 if (obj == NULL) 185 if (obj == NULL) {
191 {
192 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID); 186 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID);
193 return(NULL); 187 return(NULL);
194 } 188 }
195 ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data); 189 ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data);
196 if (ret == NULL) ASN1_OBJECT_free(obj); 190 if (ret == NULL) ASN1_OBJECT_free(obj);
197 return(ret); 191 return(ret);
198 } 192}
199 193
200X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, 194X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
201 ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data) 195 ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data)
202 { 196{
203 X509_EXTENSION *ret; 197 X509_EXTENSION *ret;
204 198
205 if ((ex == NULL) || (*ex == NULL)) 199 if ((ex == NULL) || (*ex == NULL)) {
206 {
207 if ((ret=X509_EXTENSION_new()) == NULL) 200 if ((ret=X509_EXTENSION_new()) == NULL)
208 { 201 {
209 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE); 202 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE);
210 return(NULL); 203 return(NULL);
211 }
212 } 204 }
213 else 205 } else
214 ret= *ex; 206 ret= *ex;
215 207
216 if (!X509_EXTENSION_set_object(ret,obj)) 208 if (!X509_EXTENSION_set_object(ret,obj))
@@ -226,49 +218,49 @@ err:
226 if ((ex == NULL) || (ret != *ex)) 218 if ((ex == NULL) || (ret != *ex))
227 X509_EXTENSION_free(ret); 219 X509_EXTENSION_free(ret);
228 return(NULL); 220 return(NULL);
229 } 221}
230 222
231int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj) 223int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj)
232 { 224{
233 if ((ex == NULL) || (obj == NULL)) 225 if ((ex == NULL) || (obj == NULL))
234 return(0); 226 return(0);
235 ASN1_OBJECT_free(ex->object); 227 ASN1_OBJECT_free(ex->object);
236 ex->object=OBJ_dup(obj); 228 ex->object=OBJ_dup(obj);
237 return(1); 229 return(1);
238 } 230}
239 231
240int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit) 232int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)
241 { 233{
242 if (ex == NULL) return(0); 234 if (ex == NULL) return(0);
243 ex->critical=(crit)?0xFF:-1; 235 ex->critical=(crit)?0xFF:-1;
244 return(1); 236 return(1);
245 } 237}
246 238
247int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data) 239int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
248 { 240{
249 int i; 241 int i;
250 242
251 if (ex == NULL) return(0); 243 if (ex == NULL) return(0);
252 i=M_ASN1_OCTET_STRING_set(ex->value,data->data,data->length); 244 i=M_ASN1_OCTET_STRING_set(ex->value,data->data,data->length);
253 if (!i) return(0); 245 if (!i) return(0);
254 return(1); 246 return(1);
255 } 247}
256 248
257ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex) 249ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)
258 { 250{
259 if (ex == NULL) return(NULL); 251 if (ex == NULL) return(NULL);
260 return(ex->object); 252 return(ex->object);
261 } 253}
262 254
263ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex) 255ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)
264 { 256{
265 if (ex == NULL) return(NULL); 257 if (ex == NULL) return(NULL);
266 return(ex->value); 258 return(ex->value);
267 } 259}
268 260
269int X509_EXTENSION_get_critical(X509_EXTENSION *ex) 261int X509_EXTENSION_get_critical(X509_EXTENSION *ex)
270 { 262{
271 if (ex == NULL) return(0); 263 if (ex == NULL) return(0);
272 if(ex->critical > 0) return 1; 264 if(ex->critical > 0) return 1;
273 return 0; 265 return 0;
274 } 266}