diff options
author | tb <> | 2023-07-28 09:58:30 +0000 |
---|---|---|
committer | tb <> | 2023-07-28 09:58:30 +0000 |
commit | b57b8995befab5a960cda55abaa2c8eeb444dd0a (patch) | |
tree | a8ef39245b59cd5d4747a1efefdf2919068bb6e3 | |
parent | d4949db8e78438e8bb53c9c1297b068ac0df7827 (diff) | |
download | openbsd-b57b8995befab5a960cda55abaa2c8eeb444dd0a.tar.gz openbsd-b57b8995befab5a960cda55abaa2c8eeb444dd0a.tar.bz2 openbsd-b57b8995befab5a960cda55abaa2c8eeb444dd0a.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
-rw-r--r-- | src/lib/libcrypto/Symbols.list | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/Symbols.namespace | 5 | ||||
-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 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio.h | 17 | ||||
-rw-r--r-- | src/lib/libcrypto/hidden/openssl/asn1.h | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/hidden/openssl/bio.h | 6 |
9 files changed, 15 insertions, 84 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list index d0484a5d4c..7dabfa1188 100644 --- a/src/lib/libcrypto/Symbols.list +++ b/src/lib/libcrypto/Symbols.list | |||
@@ -253,10 +253,6 @@ BIGNUM_it | |||
253 | BIO_CONNECT_free | 253 | BIO_CONNECT_free |
254 | BIO_CONNECT_new | 254 | BIO_CONNECT_new |
255 | BIO_accept | 255 | BIO_accept |
256 | BIO_asn1_get_prefix | ||
257 | BIO_asn1_get_suffix | ||
258 | BIO_asn1_set_prefix | ||
259 | BIO_asn1_set_suffix | ||
260 | BIO_callback_ctrl | 256 | BIO_callback_ctrl |
261 | BIO_clear_flags | 257 | BIO_clear_flags |
262 | BIO_copy_next_retry | 258 | BIO_copy_next_retry |
@@ -275,7 +271,6 @@ BIO_dump_indent | |||
275 | BIO_dump_indent_cb | 271 | BIO_dump_indent_cb |
276 | BIO_dump_indent_fp | 272 | BIO_dump_indent_fp |
277 | BIO_dup_chain | 273 | BIO_dup_chain |
278 | BIO_f_asn1 | ||
279 | BIO_f_base64 | 274 | BIO_f_base64 |
280 | BIO_f_buffer | 275 | BIO_f_buffer |
281 | BIO_f_cipher | 276 | BIO_f_cipher |
diff --git a/src/lib/libcrypto/Symbols.namespace b/src/lib/libcrypto/Symbols.namespace index b8ca3539ec..d1afd92c08 100644 --- a/src/lib/libcrypto/Symbols.namespace +++ b/src/lib/libcrypto/Symbols.namespace | |||
@@ -1120,7 +1120,6 @@ _libre_ASN1_PCTX_get_oid_flags | |||
1120 | _libre_ASN1_PCTX_set_oid_flags | 1120 | _libre_ASN1_PCTX_set_oid_flags |
1121 | _libre_ASN1_PCTX_get_str_flags | 1121 | _libre_ASN1_PCTX_get_str_flags |
1122 | _libre_ASN1_PCTX_set_str_flags | 1122 | _libre_ASN1_PCTX_set_str_flags |
1123 | _libre_BIO_f_asn1 | ||
1124 | _libre_SMIME_crlf_copy | 1123 | _libre_SMIME_crlf_copy |
1125 | _libre_SMIME_text | 1124 | _libre_SMIME_text |
1126 | _libre_ERR_load_ASN1_strings | 1125 | _libre_ERR_load_ASN1_strings |
@@ -1164,10 +1163,6 @@ _libre_BIO_set_ex_data | |||
1164 | _libre_BIO_get_ex_data | 1163 | _libre_BIO_get_ex_data |
1165 | _libre_BIO_number_read | 1164 | _libre_BIO_number_read |
1166 | _libre_BIO_number_written | 1165 | _libre_BIO_number_written |
1167 | _libre_BIO_asn1_set_prefix | ||
1168 | _libre_BIO_asn1_get_prefix | ||
1169 | _libre_BIO_asn1_set_suffix | ||
1170 | _libre_BIO_asn1_get_suffix | ||
1171 | _libre_BIO_get_new_index | 1166 | _libre_BIO_get_new_index |
1172 | _libre_BIO_s_file | 1167 | _libre_BIO_s_file |
1173 | _libre_BIO_new_file | 1168 | _libre_BIO_new_file |
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, |
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index 124690b1ee..8450780f69 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bio.h,v 1.58 2023/07/05 19:25:01 tb Exp $ */ | 1 | /* $OpenBSD: bio.h,v 1.59 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 | * |
@@ -371,11 +371,6 @@ int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, | |||
371 | #define BIO_C_RESET_READ_REQUEST 147 | 371 | #define BIO_C_RESET_READ_REQUEST 147 |
372 | #define BIO_C_SET_MD_CTX 148 | 372 | #define BIO_C_SET_MD_CTX 148 |
373 | 373 | ||
374 | #define BIO_C_SET_PREFIX 149 | ||
375 | #define BIO_C_GET_PREFIX 150 | ||
376 | #define BIO_C_SET_SUFFIX 151 | ||
377 | #define BIO_C_GET_SUFFIX 152 | ||
378 | |||
379 | #define BIO_C_SET_EX_ARG 153 | 374 | #define BIO_C_SET_EX_ARG 153 |
380 | #define BIO_C_GET_EX_ARG 154 | 375 | #define BIO_C_GET_EX_ARG 154 |
381 | 376 | ||
@@ -535,16 +530,6 @@ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | |||
535 | unsigned long BIO_number_read(BIO *bio); | 530 | unsigned long BIO_number_read(BIO *bio); |
536 | unsigned long BIO_number_written(BIO *bio); | 531 | unsigned long BIO_number_written(BIO *bio); |
537 | 532 | ||
538 | /* For BIO_f_asn1() */ | ||
539 | int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, | ||
540 | asn1_ps_func *prefix_free); | ||
541 | int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix, | ||
542 | asn1_ps_func **pprefix_free); | ||
543 | int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, | ||
544 | asn1_ps_func *suffix_free); | ||
545 | int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix, | ||
546 | asn1_ps_func **psuffix_free); | ||
547 | |||
548 | int BIO_get_new_index(void); | 533 | int BIO_get_new_index(void); |
549 | const BIO_METHOD *BIO_s_file(void); | 534 | const BIO_METHOD *BIO_s_file(void); |
550 | BIO *BIO_new_file(const char *filename, const char *mode); | 535 | BIO *BIO_new_file(const char *filename, const char *mode); |
diff --git a/src/lib/libcrypto/hidden/openssl/asn1.h b/src/lib/libcrypto/hidden/openssl/asn1.h index 7e41ec862c..e3095e0631 100644 --- a/src/lib/libcrypto/hidden/openssl/asn1.h +++ b/src/lib/libcrypto/hidden/openssl/asn1.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.3 2023/07/28 09:58:30 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -250,7 +250,6 @@ LCRYPTO_USED(ASN1_PCTX_get_oid_flags); | |||
250 | LCRYPTO_USED(ASN1_PCTX_set_oid_flags); | 250 | LCRYPTO_USED(ASN1_PCTX_set_oid_flags); |
251 | LCRYPTO_USED(ASN1_PCTX_get_str_flags); | 251 | LCRYPTO_USED(ASN1_PCTX_get_str_flags); |
252 | LCRYPTO_USED(ASN1_PCTX_set_str_flags); | 252 | LCRYPTO_USED(ASN1_PCTX_set_str_flags); |
253 | LCRYPTO_USED(BIO_f_asn1); | ||
254 | LCRYPTO_USED(SMIME_crlf_copy); | 253 | LCRYPTO_USED(SMIME_crlf_copy); |
255 | LCRYPTO_USED(SMIME_text); | 254 | LCRYPTO_USED(SMIME_text); |
256 | LCRYPTO_USED(ERR_load_ASN1_strings); | 255 | LCRYPTO_USED(ERR_load_ASN1_strings); |
diff --git a/src/lib/libcrypto/hidden/openssl/bio.h b/src/lib/libcrypto/hidden/openssl/bio.h index c04a0a447f..46cbdf72fe 100644 --- a/src/lib/libcrypto/hidden/openssl/bio.h +++ b/src/lib/libcrypto/hidden/openssl/bio.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bio.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ | 1 | /* $OpenBSD: bio.h,v 1.3 2023/07/28 09:58:30 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -63,10 +63,6 @@ LCRYPTO_USED(BIO_set_ex_data); | |||
63 | LCRYPTO_USED(BIO_get_ex_data); | 63 | LCRYPTO_USED(BIO_get_ex_data); |
64 | LCRYPTO_USED(BIO_number_read); | 64 | LCRYPTO_USED(BIO_number_read); |
65 | LCRYPTO_USED(BIO_number_written); | 65 | LCRYPTO_USED(BIO_number_written); |
66 | LCRYPTO_USED(BIO_asn1_set_prefix); | ||
67 | LCRYPTO_USED(BIO_asn1_get_prefix); | ||
68 | LCRYPTO_USED(BIO_asn1_set_suffix); | ||
69 | LCRYPTO_USED(BIO_asn1_get_suffix); | ||
70 | LCRYPTO_USED(BIO_get_new_index); | 66 | LCRYPTO_USED(BIO_get_new_index); |
71 | LCRYPTO_USED(BIO_s_file); | 67 | LCRYPTO_USED(BIO_s_file); |
72 | LCRYPTO_USED(BIO_new_file); | 68 | LCRYPTO_USED(BIO_new_file); |