diff options
author | markus <> | 2004-04-25 18:57:51 +0000 |
---|---|---|
committer | markus <> | 2004-04-25 18:57:51 +0000 |
commit | ec90872076c947d6b86d8bff4bcf978c38dd75c4 (patch) | |
tree | 9d6b667fe6d855e88f569f058c1670d35c580a79 | |
parent | 77d5833441f96bb08cfa47daaaad2f4246be07fa (diff) | |
download | openbsd-ec90872076c947d6b86d8bff4bcf978c38dd75c4.tar.gz openbsd-ec90872076c947d6b86d8bff4bcf978c38dd75c4.tar.bz2 openbsd-ec90872076c947d6b86d8bff4bcf978c38dd75c4.zip |
update missing pieces from 0.9.7d; ok henning
crank minor for API extensions
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_txt.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_vfy.c | 55 | ||||
-rw-r--r-- | src/lib/libssl/crypto/shlib_version | 2 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/evp/digest.c | 15 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_txt.c | 8 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_vfy.c | 55 |
7 files changed, 135 insertions, 23 deletions
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index b22eed4421..0623ddf1f0 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -248,6 +248,7 @@ int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
248 | 248 | ||
249 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | 249 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) |
250 | { | 250 | { |
251 | unsigned char *tmp_buf; | ||
251 | if ((in == NULL) || (in->digest == NULL)) | 252 | if ((in == NULL) || (in->digest == NULL)) |
252 | { | 253 | { |
253 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | 254 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); |
@@ -262,15 +263,22 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
262 | } | 263 | } |
263 | #endif | 264 | #endif |
264 | 265 | ||
266 | if (out->digest == in->digest) | ||
267 | { | ||
268 | tmp_buf = out->md_data; | ||
269 | EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE); | ||
270 | } | ||
271 | else tmp_buf = NULL; | ||
265 | EVP_MD_CTX_cleanup(out); | 272 | EVP_MD_CTX_cleanup(out); |
266 | memcpy(out,in,sizeof *out); | 273 | memcpy(out,in,sizeof *out); |
267 | 274 | ||
268 | if (out->digest->ctx_size) | 275 | if (out->digest->ctx_size) |
269 | { | 276 | { |
270 | out->md_data=OPENSSL_malloc(out->digest->ctx_size); | 277 | if (tmp_buf) out->md_data = tmp_buf; |
278 | else out->md_data=OPENSSL_malloc(out->digest->ctx_size); | ||
271 | memcpy(out->md_data,in->md_data,out->digest->ctx_size); | 279 | memcpy(out->md_data,in->md_data,out->digest->ctx_size); |
272 | } | 280 | } |
273 | 281 | ||
274 | if (out->digest->copy) | 282 | if (out->digest->copy) |
275 | return out->digest->copy(out,in); | 283 | return out->digest->copy(out,in); |
276 | 284 | ||
@@ -308,7 +316,8 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
308 | if (ctx->digest && ctx->digest->cleanup | 316 | if (ctx->digest && ctx->digest->cleanup |
309 | && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) | 317 | && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) |
310 | ctx->digest->cleanup(ctx); | 318 | ctx->digest->cleanup(ctx); |
311 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) | 319 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data |
320 | && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) | ||
312 | { | 321 | { |
313 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); | 322 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
314 | OPENSSL_free(ctx->md_data); | 323 | OPENSSL_free(ctx->md_data); |
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c index 9d09ae17e8..e31ebc6741 100644 --- a/src/lib/libcrypto/x509/x509_txt.c +++ b/src/lib/libcrypto/x509/x509_txt.c | |||
@@ -147,8 +147,14 @@ const char *X509_verify_cert_error_string(long n) | |||
147 | case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: | 147 | case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: |
148 | return("unhandled critical extension"); | 148 | return("unhandled critical extension"); |
149 | 149 | ||
150 | case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN: | ||
151 | return("key usage does not include CRL signing"); | ||
152 | |||
153 | case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION: | ||
154 | return("unhandled critical CRL extension"); | ||
155 | |||
150 | default: | 156 | default: |
151 | snprintf(buf,sizeof buf,"error number %ld",n); | 157 | BIO_snprintf(buf,sizeof buf,"error number %ld",n); |
152 | return(buf); | 158 | return(buf); |
153 | } | 159 | } |
154 | } | 160 | } |
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c index 2bb21b443e..2e4d0b823a 100644 --- a/src/lib/libcrypto/x509/x509_vfy.c +++ b/src/lib/libcrypto/x509/x509_vfy.c | |||
@@ -383,6 +383,7 @@ static int check_chain_purpose(X509_STORE_CTX *ctx) | |||
383 | /* Check all untrusted certificates */ | 383 | /* Check all untrusted certificates */ |
384 | for (i = 0; i < ctx->last_untrusted; i++) | 384 | for (i = 0; i < ctx->last_untrusted; i++) |
385 | { | 385 | { |
386 | int ret; | ||
386 | x = sk_X509_value(ctx->chain, i); | 387 | x = sk_X509_value(ctx->chain, i); |
387 | if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL) | 388 | if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL) |
388 | && (x->ex_flags & EXFLAG_CRITICAL)) | 389 | && (x->ex_flags & EXFLAG_CRITICAL)) |
@@ -393,7 +394,10 @@ static int check_chain_purpose(X509_STORE_CTX *ctx) | |||
393 | ok=cb(0,ctx); | 394 | ok=cb(0,ctx); |
394 | if (!ok) goto end; | 395 | if (!ok) goto end; |
395 | } | 396 | } |
396 | if (!X509_check_purpose(x, ctx->purpose, i)) | 397 | ret = X509_check_purpose(x, ctx->purpose, i); |
398 | if ((ret == 0) | ||
399 | || ((ctx->flags & X509_V_FLAG_X509_STRICT) | ||
400 | && (ret != 1))) | ||
397 | { | 401 | { |
398 | if (i) | 402 | if (i) |
399 | ctx->error = X509_V_ERR_INVALID_CA; | 403 | ctx->error = X509_V_ERR_INVALID_CA; |
@@ -537,6 +541,14 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) | |||
537 | 541 | ||
538 | if(issuer) | 542 | if(issuer) |
539 | { | 543 | { |
544 | /* Check for cRLSign bit if keyUsage present */ | ||
545 | if ((issuer->ex_flags & EXFLAG_KUSAGE) && | ||
546 | !(issuer->ex_kusage & KU_CRL_SIGN)) | ||
547 | { | ||
548 | ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN; | ||
549 | ok = ctx->verify_cb(0, ctx); | ||
550 | if(!ok) goto err; | ||
551 | } | ||
540 | 552 | ||
541 | /* Attempt to get issuer certificate public key */ | 553 | /* Attempt to get issuer certificate public key */ |
542 | ikey = X509_get_pubkey(issuer); | 554 | ikey = X509_get_pubkey(issuer); |
@@ -611,17 +623,46 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) | |||
611 | { | 623 | { |
612 | int idx, ok; | 624 | int idx, ok; |
613 | X509_REVOKED rtmp; | 625 | X509_REVOKED rtmp; |
626 | STACK_OF(X509_EXTENSION) *exts; | ||
627 | X509_EXTENSION *ext; | ||
614 | /* Look for serial number of certificate in CRL */ | 628 | /* Look for serial number of certificate in CRL */ |
615 | rtmp.serialNumber = X509_get_serialNumber(x); | 629 | rtmp.serialNumber = X509_get_serialNumber(x); |
616 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); | 630 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); |
617 | /* Not found: OK */ | 631 | /* If found assume revoked: want something cleverer than |
618 | if(idx == -1) return 1; | ||
619 | /* Otherwise revoked: want something cleverer than | ||
620 | * this to handle entry extensions in V2 CRLs. | 632 | * this to handle entry extensions in V2 CRLs. |
621 | */ | 633 | */ |
622 | ctx->error = X509_V_ERR_CERT_REVOKED; | 634 | if(idx >= 0) |
623 | ok = ctx->verify_cb(0, ctx); | 635 | { |
624 | return ok; | 636 | ctx->error = X509_V_ERR_CERT_REVOKED; |
637 | ok = ctx->verify_cb(0, ctx); | ||
638 | if (!ok) return 0; | ||
639 | } | ||
640 | |||
641 | if (ctx->flags & X509_V_FLAG_IGNORE_CRITICAL) | ||
642 | return 1; | ||
643 | |||
644 | /* See if we have any critical CRL extensions: since we | ||
645 | * currently don't handle any CRL extensions the CRL must be | ||
646 | * rejected. | ||
647 | * This code accesses the X509_CRL structure directly: applications | ||
648 | * shouldn't do this. | ||
649 | */ | ||
650 | |||
651 | exts = crl->crl->extensions; | ||
652 | |||
653 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) | ||
654 | { | ||
655 | ext = sk_X509_EXTENSION_value(exts, idx); | ||
656 | if (ext->critical > 0) | ||
657 | { | ||
658 | ctx->error = | ||
659 | X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION; | ||
660 | ok = ctx->verify_cb(0, ctx); | ||
661 | if(!ok) return 0; | ||
662 | break; | ||
663 | } | ||
664 | } | ||
665 | return 1; | ||
625 | } | 666 | } |
626 | 667 | ||
627 | static int internal_verify(X509_STORE_CTX *ctx) | 668 | static int internal_verify(X509_STORE_CTX *ctx) |
diff --git a/src/lib/libssl/crypto/shlib_version b/src/lib/libssl/crypto/shlib_version index c6fa1d0271..57f40b7e5d 100644 --- a/src/lib/libssl/crypto/shlib_version +++ b/src/lib/libssl/crypto/shlib_version | |||
@@ -1,2 +1,2 @@ | |||
1 | major=10 | 1 | major=10 |
2 | minor=3 | 2 | minor=4 |
diff --git a/src/lib/libssl/src/crypto/evp/digest.c b/src/lib/libssl/src/crypto/evp/digest.c index b22eed4421..0623ddf1f0 100644 --- a/src/lib/libssl/src/crypto/evp/digest.c +++ b/src/lib/libssl/src/crypto/evp/digest.c | |||
@@ -248,6 +248,7 @@ int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
248 | 248 | ||
249 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | 249 | int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) |
250 | { | 250 | { |
251 | unsigned char *tmp_buf; | ||
251 | if ((in == NULL) || (in->digest == NULL)) | 252 | if ((in == NULL) || (in->digest == NULL)) |
252 | { | 253 | { |
253 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | 254 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); |
@@ -262,15 +263,22 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
262 | } | 263 | } |
263 | #endif | 264 | #endif |
264 | 265 | ||
266 | if (out->digest == in->digest) | ||
267 | { | ||
268 | tmp_buf = out->md_data; | ||
269 | EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE); | ||
270 | } | ||
271 | else tmp_buf = NULL; | ||
265 | EVP_MD_CTX_cleanup(out); | 272 | EVP_MD_CTX_cleanup(out); |
266 | memcpy(out,in,sizeof *out); | 273 | memcpy(out,in,sizeof *out); |
267 | 274 | ||
268 | if (out->digest->ctx_size) | 275 | if (out->digest->ctx_size) |
269 | { | 276 | { |
270 | out->md_data=OPENSSL_malloc(out->digest->ctx_size); | 277 | if (tmp_buf) out->md_data = tmp_buf; |
278 | else out->md_data=OPENSSL_malloc(out->digest->ctx_size); | ||
271 | memcpy(out->md_data,in->md_data,out->digest->ctx_size); | 279 | memcpy(out->md_data,in->md_data,out->digest->ctx_size); |
272 | } | 280 | } |
273 | 281 | ||
274 | if (out->digest->copy) | 282 | if (out->digest->copy) |
275 | return out->digest->copy(out,in); | 283 | return out->digest->copy(out,in); |
276 | 284 | ||
@@ -308,7 +316,8 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
308 | if (ctx->digest && ctx->digest->cleanup | 316 | if (ctx->digest && ctx->digest->cleanup |
309 | && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) | 317 | && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED)) |
310 | ctx->digest->cleanup(ctx); | 318 | ctx->digest->cleanup(ctx); |
311 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) | 319 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data |
320 | && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) | ||
312 | { | 321 | { |
313 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); | 322 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
314 | OPENSSL_free(ctx->md_data); | 323 | OPENSSL_free(ctx->md_data); |
diff --git a/src/lib/libssl/src/crypto/x509/x509_txt.c b/src/lib/libssl/src/crypto/x509/x509_txt.c index 9d09ae17e8..e31ebc6741 100644 --- a/src/lib/libssl/src/crypto/x509/x509_txt.c +++ b/src/lib/libssl/src/crypto/x509/x509_txt.c | |||
@@ -147,8 +147,14 @@ const char *X509_verify_cert_error_string(long n) | |||
147 | case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: | 147 | case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: |
148 | return("unhandled critical extension"); | 148 | return("unhandled critical extension"); |
149 | 149 | ||
150 | case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN: | ||
151 | return("key usage does not include CRL signing"); | ||
152 | |||
153 | case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION: | ||
154 | return("unhandled critical CRL extension"); | ||
155 | |||
150 | default: | 156 | default: |
151 | snprintf(buf,sizeof buf,"error number %ld",n); | 157 | BIO_snprintf(buf,sizeof buf,"error number %ld",n); |
152 | return(buf); | 158 | return(buf); |
153 | } | 159 | } |
154 | } | 160 | } |
diff --git a/src/lib/libssl/src/crypto/x509/x509_vfy.c b/src/lib/libssl/src/crypto/x509/x509_vfy.c index 2bb21b443e..2e4d0b823a 100644 --- a/src/lib/libssl/src/crypto/x509/x509_vfy.c +++ b/src/lib/libssl/src/crypto/x509/x509_vfy.c | |||
@@ -383,6 +383,7 @@ static int check_chain_purpose(X509_STORE_CTX *ctx) | |||
383 | /* Check all untrusted certificates */ | 383 | /* Check all untrusted certificates */ |
384 | for (i = 0; i < ctx->last_untrusted; i++) | 384 | for (i = 0; i < ctx->last_untrusted; i++) |
385 | { | 385 | { |
386 | int ret; | ||
386 | x = sk_X509_value(ctx->chain, i); | 387 | x = sk_X509_value(ctx->chain, i); |
387 | if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL) | 388 | if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL) |
388 | && (x->ex_flags & EXFLAG_CRITICAL)) | 389 | && (x->ex_flags & EXFLAG_CRITICAL)) |
@@ -393,7 +394,10 @@ static int check_chain_purpose(X509_STORE_CTX *ctx) | |||
393 | ok=cb(0,ctx); | 394 | ok=cb(0,ctx); |
394 | if (!ok) goto end; | 395 | if (!ok) goto end; |
395 | } | 396 | } |
396 | if (!X509_check_purpose(x, ctx->purpose, i)) | 397 | ret = X509_check_purpose(x, ctx->purpose, i); |
398 | if ((ret == 0) | ||
399 | || ((ctx->flags & X509_V_FLAG_X509_STRICT) | ||
400 | && (ret != 1))) | ||
397 | { | 401 | { |
398 | if (i) | 402 | if (i) |
399 | ctx->error = X509_V_ERR_INVALID_CA; | 403 | ctx->error = X509_V_ERR_INVALID_CA; |
@@ -537,6 +541,14 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) | |||
537 | 541 | ||
538 | if(issuer) | 542 | if(issuer) |
539 | { | 543 | { |
544 | /* Check for cRLSign bit if keyUsage present */ | ||
545 | if ((issuer->ex_flags & EXFLAG_KUSAGE) && | ||
546 | !(issuer->ex_kusage & KU_CRL_SIGN)) | ||
547 | { | ||
548 | ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN; | ||
549 | ok = ctx->verify_cb(0, ctx); | ||
550 | if(!ok) goto err; | ||
551 | } | ||
540 | 552 | ||
541 | /* Attempt to get issuer certificate public key */ | 553 | /* Attempt to get issuer certificate public key */ |
542 | ikey = X509_get_pubkey(issuer); | 554 | ikey = X509_get_pubkey(issuer); |
@@ -611,17 +623,46 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) | |||
611 | { | 623 | { |
612 | int idx, ok; | 624 | int idx, ok; |
613 | X509_REVOKED rtmp; | 625 | X509_REVOKED rtmp; |
626 | STACK_OF(X509_EXTENSION) *exts; | ||
627 | X509_EXTENSION *ext; | ||
614 | /* Look for serial number of certificate in CRL */ | 628 | /* Look for serial number of certificate in CRL */ |
615 | rtmp.serialNumber = X509_get_serialNumber(x); | 629 | rtmp.serialNumber = X509_get_serialNumber(x); |
616 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); | 630 | idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp); |
617 | /* Not found: OK */ | 631 | /* If found assume revoked: want something cleverer than |
618 | if(idx == -1) return 1; | ||
619 | /* Otherwise revoked: want something cleverer than | ||
620 | * this to handle entry extensions in V2 CRLs. | 632 | * this to handle entry extensions in V2 CRLs. |
621 | */ | 633 | */ |
622 | ctx->error = X509_V_ERR_CERT_REVOKED; | 634 | if(idx >= 0) |
623 | ok = ctx->verify_cb(0, ctx); | 635 | { |
624 | return ok; | 636 | ctx->error = X509_V_ERR_CERT_REVOKED; |
637 | ok = ctx->verify_cb(0, ctx); | ||
638 | if (!ok) return 0; | ||
639 | } | ||
640 | |||
641 | if (ctx->flags & X509_V_FLAG_IGNORE_CRITICAL) | ||
642 | return 1; | ||
643 | |||
644 | /* See if we have any critical CRL extensions: since we | ||
645 | * currently don't handle any CRL extensions the CRL must be | ||
646 | * rejected. | ||
647 | * This code accesses the X509_CRL structure directly: applications | ||
648 | * shouldn't do this. | ||
649 | */ | ||
650 | |||
651 | exts = crl->crl->extensions; | ||
652 | |||
653 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) | ||
654 | { | ||
655 | ext = sk_X509_EXTENSION_value(exts, idx); | ||
656 | if (ext->critical > 0) | ||
657 | { | ||
658 | ctx->error = | ||
659 | X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION; | ||
660 | ok = ctx->verify_cb(0, ctx); | ||
661 | if(!ok) return 0; | ||
662 | break; | ||
663 | } | ||
664 | } | ||
665 | return 1; | ||
625 | } | 666 | } |
626 | 667 | ||
627 | static int internal_verify(X509_STORE_CTX *ctx) | 668 | static int internal_verify(X509_STORE_CTX *ctx) |