]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
tls-crypto: Add method to hash handshake data and use result as initial transcript
authorTobias Brunner <tobias@strongswan.org>
Tue, 25 Aug 2020 15:17:55 +0000 (17:17 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 12 Feb 2021 10:45:44 +0000 (11:45 +0100)
This is used for HelloRetryRequest.

src/libtls/tls_crypto.c
src/libtls/tls_crypto.h

index 04fe4ef0f40046fd8f938dab3d9bd4750927bcf0..39adcaebf7b04e5aea3758714c13a516489afd36 100644 (file)
@@ -1579,6 +1579,30 @@ static bool hash_data(private_tls_crypto_t *this, chunk_t data, chunk_t *hash)
        return TRUE;
 }
 
+METHOD(tls_crypto_t, hash_handshake, bool,
+       private_tls_crypto_t *this, chunk_t *out)
+{
+       chunk_t hash;
+
+       if (!hash_data(this, this->handshake, &hash))
+       {
+               return FALSE;
+       }
+
+       chunk_free(&this->handshake);
+       append_handshake(this, TLS_MESSAGE_HASH, hash);
+
+       if (out)
+       {
+               *out = hash;
+       }
+       else
+       {
+               free(hash.ptr);
+       }
+       return TRUE;
+}
+
 /**
  * TLS 1.3 static part of the data the server signs (64 spaces followed by the
  * context string "TLS 1.3, server CertificateVerify" and a 0 byte).
@@ -2118,6 +2142,7 @@ tls_crypto_t *tls_crypto_create(tls_t *tls, tls_cache_t *cache)
                        .create_ec_enumerator = _create_ec_enumerator,
                        .set_protection = _set_protection,
                        .append_handshake = _append_handshake,
+                       .hash_handshake = _hash_handshake,
                        .sign = _sign,
                        .verify = _verify,
                        .sign_handshake = _sign_handshake,
index 3f48cfe1329d028b2d80585eeadfae624462240c..d8d7ebe729b72506d806dc0093d85173f8d47f4a 100644 (file)
@@ -474,6 +474,14 @@ struct tls_crypto_t {
        void (*append_handshake)(tls_crypto_t *this,
                                                         tls_handshake_type_t type, chunk_t data);
 
+       /**
+        * Hash the stored handshake data and store it.  It is optionally returned
+        * so it could be sent in a cookie extension.
+        *
+        * @param hash                  optionally returned hash (allocated)
+        */
+       bool (*hash_handshake)(tls_crypto_t *this, chunk_t *hash);
+
        /**
         * Sign a blob of data, append signature to writer.
         *