diff options
| author | tb <> | 2023-07-28 09:58:30 +0000 |
|---|---|---|
| committer | tb <> | 2023-07-28 09:58:30 +0000 |
| commit | 01880b11cac352ccba5d827f27af88f31718069a (patch) | |
| tree | a8ef39245b59cd5d4747a1efefdf2919068bb6e3 /src/lib/libcrypto/asn1 | |
| parent | b5382a6334a2ec0fe73ab6c49ebefb47af93329c (diff) | |
| download | openbsd-01880b11cac352ccba5d827f27af88f31718069a.tar.gz openbsd-01880b11cac352ccba5d827f27af88f31718069a.tar.bz2 openbsd-01880b11cac352ccba5d827f27af88f31718069a.zip | |
Make ASN.1 BIO internal
With every bump we can remove a bit more of the ASN.1 BIO and the
streaming interface. At some point enough will be internal so that
we can rewrite it and bring it in a shape where mere mortals can
follow all the twists and turns. This is the next step: BIO_f_asn1(3)
goes away and takes BIO_asn1_{get,set}_{prefix,suffix}() with it,
a bunch of functions helping along in a write-after-free recently.
The getters go away, the setters stay for now.
ok jsing
Diffstat (limited to 'src/lib/libcrypto/asn1')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_local.h | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/bio_asn1.c | 50 | ||||
| -rw-r--r-- | src/lib/libcrypto/asn1/bio_ndef.c | 5 |
4 files changed, 12 insertions, 51 deletions
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index 5be4668be0..fbc5d098d8 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1.h,v 1.76 2023/04/25 19:08:30 tb Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.77 2023/07/28 09:58:30 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -922,8 +922,6 @@ void ASN1_PCTX_set_oid_flags(ASN1_PCTX *p, unsigned long flags); | |||
| 922 | unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); | 922 | unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); |
| 923 | void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); | 923 | void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); |
| 924 | 924 | ||
| 925 | const BIO_METHOD *BIO_f_asn1(void); | ||
| 926 | |||
| 927 | int SMIME_crlf_copy(BIO *in, BIO *out, int flags); | 925 | int SMIME_crlf_copy(BIO *in, BIO *out, int flags); |
| 928 | int SMIME_text(BIO *in, BIO *out); | 926 | int SMIME_text(BIO *in, BIO *out); |
| 929 | 927 | ||
diff --git a/src/lib/libcrypto/asn1/asn1_local.h b/src/lib/libcrypto/asn1/asn1_local.h index 52b8a46aeb..0ef5101fcb 100644 --- a/src/lib/libcrypto/asn1/asn1_local.h +++ b/src/lib/libcrypto/asn1/asn1_local.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1_local.h,v 1.2 2023/04/25 19:08:30 tb Exp $ */ | 1 | /* $OpenBSD: asn1_local.h,v 1.3 2023/07/28 09:58:30 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2006. | 3 | * project 2006. |
| 4 | */ | 4 | */ |
| @@ -250,6 +250,8 @@ int asn1_time_tm_to_time_t(const struct tm *tm, time_t *out); | |||
| 250 | 250 | ||
| 251 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); | 251 | int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); |
| 252 | 252 | ||
| 253 | const BIO_METHOD *BIO_f_asn1(void); | ||
| 254 | |||
| 253 | BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); | 255 | BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); |
| 254 | 256 | ||
| 255 | int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | 257 | int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, |
diff --git a/src/lib/libcrypto/asn1/bio_asn1.c b/src/lib/libcrypto/asn1/bio_asn1.c index e544bf9c9c..b9f54cd4ef 100644 --- a/src/lib/libcrypto/asn1/bio_asn1.c +++ b/src/lib/libcrypto/asn1/bio_asn1.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bio_asn1.c,v 1.22 2023/07/05 21:23:36 beck Exp $ */ | 1 | /* $OpenBSD: bio_asn1.c,v 1.23 2023/07/28 09:58:30 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -69,6 +69,9 @@ | |||
| 69 | 69 | ||
| 70 | #include "bio_local.h" | 70 | #include "bio_local.h" |
| 71 | 71 | ||
| 72 | #define BIO_C_SET_PREFIX 149 | ||
| 73 | #define BIO_C_SET_SUFFIX 151 | ||
| 74 | |||
| 72 | /* Must be large enough for biggest tag+length */ | 75 | /* Must be large enough for biggest tag+length */ |
| 73 | #define DEFAULT_ASN1_BUF_SIZE 20 | 76 | #define DEFAULT_ASN1_BUF_SIZE 20 |
| 74 | 77 | ||
| @@ -144,7 +147,6 @@ BIO_f_asn1(void) | |||
| 144 | { | 147 | { |
| 145 | return (&methods_asn1); | 148 | return (&methods_asn1); |
| 146 | } | 149 | } |
| 147 | LCRYPTO_ALIAS(BIO_f_asn1); | ||
| 148 | 150 | ||
| 149 | static int | 151 | static int |
| 150 | asn1_bio_new(BIO *b) | 152 | asn1_bio_new(BIO *b) |
| @@ -376,24 +378,12 @@ asn1_bio_ctrl(BIO *b, int cmd, long arg1, void *arg2) | |||
| 376 | ctx->prefix_free = ex_func->ex_free_func; | 378 | ctx->prefix_free = ex_func->ex_free_func; |
| 377 | break; | 379 | break; |
| 378 | 380 | ||
| 379 | case BIO_C_GET_PREFIX: | ||
| 380 | ex_func = arg2; | ||
| 381 | ex_func->ex_func = ctx->prefix; | ||
| 382 | ex_func->ex_free_func = ctx->prefix_free; | ||
| 383 | break; | ||
| 384 | |||
| 385 | case BIO_C_SET_SUFFIX: | 381 | case BIO_C_SET_SUFFIX: |
| 386 | ex_func = arg2; | 382 | ex_func = arg2; |
| 387 | ctx->suffix = ex_func->ex_func; | 383 | ctx->suffix = ex_func->ex_func; |
| 388 | ctx->suffix_free = ex_func->ex_free_func; | 384 | ctx->suffix_free = ex_func->ex_free_func; |
| 389 | break; | 385 | break; |
| 390 | 386 | ||
| 391 | case BIO_C_GET_SUFFIX: | ||
| 392 | ex_func = arg2; | ||
| 393 | ex_func->ex_func = ctx->suffix; | ||
| 394 | ex_func->ex_free_func = ctx->suffix_free; | ||
| 395 | break; | ||
| 396 | |||
| 397 | case BIO_C_SET_EX_ARG: | 387 | case BIO_C_SET_EX_ARG: |
| 398 | ctx->ex_arg = arg2; | 388 | ctx->ex_arg = arg2; |
| 399 | break; | 389 | break; |
| @@ -450,46 +440,14 @@ asn1_bio_set_ex(BIO *b, int cmd, asn1_ps_func *ex_func, asn1_ps_func | |||
| 450 | return BIO_ctrl(b, cmd, 0, &extmp); | 440 | return BIO_ctrl(b, cmd, 0, &extmp); |
| 451 | } | 441 | } |
| 452 | 442 | ||
| 453 | static int | ||
| 454 | asn1_bio_get_ex(BIO *b, int cmd, asn1_ps_func **ex_func, | ||
| 455 | asn1_ps_func **ex_free_func) | ||
| 456 | { | ||
| 457 | BIO_ASN1_EX_FUNCS extmp; | ||
| 458 | int ret; | ||
| 459 | |||
| 460 | if ((ret = BIO_ctrl(b, cmd, 0, &extmp)) <= 0) | ||
| 461 | return ret; | ||
| 462 | |||
| 463 | *ex_func = extmp.ex_func; | ||
| 464 | *ex_free_func = extmp.ex_free_func; | ||
| 465 | |||
| 466 | return ret; | ||
| 467 | } | ||
| 468 | |||
| 469 | int | 443 | int |
| 470 | BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) | 444 | BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) |
| 471 | { | 445 | { |
| 472 | return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); | 446 | return asn1_bio_set_ex(b, BIO_C_SET_PREFIX, prefix, prefix_free); |
| 473 | } | 447 | } |
| 474 | LCRYPTO_ALIAS(BIO_asn1_set_prefix); | ||
| 475 | |||
| 476 | int | ||
| 477 | BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, asn1_ps_func **pprefix_free) | ||
| 478 | { | ||
| 479 | return asn1_bio_get_ex(b, BIO_C_GET_PREFIX, pprefix, pprefix_free); | ||
| 480 | } | ||
| 481 | LCRYPTO_ALIAS(BIO_asn1_get_prefix); | ||
| 482 | 448 | ||
| 483 | int | 449 | int |
| 484 | BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) | 450 | BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) |
| 485 | { | 451 | { |
| 486 | return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); | 452 | return asn1_bio_set_ex(b, BIO_C_SET_SUFFIX, suffix, suffix_free); |
| 487 | } | 453 | } |
| 488 | LCRYPTO_ALIAS(BIO_asn1_set_suffix); | ||
| 489 | |||
| 490 | int | ||
| 491 | BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, asn1_ps_func **psuffix_free) | ||
| 492 | { | ||
| 493 | return asn1_bio_get_ex(b, BIO_C_GET_SUFFIX, psuffix, psuffix_free); | ||
| 494 | } | ||
| 495 | LCRYPTO_ALIAS(BIO_asn1_get_suffix); | ||
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c index 11e51edade..98bb1cd197 100644 --- a/src/lib/libcrypto/asn1/bio_ndef.c +++ b/src/lib/libcrypto/asn1/bio_ndef.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bio_ndef.c,v 1.23 2023/07/09 19:22:43 tb Exp $ */ | 1 | /* $OpenBSD: bio_ndef.c,v 1.24 2023/07/28 09:58:30 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project. | 3 | * project. |
| 4 | */ | 4 | */ |
| @@ -61,6 +61,9 @@ | |||
| 61 | 61 | ||
| 62 | #include "asn1_local.h" | 62 | #include "asn1_local.h" |
| 63 | 63 | ||
| 64 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free); | ||
| 65 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free); | ||
| 66 | |||
| 64 | /* Experimental NDEF ASN1 BIO support routines */ | 67 | /* Experimental NDEF ASN1 BIO support routines */ |
| 65 | 68 | ||
| 66 | /* The usage is quite simple, initialize an ASN1 structure, | 69 | /* The usage is quite simple, initialize an ASN1 structure, |
