]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
keymat_v2: Add method to calculate IntAuth for IKE_INTERMEDIATE exchanges
authorTobias Brunner <tobias@strongswan.org>
Tue, 2 Jul 2019 13:01:26 +0000 (15:01 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 29 Mar 2020 11:47:22 +0000 (13:47 +0200)
src/charon-tkm/src/tkm/tkm_keymat.c
src/libcharon/sa/ikev2/keymat_v2.c
src/libcharon/sa/ikev2/keymat_v2.h

index 1fb94f50bf0b4e204a7eb813a5a17dce1ad87ecc..adb060327b0fe09efd396f7025beca44806e752b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Tobias Brunner
+ * Copyright (C) 2015-2019 Tobias Brunner
  * Copyright (C) 2012 Reto Buerki
  * Copyright (C) 2012 Adrian-Ken Rueegsegger
  * HSR Hochschule fuer Technik Rapperswil
@@ -383,6 +383,13 @@ METHOD(keymat_t, get_aead, aead_t*,
        return in ? this->aead_in : this->aead_out;
 }
 
+METHOD(keymat_v2_t, get_int_auth, bool,
+       private_tkm_keymat_t *this, bool verify, chunk_t data, chunk_t *auth)
+{
+       DBG1(DBG_IKE, "TKM doesn't support IntAuth calculation");
+       return FALSE;
+}
+
 METHOD(keymat_v2_t, get_auth_octets, bool,
        private_tkm_keymat_t *this, bool verify, chunk_t ike_sa_init,
        chunk_t nonce, chunk_t ppk, identification_t *id, char reserved[3],
@@ -526,6 +533,7 @@ tkm_keymat_t *tkm_keymat_create(bool initiator)
                                .derive_ike_keys_ppk = (void*)return_false,
                                .derive_child_keys = _derive_child_keys,
                                .get_skd = _get_skd,
+                               .get_int_auth = _get_int_auth,
                                .get_auth_octets = _get_auth_octets,
                                .get_psk_sig = _get_psk_sig,
                                .add_hash_algorithm = _add_hash_algorithm,
index 50a4e3ac86ee267a0089bfea65cac5945567493e..fb09145eb671764ea4dceb920535ca28947dcae5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Tobias Brunner
+ * Copyright (C) 2015-2019 Tobias Brunner
  * Copyright (C) 2008 Martin Willi
  * HSR Hochschule fuer Technik Rapperswil
  *
@@ -326,6 +326,7 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
                return FALSE;
        }
        this->prf_alg = alg;
+       DESTROY_IF(this->prf);
        this->prf = lib->crypto->create_prf(lib->crypto, alg);
        if (this->prf == NULL)
        {
@@ -717,6 +718,24 @@ METHOD(keymat_t, get_aead, aead_t*,
        return in ? this->aead_in : this->aead_out;
 }
 
+METHOD(keymat_v2_t, get_int_auth, bool,
+       private_keymat_v2_t *this, bool verify, chunk_t data, chunk_t *auth)
+{
+       chunk_t skp;
+
+       skp = verify ? this->skp_verify : this->skp_build;
+
+       DBG3(DBG_IKE, "IntAuth_A|P %B", &data);
+       DBG4(DBG_IKE, "SK_p %B", &skp);
+       if (!this->prf->set_key(this->prf, skp) ||
+               !this->prf->allocate_bytes(this->prf, data, auth))
+       {
+               return FALSE;
+       }
+       DBG3(DBG_IKE, "IntAuth = prf(Sk_px, data) %B", auth);
+       return TRUE;
+}
+
 METHOD(keymat_v2_t, get_auth_octets, bool,
        private_keymat_v2_t *this, bool verify, chunk_t ike_sa_init,
        chunk_t nonce, chunk_t ppk, identification_t *id, char reserved[3],
@@ -810,7 +829,6 @@ failure:
        chunk_free(&octets);
        chunk_free(&key);
        return success;
-
 }
 
 METHOD(keymat_v2_t, hash_algorithm_supported, bool,
@@ -866,6 +884,7 @@ keymat_v2_t *keymat_v2_create(bool initiator)
                        .derive_ike_keys_ppk = _derive_ike_keys_ppk,
                        .derive_child_keys = _derive_child_keys,
                        .get_skd = _get_skd,
+                       .get_int_auth = _get_int_auth,
                        .get_auth_octets = _get_auth_octets,
                        .get_psk_sig = _get_psk_sig,
                        .add_hash_algorithm = _add_hash_algorithm,
index d9d0967f437b736ca04e01d62b745e0f4d42c956..1ebffda0ba008d50c0ecd42254f4bcc4eb68560a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011-2015 Tobias Brunner
+ * Copyright (C) 2011-2019 Tobias Brunner
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -90,6 +90,7 @@ struct keymat_v2_t {
                                                          chunk_t nonce_i, chunk_t nonce_r,
                                                          chunk_t *encr_i, chunk_t *integ_i,
                                                          chunk_t *encr_r, chunk_t *integ_r);
+
        /**
         * Get SKd to pass to derive_ikey_keys() during rekeying.
         *
@@ -98,6 +99,21 @@ struct keymat_v2_t {
         */
        pseudo_random_function_t (*get_skd)(keymat_v2_t *this, chunk_t *skd);
 
+       /**
+        * Generate data for signed octets when using IKE_INTEMEDIATE exchanges.
+        *
+        * The supplied chunk must contain the IKE header until the end of the
+        * Encrypted Payload header followed by the plaintext contents of the
+        * latter.
+        *
+        * @param verify                TRUE as recipient, FALSE as sender
+        * @param data                  IKE_INTERMEDIATE packet data
+        * @param[out] auth             IntAuth data to be used later with get_auth_octets()
+        * @return                              TRUE if octets created successfully
+        */
+       bool (*get_int_auth)(keymat_v2_t *this, bool verify, chunk_t data,
+                                                chunk_t *auth);
+
        /**
         * Generate octets to use for authentication procedure (RFC4306 2.15).
         *