Pass TLS records to newly introduced TLS stack

This commit is contained in:
Martin Willi
2010-08-03 15:39:24 +02:00
parent f7f63c52e1
commit dcbbeb2d09
3 changed files with 158 additions and 11 deletions
+58
View File
@@ -15,6 +15,8 @@
#include "tls.h"
#include <daemon.h>
ENUM(tls_version_names, SSL_2_0, TLS_1_2,
"SSLv2",
"SSLv3",
@@ -44,3 +46,59 @@ ENUM_NEXT(tls_handshake_type_names, TLS_CERTIFICATE, TLS_CLIENT_KEY_EXCHANGE, TL
ENUM_NEXT(tls_handshake_type_names, TLS_FINISHED, TLS_FINISHED, TLS_CLIENT_KEY_EXCHANGE,
"Finished");
ENUM_END(tls_handshake_type_names, TLS_FINISHED);
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;
};
METHOD(tls_t, process, status_t,
private_tls_t *this, tls_content_type_t type, chunk_t data)
{
return NEED_MORE;
}
METHOD(tls_t, build, status_t,
private_tls_t *this, tls_content_type_t *type, chunk_t *data)
{
return INVALID_STATE;
}
METHOD(tls_t, destroy, void,
private_tls_t *this)
{
free(this);
}
/**
* See header
*/
tls_t *tls_create(bool is_server)
{
private_tls_t *this;
INIT(this,
.public = {
.process = _process,
.build = _build,
.destroy = _destroy,
},
.is_server = is_server,
);
return &this->public;
}
+45
View File
@@ -28,6 +28,7 @@ typedef enum tls_version_t tls_version_t;
typedef enum tls_content_type_t tls_content_type_t;
typedef enum tls_handshake_type_t tls_handshake_type_t;
typedef enum tls_cipher_suite_t tls_cipher_suite_t;
typedef struct tls_t tls_t;
#include <library.h>
@@ -123,4 +124,48 @@ enum tls_cipher_suite_t {
TLS_DH_ANON_WITH_AES_256_CBC_SHA256 = 0x6D,
};
/**
* A bottom-up driven TLS stack, suitable for EAP implementations.
*/
struct tls_t {
/**
* Process a TLS record, pass it to upper layers.
*
* @param type type of the TLS record to process
* @param data associated TLS record data
* @return
* - SUCCESS if TLS negotiation complete
* - FAILED if TLS handshake failed
* - NEED_MORE if more invocations to process/build needed
*/
status_t (*process)(tls_t *this, tls_content_type_t type, chunk_t data);
/**
* Query upper layer for TLS record, build protected record.
*
* @param type type of the built TLS record
* @param data allocated data of the built TLS record
* @return
* - SUCCESS if TLS negotiation complete
* - FAILED if TLS handshake failed
* - NEED_MORE if upper layers have more records to send
* - INVALID_STATE if more input records required
*/
status_t (*build)(tls_t *this, tls_content_type_t *type, chunk_t *data);
/**
* Destroy a tls_t.
*/
void (*destroy)(tls_t *this);
};
/**
* Create a tls instance.
*
* @param is_server TRUE to act as server, FALSE for client
* @return TLS stack
*/
tls_t *tls_create(bool is_server);
#endif /** TLS_H_ @}*/