Introducing simple purposes for the TLS stack, switches various options

This commit is contained in:
Martin Willi
2010-08-20 15:09:08 +02:00
parent 6291fbedcb
commit 96b2fbcc2c
9 changed files with 113 additions and 30 deletions
+39 -5
View File
@@ -439,10 +439,30 @@ static void filter_suite(private_tls_crypto_t *this,
*count = remaining;
}
/**
* Purge NULL encryption cipher suites from list
*/
static void filter_null_suites(private_tls_crypto_t *this,
suite_algs_t suites[], int *count)
{
int i, remaining = 0;
for (i = 0; i < *count; i++)
{
if (suites[i].encr != ENCR_NULL)
{
suites[remaining] = suites[i];
remaining++;
}
}
*count = remaining;
}
/**
* Initialize the cipher suite list
*/
static void build_cipher_suite_list(private_tls_crypto_t *this)
static void build_cipher_suite_list(private_tls_crypto_t *this,
bool require_encryption)
{
suite_algs_t suites[countof(suite_algs)];
int count = countof(suite_algs), i;
@@ -452,6 +472,10 @@ static void build_cipher_suite_list(private_tls_crypto_t *this)
{
suites[i] = suite_algs[i];
}
if (require_encryption)
{
filter_null_suites(this, suites, &count);
}
/* filter suite list by each algorithm */
filter_suite(this, suites, &count, offsetof(suite_algs_t, encr),
lib->crypto->create_crypter_enumerator);
@@ -872,7 +896,7 @@ METHOD(tls_crypto_t, destroy, void,
/**
* See header
*/
tls_crypto_t *tls_crypto_create(tls_t *tls, char *msk_label)
tls_crypto_t *tls_crypto_create(tls_t *tls)
{
private_tls_crypto_t *this;
@@ -892,10 +916,20 @@ tls_crypto_t *tls_crypto_create(tls_t *tls, char *msk_label)
.destroy = _destroy,
},
.tls = tls,
.msk_label = msk_label
);
build_cipher_suite_list(this);
switch (tls->get_purpose(tls))
{
case TLS_PURPOSE_EAP_TLS:
/* MSK PRF ASCII constant label according to EAP-TLS RFC 5216 */
this->msk_label = "client EAP encryption";
build_cipher_suite_list(this, FALSE);
break;
case TLS_PURPOSE_EAP_TTLS:
/* MSK PRF ASCII constant label according to EAP-TTLS RFC 5281 */
this->msk_label = "ttls keying material";
build_cipher_suite_list(this, TRUE);
break;
}
return &this->public;
}