From: "plaisthos (Code Review)" Date: Mon, 11 Nov 2024 01:59:53 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <8225d8826baedeb4f58e8c6fa268d12bcfcce7d2-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="aOOTA5wJ0CI="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Change API of init_key_ctx to use struct key_paramters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --aOOTA5wJ0CI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/801?usp=3Demail to review the following change. Change subject: Change API of init_key_ctx to use struct key_paramters ...................................................................... Change API of init_key_ctx to use struct key_paramters This introduces a new structure key_paramters. The reason is that the current struct serves both as an internal struct as well as an on-wire/in-file format. Separate these two different usages to allow extending the struct. Change-Id: I4a981c5a70717e2276d89bf83a06c7fdbe6712d7 Signed-off-by: Arne Schwabe --- M src/openvpn/auth_token.c M src/openvpn/crypto.c M src/openvpn/crypto.h M src/openvpn/tls_crypt.c M tests/unit_tests/openvpn/test_auth_token.c M tests/unit_tests/openvpn/test_tls_crypt.c 6 files changed, 85 insertions(+), 37 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/01/801/1 diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c index 192c7c2..3cf55e8 100644 --- a/src/openvpn/auth_token.c +++ b/src/openvpn/auth_token.c @@ -152,7 +152,10 @@ { msg(M_FATAL, "ERROR: not enough data in auth-token secret"); } - init_key_ctx(key_ctx, &key, &kt, false, "auth-token secret"); + + struct key_parameters key_params; + key_parameters_from_key(&key_params, &key); + init_key_ctx(key_ctx, &key_params, &kt, false, "auth-token secret"); free_buf(&server_secret_key); } diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 44c226c..f4453d8 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -903,7 +903,7 @@ * @param key key, hmac part used to calculate implicit = IV */ static void -key_ctx_update_implicit_iv(struct key_ctx *ctx, const struct key *key) +key_ctx_update_implicit_iv(struct key_ctx *ctx, const struct key_parameter= s *key) { /* Only use implicit IV in AEAD cipher mode, where HMAC key is not use= d */ if (cipher_ctx_mode_aead(ctx->cipher)) @@ -913,6 +913,7 @@ impl_iv_len =3D cipher_ctx_iv_length(ctx->cipher) - sizeof(packet_= id_type); ASSERT(impl_iv_len <=3D OPENVPN_MAX_IV_LENGTH); ASSERT(impl_iv_len <=3D MAX_HMAC_KEY_LENGTH); + ASSERT(key->hmac_size >=3D impl_iv_len); CLEAR(ctx->implicit_iv); /* The first bytes of the IV are filled with the packet id */ memcpy(ctx->implicit_iv + sizeof(packet_id_type), key->hmac, impl_= iv_len); @@ -921,7 +922,7 @@ /* given a key and key_type, build a key_ctx */ void -init_key_ctx(struct key_ctx *ctx, const struct key *key, +init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const struct key_type *kt, int enc, const char *prefix) { @@ -929,7 +930,7 @@ CLEAR(*ctx); if (cipher_defined(kt->cipher)) { - + ASSERT(key->cipher_size >=3D cipher_kt_key_size(kt->cipher)); ctx->cipher =3D cipher_ctx_new(); cipher_ctx_init(ctx->cipher, key->cipher, kt->cipher, enc); @@ -944,8 +945,10 @@ cipher_kt_iv_size(kt->cipher)); warn_insecure_key_type(ciphername); } + if (md_defined(kt->digest)) { + ASSERT(key->hmac_size >=3D md_kt_size(kt->digest)); ctx->hmac =3D hmac_ctx_new(); hmac_ctx_init(ctx->hmac, key->hmac, kt->digest); @@ -966,41 +969,43 @@ } void -init_key_bi_ctx_send(struct key_ctx *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, const c= har *name) +init_key_bi_ctx_send(struct key_ctx *ctx, const struct key_parameters *key= _params, + const struct key_type *kt, const char *name) { char log_prefix[128] =3D { 0 }; - struct key_direction_state kds; - - key_direction_state_init(&kds, key_direction); snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s", name); - init_key_ctx(ctx, &key2->keys[kds.out_key], kt, - OPENVPN_OP_ENCRYPT, log_prefix); - key_ctx_update_implicit_iv(ctx, &key2->keys[kds.out_key]); + init_key_ctx(ctx, key_params, kt, OPENVPN_OP_ENCRYPT, log_prefix); + key_ctx_update_implicit_iv(ctx, key_params); } void -init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, const c= har *name) +init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key_parameters *key= _params, + const struct key_type *kt, const char *name) { char log_prefix[128] =3D { 0 }; - struct key_direction_state kds; - - key_direction_state_init(&kds, key_direction); snprintf(log_prefix, sizeof(log_prefix), "Incoming %s", name); - init_key_ctx(ctx, &key2->keys[kds.in_key], kt, - OPENVPN_OP_DECRYPT, log_prefix); - key_ctx_update_implicit_iv(ctx, &key2->keys[kds.in_key]); + init_key_ctx(ctx, key_params, kt, OPENVPN_OP_DECRYPT, log_prefix); + key_ctx_update_implicit_iv(ctx, key_params); } void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, int key_direction, const struct key_type *kt, const char *= name) { - init_key_bi_ctx_send(&ctx->encrypt, key2, key_direction, kt, name); - init_key_bi_ctx_recv(&ctx->decrypt, key2, key_direction, kt, name); + struct key_direction_state kds; + + key_direction_state_init(&kds, key_direction); + + struct key_parameters send_key; + struct key_parameters recv_key; + + key_parameters_from_key(&send_key, &key2->keys[kds.out_key]); + key_parameters_from_key(&recv_key, &key2->keys[kds.in_key]); + + init_key_bi_ctx_send(&ctx->encrypt, &send_key, kt, name); + init_key_bi_ctx_recv(&ctx->decrypt, &recv_key, kt, name); ctx->initialized =3D true; } @@ -1117,6 +1122,16 @@ } void +key_parameters_from_key(struct key_parameters *key_params, const struct ke= y *key) +{ + CLEAR(*key_params); + memcpy(key_params->cipher, key->cipher, MAX_CIPHER_KEY_LENGTH); + key_params->cipher_size =3D MAX_HMAC_KEY_LENGTH; + memcpy(key_params->hmac, key->hmac, MAX_CIPHER_KEY_LENGTH); + key_params->hmac_size =3D MAX_HMAC_KEY_LENGTH; +} + +void test_crypto(struct crypto_options *co, struct frame *frame) { int i, j; diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 3331672..ff24f87 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -144,7 +144,8 @@ /** * Container for unidirectional cipher and HMAC %key material. - * @ingroup control_processor + * @ingroup control_processor. This is used as a wire format/file format + * key, so it cannot be changed to add fields or change the length of fiel= ds */ struct key { @@ -154,6 +155,30 @@ /**< %Key material for HMAC operations. */ }; +/** internal structure similar to struct key that hold key information + * but is not represented on wire and can be changed/extended + */ +struct key_parameters { + /** %Key material for cipher operations. */ + uint8_t cipher[MAX_CIPHER_KEY_LENGTH]; + + /** Number of bytes set in the cipher key material */ + int cipher_size; + + /** %Key material for HMAC operations. */ + uint8_t hmac[MAX_HMAC_KEY_LENGTH]; + + /** Number of bytes set in the HMac key material */ + int hmac_size; +}; + +/** + * Converts a struct key representation into a struct key_params represent= ation. + * @param key_params destination for the converted struct + * @param key source of the conversion + */ +void +key_parameters_from_key(struct key_parameters *key_params, const struct ke= y *key); /** * Container for one set of cipher and/or HMAC contexts. @@ -340,19 +365,17 @@ * Key context functions */ -void init_key_ctx(struct key_ctx *ctx, const struct key *key, +void init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const struct key_type *kt, int enc, const char *prefix); void -init_key_bi_ctx_send(struct key_ctx *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, - const char *name); +init_key_bi_ctx_send(struct key_ctx *ctx, const struct key_parameters *key, + const struct key_type *kt, const char *name); void -init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key2 *key2, - int key_direction, const struct key_type *kt, - const char *name); +init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key_parameters *key, + const struct key_type *kt, const char *name); void free_key_ctx(struct key_ctx *ctx); diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index b8894db..76f06bc 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -377,7 +377,11 @@ { msg(M_FATAL, "ERROR: --tls-crypt-v2 not supported"); } - init_key_ctx(key_ctx, &srv_key, &kt, encrypt, "tls-crypt-v2 server key= "); + struct key_parameters srv_key_params; + + key_parameters_from_key(&srv_key_params, &srv_key); + + init_key_ctx(key_ctx, &srv_key_params, &kt, encrypt, "tls-crypt-v2 ser= ver key"); secure_memzero(&srv_key, sizeof(srv_key)); } diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/tests/unit_tests/= openvpn/test_auth_token.c index 8a0c16a..9a21abf 100644 --- a/tests/unit_tests/openvpn/test_auth_token.c +++ b/tests/unit_tests/openvpn/test_auth_token.c @@ -87,7 +87,8 @@ struct test_context *ctx =3D calloc(1, sizeof(*ctx)); *state =3D ctx; - struct key key =3D { 0 }; + struct key_parameters key =3D { 0 }; + key.hmac_size =3D 64; /* 64 byte of 0 */ ctx->kt =3D auth_token_kt(); if (!ctx->kt.digest) @@ -148,15 +149,17 @@ AUTH_TOKEN_HMAC_OK); /* Change auth-token key */ - struct key key; - memset(&key, '1', sizeof(key)); + struct key_parameters key; + memset(key.hmac, '1', sizeof(key.hmac)); + key.hmac_size =3D MAX_HMAC_KEY_LENGTH; + free_key_ctx(&ctx->multi.opt.auth_token_key); init_key_ctx(&ctx->multi.opt.auth_token_key, &key, &ctx->kt, false, "T= EST"); assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), 0); /* Load original test key again */ - memset(&key, 0, sizeof(key)); + memset(&key.hmac, 0, sizeof(key.hmac)); free_key_ctx(&ctx->multi.opt.auth_token_key); init_key_ctx(&ctx->multi.opt.auth_token_key, &key, &ctx->kt, false, "T= EST"); assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/o= penvpn/test_tls_crypt.c index 4f12f88..f4b30b7 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -157,7 +157,7 @@ struct test_tls_crypt_context *ctx =3D calloc(1, sizeof(*ctx)); *state =3D ctx; - struct key key =3D { 0 }; + struct key_parameters key =3D { .cipher =3D { 0 }, .hmac =3D { 0 }, .h= mac_size =3D 64, .cipher_size =3D 64 }; ctx->kt =3D tls_crypt_kt(); if (!ctx->kt.cipher || !ctx->kt.digest) @@ -367,7 +367,7 @@ skip_if_tls_crypt_not_supported(ctx); /* Change decrypt key */ - struct key key =3D { { 1 } }; + struct key_parameters key =3D { .cipher =3D { 1 }, .hmac =3D { 1 }, .c= ipher_size =3D 64, .hmac_size =3D 64 }; free_key_ctx(&ctx->co.key_ctx_bi.decrypt); init_key_ctx(&ctx->co.key_ctx_bi.decrypt, &key, &ctx->kt, false, "TEST= "); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/801?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I4a981c5a70717e2276d89bf83a06c7fdbe6712d7 Gerrit-Change-Number: 801 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --aOOTA5wJ0CI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

Vi= ew Change

Change API of init_key_ctx to use struct key_paramters
This introduces a new structure key_paramters. The reason is that the
c= urrent struct serves both as an internal struct as well as an
on-wire/in= -file format. Separate these two different usages to allow
extending the= struct.

Change-Id: I4a981c5a70717e2276d89bf83a06c7fdbe6712d7
Sig= ned-off-by: Arne Schwabe <arne@...1227...>
---
M src/openvpn/au= th_token.c
M src/openvpn/crypto.c
M src/openvpn/crypto.h
M src/ope= nvpn/tls_crypt.c
M tests/unit_tests/openvpn/test_auth_token.c
M tests= /unit_tests/openvpn/test_tls_crypt.c
6 files changed, 85 insertions(+), = 37 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/01/801/1
diff --git a/src/openvpn/auth_token.c b/src/op=
envpn/auth_token.c
index 192c7c2..3cf55e8 100644
= --- a/src/openvpn/auth_token.c
+++ b/src/openvpn/auth= _token.c
@@ -152,7 +152,10 @@
{=
msg(M_FATAL, "ERROR: not enough data in auth-token = secret");
}
- init_key_ctx(key_ctx, &key, &kt, false, "a= uth-token secret");
+
+ struct key= _parameters key_params;
+ key_parameters_from_key(&key_params, &key);
+ init_key_ctx(key_ctx, &key_= params, &kt, false, "auth-token secret");

free_buf(&server_secret_key);
}
diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 44c226c..f4453d8 100644
--- a/src/openvpn= /crypto.c
+++ b/src/openvpn/crypto.c
@@ -90= 3,7 +903,7 @@
* @param key key, hmac pa= rt used to calculate implicit IV
*/
stat= ic void
-key_ctx_update= _implicit_iv(struct key_ctx *ctx, const struct key *key)
+key_ctx_update_implicit_iv(struct key_= ctx *ctx, const struct key_parameters *key)
{
/* Only use implicit IV in AEAD cipher mode, where HMAC key is not= used */

if (cipher_ctx_mode_aead(ctx->cipher))
@@ -913,6 +913,7 @@
impl_iv_len =3D c= ipher_ctx_iv_length(ctx->cipher) - sizeof(packet_id_type);
ASSERT(impl_iv_len <=3D OPENVPN_MAX_IV_LENGTH);

ASSERT(impl_iv_len <=3D MAX_HMAC_KEY_LENGTH);

+ ASSERT(key->hmac_size = >=3D impl_iv_len);

CLEAR(ctx->implicit_iv);<= /span>
/* The first bytes of the IV are filled with the p= acket id */
memcpy(ctx->implicit_iv + sizeof(pa= cket_id_type), key->hmac, impl_iv_len);
@@ -921,7 +922,7= @@

/* given a key and key_type, build a= key_ctx */
void
-init_key_ctx(struct key_ctx *ctx, const struct key *key,=
+init_key_ctx(struct key_ct= x *ctx, const struct key_parameters *key,
con= st struct key_type *kt, int enc,
const char *= prefix)
{
@@ -929,7 +930,7 @@
CLEAR(*ctx);

if (cipher_defined(kt->cipher= ))
{
-
+ ASSERT(= key->cipher_size >=3D cipher_kt_key_size(kt->cipher));
<= span> ctx->cipher =3D cipher_ctx_new();
= cipher_ctx_init(ctx->cipher, key->cipher, kt->cipher, enc);


@@ -944,8 +945,10 @@
= cipher_kt_iv_size(kt->cipher));
warn_insec= ure_key_type(ciphername);
}
+
if (md_defined(kt->di= gest))
{
+ ASSERT(key->hmac_size >=3D md_kt_size(kt->digest= ));
ctx->hmac =3D hmac_ctx_new();
hmac_ctx_init(ctx->hmac, key->hmac, kt->digest);

@@ -966,41 +969,43 @@
}

void
-init_key_bi_ctx_send(struct key_ctx *ctx, const struct key2 *k= ey2,
- = int key_direction, const struct key_type *kt, const char *name)<= br>+init_key_bi_ctx_send(struct= key_ctx *ctx, const struct key_parameters *key_params,
+ const struct key_t= ype *kt, const char *name)
{
char log= _prefix[128] =3D { 0 };
- struct key_direction_state kds;
-
- k= ey_direction_state_init(&kds, key_direction);
<= br> snprintf(log_prefix, sizeof(log_prefix), "Outgoing %s&qu= ot;, name);
- init_k= ey_ctx(ctx, &key2->keys[kds.out_key], kt,
- OPENVPN_OP_ENCRYPT, log_prefix)= ;
- key_ctx_update_i= mplicit_iv(ctx, &key2->keys[kds.out_key]);
+ init_key_ctx(ctx, key_params, kt, OPENVPN= _OP_ENCRYPT, log_prefix);
+ key_ctx_update_implicit_iv(ctx, key_params);
}

void
-init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key= 2 *key2,
- = int key_direction, const struct key_type *kt, const char *name)

+init_key_bi_ctx_recv(st= ruct key_ctx *ctx, const struct key_parameters *key_params,
+ const struct k= ey_type *kt, const char *name)
{
char= log_prefix[128] =3D { 0 };
- struct key_direction_state kds;
-
- = key_direction_state_init(&kds, key_direction);

snprintf(log_prefix, sizeof(log_prefix), "Incoming %= s", name);
- in= it_key_ctx(ctx, &key2->keys[kds.in_key], kt,
- OPENVPN_OP_DECRYPT, log_pr= efix);
- key_ctx_upd= ate_implicit_iv(ctx, &key2->keys[kds.in_key]);
+ init_key_ctx(ctx, key_params, kt, OPE= NVPN_OP_DECRYPT, log_prefix);
+ key_ctx_update_implicit_iv(ctx, key_params);
= }

void
init_key_ctx_bi= (struct key_ctx_bi *ctx, const struct key2 *key2,
= int key_direction, const struct key_type *kt, const char *name)
{
- in= it_key_bi_ctx_send(&ctx->encrypt, key2, key_direction, kt, name);
- init_key_bi_ctx_recv= (&ctx->decrypt, key2, key_direction, kt, name);
+ struct key_direction_state kds;
+
+ key_direction_state_init(&kds, ke= y_direction);
+

+ struct key_parameters= send_key;
+ struc= t key_parameters recv_key;
+
+ key_para= meters_from_key(&send_key, &key2->keys[kds.out_key]);
= + key_parameters_from_key(&a= mp;recv_key, &key2->keys[kds.in_key]);
+
+ init_key_bi_ctx_send(&ctx->encrypt, &send_key, kt, na= me);
+ init_key_bi= _ctx_recv(&ctx->decrypt, &recv_key, kt, name);
= ctx->initialized =3D true;
}

@@ -1117,6 +1122,16 @@
}

void
+k= ey_parameters_from_key(struct key_parameters *key_params, const struct key = *key)
+{
+ CLEAR(*key_params);
+ memcpy(key_params->ci= pher, key->cipher, MAX_CIPHER_KEY_LENGTH);
+ key_params->cipher_size =3D MAX_HMAC_KEY_L= ENGTH;
+ memcpy(ke= y_params->hmac, key->hmac, MAX_CIPHER_KEY_LENGTH);
+ key_params->hmac_size =3D MAX_H= MAC_KEY_LENGTH;
+}
+
+void
test_crypto(struct = crypto_options *co, struct frame *frame)
{
int i, j;

diff --git a/src/openvpn/crypto.h b/src/ope= nvpn/crypto.h
index 3331672..ff24f87 100644
--- a/src/openvpn/crypto.h

+++ b/src/openvpn/crypto.h
@@ -144,7 +144,8 @@

/**
* Container for unidirectional cipher and HMAC %key material.=
- * @ingroup control_p= rocessor
+ * @ingroup= control_processor. This is used as a wire format/file format
+ * key, so it cannot be changed t= o add fields or change the length of fields

*/
= struct key
{
@@ -154,6 +155,30 @@
/**< %Key material for HMAC operations. */ };

+/** internal structure similar to struct key that hold key informa= tion
+ * but is not r= epresented on wire and can be changed/extended
+ */
+struct key_parameters {
+ /** %Key material for cipher operations. */
+ uint8_t cipher[MAX_CIPHER_KE= Y_LENGTH];

++ /** Number of bytes set = in the cipher key material */
+ int cipher_size;
+
+ /** = %Key material for HMAC operations. */
+ uint8_t hmac[MAX_HMAC_KEY_LENGTH];
+
+ /** Number of bytes set in the HMac key material */
+ int hmac_size;
+};
+
+/**
= + * Converts a struct key representation into a struct key_params represent= ation.
+ * @param key= _params destination for the converted struct
+ * @param key source of the conversio= n
+ */
+void

+key_parameters_from_key(struct key_parameters *ke= y_params, const struct key *key);

/**
* Container for one set of cipher and/or HMAC contexts.
@@ -340,19 +365,17 @@
* Key context function= s
*/

-void init_key_ctx(struct key_ctx *ctx, const struct key = *key,
+void init_key_= ctx(struct key_ctx *ctx, const struct key_parameters *key,
= const struct key_type *kt, int enc,
= const char *prefix);

void=
-init_key_bi_ctx_send(= struct key_ctx *ctx, const struct key2 *key2,
- int key_direction, const struc= t key_type *kt,
- = const char *name);
+init_key_bi_ctx_send(struct key_ctx *ctx, const struct key_pa= rameters *key,
+ = const struct key_type *kt, const char *name);

void
-init_key_bi_ctx_recv(struct key_ctx *ctx, const struct key2 *key2,
- int = key_direction, const struct key_type *kt,
- const char *name);
+init_key_bi_ctx_recv(struct key_ctx= *ctx, const struct key_parameters *key,

+ const struct key_type *kt, const = char *name);

void free_key_ctx(struct ke= y_ctx *ctx);

diff --git a/src/openvpn/tls= _crypt.c b/src/openvpn/tls_crypt.c
index b8894db..76f06bc 1= 00644
--- a/src/openvpn/tls_crypt.c
+++ b/s= rc/openvpn/tls_crypt.c
@@ -377,7 +377,11 @@
{

msg(M_FATAL, "ERROR: --tls-crypt-v2 n= ot supported");
}
- init_key_ctx(key_ctx, &srv_key, &kt, encr= ypt, "tls-crypt-v2 server key");
+ struct key_parameters srv_key_params;
= +
+ key_parameters_from_key(&srv_key_params, = &srv_key);
+
+ init_key_ctx(key_ctx= , &srv_key_params, &kt, encrypt, "tls-crypt-v2 server key"= ;);
secure_memzero(&srv_key, sizeof(srv_key));
}

diff --git a/tests/unit_t= ests/openvpn/test_auth_token.c b/tests/unit_tests/openvpn/test_auth_token.c=
index 8a0c16a..9a21abf 100644
--- a/tests/= unit_tests/openvpn/test_auth_token.c
+++ b/tests/unit_tests= /openvpn/test_auth_token.c
@@ -87,7 +87,8 @@
struct test_context *ctx =3D calloc(1, sizeof(*ctx));

*state =3D ctx;


- struct key key =3D { 0 };
+ struct key_parameters key =3D { 0 };
+ key.hmac_size =3D 64;= /* 64 byte of 0 */

ctx->kt = =3D auth_token_kt();
if (!ctx->kt.digest)@@ -148,15 +149,17 @@
AUTH_TOK= EN_HMAC_OK);

/* Change auth-token ke= y */
- struct key ke= y;
- memset(&key= , '1', sizeof(key));
+ struct key_parameters key;
+ memset(key.hmac, '1', sizeof(key.hmac));
+ key.hmac_size =3D = MAX_HMAC_KEY_LENGTH;
= +
free_key_ctx(&ctx->multi.opt.auth_token_key);=
init_key_ctx(&ctx->multi.opt.auth_token_key, &= amp;key, &ctx->kt, false, "TEST");

assert_int_equal(verify_auth_token(&ctx->up, &ct= x->multi, ctx->session), 0);

/= * Load original test key again */
- memset(&key, 0, sizeof(key));
+ memset(&key.hmac, 0, sizeof(key.hmac)= );
free_key_ctx(&ctx->multi.opt.auth_token_key)= ;
init_key_ctx(&ctx->multi.opt.auth_token_key, = &key, &ctx->kt, false, "TEST");
a= ssert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx-= >session),
diff --git a/tests/unit_tests/openvpn/test_tl= s_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c
index= 4f12f88..f4b30b7 100644
--- a/tests/unit_tests/openvpn/tes= t_tls_crypt.c
+++ b/tests/unit_tests/openvpn/test_tls_crypt= .c
@@ -157,7 +157,7 @@
struct test_tls= _crypt_context *ctx =3D calloc(1, sizeof(*ctx));
*stat= e =3D ctx;

- struct key key =3D { 0 };
+ struct key_parameters key =3D { .cipher =3D { 0 }, .hm= ac =3D { 0 }, .hmac_size =3D 64, .cipher_size =3D 64 };

ctx->kt =3D tls_crypt_kt();
if = (!ctx->kt.cipher || !ctx->kt.digest)
@@ -367,7 +367,7= @@
skip_if_tls_crypt_not_supported(ctx);

/* Change decrypt key */
- struct key key =3D { { 1 } };+ struct key_parameters key= =3D { .cipher =3D { 1 }, .hmac =3D { 1 }, .cipher_size =3D 64, .hmac_size = =3D 64 };
free_key_ctx(&ctx->co.key_ctx_bi.decr= ypt);
init_key_ctx(&ctx->co.key_ctx_bi.decrypt,= &key, &ctx->kt, false, "TEST");


To view, visit change 801. To unsubscribe, or f= or help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4a981c5a70717e2276d89bf83a0= 6c7fdbe6712d7
Gerrit-Change-Number: 801
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--aOOTA5wJ0CI=--