Skip to contentSkip to conversation

Make return code external tls key match docs

PATCH In review Joost Rijneveld 3 participants 3 messages Feb 28, 2018 – Mar 4, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make return code external tls key match docs

In tls_ctx_use_external_private_key, the return codes were inverted compared to what is documented in ssl_backend.h (and what can reasonably be expected). Internally the return code is never checked, so this did not directly result in any change of behavior.

---
 src/openvpn/ssl_mbedtls.c | 6 +++---
 src/openvpn/ssl_openssl.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
src/openvpn/ssl_mbedtls.c +3 -3
index 3906cd55..8e31980a 100644
@@ -630,7 +630,7 @@ tls_ctx_use_external_private_key(struct tls_root_ctx *ctx,
 
     if (ctx->crt_chain == NULL)
     {
-        return 0;
+        return 1;
     }
 
     ALLOC_OBJ_CLEAR(ctx->external_key, struct external_context);
@@ -640,10 +640,10 @@ tls_ctx_use_external_private_key(struct tls_root_ctx *ctx,
     if (!mbed_ok(mbedtls_pk_setup_rsa_alt(ctx->priv_key, ctx->external_key,
                                           NULL, external_pkcs1_sign, external_key_len)))
     {
-        return 0;
+        return 1;
     }
 
-    return 1;
+    return 0;
 }
 #endif /* ifdef MANAGMENT_EXTERNAL_KEY */
 
src/openvpn/ssl_openssl.c +2 -2
index d91458b0..8ef68ebd 100644
@@ -1327,11 +1327,11 @@ tls_ctx_use_external_private_key(struct tls_root_ctx *ctx,
         goto err;
     }
 #endif /* OPENSSL_VERSION_NUMBER > 1.1.0 dev */
-    return 1;
+    return 0;
 
 err:
     crypto_msg(M_FATAL, "Cannot enable SSL external private key capability");
-    return 0;
+    return 1;
 }
 
 #endif /* ifdef MANAGMENT_EXTERNAL_KEY */
Signature · 1 line
2.16.2
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 44 lines · Joost Rijneveld

In tls_ctx_use_external_private_key, the return codes were inverted compared to what is documented in ssl_backend.h (and what can reasonably be expected). Internally the return code is never checked, so this did not directly result in any change of behavior.

---
 src/openvpn/ssl_mbedtls.c | 6 +++---
 src/openvpn/ssl_openssl.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
src/openvpn/ssl_mbedtls.c +3 -3
index 3906cd55..8e31980a 100644
@@ -630,7 +630,7 @@ tls_ctx_use_external_private_key(struct tls_root_ctx *ctx,
 
     if (ctx->crt_chain == NULL)
     {
-        return 0;
+        return 1;
     }
 
     ALLOC_OBJ_CLEAR(ctx->external_key, struct external_context);
@@ -640,10 +640,10 @@ tls_ctx_use_external_private_key(struct tls_root_ctx *ctx,
     if (!mbed_ok(mbedtls_pk_setup_rsa_alt(ctx->priv_key, ctx->external_key,
                                           NULL, external_pkcs1_sign, external_key_len)))
     {
-        return 0;
+        return 1;
     }
 
-    return 1;
+    return 0;
 }
 #endif /* ifdef MANAGMENT_EXTERNAL_KEY */
 
src/openvpn/ssl_openssl.c +0 -0
index d91458b0..8ef68ebd 100644
@@ -1327,11 +1327,11 @@ tls_ctx_use_external_private_key(struct tls_root_ctx *ctx,
         goto err;
     }
 #endif /* OPENSSL_VERSION_NUMBER > 1.1.0 dev */

src/openvpn/ssl_openssl.c tls_ctx_use_external_private_key(struct tls_root_ctx *ctx, · line 1337

Quoted 10 lines
src/openvpn/ssl_openssl.c +2 -2
-    return 1;
+    return 0;
 
 err:
     crypto_msg(M_FATAL, "Cannot enable SSL external private key capability");
-    return 0;
+    return 1;
 }
 
 #endif /* ifdef MANAGMENT_EXTERNAL_KEY */

Thanks for the patch, and pointing out this inconsistency. Changes make sense and make this function follow what seems to be the default pattern in the surrounding code.

(What bothers me more is that we don't actually check the return values, but I'll send a follow-up patch to fix that.)

-Steffan

#2 lore raw
In reply to Joost Rijneveld

Your patch has been applied to the master and release/2.4 branch (with some conflicts due to changed context in master, but that was easy enough to resolve).

Thanks.

commit 6bee1a1fc01f3d3ddf114b48e52e5b10d57033cb (master) commit 1f342aad6a13aaae1cc54f632498e0646a1bfe1a (release/2.4)

Author: Joost Rijneveld
Date:   Wed Feb 28 14:52:40 2018 +0100
     Make return code external tls key match docs

     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg16577.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering