]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add tls_get_tls_unique() to fetch "tls-unique" for channel binding
authorJouni Malinen <j@w1.fi>
Mon, 10 Aug 2015 18:21:40 +0000 (21:21 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 9 Jul 2019 13:10:44 +0000 (16:10 +0300)
This implements "tls-unique" derivation per RFC 5929, Section 3. This
will be needed for channel binding, e.g., with EAP-TEAP.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/crypto/tls.h
src/crypto/tls_openssl.c

index 9f07e10d963003c2a68237a9001873c3cbd292fc..e199187e82a513eb62f3a09dca8e245303f62ee7 100644 (file)
@@ -646,4 +646,17 @@ tls_connection_get_success_data(struct tls_connection *conn);
 
 void tls_connection_remove_session(struct tls_connection *conn);
 
+/**
+ * tls_get_tls_unique - Fetch "tls-unique" for channel binding
+ * @conn: Connection context data from tls_connection_init()
+ * @buf: Buffer for returning the value
+ * @max_len: Maximum length of the buffer in bytes
+ * Returns: Number of bytes written to buf or -1 on error
+ *
+ * This function can be used to fetch "tls-unique" (RFC 5929, Section 3) which
+ * is the first TLS Finished message sent in the most recent TLS handshake of
+ * the TLS connection.
+ */
+int tls_get_tls_unique(struct tls_connection *conn, u8 *buf, size_t max_len);
+
 #endif /* TLS_H */
index 1073f64501f52b630ee14ef10381ea13f1f7c2e8..a7a77938064ec629440894d110ffd46a7236bc0a 100644 (file)
@@ -5332,3 +5332,21 @@ void tls_connection_remove_session(struct tls_connection *conn)
                wpa_printf(MSG_DEBUG,
                           "OpenSSL: Removed cached session to disable session resumption");
 }
+
+
+int tls_get_tls_unique(struct tls_connection *conn, u8 *buf, size_t max_len)
+{
+       size_t len;
+       int reused;
+
+       reused = SSL_session_reused(conn->ssl);
+       if ((conn->server && !reused) || (!conn->server && reused))
+               len = SSL_get_peer_finished(conn->ssl, buf, max_len);
+       else
+               len = SSL_get_finished(conn->ssl, buf, max_len);
+
+       if (len == 0 || len > max_len)
+               return -1;
+
+       return len;
+}