Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2351?usp=email
to review the following change.
Change subject: ssl_openssl: add bio_new_file_or_inline() helper
......................................................................
ssl_openssl: add bio_new_file_or_inline() helper
Four loaders opened their input as a memory BIO when inline and as a
file BIO otherwise, each with its own copy of the if/else. Move that
into one helper.
Change-Id: I23ae372cd5d83a8b07cc1dd491349473b816c576
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/openvpn/ssl_openssl.c
1 file changed, 15 insertions(+), 41 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/51/2351/1
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index 03e0279..ac2ac4c 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -1201,24 +1201,26 @@
#endif /* defined(HAVE_OPENSSL_STORE_API */
}
+/* Open file for reading, or a memory BIO over its contents if is_inline */
+static BIO *
+bio_new_file_or_inline(const char *file, bool is_inline)
+{
+ if (is_inline)
+ {
+ return BIO_new_mem_buf(file, -1);
+ }
+ return BIO_new_file(file, "r");
+}
+
static void
tls_ctx_load_cert_pem_file(struct tls_root_ctx *ctx, const char *cert_file,
bool cert_file_inline)
{
- BIO *in = NULL;
X509 *x = NULL;
int ret = 0;
ASSERT(NULL != ctx);
- if (cert_file_inline)
- {
- in = BIO_new_mem_buf((char *)cert_file, -1);
- }
- else
- {
- in = BIO_new_file((char *)cert_file, "r");
- }
-
+ BIO *in = bio_new_file_or_inline(cert_file, cert_file_inline);
if (in == NULL)
{
SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_SYS_LIB);
@@ -1331,7 +1333,6 @@
void
backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file,
bool crl_inline)
{
- BIO *in = NULL;
STACK_OF(X509_CRL) *crls = NULL;
X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx->ctx);
@@ -1345,15 +1346,7 @@
X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK |
X509_V_FLAG_CRL_CHECK_ALL);
- if (crl_inline)
- {
- in = BIO_new_mem_buf((char *)crl_file, -1);
- }
- else
- {
- in = BIO_new_file(crl_file, "r");
- }
-
+ BIO *in = bio_new_file_or_inline(crl_file, crl_inline);
if (in == NULL)
{
msg(M_WARN, "CRL: cannot read: %s", print_key_filename(crl_file,
crl_inline));
@@ -1831,17 +1824,7 @@
if (ca_file)
{
openssl_stack_size_t added = 0;
- BIO *in = NULL;
-
- if (ca_file_inline)
- {
- in = BIO_new_mem_buf((char *)ca_file, -1);
- }
- else
- {
- in = BIO_new_file(ca_file, "r");
- }
-
+ BIO *in = bio_new_file_or_inline(ca_file, ca_file_inline);
if (in)
{
info_stack = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
@@ -1968,16 +1951,7 @@
tls_ctx_load_extra_certs(struct tls_root_ctx *ctx, const char
*extra_certs_file,
bool extra_certs_file_inline)
{
- BIO *in;
- if (extra_certs_file_inline)
- {
- in = BIO_new_mem_buf((char *)extra_certs_file, -1);
- }
- else
- {
- in = BIO_new_file(extra_certs_file, "r");
- }
-
+ BIO *in = bio_new_file_or_inline(extra_certs_file,
extra_certs_file_inline);
if (in == NULL)
{
crypto_msg(M_FATAL, "Cannot load extra-certs file: %s",
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2351?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23ae372cd5d83a8b07cc1dd491349473b816c576
Gerrit-Change-Number: 2351
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel