summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/t_x509.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/t_x509.c')
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c55
1 files changed, 10 insertions, 45 deletions
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index edbb39a02f..e061f2ffad 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -72,7 +72,6 @@
72#include <openssl/objects.h> 72#include <openssl/objects.h>
73#include <openssl/x509.h> 73#include <openssl/x509.h>
74#include <openssl/x509v3.h> 74#include <openssl/x509v3.h>
75#include "asn1_locl.h"
76 75
77#ifndef OPENSSL_NO_FP_API 76#ifndef OPENSSL_NO_FP_API
78int X509_print_fp(FILE *fp, X509 *x) 77int X509_print_fp(FILE *fp, X509 *x)
@@ -138,10 +137,10 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
138 if (BIO_write(bp," Serial Number:",22) <= 0) goto err; 137 if (BIO_write(bp," Serial Number:",22) <= 0) goto err;
139 138
140 bs=X509_get_serialNumber(x); 139 bs=X509_get_serialNumber(x);
141 if (bs->length <= (int)sizeof(long)) 140 if (bs->length <= 4)
142 { 141 {
143 l=ASN1_INTEGER_get(bs); 142 l=ASN1_INTEGER_get(bs);
144 if (bs->type == V_ASN1_NEG_INTEGER) 143 if (l < 0)
145 { 144 {
146 l= -l; 145 l= -l;
147 neg="-"; 146 neg="-";
@@ -168,16 +167,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
168 167
169 if(!(cflag & X509_FLAG_NO_SIGNAME)) 168 if(!(cflag & X509_FLAG_NO_SIGNAME))
170 { 169 {
171 if(X509_signature_print(bp, x->sig_alg, NULL) <= 0)
172 goto err;
173#if 0
174 if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0) 170 if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0)
175 goto err; 171 goto err;
176 if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) 172 if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0)
177 goto err; 173 goto err;
178 if (BIO_puts(bp, "\n") <= 0) 174 if (BIO_puts(bp, "\n") <= 0)
179 goto err; 175 goto err;
180#endif
181 } 176 }
182 177
183 if(!(cflag & X509_FLAG_NO_ISSUER)) 178 if(!(cflag & X509_FLAG_NO_ISSUER))
@@ -260,8 +255,7 @@ int X509_ocspid_print (BIO *bp, X509 *x)
260 goto err; 255 goto err;
261 i2d_X509_NAME(x->cert_info->subject, &dertmp); 256 i2d_X509_NAME(x->cert_info->subject, &dertmp);
262 257
263 if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) 258 EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL);
264 goto err;
265 for (i=0; i < SHA_DIGEST_LENGTH; i++) 259 for (i=0; i < SHA_DIGEST_LENGTH; i++)
266 { 260 {
267 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; 261 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
@@ -274,10 +268,8 @@ int X509_ocspid_print (BIO *bp, X509 *x)
274 if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) 268 if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0)
275 goto err; 269 goto err;
276 270
277 if (!EVP_Digest(x->cert_info->key->public_key->data, 271 EVP_Digest(x->cert_info->key->public_key->data,
278 x->cert_info->key->public_key->length, 272 x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL);
279 SHA1md, NULL, EVP_sha1(), NULL))
280 goto err;
281 for (i=0; i < SHA_DIGEST_LENGTH; i++) 273 for (i=0; i < SHA_DIGEST_LENGTH; i++)
282 { 274 {
283 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) 275 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
@@ -291,50 +283,23 @@ err:
291 return(0); 283 return(0);
292 } 284 }
293 285
294int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) 286int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
295{ 287{
296 const unsigned char *s; 288 unsigned char *s;
297 int i, n; 289 int i, n;
290 if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0;
291 if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
298 292
299 n=sig->length; 293 n=sig->length;
300 s=sig->data; 294 s=sig->data;
301 for (i=0; i<n; i++) 295 for (i=0; i<n; i++)
302 { 296 {
303 if ((i%18) == 0) 297 if ((i%18) == 0)
304 { 298 if (BIO_write(bp,"\n ",9) <= 0) return 0;
305 if (BIO_write(bp,"\n",1) <= 0) return 0;
306 if (BIO_indent(bp, indent, indent) <= 0) return 0;
307 }
308 if (BIO_printf(bp,"%02x%s",s[i], 299 if (BIO_printf(bp,"%02x%s",s[i],
309 ((i+1) == n)?"":":") <= 0) return 0; 300 ((i+1) == n)?"":":") <= 0) return 0;
310 } 301 }
311 if (BIO_write(bp,"\n",1) != 1) return 0; 302 if (BIO_write(bp,"\n",1) != 1) return 0;
312
313 return 1;
314}
315
316int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
317{
318 int sig_nid;
319 if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0;
320 if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
321
322 sig_nid = OBJ_obj2nid(sigalg->algorithm);
323 if (sig_nid != NID_undef)
324 {
325 int pkey_nid, dig_nid;
326 const EVP_PKEY_ASN1_METHOD *ameth;
327 if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid))
328 {
329 ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
330 if (ameth && ameth->sig_print)
331 return ameth->sig_print(bp, sigalg, sig, 9, 0);
332 }
333 }
334 if (sig)
335 return X509_signature_dump(bp, sig, 9);
336 else if (BIO_puts(bp, "\n") <= 0)
337 return 0;
338 return 1; 303 return 1;
339} 304}
340 305