From: Richard Levitte Date: Thu, 9 Jul 2020 16:55:44 +0000 (+0200) Subject: CORE: Add upcalls for BIO_gets() and BIO_puts() X-Git-Tag: openssl-3.0.0-alpha6~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=853ca12813dee0ec7ac75cfe5f1c9685ffb2d420;p=thirdparty%2Fopenssl.git CORE: Add upcalls for BIO_gets() and BIO_puts() Reviewed-by: Matt Caswell Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/12410) --- diff --git a/crypto/provider_core.c b/crypto/provider_core.c index b6586f904e3..79c330383c1 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -1061,6 +1061,8 @@ static const OSSL_DISPATCH core_dispatch_[] = { { OSSL_FUNC_BIO_NEW_MEMBUF, (void (*)(void))BIO_new_mem_buf }, { OSSL_FUNC_BIO_READ_EX, (void (*)(void))BIO_read_ex }, { OSSL_FUNC_BIO_WRITE_EX, (void (*)(void))BIO_write_ex }, + { OSSL_FUNC_BIO_GETS, (void (*)(void))BIO_gets }, + { OSSL_FUNC_BIO_PUTS, (void (*)(void))BIO_puts }, { OSSL_FUNC_BIO_FREE, (void (*)(void))BIO_free }, { OSSL_FUNC_BIO_VPRINTF, (void (*)(void))BIO_vprintf }, { OSSL_FUNC_BIO_VSNPRINTF, (void (*)(void))BIO_vsnprintf }, diff --git a/include/openssl/core_dispatch.h b/include/openssl/core_dispatch.h index 8dba65b5560..c3f6c88f461 100644 --- a/include/openssl/core_dispatch.h +++ b/include/openssl/core_dispatch.h @@ -135,6 +135,9 @@ OSSL_CORE_MAKE_FUNC(void, #define OSSL_FUNC_BIO_FREE 44 #define OSSL_FUNC_BIO_VPRINTF 45 #define OSSL_FUNC_BIO_VSNPRINTF 46 +#define OSSL_FUNC_BIO_PUTS 47 +#define OSSL_FUNC_BIO_GETS 48 + OSSL_CORE_MAKE_FUNC(OSSL_CORE_BIO *, BIO_new_file, (const char *filename, const char *mode)) @@ -143,6 +146,8 @@ OSSL_CORE_MAKE_FUNC(int, BIO_read_ex, (OSSL_CORE_BIO *bio, void *data, size_t data_len, size_t *bytes_read)) OSSL_CORE_MAKE_FUNC(int, BIO_write_ex, (OSSL_CORE_BIO *bio, const void *data, size_t data_len, size_t *written)) +OSSL_CORE_MAKE_FUNC(int, BIO_gets, (OSSL_CORE_BIO *bio, char *buf, int size)) +OSSL_CORE_MAKE_FUNC(int, BIO_puts, (OSSL_CORE_BIO *bio, const char *str)) OSSL_CORE_MAKE_FUNC(int, BIO_free, (OSSL_CORE_BIO *bio)) OSSL_CORE_MAKE_FUNC(int, BIO_vprintf, (OSSL_CORE_BIO *bio, const char *format, va_list args)) diff --git a/providers/common/bio_prov.c b/providers/common/bio_prov.c index c193658c584..fc1f8b2b266 100644 --- a/providers/common/bio_prov.c +++ b/providers/common/bio_prov.c @@ -16,6 +16,8 @@ static OSSL_FUNC_BIO_new_file_fn *c_bio_new_file = NULL; static OSSL_FUNC_BIO_new_membuf_fn *c_bio_new_membuf = NULL; static OSSL_FUNC_BIO_read_ex_fn *c_bio_read_ex = NULL; static OSSL_FUNC_BIO_write_ex_fn *c_bio_write_ex = NULL; +static OSSL_FUNC_BIO_gets_fn *c_bio_gets = NULL; +static OSSL_FUNC_BIO_puts_fn *c_bio_puts = NULL; static OSSL_FUNC_BIO_free_fn *c_bio_free = NULL; static OSSL_FUNC_BIO_vprintf_fn *c_bio_vprintf = NULL; @@ -39,6 +41,14 @@ int ossl_prov_bio_from_dispatch(const OSSL_DISPATCH *fns) if (c_bio_write_ex == NULL) c_bio_write_ex = OSSL_FUNC_BIO_write_ex(fns); break; + case OSSL_FUNC_BIO_GETS: + if (c_bio_gets == NULL) + c_bio_gets = OSSL_FUNC_BIO_gets(fns); + break; + case OSSL_FUNC_BIO_PUTS: + if (c_bio_puts == NULL) + c_bio_puts = OSSL_FUNC_BIO_puts(fns); + break; case OSSL_FUNC_BIO_FREE: if (c_bio_free == NULL) c_bio_free = OSSL_FUNC_BIO_free(fns); @@ -83,6 +93,20 @@ int ossl_prov_bio_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len return c_bio_write_ex(bio, data, data_len, written); } +int ossl_prov_bio_gets(OSSL_CORE_BIO *bio, char *buf, int size) +{ + if (c_bio_gets == NULL) + return -1; + return c_bio_gets(bio, buf, size); +} + +int ossl_prov_bio_puts(OSSL_CORE_BIO *bio, const char *str) +{ + if (c_bio_puts == NULL) + return -1; + return c_bio_puts(bio, str); +} + int ossl_prov_bio_free(OSSL_CORE_BIO *bio) { if (c_bio_free == NULL) @@ -134,16 +158,12 @@ static long bio_core_ctrl(BIO *bio, int cmd, long num, void *ptr) static int bio_core_gets(BIO *bio, char *buf, int size) { - /* We don't support this */ - assert(0); - return -1; + return ossl_prov_bio_gets(BIO_get_data(bio), buf, size); } static int bio_core_puts(BIO *bio, const char *str) { - /* We don't support this */ - assert(0); - return -1; + return ossl_prov_bio_puts(BIO_get_data(bio), str); } static int bio_core_new(BIO *bio) diff --git a/providers/common/include/prov/bio.h b/providers/common/include/prov/bio.h index c63f6b5da54..3cef89ce18c 100644 --- a/providers/common/include/prov/bio.h +++ b/providers/common/include/prov/bio.h @@ -20,6 +20,8 @@ int ossl_prov_bio_read_ex(OSSL_CORE_BIO *bio, void *data, size_t data_len, size_t *bytes_read); int ossl_prov_bio_write_ex(OSSL_CORE_BIO *bio, const void *data, size_t data_len, size_t *written); +int ossl_prov_bio_gets(OSSL_CORE_BIO *bio, char *buf, int size); +int ossl_prov_bio_puts(OSSL_CORE_BIO *bio, const char *str); int ossl_prov_bio_free(OSSL_CORE_BIO *bio); int ossl_prov_bio_vprintf(OSSL_CORE_BIO *bio, const char *format, va_list ap); int ossl_prov_bio_printf(OSSL_CORE_BIO *bio, const char *format, ...);