2010-01-21 14:11:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Martin Willi
|
|
|
|
* Copyright (C) 2010 revosec AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tls.h"
|
|
|
|
|
2012-10-16 14:03:21 +00:00
|
|
|
#include <utils/debug.h>
|
2010-08-23 14:21:49 +00:00
|
|
|
|
2010-01-22 16:24:17 +00:00
|
|
|
#include "tls_protection.h"
|
|
|
|
#include "tls_compression.h"
|
|
|
|
#include "tls_fragmentation.h"
|
2010-01-25 11:21:57 +00:00
|
|
|
#include "tls_crypto.h"
|
2010-01-25 09:44:35 +00:00
|
|
|
#include "tls_server.h"
|
|
|
|
#include "tls_peer.h"
|
2010-01-22 16:24:17 +00:00
|
|
|
|
2010-01-25 16:31:55 +00:00
|
|
|
ENUM_BEGIN(tls_version_names, SSL_2_0, SSL_2_0,
|
|
|
|
"SSLv2");
|
|
|
|
ENUM_NEXT(tls_version_names, SSL_3_0, TLS_1_2, SSL_2_0,
|
2010-01-21 14:11:38 +00:00
|
|
|
"SSLv3",
|
|
|
|
"TLS 1.0",
|
|
|
|
"TLS 1.1",
|
2010-01-25 16:31:55 +00:00
|
|
|
"TLS 1.2");
|
|
|
|
ENUM_END(tls_version_names, TLS_1_2);
|
2010-01-21 14:11:38 +00:00
|
|
|
|
|
|
|
ENUM(tls_content_type_names, TLS_CHANGE_CIPHER_SPEC, TLS_APPLICATION_DATA,
|
|
|
|
"ChangeCipherSpec",
|
|
|
|
"Alert",
|
|
|
|
"Handshake",
|
|
|
|
"ApplicationData",
|
|
|
|
);
|
|
|
|
|
|
|
|
ENUM_BEGIN(tls_handshake_type_names, TLS_HELLO_REQUEST, TLS_SERVER_HELLO,
|
|
|
|
"HelloRequest",
|
|
|
|
"ClientHello",
|
|
|
|
"ServerHello");
|
2010-09-06 08:54:11 +00:00
|
|
|
ENUM_NEXT(tls_handshake_type_names,
|
|
|
|
TLS_CERTIFICATE, TLS_CLIENT_KEY_EXCHANGE, TLS_SERVER_HELLO,
|
2010-01-21 14:11:38 +00:00
|
|
|
"Certificate",
|
|
|
|
"ServerKeyExchange",
|
|
|
|
"CertificateRequest",
|
|
|
|
"ServerHelloDone",
|
|
|
|
"CertificateVerify",
|
|
|
|
"ClientKeyExchange");
|
2010-09-06 08:54:11 +00:00
|
|
|
ENUM_NEXT(tls_handshake_type_names,
|
|
|
|
TLS_FINISHED, TLS_FINISHED, TLS_CLIENT_KEY_EXCHANGE,
|
2010-01-21 14:11:38 +00:00
|
|
|
"Finished");
|
|
|
|
ENUM_END(tls_handshake_type_names, TLS_FINISHED);
|
2010-01-22 14:35:29 +00:00
|
|
|
|
2010-09-06 08:54:11 +00:00
|
|
|
ENUM_BEGIN(tls_extension_names, TLS_EXT_SERVER_NAME, TLS_EXT_STATUS_REQUEST,
|
|
|
|
"server name",
|
|
|
|
"max fragment length",
|
|
|
|
"client certificate url",
|
|
|
|
"trusted ca keys",
|
|
|
|
"truncated hmac",
|
|
|
|
"status request");
|
|
|
|
ENUM_NEXT(tls_extension_names,
|
|
|
|
TLS_EXT_ELLIPTIC_CURVES, TLS_EXT_EC_POINT_FORMATS,
|
|
|
|
TLS_EXT_STATUS_REQUEST,
|
2010-09-03 09:45:55 +00:00
|
|
|
"elliptic curves",
|
2010-09-06 08:54:11 +00:00
|
|
|
"ec point formats");
|
|
|
|
ENUM_NEXT(tls_extension_names,
|
|
|
|
TLS_EXT_SIGNATURE_ALGORITHMS, TLS_EXT_SIGNATURE_ALGORITHMS,
|
|
|
|
TLS_EXT_EC_POINT_FORMATS,
|
|
|
|
"signature algorithms");
|
2011-04-14 14:54:34 +00:00
|
|
|
ENUM_NEXT(tls_extension_names,
|
|
|
|
TLS_EXT_RENEGOTIATION_INFO, TLS_EXT_RENEGOTIATION_INFO,
|
|
|
|
TLS_EXT_SIGNATURE_ALGORITHMS,
|
|
|
|
"renegotiation info");
|
|
|
|
ENUM_END(tls_extension_names, TLS_EXT_RENEGOTIATION_INFO);
|
2010-09-02 17:07:45 +00:00
|
|
|
|
2010-08-31 08:03:03 +00:00
|
|
|
/**
|
|
|
|
* TLS record
|
|
|
|
*/
|
|
|
|
typedef struct __attribute__((packed)) {
|
2016-03-22 12:22:01 +00:00
|
|
|
uint8_t type;
|
|
|
|
uint16_t version;
|
|
|
|
uint16_t length;
|
2010-08-31 08:03:03 +00:00
|
|
|
char data[];
|
|
|
|
} tls_record_t;
|
2010-01-22 14:35:29 +00:00
|
|
|
|
|
|
|
typedef struct private_tls_t private_tls_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data of an tls_protection_t object.
|
|
|
|
*/
|
|
|
|
struct private_tls_t {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public tls_t interface.
|
|
|
|
*/
|
|
|
|
tls_t public;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Role this TLS stack acts as.
|
|
|
|
*/
|
|
|
|
bool is_server;
|
2010-01-22 16:24:17 +00:00
|
|
|
|
2010-01-25 16:31:55 +00:00
|
|
|
/**
|
|
|
|
* Negotiated TLS version
|
|
|
|
*/
|
|
|
|
tls_version_t version;
|
|
|
|
|
2010-08-20 13:02:25 +00:00
|
|
|
/**
|
|
|
|
* TLS stack purpose, as given to constructor
|
|
|
|
*/
|
|
|
|
tls_purpose_t purpose;
|
|
|
|
|
2010-01-22 16:24:17 +00:00
|
|
|
/**
|
|
|
|
* TLS record protection layer
|
|
|
|
*/
|
|
|
|
tls_protection_t *protection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TLS record compression layer
|
|
|
|
*/
|
|
|
|
tls_compression_t *compression;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TLS record fragmentation layer
|
|
|
|
*/
|
|
|
|
tls_fragmentation_t *fragmentation;
|
2010-01-25 09:44:35 +00:00
|
|
|
|
2010-08-23 12:22:38 +00:00
|
|
|
/**
|
|
|
|
* TLS alert handler
|
|
|
|
*/
|
|
|
|
tls_alert_t *alert;
|
|
|
|
|
2010-01-25 11:21:57 +00:00
|
|
|
/**
|
|
|
|
* TLS crypto helper context
|
|
|
|
*/
|
|
|
|
tls_crypto_t *crypto;
|
|
|
|
|
2010-01-25 09:44:35 +00:00
|
|
|
/**
|
|
|
|
* TLS handshake protocol handler
|
|
|
|
*/
|
|
|
|
tls_handshake_t *handshake;
|
2010-08-12 21:56:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TLS application data handler
|
|
|
|
*/
|
|
|
|
tls_application_t *application;
|
2010-08-26 10:27:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocated input buffer
|
|
|
|
*/
|
|
|
|
chunk_t input;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of bytes read in input buffer
|
|
|
|
*/
|
|
|
|
size_t inpos;
|
2010-08-31 06:57:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocated output buffer
|
|
|
|
*/
|
|
|
|
chunk_t output;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of bytes processed from output buffer
|
|
|
|
*/
|
|
|
|
size_t outpos;
|
2010-01-22 14:35:29 +00:00
|
|
|
|
2010-08-31 08:03:03 +00:00
|
|
|
/**
|
2014-05-08 11:31:18 +00:00
|
|
|
* Position in partially received record header
|
2010-08-31 08:03:03 +00:00
|
|
|
*/
|
2014-05-08 11:31:18 +00:00
|
|
|
size_t headpos;
|
2010-08-31 08:03:03 +00:00
|
|
|
|
|
|
|
/**
|
2014-05-08 11:31:18 +00:00
|
|
|
* Partial TLS record header received
|
2010-08-31 08:03:03 +00:00
|
|
|
*/
|
2014-05-08 11:31:18 +00:00
|
|
|
tls_record_t head;
|
2010-08-31 08:03:03 +00:00
|
|
|
};
|
2010-08-23 14:21:49 +00:00
|
|
|
|
2011-11-08 19:27:17 +00:00
|
|
|
/**
|
|
|
|
* Described in header.
|
|
|
|
*/
|
|
|
|
void libtls_init(void)
|
|
|
|
{
|
|
|
|
/* empty */
|
|
|
|
}
|
|
|
|
|
2010-01-22 14:35:29 +00:00
|
|
|
METHOD(tls_t, process, status_t,
|
2010-08-31 06:57:26 +00:00
|
|
|
private_tls_t *this, void *buf, size_t buflen)
|
2010-01-22 14:35:29 +00:00
|
|
|
{
|
2010-08-23 14:21:49 +00:00
|
|
|
tls_record_t *record;
|
|
|
|
status_t status;
|
2010-08-26 10:27:56 +00:00
|
|
|
u_int len;
|
2010-08-23 14:21:49 +00:00
|
|
|
|
2010-08-31 08:03:03 +00:00
|
|
|
if (this->headpos)
|
|
|
|
{ /* have a partial TLS record header, try to complete it */
|
|
|
|
len = min(buflen, sizeof(this->head) - this->headpos);
|
|
|
|
memcpy(((char*)&this->head) + this->headpos, buf, len);
|
|
|
|
this->headpos += len;
|
|
|
|
buflen -= len;
|
|
|
|
buf += len;
|
|
|
|
if (this->headpos == sizeof(this->head))
|
|
|
|
{ /* header complete, allocate space with new header */
|
|
|
|
len = untoh16(&this->head.length);
|
|
|
|
this->input = chunk_alloc(len + sizeof(tls_record_t));
|
|
|
|
memcpy(this->input.ptr, &this->head, sizeof(this->head));
|
|
|
|
this->inpos = sizeof(this->head);
|
|
|
|
this->headpos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-31 06:57:26 +00:00
|
|
|
while (buflen)
|
2010-08-23 14:21:49 +00:00
|
|
|
{
|
2010-08-26 10:27:56 +00:00
|
|
|
if (this->input.len == 0)
|
2010-08-23 14:21:49 +00:00
|
|
|
{
|
2014-03-21 08:29:44 +00:00
|
|
|
while (buflen >= sizeof(tls_record_t))
|
2010-08-26 10:27:56 +00:00
|
|
|
{
|
|
|
|
/* try to process records inline */
|
2010-08-31 06:57:26 +00:00
|
|
|
record = buf;
|
2010-08-26 10:27:56 +00:00
|
|
|
len = untoh16(&record->length);
|
|
|
|
|
2010-08-31 06:57:26 +00:00
|
|
|
if (len + sizeof(tls_record_t) > buflen)
|
2010-08-26 10:27:56 +00:00
|
|
|
{ /* not a full record, read to buffer */
|
|
|
|
this->input = chunk_alloc(len + sizeof(tls_record_t));
|
|
|
|
this->inpos = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBG2(DBG_TLS, "processing TLS %N record (%d bytes)",
|
|
|
|
tls_content_type_names, record->type, len);
|
|
|
|
status = this->protection->process(this->protection,
|
|
|
|
record->type, chunk_create(record->data, len));
|
|
|
|
if (status != NEED_MORE)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
2010-08-31 06:57:26 +00:00
|
|
|
buf += len + sizeof(tls_record_t);
|
|
|
|
buflen -= len + sizeof(tls_record_t);
|
|
|
|
if (buflen == 0)
|
2010-08-26 10:27:56 +00:00
|
|
|
{
|
|
|
|
return NEED_MORE;
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 08:29:44 +00:00
|
|
|
if (buflen < sizeof(tls_record_t))
|
|
|
|
{
|
|
|
|
DBG2(DBG_TLS, "received incomplete TLS record header");
|
|
|
|
memcpy(&this->head, buf, buflen);
|
|
|
|
this->headpos = buflen;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-23 14:21:49 +00:00
|
|
|
}
|
2010-08-31 06:57:26 +00:00
|
|
|
len = min(buflen, this->input.len - this->inpos);
|
|
|
|
memcpy(this->input.ptr + this->inpos, buf, len);
|
|
|
|
buf += len;
|
|
|
|
buflen -= len;
|
2010-08-26 10:27:56 +00:00
|
|
|
this->inpos += len;
|
2010-08-31 21:22:39 +00:00
|
|
|
DBG2(DBG_TLS, "buffering %d bytes, %d bytes of %d byte TLS record received",
|
2010-08-26 10:27:56 +00:00
|
|
|
len, this->inpos, this->input.len);
|
|
|
|
if (this->input.len == this->inpos)
|
2010-08-23 14:21:49 +00:00
|
|
|
{
|
2010-08-26 10:27:56 +00:00
|
|
|
record = (tls_record_t*)this->input.ptr;
|
|
|
|
len = untoh16(&record->length);
|
|
|
|
|
|
|
|
DBG2(DBG_TLS, "processing buffered TLS %N record (%d bytes)",
|
|
|
|
tls_content_type_names, record->type, len);
|
|
|
|
status = this->protection->process(this->protection,
|
|
|
|
record->type, chunk_create(record->data, len));
|
|
|
|
chunk_free(&this->input);
|
|
|
|
this->inpos = 0;
|
|
|
|
if (status != NEED_MORE)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
2010-08-23 14:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NEED_MORE;
|
2010-01-22 14:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(tls_t, build, status_t,
|
2010-08-31 06:57:26 +00:00
|
|
|
private_tls_t *this, void *buf, size_t *buflen, size_t *msglen)
|
2010-01-22 14:35:29 +00:00
|
|
|
{
|
2010-08-31 06:57:26 +00:00
|
|
|
tls_content_type_t type;
|
2010-08-23 14:21:49 +00:00
|
|
|
tls_record_t record;
|
|
|
|
status_t status;
|
2010-08-31 06:57:26 +00:00
|
|
|
chunk_t data;
|
|
|
|
size_t len;
|
2010-08-23 14:21:49 +00:00
|
|
|
|
2010-08-31 06:57:26 +00:00
|
|
|
len = *buflen;
|
|
|
|
if (this->output.len == 0)
|
2010-08-23 14:21:49 +00:00
|
|
|
{
|
2010-08-31 06:57:26 +00:00
|
|
|
/* query upper layers for new records, as many as we can get */
|
|
|
|
while (TRUE)
|
2010-08-23 14:21:49 +00:00
|
|
|
{
|
2010-08-31 06:57:26 +00:00
|
|
|
status = this->protection->build(this->protection, &type, &data);
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case NEED_MORE:
|
|
|
|
record.type = type;
|
|
|
|
htoun16(&record.version, this->version);
|
|
|
|
htoun16(&record.length, data.len);
|
|
|
|
this->output = chunk_cat("mcm", this->output,
|
|
|
|
chunk_from_thing(record), data);
|
|
|
|
DBG2(DBG_TLS, "sending TLS %N record (%d bytes)",
|
|
|
|
tls_content_type_names, type, data.len);
|
|
|
|
continue;
|
|
|
|
case INVALID_STATE:
|
|
|
|
if (this->output.len == 0)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (msglen)
|
|
|
|
{
|
|
|
|
*msglen = this->output.len;
|
2010-08-23 14:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-31 06:57:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (msglen)
|
|
|
|
{
|
|
|
|
*msglen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = min(len, this->output.len - this->outpos);
|
|
|
|
memcpy(buf, this->output.ptr + this->outpos, len);
|
|
|
|
this->outpos += len;
|
|
|
|
*buflen = len;
|
|
|
|
if (this->outpos == this->output.len)
|
|
|
|
{
|
|
|
|
chunk_free(&this->output);
|
|
|
|
this->outpos = 0;
|
|
|
|
return ALREADY_DONE;
|
|
|
|
}
|
|
|
|
return NEED_MORE;
|
2010-01-22 14:35:29 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 17:18:10 +00:00
|
|
|
METHOD(tls_t, is_server, bool,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
|
|
|
return this->is_server;
|
|
|
|
}
|
|
|
|
|
2013-01-20 22:36:31 +00:00
|
|
|
METHOD(tls_t, get_server_id, identification_t*,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
2013-02-28 10:39:55 +00:00
|
|
|
return this->handshake->get_server_id(this->handshake);
|
2013-01-20 22:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(tls_t, get_peer_id, identification_t*,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
2013-02-28 10:39:55 +00:00
|
|
|
return this->handshake->get_peer_id(this->handshake);
|
2013-01-20 22:36:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 16:31:55 +00:00
|
|
|
METHOD(tls_t, get_version, tls_version_t,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
|
|
|
return this->version;
|
|
|
|
}
|
|
|
|
|
2010-08-20 14:08:59 +00:00
|
|
|
METHOD(tls_t, set_version, bool,
|
2010-01-25 16:31:55 +00:00
|
|
|
private_tls_t *this, tls_version_t version)
|
|
|
|
{
|
2010-08-20 14:08:59 +00:00
|
|
|
if (version > this->version)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
switch (version)
|
|
|
|
{
|
|
|
|
case TLS_1_0:
|
|
|
|
case TLS_1_1:
|
|
|
|
case TLS_1_2:
|
|
|
|
this->version = version;
|
2010-08-23 12:22:38 +00:00
|
|
|
this->protection->set_version(this->protection, version);
|
2010-08-20 14:08:59 +00:00
|
|
|
return TRUE;
|
|
|
|
case SSL_2_0:
|
|
|
|
case SSL_3_0:
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-01-25 16:31:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 13:02:25 +00:00
|
|
|
METHOD(tls_t, get_purpose, tls_purpose_t,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
|
|
|
return this->purpose;
|
|
|
|
}
|
|
|
|
|
2010-02-09 17:19:25 +00:00
|
|
|
METHOD(tls_t, is_complete, bool,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
2010-08-24 06:40:28 +00:00
|
|
|
if (this->handshake->finished(this->handshake))
|
|
|
|
{
|
|
|
|
if (!this->application)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return this->fragmentation->application_finished(this->fragmentation);
|
|
|
|
}
|
|
|
|
return FALSE;
|
2010-02-09 17:19:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 11:28:48 +00:00
|
|
|
METHOD(tls_t, get_eap_msk, chunk_t,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
|
|
|
return this->crypto->get_eap_msk(this->crypto);
|
|
|
|
}
|
|
|
|
|
2015-01-29 10:13:42 +00:00
|
|
|
METHOD(tls_t, get_auth, auth_cfg_t*,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
|
|
|
return this->handshake->get_auth(this->handshake);
|
|
|
|
}
|
|
|
|
|
2010-01-22 14:35:29 +00:00
|
|
|
METHOD(tls_t, destroy, void,
|
|
|
|
private_tls_t *this)
|
|
|
|
{
|
2010-01-22 16:24:17 +00:00
|
|
|
this->protection->destroy(this->protection);
|
|
|
|
this->compression->destroy(this->compression);
|
|
|
|
this->fragmentation->destroy(this->fragmentation);
|
2010-01-25 11:21:57 +00:00
|
|
|
this->crypto->destroy(this->crypto);
|
2010-01-25 09:44:35 +00:00
|
|
|
this->handshake->destroy(this->handshake);
|
2010-08-12 21:56:44 +00:00
|
|
|
DESTROY_IF(this->application);
|
2010-08-23 12:22:38 +00:00
|
|
|
this->alert->destroy(this->alert);
|
2010-01-22 16:24:17 +00:00
|
|
|
|
2010-08-26 10:27:56 +00:00
|
|
|
free(this->input.ptr);
|
2010-08-31 06:57:26 +00:00
|
|
|
free(this->output.ptr);
|
2010-08-26 10:27:56 +00:00
|
|
|
|
2010-01-22 14:35:29 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See header
|
|
|
|
*/
|
2010-02-03 18:53:40 +00:00
|
|
|
tls_t *tls_create(bool is_server, identification_t *server,
|
2010-08-20 13:02:25 +00:00
|
|
|
identification_t *peer, tls_purpose_t purpose,
|
2011-12-31 00:41:56 +00:00
|
|
|
tls_application_t *application, tls_cache_t *cache)
|
2010-01-22 14:35:29 +00:00
|
|
|
{
|
|
|
|
private_tls_t *this;
|
|
|
|
|
2010-08-20 13:02:25 +00:00
|
|
|
switch (purpose)
|
|
|
|
{
|
|
|
|
case TLS_PURPOSE_EAP_TLS:
|
|
|
|
case TLS_PURPOSE_EAP_TTLS:
|
2011-04-05 16:16:28 +00:00
|
|
|
case TLS_PURPOSE_EAP_PEAP:
|
2010-08-25 10:51:01 +00:00
|
|
|
case TLS_PURPOSE_GENERIC:
|
2014-03-25 08:49:04 +00:00
|
|
|
case TLS_PURPOSE_GENERIC_NULLOK:
|
2010-08-20 13:02:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-22 14:35:29 +00:00
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.process = _process,
|
|
|
|
.build = _build,
|
2010-02-04 17:18:10 +00:00
|
|
|
.is_server = _is_server,
|
2013-01-20 22:36:31 +00:00
|
|
|
.get_server_id = _get_server_id,
|
|
|
|
.get_peer_id = _get_peer_id,
|
2010-01-25 16:31:55 +00:00
|
|
|
.get_version = _get_version,
|
|
|
|
.set_version = _set_version,
|
2010-08-20 13:02:25 +00:00
|
|
|
.get_purpose = _get_purpose,
|
2010-02-09 17:19:25 +00:00
|
|
|
.is_complete = _is_complete,
|
2010-02-05 11:28:48 +00:00
|
|
|
.get_eap_msk = _get_eap_msk,
|
2015-01-29 10:13:42 +00:00
|
|
|
.get_auth = _get_auth,
|
2010-01-22 14:35:29 +00:00
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
.is_server = is_server,
|
2010-01-25 16:31:55 +00:00
|
|
|
.version = TLS_1_2,
|
2010-08-12 21:56:44 +00:00
|
|
|
.application = application,
|
2010-08-20 13:02:25 +00:00
|
|
|
.purpose = purpose,
|
2010-01-22 14:35:29 +00:00
|
|
|
);
|
2014-01-28 16:26:50 +00:00
|
|
|
lib->settings->add_fallback(lib->settings, "%s.tls", "libtls", lib->ns);
|
2010-01-22 14:35:29 +00:00
|
|
|
|
2011-12-31 00:41:56 +00:00
|
|
|
this->crypto = tls_crypto_create(&this->public, cache);
|
2010-08-23 12:22:38 +00:00
|
|
|
this->alert = tls_alert_create();
|
2010-01-25 09:44:35 +00:00
|
|
|
if (is_server)
|
|
|
|
{
|
2010-02-03 18:53:40 +00:00
|
|
|
this->handshake = &tls_server_create(&this->public, this->crypto,
|
2013-02-28 10:39:55 +00:00
|
|
|
this->alert, server, peer)->handshake;
|
2010-01-25 09:44:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-03 18:53:40 +00:00
|
|
|
this->handshake = &tls_peer_create(&this->public, this->crypto,
|
2013-02-28 10:39:55 +00:00
|
|
|
this->alert, peer, server)->handshake;
|
2010-01-25 09:44:35 +00:00
|
|
|
}
|
2010-08-23 12:22:38 +00:00
|
|
|
this->fragmentation = tls_fragmentation_create(this->handshake, this->alert,
|
2015-02-05 08:13:57 +00:00
|
|
|
this->application, purpose);
|
2010-08-23 12:22:38 +00:00
|
|
|
this->compression = tls_compression_create(this->fragmentation, this->alert);
|
|
|
|
this->protection = tls_protection_create(this->compression, this->alert);
|
2010-02-05 13:39:19 +00:00
|
|
|
this->crypto->set_protection(this->crypto, this->protection);
|
2010-01-22 16:24:17 +00:00
|
|
|
|
2010-01-22 14:35:29 +00:00
|
|
|
return &this->public;
|
|
|
|
}
|