2 * TLSv1 client - write handshake message
3 * Copyright (c) 2006-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "crypto/md5.h"
13 #include "crypto/sha1.h"
14 #include "crypto/sha256.h"
15 #include "crypto/tls.h"
16 #include "crypto/random.h"
18 #include "tlsv1_common.h"
19 #include "tlsv1_record.h"
20 #include "tlsv1_client.h"
21 #include "tlsv1_client_i.h"
24 static size_t tls_client_cert_chain_der_len(struct tlsv1_client *conn)
27 struct x509_certificate *cert;
29 if (conn->cred == NULL)
32 cert = conn->cred->cert;
34 len += 3 + cert->cert_len;
35 if (x509_certificate_self_signed(cert))
37 cert = x509_certificate_get_subject(conn->cred->trusted_certs,
45 u8 * tls_send_client_hello(struct tlsv1_client *conn, size_t *out_len)
47 u8 *hello, *end, *pos, *hs_length, *hs_start, *rhdr;
51 wpa_printf(MSG_DEBUG, "TLSv1: Send ClientHello");
55 WPA_PUT_BE32(conn->client_random, now.sec);
56 if (random_get_bytes(conn->client_random + 4, TLS_RANDOM_LEN - 4)) {
57 wpa_printf(MSG_ERROR, "TLSv1: Could not generate "
61 wpa_hexdump(MSG_MSGDUMP, "TLSv1: client_random",
62 conn->client_random, TLS_RANDOM_LEN);
64 len = 100 + conn->num_cipher_suites * 2 + conn->client_hello_ext_len;
65 hello = os_malloc(len);
71 pos = rhdr + TLS_RECORD_HEADER_LEN;
73 /* opaque fragment[TLSPlaintext.length] */
77 /* HandshakeType msg_type */
78 *pos++ = TLS_HANDSHAKE_TYPE_CLIENT_HELLO;
79 /* uint24 length (to be filled) */
82 /* body - ClientHello */
83 /* ProtocolVersion client_version */
84 WPA_PUT_BE16(pos, TLS_VERSION);
86 /* Random random: uint32 gmt_unix_time, opaque random_bytes */
87 os_memcpy(pos, conn->client_random, TLS_RANDOM_LEN);
88 pos += TLS_RANDOM_LEN;
89 /* SessionID session_id */
90 *pos++ = conn->session_id_len;
91 os_memcpy(pos, conn->session_id, conn->session_id_len);
92 pos += conn->session_id_len;
93 /* CipherSuite cipher_suites<2..2^16-1> */
94 WPA_PUT_BE16(pos, 2 * conn->num_cipher_suites);
96 for (i = 0; i < conn->num_cipher_suites; i++) {
97 WPA_PUT_BE16(pos, conn->cipher_suites[i]);
100 /* CompressionMethod compression_methods<1..2^8-1> */
102 *pos++ = TLS_COMPRESSION_NULL;
104 if (conn->client_hello_ext) {
105 os_memcpy(pos, conn->client_hello_ext,
106 conn->client_hello_ext_len);
107 pos += conn->client_hello_ext_len;
110 WPA_PUT_BE24(hs_length, pos - hs_length - 3);
111 tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
113 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
114 rhdr, end - rhdr, hs_start, pos - hs_start,
116 wpa_printf(MSG_DEBUG, "TLSv1: Failed to create TLS record");
117 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
118 TLS_ALERT_INTERNAL_ERROR);
123 conn->state = SERVER_HELLO;
129 static int tls_write_client_certificate(struct tlsv1_client *conn,
130 u8 **msgpos, u8 *end)
132 u8 *pos, *rhdr, *hs_start, *hs_length, *cert_start;
134 struct x509_certificate *cert;
138 wpa_printf(MSG_DEBUG, "TLSv1: Send Certificate");
140 pos += TLS_RECORD_HEADER_LEN;
142 /* opaque fragment[TLSPlaintext.length] */
146 /* HandshakeType msg_type */
147 *pos++ = TLS_HANDSHAKE_TYPE_CERTIFICATE;
148 /* uint24 length (to be filled) */
151 /* body - Certificate */
152 /* uint24 length (to be filled) */
155 cert = conn->cred ? conn->cred->cert : NULL;
157 if (pos + 3 + cert->cert_len > end) {
158 wpa_printf(MSG_DEBUG, "TLSv1: Not enough buffer space "
159 "for Certificate (cert_len=%lu left=%lu)",
160 (unsigned long) cert->cert_len,
161 (unsigned long) (end - pos));
162 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
163 TLS_ALERT_INTERNAL_ERROR);
166 WPA_PUT_BE24(pos, cert->cert_len);
168 os_memcpy(pos, cert->cert_start, cert->cert_len);
169 pos += cert->cert_len;
171 if (x509_certificate_self_signed(cert))
173 cert = x509_certificate_get_subject(conn->cred->trusted_certs,
176 if (conn->cred == NULL || cert == conn->cred->cert || cert == NULL) {
178 * Client was not configured with all the needed certificates
179 * to form a full certificate chain. The server may fail to
180 * validate the chain unless it is configured with all the
181 * missing CA certificates.
183 wpa_printf(MSG_DEBUG, "TLSv1: Full client certificate chain "
184 "not configured - validation may fail");
186 WPA_PUT_BE24(cert_start, pos - cert_start - 3);
188 WPA_PUT_BE24(hs_length, pos - hs_length - 3);
190 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
191 rhdr, end - rhdr, hs_start, pos - hs_start,
193 wpa_printf(MSG_DEBUG, "TLSv1: Failed to generate a record");
194 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
195 TLS_ALERT_INTERNAL_ERROR);
200 tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
208 static int tlsv1_key_x_dh(struct tlsv1_client *conn, u8 **pos, u8 *end)
210 /* ClientDiffieHellmanPublic */
211 u8 *csecret, *csecret_start, *dh_yc, *shared;
212 size_t csecret_len, dh_yc_len, shared_len;
214 csecret_len = conn->dh_p_len;
215 csecret = os_malloc(csecret_len);
216 if (csecret == NULL) {
217 wpa_printf(MSG_DEBUG, "TLSv1: Failed to allocate "
218 "memory for Yc (Diffie-Hellman)");
219 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
220 TLS_ALERT_INTERNAL_ERROR);
223 if (random_get_bytes(csecret, csecret_len)) {
224 wpa_printf(MSG_DEBUG, "TLSv1: Failed to get random "
225 "data for Diffie-Hellman");
226 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
227 TLS_ALERT_INTERNAL_ERROR);
232 if (os_memcmp(csecret, conn->dh_p, csecret_len) > 0)
233 csecret[0] = 0; /* make sure Yc < p */
235 csecret_start = csecret;
236 while (csecret_len > 1 && *csecret_start == 0) {
240 wpa_hexdump_key(MSG_DEBUG, "TLSv1: DH client's secret value",
241 csecret_start, csecret_len);
243 /* Yc = g^csecret mod p */
244 dh_yc_len = conn->dh_p_len;
245 dh_yc = os_malloc(dh_yc_len);
247 wpa_printf(MSG_DEBUG, "TLSv1: Failed to allocate "
248 "memory for Diffie-Hellman");
249 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
250 TLS_ALERT_INTERNAL_ERROR);
254 if (crypto_mod_exp(conn->dh_g, conn->dh_g_len,
255 csecret_start, csecret_len,
256 conn->dh_p, conn->dh_p_len,
257 dh_yc, &dh_yc_len)) {
258 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
259 TLS_ALERT_INTERNAL_ERROR);
265 wpa_hexdump(MSG_DEBUG, "TLSv1: DH Yc (client's public value)",
268 WPA_PUT_BE16(*pos, dh_yc_len);
270 if (*pos + dh_yc_len > end) {
271 wpa_printf(MSG_DEBUG, "TLSv1: Not enough room in the "
272 "message buffer for Yc");
273 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
274 TLS_ALERT_INTERNAL_ERROR);
279 os_memcpy(*pos, dh_yc, dh_yc_len);
283 shared_len = conn->dh_p_len;
284 shared = os_malloc(shared_len);
285 if (shared == NULL) {
286 wpa_printf(MSG_DEBUG, "TLSv1: Could not allocate memory for "
288 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
289 TLS_ALERT_INTERNAL_ERROR);
294 /* shared = Ys^csecret mod p */
295 if (crypto_mod_exp(conn->dh_ys, conn->dh_ys_len,
296 csecret_start, csecret_len,
297 conn->dh_p, conn->dh_p_len,
298 shared, &shared_len)) {
299 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
300 TLS_ALERT_INTERNAL_ERROR);
305 wpa_hexdump_key(MSG_DEBUG, "TLSv1: Shared secret from DH key exchange",
308 os_memset(csecret_start, 0, csecret_len);
310 if (tls_derive_keys(conn, shared, shared_len)) {
311 wpa_printf(MSG_DEBUG, "TLSv1: Failed to derive keys");
312 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
313 TLS_ALERT_INTERNAL_ERROR);
317 os_memset(shared, 0, shared_len);
319 tlsv1_client_free_dh(conn);
324 static int tlsv1_key_x_rsa(struct tlsv1_client *conn, u8 **pos, u8 *end)
326 u8 pre_master_secret[TLS_PRE_MASTER_SECRET_LEN];
330 if (tls_derive_pre_master_secret(pre_master_secret) < 0 ||
331 tls_derive_keys(conn, pre_master_secret,
332 TLS_PRE_MASTER_SECRET_LEN)) {
333 wpa_printf(MSG_DEBUG, "TLSv1: Failed to derive keys");
334 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
335 TLS_ALERT_INTERNAL_ERROR);
339 /* EncryptedPreMasterSecret */
340 if (conn->server_rsa_key == NULL) {
341 wpa_printf(MSG_DEBUG, "TLSv1: No server RSA key to "
342 "use for encrypting pre-master secret");
343 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
344 TLS_ALERT_INTERNAL_ERROR);
348 /* RSA encrypted value is encoded with PKCS #1 v1.5 block type 2. */
351 res = crypto_public_key_encrypt_pkcs1_v15(
352 conn->server_rsa_key,
353 pre_master_secret, TLS_PRE_MASTER_SECRET_LEN,
355 os_memset(pre_master_secret, 0, TLS_PRE_MASTER_SECRET_LEN);
357 wpa_printf(MSG_DEBUG, "TLSv1: RSA encryption failed");
358 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
359 TLS_ALERT_INTERNAL_ERROR);
362 WPA_PUT_BE16(*pos - 2, clen);
363 wpa_hexdump(MSG_MSGDUMP, "TLSv1: Encrypted pre_master_secret",
371 static int tls_write_client_key_exchange(struct tlsv1_client *conn,
372 u8 **msgpos, u8 *end)
374 u8 *pos, *rhdr, *hs_start, *hs_length;
376 tls_key_exchange keyx;
377 const struct tls_cipher_suite *suite;
379 suite = tls_get_cipher_suite(conn->rl.cipher_suite);
381 keyx = TLS_KEY_X_NULL;
383 keyx = suite->key_exchange;
387 wpa_printf(MSG_DEBUG, "TLSv1: Send ClientKeyExchange");
390 pos += TLS_RECORD_HEADER_LEN;
392 /* opaque fragment[TLSPlaintext.length] */
396 /* HandshakeType msg_type */
397 *pos++ = TLS_HANDSHAKE_TYPE_CLIENT_KEY_EXCHANGE;
398 /* uint24 length (to be filled) */
401 /* body - ClientKeyExchange */
402 if (keyx == TLS_KEY_X_DH_anon || keyx == TLS_KEY_X_DHE_RSA) {
403 if (tlsv1_key_x_dh(conn, &pos, end) < 0)
406 if (tlsv1_key_x_rsa(conn, &pos, end) < 0)
410 WPA_PUT_BE24(hs_length, pos - hs_length - 3);
412 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
413 rhdr, end - rhdr, hs_start, pos - hs_start,
415 wpa_printf(MSG_DEBUG, "TLSv1: Failed to create a record");
416 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
417 TLS_ALERT_INTERNAL_ERROR);
421 tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
429 static int tls_write_client_certificate_verify(struct tlsv1_client *conn,
430 u8 **msgpos, u8 *end)
432 u8 *pos, *rhdr, *hs_start, *hs_length, *signed_start;
433 size_t rlen, hlen, clen;
438 wpa_printf(MSG_DEBUG, "TLSv1: Send CertificateVerify");
440 pos += TLS_RECORD_HEADER_LEN;
444 /* HandshakeType msg_type */
445 *pos++ = TLS_HANDSHAKE_TYPE_CERTIFICATE_VERIFY;
446 /* uint24 length (to be filled) */
451 * RFC 2246: 7.4.3 and 7.4.8:
452 * Signature signature
455 * digitally-signed struct {
456 * opaque md5_hash[16];
457 * opaque sha_hash[20];
461 * digitally-signed struct {
462 * opaque sha_hash[20];
465 * The hash values are calculated over all handshake messages sent or
466 * received starting at ClientHello up to, but not including, this
467 * CertificateVerify message, including the type and length fields of
468 * the handshake messages.
474 if (conn->rl.tls_version == TLS_VERSION_1_2) {
475 hlen = SHA256_MAC_LEN;
476 if (conn->verify.sha256_cert == NULL ||
477 crypto_hash_finish(conn->verify.sha256_cert, hpos, &hlen) <
479 conn->verify.sha256_cert = NULL;
480 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
481 TLS_ALERT_INTERNAL_ERROR);
484 conn->verify.sha256_cert = NULL;
487 * RFC 3447, A.2.4 RSASSA-PKCS1-v1_5
489 * DigestInfo ::= SEQUENCE {
490 * digestAlgorithm DigestAlgorithm,
491 * digest OCTET STRING
494 * SHA-256 OID: sha256WithRSAEncryption ::= {pkcs-1 11}
496 * DER encoded DigestInfo for SHA256 per RFC 3447:
497 * 30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00 04 20 ||
500 os_memmove(hash + 19, hash, hlen);
502 os_memcpy(hash, "\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65"
503 "\x03\x04\x02\x01\x05\x00\x04\x20", 19);
505 #endif /* CONFIG_TLSV12 */
508 if (conn->verify.md5_cert == NULL ||
509 crypto_hash_finish(conn->verify.md5_cert, hpos, &hlen) < 0) {
510 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
511 TLS_ALERT_INTERNAL_ERROR);
512 conn->verify.md5_cert = NULL;
513 crypto_hash_finish(conn->verify.sha1_cert, NULL, NULL);
514 conn->verify.sha1_cert = NULL;
519 conn->verify.md5_cert = NULL;
521 if (conn->verify.sha1_cert == NULL ||
522 crypto_hash_finish(conn->verify.sha1_cert, hpos, &hlen) < 0) {
523 conn->verify.sha1_cert = NULL;
524 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
525 TLS_ALERT_INTERNAL_ERROR);
528 conn->verify.sha1_cert = NULL;
534 #endif /* CONFIG_TLSV12 */
536 wpa_hexdump(MSG_MSGDUMP, "TLSv1: CertificateVerify hash", hash, hlen);
539 if (conn->rl.tls_version >= TLS_VERSION_1_2) {
542 * TLS v1.2 adds explicit indication of the used signature and
546 * HashAlgorithm hash;
547 * SignatureAlgorithm signature;
548 * } SignatureAndHashAlgorithm;
550 *pos++ = TLS_HASH_ALG_SHA256;
551 *pos++ = TLS_SIGN_ALG_RSA;
553 #endif /* CONFIG_TLSV12 */
557 * In digital signing, one-way hash functions are used as input for a
558 * signing algorithm. A digitally-signed element is encoded as an
559 * opaque vector <0..2^16-1>, where the length is specified by the
560 * signing algorithm and key.
562 * In RSA signing, a 36-byte structure of two hashes (one SHA and one
563 * MD5) is signed (encrypted with the private key). It is encoded with
564 * PKCS #1 block type 0 or type 1 as described in [PKCS1].
566 signed_start = pos; /* length to be filled */
569 if (conn->cred == NULL ||
570 crypto_private_key_sign_pkcs1(conn->cred->key, hash, hlen,
572 wpa_printf(MSG_DEBUG, "TLSv1: Failed to sign hash (PKCS #1)");
573 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
574 TLS_ALERT_INTERNAL_ERROR);
577 WPA_PUT_BE16(signed_start, clen);
581 WPA_PUT_BE24(hs_length, pos - hs_length - 3);
583 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
584 rhdr, end - rhdr, hs_start, pos - hs_start,
586 wpa_printf(MSG_DEBUG, "TLSv1: Failed to generate a record");
587 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
588 TLS_ALERT_INTERNAL_ERROR);
593 tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
601 static int tls_write_client_change_cipher_spec(struct tlsv1_client *conn,
602 u8 **msgpos, u8 *end)
607 wpa_printf(MSG_DEBUG, "TLSv1: Send ChangeCipherSpec");
609 payload[0] = TLS_CHANGE_CIPHER_SPEC;
611 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_CHANGE_CIPHER_SPEC,
612 *msgpos, end - *msgpos, payload, sizeof(payload),
614 wpa_printf(MSG_DEBUG, "TLSv1: Failed to create a record");
615 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
616 TLS_ALERT_INTERNAL_ERROR);
620 if (tlsv1_record_change_write_cipher(&conn->rl) < 0) {
621 wpa_printf(MSG_DEBUG, "TLSv1: Failed to set write cipher for "
623 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
624 TLS_ALERT_INTERNAL_ERROR);
634 static int tls_write_client_finished(struct tlsv1_client *conn,
635 u8 **msgpos, u8 *end)
639 u8 verify_data[1 + 3 + TLS_VERIFY_DATA_LEN];
640 u8 hash[MD5_MAC_LEN + SHA1_MAC_LEN];
642 wpa_printf(MSG_DEBUG, "TLSv1: Send Finished");
644 /* Encrypted Handshake Message: Finished */
647 if (conn->rl.tls_version >= TLS_VERSION_1_2) {
648 hlen = SHA256_MAC_LEN;
649 if (conn->verify.sha256_client == NULL ||
650 crypto_hash_finish(conn->verify.sha256_client, hash, &hlen)
652 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
653 TLS_ALERT_INTERNAL_ERROR);
654 conn->verify.sha256_client = NULL;
657 conn->verify.sha256_client = NULL;
659 #endif /* CONFIG_TLSV12 */
662 if (conn->verify.md5_client == NULL ||
663 crypto_hash_finish(conn->verify.md5_client, hash, &hlen) < 0) {
664 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
665 TLS_ALERT_INTERNAL_ERROR);
666 conn->verify.md5_client = NULL;
667 crypto_hash_finish(conn->verify.sha1_client, NULL, NULL);
668 conn->verify.sha1_client = NULL;
671 conn->verify.md5_client = NULL;
673 if (conn->verify.sha1_client == NULL ||
674 crypto_hash_finish(conn->verify.sha1_client, hash + MD5_MAC_LEN,
676 conn->verify.sha1_client = NULL;
677 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
678 TLS_ALERT_INTERNAL_ERROR);
681 conn->verify.sha1_client = NULL;
682 hlen = MD5_MAC_LEN + SHA1_MAC_LEN;
686 #endif /* CONFIG_TLSV12 */
688 if (tls_prf(conn->rl.tls_version,
689 conn->master_secret, TLS_MASTER_SECRET_LEN,
690 "client finished", hash, hlen,
691 verify_data + 1 + 3, TLS_VERIFY_DATA_LEN)) {
692 wpa_printf(MSG_DEBUG, "TLSv1: Failed to generate verify_data");
693 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
694 TLS_ALERT_INTERNAL_ERROR);
697 wpa_hexdump_key(MSG_DEBUG, "TLSv1: verify_data (client)",
698 verify_data + 1 + 3, TLS_VERIFY_DATA_LEN);
701 pos = hs_start = verify_data;
702 /* HandshakeType msg_type */
703 *pos++ = TLS_HANDSHAKE_TYPE_FINISHED;
705 WPA_PUT_BE24(pos, TLS_VERIFY_DATA_LEN);
707 pos += TLS_VERIFY_DATA_LEN; /* verify_data already in place */
708 tls_verify_hash_add(&conn->verify, hs_start, pos - hs_start);
710 if (tlsv1_record_send(&conn->rl, TLS_CONTENT_TYPE_HANDSHAKE,
711 *msgpos, end - *msgpos, hs_start, pos - hs_start,
713 wpa_printf(MSG_DEBUG, "TLSv1: Failed to create a record");
714 tls_alert(conn, TLS_ALERT_LEVEL_FATAL,
715 TLS_ALERT_INTERNAL_ERROR);
725 static u8 * tls_send_client_key_exchange(struct tlsv1_client *conn,
734 if (conn->certificate_requested)
735 msglen += tls_client_cert_chain_der_len(conn);
737 msg = os_malloc(msglen);
744 if (conn->certificate_requested) {
745 if (tls_write_client_certificate(conn, &pos, end) < 0) {
751 if (tls_write_client_key_exchange(conn, &pos, end) < 0 ||
752 (conn->certificate_requested && conn->cred && conn->cred->key &&
753 tls_write_client_certificate_verify(conn, &pos, end) < 0) ||
754 tls_write_client_change_cipher_spec(conn, &pos, end) < 0 ||
755 tls_write_client_finished(conn, &pos, end) < 0) {
760 *out_len = pos - msg;
762 conn->state = SERVER_CHANGE_CIPHER_SPEC;
768 static u8 * tls_send_change_cipher_spec(struct tlsv1_client *conn,
775 msg = os_malloc(1000);
782 if (tls_write_client_change_cipher_spec(conn, &pos, end) < 0 ||
783 tls_write_client_finished(conn, &pos, end) < 0) {
788 *out_len = pos - msg;
790 wpa_printf(MSG_DEBUG, "TLSv1: Session resumption completed "
792 conn->state = ESTABLISHED;
798 u8 * tlsv1_client_handshake_write(struct tlsv1_client *conn, size_t *out_len,
801 switch (conn->state) {
802 case CLIENT_KEY_EXCHANGE:
803 return tls_send_client_key_exchange(conn, out_len);
804 case CHANGE_CIPHER_SPEC:
805 return tls_send_change_cipher_spec(conn, out_len);
807 wpa_printf(MSG_DEBUG, "TLSv1: Handshake completed "
809 conn->state = ESTABLISHED;
812 /* Need to return something to get final TLS ACK. */
817 wpa_printf(MSG_DEBUG, "TLSv1: Unexpected state %d while "
818 "generating reply", conn->state);
824 u8 * tlsv1_client_send_alert(struct tlsv1_client *conn, u8 level,
825 u8 description, size_t *out_len)
827 u8 *alert, *pos, *length;
829 wpa_printf(MSG_DEBUG, "TLSv1: Send Alert(%d:%d)", level, description);
832 alert = os_malloc(10);
839 /* ContentType type */
840 *pos++ = TLS_CONTENT_TYPE_ALERT;
841 /* ProtocolVersion version */
842 WPA_PUT_BE16(pos, conn->rl.tls_version ? conn->rl.tls_version :
845 /* uint16 length (to be filled) */
848 /* opaque fragment[TLSPlaintext.length] */
851 /* AlertLevel level */
853 /* AlertDescription description */
854 *pos++ = description;
856 WPA_PUT_BE16(length, pos - length - 2);
857 *out_len = pos - alert;