]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fixup EAP-SIM/AKA encode/decode ctxs
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 29 May 2018 08:37:52 +0000 (14:37 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 29 May 2018 09:41:33 +0000 (15:41 +0600)
src/modules/rlm_eap/lib/sim/decode.c
src/modules/rlm_eap/lib/sim/encode.c

index 02280a006119dba7a9f869ddc781678dab7312f5..9bf5350eaa26422671a424029c4b6726fee4911c 100644 (file)
@@ -1022,65 +1022,67 @@ int fr_sim_decode(REQUEST *request, fr_cursor_t *decoded,
        return 0;
 }
 
-/*
- *     Test ctx data
- */
-static void *decode_test_ctx_sim(UNUSED TALLOC_CTX *ctx)
+static int _test_ctx_free(UNUSED fr_sim_decode_ctx_t *ctx)
 {
-       static fr_sim_decode_ctx_t      test_ctx;
-       static fr_sim_keys_t            keys = {
-                                               .k_encr = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
-                                                           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }
-                                       };
-
-       fr_sim_init();
-
-       test_ctx.root = attr_eap_sim_root;
-       test_ctx.keys = &keys;
-       memset(&test_ctx.iv, 0, sizeof(test_ctx.iv));
-       test_ctx.have_iv = true;        /* Ensures IV is all zeros */
-
        fr_sim_free();
 
-       return &test_ctx;
+       return 0;
 }
 
-static void *decode_test_ctx_aka(UNUSED TALLOC_CTX *ctx)
+static fr_sim_decode_ctx_t *test_ctx_init(TALLOC_CTX *ctx, uint8_t const *k_encr, size_t k_encr_len)
 {
-       static fr_sim_decode_ctx_t      test_ctx;
-       static fr_sim_keys_t            keys = {
-                                               .k_encr = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
-                                                           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }
-                                       };
+       fr_sim_decode_ctx_t     *test_ctx;
+       fr_sim_keys_t           *keys;
+
+       test_ctx = talloc_zero(ctx, fr_sim_decode_ctx_t);
+       test_ctx->keys = keys = talloc_zero(test_ctx, fr_sim_keys_t);
+       memcpy(keys->k_encr, k_encr, k_encr_len);
+       talloc_set_destructor(test_ctx, _test_ctx_free);
 
        fr_sim_init();
 
-       test_ctx.root = attr_eap_aka_root;
-       test_ctx.keys = &keys;
-       memset(&test_ctx.iv, 0, sizeof(test_ctx.iv));
-       test_ctx.have_iv = true;        /* Ensures IV is all zeros */
+       return test_ctx;
+}
+/*
+ *     Test ctx data
+ */
+static void *decode_test_ctx_sim(TALLOC_CTX *ctx)
+{
+       fr_sim_decode_ctx_t     *test_ctx;
+       static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
+                                            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
 
-       fr_sim_free();
+       test_ctx = test_ctx_init(ctx, k_encr, sizeof(k_encr));
+       test_ctx->root = attr_eap_sim_root;
+       test_ctx->have_iv = true;       /* Ensures IV is all zeros */
 
-       return &test_ctx;
+       return test_ctx;
 }
 
-static void *decode_test_ctx_sim_rfc4186(UNUSED TALLOC_CTX *ctx)
+
+static void *decode_test_ctx_aka(TALLOC_CTX *ctx)
 {
-       static fr_sim_decode_ctx_t      test_ctx;
-       static fr_sim_keys_t            keys = {
-                                               .k_encr = { 0x53, 0x6e, 0x5e, 0xbc, 0x44 ,0x65, 0x58, 0x2a,
-                                                           0xa6, 0xa8, 0xec, 0x99, 0x86, 0xeb, 0xb6, 0x20 }
-                                       };
+       fr_sim_decode_ctx_t *test_ctx;
+       static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
+                                            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
 
-       fr_sim_init();
+       test_ctx = test_ctx_init(ctx, k_encr, sizeof(k_encr));
+       test_ctx->root = attr_eap_aka_root;
+       test_ctx->have_iv = true;       /* Ensures IV is all zeros */
 
-       test_ctx.root = attr_eap_sim_root;
-       test_ctx.keys = &keys;
+       return test_ctx;
+}
 
-       fr_sim_free();
+static void *decode_test_ctx_sim_rfc4186(TALLOC_CTX *ctx)
+{
+       fr_sim_decode_ctx_t *test_ctx;
+       static uint8_t          k_encr[] = { 0x53, 0x6e, 0x5e, 0xbc, 0x44 ,0x65, 0x58, 0x2a,
+                                            0xa6, 0xa8, 0xec, 0x99, 0x86, 0xeb, 0xb6, 0x20 };
+
+       test_ctx = test_ctx_init(ctx, k_encr, sizeof(k_encr));
+       test_ctx->root = attr_eap_sim_root;
 
-       return &test_ctx;
+       return test_ctx;
 }
 
 /*
index 27505c0ebdd15a6cc496f34c19cf5fac58e238bc..dba356af69c56d1ac3d68c8500af62d3bfb54b9e 100644 (file)
@@ -1082,61 +1082,67 @@ ssize_t fr_sim_encode(REQUEST *request, VALUE_PAIR *to_encode, void *encode_ctx)
 /*
  *     Test ctx data
  */
-static void *encode_test_ctx_sim(UNUSED TALLOC_CTX *ctx)
+static int _test_ctx_free(UNUSED fr_sim_encode_ctx_t *ctx)
 {
-       static fr_sim_encode_ctx_t      test_ctx;
-       static fr_sim_keys_t            keys = {
-                                               .k_encr = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
-                                                           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }
-                                       };
-
-       fr_sim_init();
-
-       test_ctx.root = attr_eap_sim_root;
-       test_ctx.keys = &keys;
-       memset(&test_ctx.iv, 0, sizeof(test_ctx.iv));
-       test_ctx.iv_included = true;    /* Ensures IV is all zeros */
-
        fr_sim_free();
 
-       return &test_ctx;
+       return 0;
 }
 
-static void *encode_test_ctx_aka(UNUSED TALLOC_CTX *ctx)
+static fr_sim_encode_ctx_t *test_ctx_init(TALLOC_CTX *ctx, uint8_t const *k_encr, size_t k_encr_len)
 {
-       static fr_sim_encode_ctx_t      test_ctx;
-       static fr_sim_keys_t            keys = {
-                                               .k_encr = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
-                                                           0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }
-                                       };
+       fr_sim_encode_ctx_t     *test_ctx;
+       fr_sim_keys_t           *keys;
+
+       test_ctx = talloc_zero(ctx, fr_sim_encode_ctx_t);
+       test_ctx->keys = keys = talloc_zero(test_ctx, fr_sim_keys_t);
+       memcpy(keys->k_encr, k_encr, k_encr_len);
+       talloc_set_destructor(test_ctx, _test_ctx_free);
 
        fr_sim_init();
 
-       test_ctx.root = attr_eap_aka_root;
-       test_ctx.keys = &keys;
-       memset(&test_ctx.iv, 0, sizeof(test_ctx.iv));
-       test_ctx.iv_included = true;    /* Ensures IV is all zeros */
+       return test_ctx;
+}
 
-       fr_sim_free();
+/*
+ *     Test ctx data
+ */
+static void *encode_test_ctx_sim(TALLOC_CTX *ctx)
+{
+       fr_sim_encode_ctx_t     *test_ctx;
+       static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
+                                            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
+
+       test_ctx = test_ctx_init(ctx, k_encr, sizeof(k_encr));
+       test_ctx->root = attr_eap_sim_root;
+       test_ctx->iv_included = true;   /* Ensures IV is all zeros */
 
-       return &test_ctx;
+       return test_ctx;
 }
 
-static void *encode_test_ctx_sim_rfc4186(UNUSED TALLOC_CTX *ctx)
+static void *encode_test_ctx_aka(TALLOC_CTX *ctx)
 {
-       static fr_sim_encode_ctx_t      test_ctx;
-       static fr_sim_keys_t            keys = {
-                                               .k_encr = { 0x53, 0x6e, 0x5e, 0xbc, 0x44 ,0x65, 0x58, 0x2a,
-                                                           0xa6, 0xa8, 0xec, 0x99, 0x86, 0xeb, 0xb6, 0x20 }
-                                       };
-       fr_sim_init();
+       fr_sim_encode_ctx_t     *test_ctx;
+       static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
+                                            0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
 
-       test_ctx.root = attr_eap_sim_root;
-       test_ctx.keys = &keys;
+       test_ctx = test_ctx_init(ctx, k_encr, sizeof(k_encr));
+       test_ctx->root = attr_eap_aka_root;
+       test_ctx->iv_included = true;   /* Ensures IV is all zeros */
 
-       fr_sim_free();
+       return test_ctx;
+}
+
+static void *encode_test_ctx_sim_rfc4186(TALLOC_CTX *ctx)
+{
+       fr_sim_encode_ctx_t     *test_ctx;
+       static uint8_t          k_encr[] = { 0x53, 0x6e, 0x5e, 0xbc, 0x44 ,0x65, 0x58, 0x2a,
+                                            0xa6, 0xa8, 0xec, 0x99, 0x86, 0xeb, 0xb6, 0x20 };
+
+       test_ctx = test_ctx_init(ctx, k_encr, sizeof(k_encr));
+       test_ctx->root = attr_eap_sim_root;
 
-       return &test_ctx;
+       return test_ctx;
 }
 
 /*