]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
keymat_v2: Add optional qske_t argument to derive_child_keys()
authorTobias Brunner <tobias@strongswan.org>
Fri, 13 Jul 2018 13:31:34 +0000 (15:31 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 14 May 2019 08:54:45 +0000 (10:54 +0200)
src/charon-tkm/src/tkm/tkm_keymat.c
src/charon-tkm/tests/keymat_tests.c
src/libcharon/plugins/ha/ha_dispatcher.c
src/libcharon/sa/ikev2/keymat_v2.c
src/libcharon/sa/ikev2/keymat_v2.h
src/libcharon/sa/ikev2/tasks/child_create.c

index 3685ac4163e6c57695dbb8a017bd306446ed8799..17ce019f724f8c4041836ab48e113f0c51ee7d33 100644 (file)
@@ -342,8 +342,8 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
 
 METHOD(keymat_v2_t, derive_child_keys, bool,
        private_tkm_keymat_t *this, proposal_t *proposal, diffie_hellman_t *dh,
-       chunk_t nonce_i, chunk_t nonce_r, chunk_t *encr_i, chunk_t *integ_i,
-       chunk_t *encr_r, chunk_t *integ_r)
+       qske_t *qske, chunk_t nonce_i, chunk_t nonce_r, chunk_t *encr_i,
+       chunk_t *integ_i, chunk_t *encr_r, chunk_t *integ_r)
 {
        esa_info_t *esa_info_i, *esa_info_r;
        dh_id_type dh_id = 0;
index ee2737e3dace10d050b674c1188cc4e58cf18035..b62542a1f69a15f0988ac39baba19c57d3ca0da6 100644 (file)
@@ -93,7 +93,7 @@ START_TEST(test_derive_child_keys)
        chunk_t nonce = chunk_from_chars("test chunk");
 
        fail_unless(keymat->keymat_v2.derive_child_keys(&keymat->keymat_v2, proposal,
-                                                                                                       (diffie_hellman_t *)dh,
+                                                                                                       (diffie_hellman_t *)dh, NULL,
                                                                                                        nonce, nonce, &encr_i,
                                                                                                        &integ_i, &encr_r, &integ_r),
                                "Child key derivation failed");
index cbdaa39a200d7930f4f49ec56d2d0782663e8101..86d1ffd8bd3a9566ee7dc9654ba446bd9951705c 100644 (file)
@@ -775,7 +775,7 @@ static void process_child_add(private_ha_dispatcher_t *this,
        {
                keymat_v2_t *keymat_v2 = (keymat_v2_t*)ike_sa->get_keymat(ike_sa);
 
-               ok = keymat_v2->derive_child_keys(keymat_v2, proposal, dh,
+               ok = keymat_v2->derive_child_keys(keymat_v2, proposal, dh, NULL,
                                                nonce_i, nonce_r, &encr_i, &integ_i, &encr_r, &integ_r);
        }
        if (ike_sa->get_version(ike_sa) == IKEV1)
index 174e957506e660074ecd38e345d4b708cccace5c..1e56321fc12e6b3beb641d0ca40e0f5664893b2e 100644 (file)
@@ -610,11 +610,11 @@ METHOD(keymat_v2_t, derive_ike_keys_ppk, bool,
 
 METHOD(keymat_v2_t, derive_child_keys, bool,
        private_keymat_v2_t *this, proposal_t *proposal, diffie_hellman_t *dh,
-       chunk_t nonce_i, chunk_t nonce_r, chunk_t *encr_i, chunk_t *integ_i,
-       chunk_t *encr_r, chunk_t *integ_r)
+       qske_t *qske, chunk_t nonce_i, chunk_t nonce_r, chunk_t *encr_i,
+       chunk_t *integ_i, chunk_t *encr_r, chunk_t *integ_r)
 {
        uint16_t enc_alg, int_alg, enc_size = 0, int_size = 0;
-       chunk_t seed, secret = chunk_empty;
+       chunk_t seed, secret = chunk_empty, qske_secret = chunk_empty;
        prf_plus_t *prf_plus;
 
        if (proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM,
@@ -694,7 +694,16 @@ METHOD(keymat_v2_t, derive_child_keys, bool,
                }
                DBG4(DBG_CHD, "DH secret %B", &secret);
        }
-       seed = chunk_cata("scc", secret, nonce_i, nonce_r);
+       if (qske)
+       {
+               if (!qske->get_shared_secret(qske, &qske_secret))
+               {
+                       chunk_clear(&secret);
+                       return FALSE;
+               }
+               DBG4(DBG_CHD, "QSKE secret %B", &qske_secret);
+       }
+       seed = chunk_cata("sscc", secret, qske_secret, nonce_i, nonce_r);
        DBG4(DBG_CHD, "seed %B", &seed);
 
        prf_plus = prf_plus_create(this->prf, TRUE, seed);
index 053f451f5554806b564a698771f7b075bdc82ae7..ade4626628d9299e0c9c87e062c8fb3536b27e04 100644 (file)
@@ -87,10 +87,14 @@ struct keymat_v2_t {
         * The keys for the CHILD_SA are allocated in the integ and encr chunks.
         * An implementation might hand out encrypted keys only, which are
         * decrypted in the kernel before use.
-        * If no PFS is used for the CHILD_SA, dh can be NULL.
+        *
+        * If no PFS is used for the CHILD_SA, dh may be NULL.
+        *
+        * If qske is given, the shared secret is appended to the DH secret, if any.
         *
         * @param proposal      selected algorithms
-        * @param dh            diffie hellman key allocated by create_dh(), or NULL
+        * @param dh            optional diffie hellman key allocated by create_dh()
+        * @param qske          optional QSKE implementation allocated by create_qske()
         * @param nonce_i       initiators nonce value
         * @param nonce_r       responders nonce value
         * @param encr_i        chunk to write initiators encryption key to
@@ -99,8 +103,8 @@ struct keymat_v2_t {
         * @param integ_r       chunk to write responders integrity key to
         * @return                      TRUE on success
         */
-       bool (*derive_child_keys)(keymat_v2_t *this,
-                                                         proposal_t *proposal, diffie_hellman_t *dh,
+       bool (*derive_child_keys)(keymat_v2_t *this, proposal_t *proposal,
+                                                         diffie_hellman_t *dh, qske_t *qske,
                                                          chunk_t nonce_i, chunk_t nonce_r,
                                                          chunk_t *encr_i, chunk_t *integ_i,
                                                          chunk_t *encr_r, chunk_t *integ_r);
index d732c9f397600ac6c36c88c04069d9d215cca23f..11ccd175c78cbe4982a8a8dc0ba15d44cfb1c782 100644 (file)
@@ -718,8 +718,8 @@ static status_t select_and_install(private_child_create_t *this,
                this->ipcomp = IPCOMP_NONE;
        }
        status_i = status_o = FAILED;
-       if (this->keymat->derive_child_keys(this->keymat, this->proposal,
-                       this->dh, nonce_i, nonce_r, &encr_i, &integ_i, &encr_r, &integ_r))
+       if (this->keymat->derive_child_keys(this->keymat, this->proposal, this->dh,
+                       NULL, nonce_i, nonce_r, &encr_i, &integ_i, &encr_r, &integ_r))
        {
                if (this->initiator)
                {