summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
authortb <>2023-07-28 09:58:30 +0000
committertb <>2023-07-28 09:58:30 +0000
commitb57b8995befab5a960cda55abaa2c8eeb444dd0a (patch)
treea8ef39245b59cd5d4747a1efefdf2919068bb6e3 /src/lib/libcrypto/asn1
parentd4949db8e78438e8bb53c9c1297b068ac0df7827 (diff)
downloadopenbsd-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
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/asn1.h4
-rw-r--r--src/lib/libcrypto/asn1/asn1_local.h4
-rw-r--r--src/lib/libcrypto/asn1/bio_asn1.c50
-rw-r--r--src/lib/libcrypto/asn1/bio_ndef.c5
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);
922unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p); 922unsigned long ASN1_PCTX_get_str_flags(const ASN1_PCTX *p);
923void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags); 923void ASN1_PCTX_set_str_flags(ASN1_PCTX *p, unsigned long flags);
924 924
925const BIO_METHOD *BIO_f_asn1(void);
926
927int SMIME_crlf_copy(BIO *in, BIO *out, int flags); 925int SMIME_crlf_copy(BIO *in, BIO *out, int flags);
928int SMIME_text(BIO *in, BIO *out); 926int 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
251int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); 251int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
252 252
253const BIO_METHOD *BIO_f_asn1(void);
254
253BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it); 255BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it);
254 256
255int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, 257int 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}
147LCRYPTO_ALIAS(BIO_f_asn1);
148 150
149static int 151static int
150asn1_bio_new(BIO *b) 152asn1_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
453static int
454asn1_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
469int 443int
470BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free) 444BIO_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}
474LCRYPTO_ALIAS(BIO_asn1_set_prefix);
475
476int
477BIO_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}
481LCRYPTO_ALIAS(BIO_asn1_get_prefix);
482 448
483int 449int
484BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix, asn1_ps_func *suffix_free) 450BIO_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}
488LCRYPTO_ALIAS(BIO_asn1_set_suffix);
489
490int
491BIO_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}
495LCRYPTO_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
64int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix, asn1_ps_func *prefix_free);
65int 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,