]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Use wpabuf with tls_connection_ia_send_phase_finished()
authorJouni Malinen <j@w1.fi>
Sun, 20 Dec 2009 19:33:32 +0000 (21:33 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 20 Dec 2009 19:33:32 +0000 (21:33 +0200)
src/crypto/tls.h
src/crypto/tls_gnutls.c
src/crypto/tls_internal.c
src/crypto/tls_none.c
src/crypto/tls_nss.c
src/crypto/tls_openssl.c
src/crypto/tls_schannel.c
src/eap_peer/eap_ttls.c
src/eap_server/eap_ttls.c

index b1d8ca5c8ca84d213834be2279976056b3b1b2db..861ae2091fdc4c6ceaa270ec193e0070b301886b 100644 (file)
@@ -484,16 +484,13 @@ unsigned int tls_capabilities(void *tls_ctx);
  * @tls_ctx: TLS context data from tls_init()
  * @conn: Connection context data from tls_connection_init()
  * @final: 1 = FinalPhaseFinished, 0 = IntermediatePhaseFinished
- * @out_data: Pointer to output buffer (encrypted TLS/IA data)
- * @out_len: Maximum out_data length 
- * Returns: Number of bytes written to out_data on success, -1 on failure
+ * Returns: Encrypted TLS/IA data, %NULL on failure
  *
  * This function is used to send the TLS/IA end phase message, e.g., when the
  * EAP server completes EAP-TTLSv1.
  */
-int __must_check tls_connection_ia_send_phase_finished(
-       void *tls_ctx, struct tls_connection *conn, int final,
-       u8 *out_data, size_t out_len);
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final);
 
 /**
  * tls_connection_ia_final_phase_finished - Has final phase been completed
index ed85d15c0fea28cbaf9fcea9ec0e14b0e94cdc70..7547d80113430efc4361d6fa6eb2f87b9df09a61 100644 (file)
@@ -1336,16 +1336,15 @@ int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
 }
 
 
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
-                                         struct tls_connection *conn,
-                                         int final,
-                                         u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final)
 {
 #ifdef GNUTLS_IA
        int ret;
+       struct wpabuf *buf;
 
        if (conn == NULL || conn->session == NULL || !conn->tls_ia)
-               return -1;
+               return NULL;
 
        ret = gnutls_ia_permute_inner_secret(conn->session,
                                             conn->session_keys_len,
@@ -1359,26 +1358,21 @@ int tls_connection_ia_send_phase_finished(void *tls_ctx,
        if (ret) {
                wpa_printf(MSG_DEBUG, "%s: Failed to permute inner secret: %s",
                           __func__, gnutls_strerror(ret));
-               return -1;
+               return NULL;
        }
 
        ret = gnutls_ia_endphase_send(conn->session, final);
        if (ret) {
                wpa_printf(MSG_DEBUG, "%s: Failed to send endphase: %s",
                           __func__, gnutls_strerror(ret));
-               return -1;
+               return NULL;
        }
 
-       if (conn->push_buf == NULL)
-               return -1;
-       if (wpabuf_len(conn->push_buf) < out_len)
-               out_len = wpabuf_len(conn->push_buf);
-       os_memcpy(out_data, wpabuf_head(conn->push_buf), out_len);
-       wpabuf_free(conn->push_buf);
+       buf = conn->push_buf;
        conn->push_buf = NULL;
-       return out_len;
+       return buf;
 #else /* GNUTLS_IA */
-       return -1;
+       return NULL;
 #endif /* GNUTLS_IA */
 }
 
index 27a31662d641063e70df9a594b5ae8d0f3961df4..64124d8a8e3ef74c8bbaa4709d6ea208189bbb27 100644 (file)
@@ -608,12 +608,10 @@ unsigned int tls_capabilities(void *tls_ctx)
 }
 
 
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
-                                         struct tls_connection *conn,
-                                         int final,
-                                         u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final)
 {
-       return -1;
+       return NULL;
 }
 
 
index d532def84c01131f87dff421b7a2f15f548beea8..0c836bb63187316bca4b094aaa01fec025ffb663 100644 (file)
@@ -207,12 +207,10 @@ unsigned int tls_capabilities(void *tls_ctx)
 }
 
 
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
-                                         struct tls_connection *conn,
-                                         int final,
-                                         u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final)
 {
-       return -1;
+       return NULL;
 }
 
 
index b35ed07add41fa9234ae43cc0c2d373dbdb050ff..ad834b6493372a565c5060f2a384f472a74bcd3a 100644 (file)
@@ -649,12 +649,10 @@ unsigned int tls_capabilities(void *tls_ctx)
 }
 
 
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
-                                         struct tls_connection *conn,
-                                         int final,
-                                         u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final)
 {
-       return -1;
+       return NULL;
 }
 
 
index cc67938ac34893a84205d32b2f651ee6b20900fa..1914b5d3844637e0e8191d669f4b75789d82462e 100644 (file)
@@ -2493,12 +2493,10 @@ int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
 }
 
 
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
-                                         struct tls_connection *conn,
-                                         int final,
-                                         u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final)
 {
-       return -1;
+       return NULL;
 }
 
 
index 6600d42e734e99c3d4e43673665eaf4668e105b0..4a94e9911982175c5a6bec036060177c69be7cf6 100644 (file)
@@ -745,12 +745,10 @@ int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
 }
 
 
-int tls_connection_ia_send_phase_finished(void *tls_ctx,
-                                         struct tls_connection *conn,
-                                         int final,
-                                         u8 *out_data, size_t out_len)
+struct wpabuf * tls_connection_ia_send_phase_finished(
+       void *tls_ctx, struct tls_connection *conn, int final);
 {
-       return -1;
+       return NULL;
 }
 
 
index f93ba38f20f99e90282c089f36493c14826925aa..096a5830965b54780a25a269b96c5a3156d6b974 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "common.h"
 #include "crypto/ms_funcs.h"
+#include "crypto/sha1.h"
 #include "crypto/tls.h"
 #include "eap_common/chap.h"
 #include "eap_common/eap_ttls.h"
@@ -1030,27 +1031,25 @@ static int eap_ttls_phase2_request(struct eap_sm *sm,
 static struct wpabuf * eap_ttls_build_phase_finished(
        struct eap_sm *sm, struct eap_ttls_data *data, int id, int final)
 {
-       int len;
-       struct wpabuf *req;
-       u8 *pos;
-       const int max_len = 300;
+       struct wpabuf *req, *buf;
 
-       req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TTLS, 1 + max_len,
-                           EAP_CODE_RESPONSE, id);
-       if (req == NULL)
+       buf = tls_connection_ia_send_phase_finished(sm->ssl_ctx,
+                                                   data->ssl.conn,
+                                                   final);
+       if (buf == NULL)
                return NULL;
 
-       wpabuf_put_u8(req, data->ttls_version);
-
-       pos = wpabuf_put(req, 0);
-       len = tls_connection_ia_send_phase_finished(sm->ssl_ctx,
-                                                   data->ssl.conn,
-                                                   final, pos, max_len);
-       if (len < 0) {
-               wpabuf_free(req);
+       req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_TTLS,
+                           1 + wpabuf_len(buf),
+                           EAP_CODE_RESPONSE, id);
+       if (req == NULL) {
+               wpabuf_free(buf);
                return NULL;
        }
-       wpabuf_put(req, len);
+
+       wpabuf_put_u8(req, data->ttls_version);
+       wpabuf_put_buf(req, buf);
+       wpabuf_free(buf);
        eap_update_len(req);
 
        return req;
index 14c323356e7152336f49b0ad91f1aa32a05d8f8e..92583f8b133e0a6ef96ea210d89009fe3aae8a94 100644 (file)
@@ -519,25 +519,8 @@ static struct wpabuf * eap_ttls_build_phase2_mschapv2(
 static struct wpabuf * eap_ttls_build_phase_finished(
        struct eap_sm *sm, struct eap_ttls_data *data, int final)
 {
-       int len;
-       struct wpabuf *req;
-       const int max_len = 300;
-
-       req = wpabuf_alloc(max_len);
-       if (req == NULL)
-               return NULL;
-
-       len = tls_connection_ia_send_phase_finished(sm->ssl_ctx,
-                                                   data->ssl.conn, final,
-                                                   wpabuf_mhead(req),
-                                                   max_len);
-       if (len < 0) {
-               wpabuf_free(req);
-               return NULL;
-       }
-       wpabuf_put(req, len);
-
-       return req;
+       return tls_connection_ia_send_phase_finished(sm->ssl_ctx,
+                                                    data->ssl.conn, final);
 }