crypto_factory algorithm enumeration API
implementation of "ipsec listalgs"
This commit is contained in:
@@ -767,6 +767,57 @@ static void stroke_list_ocsp(linked_list_t* list, bool utc, FILE *out)
|
|||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List crypto algorithms available
|
||||||
|
*/
|
||||||
|
static void list_algs(FILE *out)
|
||||||
|
{
|
||||||
|
enumerator_t *enumerator;
|
||||||
|
encryption_algorithm_t encryption;
|
||||||
|
integrity_algorithm_t integrity;
|
||||||
|
hash_algorithm_t hash;
|
||||||
|
pseudo_random_function_t prf;
|
||||||
|
diffie_hellman_group_t group;
|
||||||
|
|
||||||
|
fprintf(out, "Userland algorithms:");
|
||||||
|
fprintf(out, "\n encryption: ");
|
||||||
|
enumerator = lib->crypto->create_crypter_enumerator(lib->crypto);
|
||||||
|
while (enumerator->enumerate(enumerator, &encryption))
|
||||||
|
{
|
||||||
|
fprintf(out, "%N ", encryption_algorithm_names, encryption);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
fprintf(out, "\n integrity: ");
|
||||||
|
enumerator = lib->crypto->create_signer_enumerator(lib->crypto);
|
||||||
|
while (enumerator->enumerate(enumerator, &integrity))
|
||||||
|
{
|
||||||
|
fprintf(out, "%N ", integrity_algorithm_names, integrity);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
fprintf(out, "\n hasher: ");
|
||||||
|
enumerator = lib->crypto->create_hasher_enumerator(lib->crypto);
|
||||||
|
while (enumerator->enumerate(enumerator, &hash))
|
||||||
|
{
|
||||||
|
fprintf(out, "%N ", hash_algorithm_names, hash);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
fprintf(out, "\n prf: ");
|
||||||
|
enumerator = lib->crypto->create_prf_enumerator(lib->crypto);
|
||||||
|
while (enumerator->enumerate(enumerator, &prf))
|
||||||
|
{
|
||||||
|
fprintf(out, "%N ", pseudo_random_function_names, prf);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
fprintf(out, "\n dh-group: ");
|
||||||
|
enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
|
||||||
|
while (enumerator->enumerate(enumerator, &group))
|
||||||
|
{
|
||||||
|
fprintf(out, "%N ", diffie_hellman_group_names, group);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
fprintf(out, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of stroke_list_t.list.
|
* Implementation of stroke_list_t.list.
|
||||||
*/
|
*/
|
||||||
@@ -817,8 +868,13 @@ static void list(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out)
|
|||||||
linked_list_t *ocsp_list = create_unique_cert_list(CERT_X509_OCSP_RESPONSE);
|
linked_list_t *ocsp_list = create_unique_cert_list(CERT_X509_OCSP_RESPONSE);
|
||||||
|
|
||||||
stroke_list_ocsp(ocsp_list, msg->list.utc, out);
|
stroke_list_ocsp(ocsp_list, msg->list.utc, out);
|
||||||
|
|
||||||
ocsp_list->destroy_offset(ocsp_list, offsetof(certificate_t, destroy));
|
ocsp_list->destroy_offset(ocsp_list, offsetof(certificate_t, destroy));
|
||||||
}
|
}
|
||||||
|
if (msg->list.flags & LIST_ALGS)
|
||||||
|
{
|
||||||
|
list_algs(out);
|
||||||
|
}
|
||||||
DESTROY_OFFSET_IF(cert_list, offsetof(certificate_t, destroy));
|
DESTROY_OFFSET_IF(cert_list, offsetof(certificate_t, destroy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -133,19 +133,19 @@ down-srcip)
|
|||||||
;;
|
;;
|
||||||
listalgs|listpubkeys|\listcards|\rereadgroups)
|
listalgs|listpubkeys|\listcards|\rereadgroups)
|
||||||
op="$1"
|
op="$1"
|
||||||
|
rc=7
|
||||||
shift
|
shift
|
||||||
if [ -e $IPSEC_PLUTO_PID ]
|
if [ -e $IPSEC_PLUTO_PID ]
|
||||||
then
|
then
|
||||||
$IPSEC_WHACK "$@" "--$op"
|
$IPSEC_WHACK "$@" "--$op"
|
||||||
exit "$?"
|
rc="$?"
|
||||||
else
|
|
||||||
if [ -e $IPSEC_CHARON_PID ]
|
|
||||||
then
|
|
||||||
exit 3
|
|
||||||
else
|
|
||||||
exit 7
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
if [ -e $IPSEC_CHARON_PID ]
|
||||||
|
then
|
||||||
|
$IPSEC_STROKE "$op"
|
||||||
|
rc="$?"
|
||||||
|
fi
|
||||||
|
exit "$rc"
|
||||||
;;
|
;;
|
||||||
listcerts|listcacerts|listaacerts|\
|
listcerts|listcacerts|listaacerts|\
|
||||||
listacerts|listgroups|listocspcerts|\
|
listacerts|listgroups|listocspcerts|\
|
||||||
|
|||||||
@@ -20,52 +20,19 @@
|
|||||||
#include <utils/linked_list.h>
|
#include <utils/linked_list.h>
|
||||||
#include <utils/mutex.h>
|
#include <utils/mutex.h>
|
||||||
|
|
||||||
typedef struct crypter_entry_t crypter_entry_t;
|
typedef struct entry_t entry_t;
|
||||||
struct crypter_entry_t {
|
struct entry_t {
|
||||||
/** encryption algorithm */
|
/** algorithm */
|
||||||
encryption_algorithm_t algo;
|
u_int algo;
|
||||||
/** associated constructor */
|
/* constructor */
|
||||||
crypter_constructor_t create;
|
union {
|
||||||
};
|
crypter_constructor_t create_crypter;
|
||||||
|
signer_constructor_t create_signer;
|
||||||
typedef struct signer_entry_t signer_entry_t;
|
hasher_constructor_t create_hasher;
|
||||||
struct signer_entry_t {
|
prf_constructor_t create_prf;
|
||||||
/** integrity algorithm */
|
rng_constructor_t create_rng;
|
||||||
integrity_algorithm_t algo;
|
dh_constructor_t create_dh;
|
||||||
/** associated constructor */
|
};
|
||||||
signer_constructor_t create;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct hasher_entry_t hasher_entry_t;
|
|
||||||
struct hasher_entry_t {
|
|
||||||
/** hash algorithm */
|
|
||||||
hash_algorithm_t algo;
|
|
||||||
/** associated constructor */
|
|
||||||
hasher_constructor_t create;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct prf_entry_t prf_entry_t;
|
|
||||||
struct prf_entry_t {
|
|
||||||
/** hash algorithm */
|
|
||||||
pseudo_random_function_t algo;
|
|
||||||
/** associated constructor */
|
|
||||||
prf_constructor_t create;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct rng_entry_t rng_entry_t;
|
|
||||||
struct rng_entry_t {
|
|
||||||
/** quality of randomness */
|
|
||||||
rng_quality_t quality;
|
|
||||||
/** associated constructor */
|
|
||||||
rng_constructor_t create;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct dh_entry_t dh_entry_t;
|
|
||||||
struct dh_entry_t {
|
|
||||||
/** hash algorithm */
|
|
||||||
diffie_hellman_group_t group;
|
|
||||||
/** associated constructor */
|
|
||||||
dh_constructor_t create;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct private_crypto_factory_t private_crypto_factory_t;
|
typedef struct private_crypto_factory_t private_crypto_factory_t;
|
||||||
@@ -81,32 +48,32 @@ struct private_crypto_factory_t {
|
|||||||
crypto_factory_t public;
|
crypto_factory_t public;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered crypters, as crypter_entry_t
|
* registered crypters, as entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *crypters;
|
linked_list_t *crypters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered signers, as signer_entry_t
|
* registered signers, as entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *signers;
|
linked_list_t *signers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered hashers, as hasher_entry_t
|
* registered hashers, as entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *hashers;
|
linked_list_t *hashers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered prfs, as prf_entry_t
|
* registered prfs, as entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *prfs;
|
linked_list_t *prfs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered rngs, as rng_entry_t
|
* registered rngs, as entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *rngs;
|
linked_list_t *rngs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* registered diffie hellman, as dh_entry_t
|
* registered diffie hellman, as entry_t
|
||||||
*/
|
*/
|
||||||
linked_list_t *dhs;
|
linked_list_t *dhs;
|
||||||
|
|
||||||
@@ -123,7 +90,7 @@ static crypter_t* create_crypter(private_crypto_factory_t *this,
|
|||||||
encryption_algorithm_t algo, size_t key_size)
|
encryption_algorithm_t algo, size_t key_size)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
crypter_entry_t *entry;
|
entry_t *entry;
|
||||||
crypter_t *crypter = NULL;
|
crypter_t *crypter = NULL;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -132,7 +99,7 @@ static crypter_t* create_crypter(private_crypto_factory_t *this,
|
|||||||
{
|
{
|
||||||
if (entry->algo == algo)
|
if (entry->algo == algo)
|
||||||
{
|
{
|
||||||
crypter = entry->create(algo, key_size);
|
crypter = entry->create_crypter(algo, key_size);
|
||||||
if (crypter)
|
if (crypter)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -151,7 +118,7 @@ static signer_t* create_signer(private_crypto_factory_t *this,
|
|||||||
integrity_algorithm_t algo)
|
integrity_algorithm_t algo)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
signer_entry_t *entry;
|
entry_t *entry;
|
||||||
signer_t *signer = NULL;
|
signer_t *signer = NULL;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -160,7 +127,7 @@ static signer_t* create_signer(private_crypto_factory_t *this,
|
|||||||
{
|
{
|
||||||
if (entry->algo == algo)
|
if (entry->algo == algo)
|
||||||
{
|
{
|
||||||
signer = entry->create(algo);
|
signer = entry->create_signer(algo);
|
||||||
if (signer)
|
if (signer)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -180,7 +147,7 @@ static hasher_t* create_hasher(private_crypto_factory_t *this,
|
|||||||
hash_algorithm_t algo)
|
hash_algorithm_t algo)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
hasher_entry_t *entry;
|
entry_t *entry;
|
||||||
hasher_t *hasher = NULL;
|
hasher_t *hasher = NULL;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -189,7 +156,7 @@ static hasher_t* create_hasher(private_crypto_factory_t *this,
|
|||||||
{
|
{
|
||||||
if (algo == HASH_PREFERRED || entry->algo == algo)
|
if (algo == HASH_PREFERRED || entry->algo == algo)
|
||||||
{
|
{
|
||||||
hasher = entry->create(entry->algo);
|
hasher = entry->create_hasher(entry->algo);
|
||||||
if (hasher)
|
if (hasher)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -208,7 +175,7 @@ static prf_t* create_prf(private_crypto_factory_t *this,
|
|||||||
pseudo_random_function_t algo)
|
pseudo_random_function_t algo)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
prf_entry_t *entry;
|
entry_t *entry;
|
||||||
prf_t *prf = NULL;
|
prf_t *prf = NULL;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
@@ -217,7 +184,7 @@ static prf_t* create_prf(private_crypto_factory_t *this,
|
|||||||
{
|
{
|
||||||
if (entry->algo == algo)
|
if (entry->algo == algo)
|
||||||
{
|
{
|
||||||
prf = entry->create(algo);
|
prf = entry->create_prf(algo);
|
||||||
if (prf)
|
if (prf)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -235,7 +202,7 @@ static prf_t* create_prf(private_crypto_factory_t *this,
|
|||||||
static rng_t* create_rng(private_crypto_factory_t *this, rng_quality_t quality)
|
static rng_t* create_rng(private_crypto_factory_t *this, rng_quality_t quality)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
rng_entry_t *entry;
|
entry_t *entry;
|
||||||
u_int diff = ~0;
|
u_int diff = ~0;
|
||||||
rng_constructor_t constr = NULL;
|
rng_constructor_t constr = NULL;
|
||||||
|
|
||||||
@@ -243,10 +210,10 @@ static rng_t* create_rng(private_crypto_factory_t *this, rng_quality_t quality)
|
|||||||
enumerator = this->rngs->create_enumerator(this->rngs);
|
enumerator = this->rngs->create_enumerator(this->rngs);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{ /* find the best matching quality, but at least as good as requested */
|
{ /* find the best matching quality, but at least as good as requested */
|
||||||
if (entry->quality >= quality && diff > entry->quality - quality)
|
if (entry->algo >= quality && diff > entry->algo - quality)
|
||||||
{
|
{
|
||||||
diff = entry->quality - quality;
|
diff = entry->algo - quality;
|
||||||
constr = entry->create;
|
constr = entry->create_rng;
|
||||||
if (diff == 0)
|
if (diff == 0)
|
||||||
{ /* perfect match, won't get better */
|
{ /* perfect match, won't get better */
|
||||||
break;
|
break;
|
||||||
@@ -269,16 +236,16 @@ static diffie_hellman_t* create_dh(private_crypto_factory_t *this,
|
|||||||
diffie_hellman_group_t group)
|
diffie_hellman_group_t group)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
dh_entry_t *entry;
|
entry_t *entry;
|
||||||
diffie_hellman_t *diffie_hellman = NULL;
|
diffie_hellman_t *diffie_hellman = NULL;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->dhs->create_enumerator(this->dhs);
|
enumerator = this->dhs->create_enumerator(this->dhs);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->group == group)
|
if (entry->algo == group)
|
||||||
{
|
{
|
||||||
diffie_hellman = entry->create(group);
|
diffie_hellman = entry->create_dh(group);
|
||||||
if (diffie_hellman)
|
if (diffie_hellman)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -297,10 +264,10 @@ static void add_crypter(private_crypto_factory_t *this,
|
|||||||
encryption_algorithm_t algo,
|
encryption_algorithm_t algo,
|
||||||
crypter_constructor_t create)
|
crypter_constructor_t create)
|
||||||
{
|
{
|
||||||
crypter_entry_t *entry = malloc_thing(crypter_entry_t);
|
entry_t *entry = malloc_thing(entry_t);
|
||||||
|
|
||||||
entry->algo = algo;
|
entry->algo = algo;
|
||||||
entry->create = create;
|
entry->create_crypter = create;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->crypters->insert_last(this->crypters, entry);
|
this->crypters->insert_last(this->crypters, entry);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
@@ -312,14 +279,14 @@ static void add_crypter(private_crypto_factory_t *this,
|
|||||||
static void remove_crypter(private_crypto_factory_t *this,
|
static void remove_crypter(private_crypto_factory_t *this,
|
||||||
crypter_constructor_t create)
|
crypter_constructor_t create)
|
||||||
{
|
{
|
||||||
crypter_entry_t *entry;
|
entry_t *entry;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->crypters->create_enumerator(this->crypters);
|
enumerator = this->crypters->create_enumerator(this->crypters);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->create == create)
|
if (entry->create_crypter == create)
|
||||||
{
|
{
|
||||||
this->crypters->remove_at(this->crypters, enumerator);
|
this->crypters->remove_at(this->crypters, enumerator);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -335,10 +302,10 @@ static void remove_crypter(private_crypto_factory_t *this,
|
|||||||
static void add_signer(private_crypto_factory_t *this,
|
static void add_signer(private_crypto_factory_t *this,
|
||||||
integrity_algorithm_t algo, signer_constructor_t create)
|
integrity_algorithm_t algo, signer_constructor_t create)
|
||||||
{
|
{
|
||||||
signer_entry_t *entry = malloc_thing(signer_entry_t);
|
entry_t *entry = malloc_thing(entry_t);
|
||||||
|
|
||||||
entry->algo = algo;
|
entry->algo = algo;
|
||||||
entry->create = create;
|
entry->create_signer = create;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->signers->insert_last(this->signers, entry);
|
this->signers->insert_last(this->signers, entry);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
@@ -350,14 +317,14 @@ static void add_signer(private_crypto_factory_t *this,
|
|||||||
static void remove_signer(private_crypto_factory_t *this,
|
static void remove_signer(private_crypto_factory_t *this,
|
||||||
signer_constructor_t create)
|
signer_constructor_t create)
|
||||||
{
|
{
|
||||||
signer_entry_t *entry;
|
entry_t *entry;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->signers->create_enumerator(this->signers);
|
enumerator = this->signers->create_enumerator(this->signers);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->create == create)
|
if (entry->create_signer == create)
|
||||||
{
|
{
|
||||||
this->signers->remove_at(this->signers, enumerator);
|
this->signers->remove_at(this->signers, enumerator);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -373,10 +340,10 @@ static void remove_signer(private_crypto_factory_t *this,
|
|||||||
static void add_hasher(private_crypto_factory_t *this, hash_algorithm_t algo,
|
static void add_hasher(private_crypto_factory_t *this, hash_algorithm_t algo,
|
||||||
hasher_constructor_t create)
|
hasher_constructor_t create)
|
||||||
{
|
{
|
||||||
hasher_entry_t *entry = malloc_thing(hasher_entry_t);
|
entry_t *entry = malloc_thing(entry_t);
|
||||||
|
|
||||||
entry->algo = algo;
|
entry->algo = algo;
|
||||||
entry->create = create;
|
entry->create_hasher = create;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->hashers->insert_last(this->hashers, entry);
|
this->hashers->insert_last(this->hashers, entry);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
@@ -388,14 +355,14 @@ static void add_hasher(private_crypto_factory_t *this, hash_algorithm_t algo,
|
|||||||
static void remove_hasher(private_crypto_factory_t *this,
|
static void remove_hasher(private_crypto_factory_t *this,
|
||||||
hasher_constructor_t create)
|
hasher_constructor_t create)
|
||||||
{
|
{
|
||||||
hasher_entry_t *entry;
|
entry_t *entry;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->hashers->create_enumerator(this->hashers);
|
enumerator = this->hashers->create_enumerator(this->hashers);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->create == create)
|
if (entry->create_hasher == create)
|
||||||
{
|
{
|
||||||
this->hashers->remove_at(this->hashers, enumerator);
|
this->hashers->remove_at(this->hashers, enumerator);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -411,10 +378,10 @@ static void remove_hasher(private_crypto_factory_t *this,
|
|||||||
static void add_prf(private_crypto_factory_t *this,
|
static void add_prf(private_crypto_factory_t *this,
|
||||||
pseudo_random_function_t algo, prf_constructor_t create)
|
pseudo_random_function_t algo, prf_constructor_t create)
|
||||||
{
|
{
|
||||||
prf_entry_t *entry = malloc_thing(prf_entry_t);
|
entry_t *entry = malloc_thing(entry_t);
|
||||||
|
|
||||||
entry->algo = algo;
|
entry->algo = algo;
|
||||||
entry->create = create;
|
entry->create_prf = create;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->prfs->insert_last(this->prfs, entry);
|
this->prfs->insert_last(this->prfs, entry);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
@@ -425,14 +392,14 @@ static void add_prf(private_crypto_factory_t *this,
|
|||||||
*/
|
*/
|
||||||
static void remove_prf(private_crypto_factory_t *this, prf_constructor_t create)
|
static void remove_prf(private_crypto_factory_t *this, prf_constructor_t create)
|
||||||
{
|
{
|
||||||
prf_entry_t *entry;
|
entry_t *entry;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->prfs->create_enumerator(this->prfs);
|
enumerator = this->prfs->create_enumerator(this->prfs);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->create == create)
|
if (entry->create_prf == create)
|
||||||
{
|
{
|
||||||
this->prfs->remove_at(this->prfs, enumerator);
|
this->prfs->remove_at(this->prfs, enumerator);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -448,10 +415,10 @@ static void remove_prf(private_crypto_factory_t *this, prf_constructor_t create)
|
|||||||
static void add_rng(private_crypto_factory_t *this, rng_quality_t quality,
|
static void add_rng(private_crypto_factory_t *this, rng_quality_t quality,
|
||||||
rng_constructor_t create)
|
rng_constructor_t create)
|
||||||
{
|
{
|
||||||
rng_entry_t *entry = malloc_thing(rng_entry_t);
|
entry_t *entry = malloc_thing(entry_t);
|
||||||
|
|
||||||
entry->quality = quality;
|
entry->algo = quality;
|
||||||
entry->create = create;
|
entry->create_rng = create;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->rngs->insert_last(this->rngs, entry);
|
this->rngs->insert_last(this->rngs, entry);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
@@ -462,14 +429,14 @@ static void add_rng(private_crypto_factory_t *this, rng_quality_t quality,
|
|||||||
*/
|
*/
|
||||||
static void remove_rng(private_crypto_factory_t *this, rng_constructor_t create)
|
static void remove_rng(private_crypto_factory_t *this, rng_constructor_t create)
|
||||||
{
|
{
|
||||||
rng_entry_t *entry;
|
entry_t *entry;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->rngs->create_enumerator(this->rngs);
|
enumerator = this->rngs->create_enumerator(this->rngs);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->create == create)
|
if (entry->create_rng == create)
|
||||||
{
|
{
|
||||||
this->rngs->remove_at(this->rngs, enumerator);
|
this->rngs->remove_at(this->rngs, enumerator);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -485,10 +452,10 @@ static void remove_rng(private_crypto_factory_t *this, rng_constructor_t create)
|
|||||||
static void add_dh(private_crypto_factory_t *this, diffie_hellman_group_t group,
|
static void add_dh(private_crypto_factory_t *this, diffie_hellman_group_t group,
|
||||||
dh_constructor_t create)
|
dh_constructor_t create)
|
||||||
{
|
{
|
||||||
dh_entry_t *entry = malloc_thing(dh_entry_t);
|
entry_t *entry = malloc_thing(entry_t);
|
||||||
|
|
||||||
entry->group = group;
|
entry->algo = group;
|
||||||
entry->create = create;
|
entry->create_dh = create;
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->dhs->insert_last(this->dhs, entry);
|
this->dhs->insert_last(this->dhs, entry);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
@@ -499,14 +466,14 @@ static void add_dh(private_crypto_factory_t *this, diffie_hellman_group_t group,
|
|||||||
*/
|
*/
|
||||||
static void remove_dh(private_crypto_factory_t *this, dh_constructor_t create)
|
static void remove_dh(private_crypto_factory_t *this, dh_constructor_t create)
|
||||||
{
|
{
|
||||||
dh_entry_t *entry;
|
entry_t *entry;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
enumerator = this->dhs->create_enumerator(this->dhs);
|
enumerator = this->dhs->create_enumerator(this->dhs);
|
||||||
while (enumerator->enumerate(enumerator, &entry))
|
while (enumerator->enumerate(enumerator, &entry))
|
||||||
{
|
{
|
||||||
if (entry->create == create)
|
if (entry->create_dh == create)
|
||||||
{
|
{
|
||||||
this->dhs->remove_at(this->dhs, enumerator);
|
this->dhs->remove_at(this->dhs, enumerator);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -516,6 +483,127 @@ static void remove_dh(private_crypto_factory_t *this, dh_constructor_t create)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* match algorithms of an entry?
|
||||||
|
*/
|
||||||
|
static bool entry_match(entry_t *a, entry_t *b)
|
||||||
|
{
|
||||||
|
return a->algo == b->algo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check for uniqueness of an entry
|
||||||
|
*/
|
||||||
|
static bool unique_check(linked_list_t *list, entry_t **in, entry_t **out)
|
||||||
|
{
|
||||||
|
if (list->find_first(list, (void*)entry_match, NULL, *in) == SUCCESS)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*out = *in;
|
||||||
|
list->insert_last(list, *in);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create an enumerator over entry->algo in list with locking and unique check
|
||||||
|
*/
|
||||||
|
static enumerator_t *create_enumerator(private_crypto_factory_t *this,
|
||||||
|
linked_list_t *list, void *filter)
|
||||||
|
{
|
||||||
|
this->mutex->lock(this->mutex);
|
||||||
|
return enumerator_create_filter(
|
||||||
|
enumerator_create_filter(
|
||||||
|
list->create_enumerator(list), (void*)unique_check,
|
||||||
|
linked_list_create(), (void*)list->destroy),
|
||||||
|
filter, this->mutex, (void*)this->mutex->unlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter function to enumerate algorithm, not entry
|
||||||
|
*/
|
||||||
|
static bool crypter_filter(void *n, entry_t **entry, encryption_algorithm_t *algo)
|
||||||
|
{
|
||||||
|
*algo = (*entry)->algo;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of crypto_factory_t.create_crypter_enumerator
|
||||||
|
*/
|
||||||
|
static enumerator_t* create_crypter_enumerator(private_crypto_factory_t *this)
|
||||||
|
{
|
||||||
|
return create_enumerator(this, this->crypters, crypter_filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter function to enumerate algorithm, not entry
|
||||||
|
*/
|
||||||
|
static bool signer_filter(void *n, entry_t **entry, integrity_algorithm_t *algo)
|
||||||
|
{
|
||||||
|
*algo = (*entry)->algo;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of crypto_factory_t.create_signer_enumerator
|
||||||
|
*/
|
||||||
|
static enumerator_t* create_signer_enumerator(private_crypto_factory_t *this)
|
||||||
|
{
|
||||||
|
return create_enumerator(this, this->signers, signer_filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter function to enumerate algorithm, not entry
|
||||||
|
*/
|
||||||
|
static bool hasher_filter(void *n, entry_t **entry, hash_algorithm_t *algo)
|
||||||
|
{
|
||||||
|
*algo = (*entry)->algo;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of crypto_factory_t.create_hasher_enumerator
|
||||||
|
*/
|
||||||
|
static enumerator_t* create_hasher_enumerator(private_crypto_factory_t *this)
|
||||||
|
{
|
||||||
|
return create_enumerator(this, this->hashers, hasher_filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter function to enumerate algorithm, not entry
|
||||||
|
*/
|
||||||
|
static bool prf_filter(void *n, entry_t **entry, pseudo_random_function_t *algo)
|
||||||
|
{
|
||||||
|
*algo = (*entry)->algo;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of crypto_factory_t.create_prf_enumerator
|
||||||
|
*/
|
||||||
|
static enumerator_t* create_prf_enumerator(private_crypto_factory_t *this)
|
||||||
|
{
|
||||||
|
return create_enumerator(this, this->prfs, prf_filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter function to enumerate algorithm, not entry
|
||||||
|
*/
|
||||||
|
static bool dh_filter(void *n, entry_t **entry, diffie_hellman_group_t *group)
|
||||||
|
{
|
||||||
|
*group = (*entry)->algo;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of crypto_factory_t.create_dh_enumerator
|
||||||
|
*/
|
||||||
|
static enumerator_t* create_dh_enumerator(private_crypto_factory_t *this)
|
||||||
|
{
|
||||||
|
return create_enumerator(this, this->dhs, dh_filter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of crypto_factory_t.destroy
|
* Implementation of crypto_factory_t.destroy
|
||||||
*/
|
*/
|
||||||
@@ -556,6 +644,11 @@ crypto_factory_t *crypto_factory_create()
|
|||||||
this->public.remove_rng = (void(*)(crypto_factory_t*, rng_constructor_t create))remove_rng;
|
this->public.remove_rng = (void(*)(crypto_factory_t*, rng_constructor_t create))remove_rng;
|
||||||
this->public.add_dh = (void(*)(crypto_factory_t*, diffie_hellman_group_t algo, dh_constructor_t create))add_dh;
|
this->public.add_dh = (void(*)(crypto_factory_t*, diffie_hellman_group_t algo, dh_constructor_t create))add_dh;
|
||||||
this->public.remove_dh = (void(*)(crypto_factory_t*, dh_constructor_t create))remove_dh;
|
this->public.remove_dh = (void(*)(crypto_factory_t*, dh_constructor_t create))remove_dh;
|
||||||
|
this->public.create_crypter_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_crypter_enumerator;
|
||||||
|
this->public.create_signer_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_signer_enumerator;
|
||||||
|
this->public.create_hasher_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_hasher_enumerator;
|
||||||
|
this->public.create_prf_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_prf_enumerator;
|
||||||
|
this->public.create_dh_enumerator = (enumerator_t*(*)(crypto_factory_t*))create_dh_enumerator;
|
||||||
this->public.destroy = (void(*)(crypto_factory_t*))destroy;
|
this->public.destroy = (void(*)(crypto_factory_t*))destroy;
|
||||||
|
|
||||||
this->crypters = linked_list_create();
|
this->crypters = linked_list_create();
|
||||||
|
|||||||
@@ -221,6 +221,41 @@ struct crypto_factory_t {
|
|||||||
*/
|
*/
|
||||||
void (*remove_dh)(crypto_factory_t *this, dh_constructor_t create);
|
void (*remove_dh)(crypto_factory_t *this, dh_constructor_t create);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an enumerator over all registered crypter algorithms.
|
||||||
|
*
|
||||||
|
* @return enumerator over encryption_algorithm_t
|
||||||
|
*/
|
||||||
|
enumerator_t* (*create_crypter_enumerator)(crypto_factory_t *this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an enumerator over all registered signer algorithms.
|
||||||
|
*
|
||||||
|
* @return enumerator over integrity_algorithm_t
|
||||||
|
*/
|
||||||
|
enumerator_t* (*create_signer_enumerator)(crypto_factory_t *this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an enumerator over all registered hasher algorithms.
|
||||||
|
*
|
||||||
|
* @return enumerator over hash_algorithm_t
|
||||||
|
*/
|
||||||
|
enumerator_t* (*create_hasher_enumerator)(crypto_factory_t *this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an enumerator over all registered PRFs.
|
||||||
|
*
|
||||||
|
* @return enumerator over pseudo_random_function_t
|
||||||
|
*/
|
||||||
|
enumerator_t* (*create_prf_enumerator)(crypto_factory_t *this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an enumerator over all registered diffie hellman groups.
|
||||||
|
*
|
||||||
|
* @return enumerator over diffie_hellman_group_t
|
||||||
|
*/
|
||||||
|
enumerator_t* (*create_dh_enumerator)(crypto_factory_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a crypto_factory instance.
|
* Destroy a crypto_factory instance.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ static int list_flags[] = {
|
|||||||
LIST_CAINFOS,
|
LIST_CAINFOS,
|
||||||
LIST_CRLS,
|
LIST_CRLS,
|
||||||
LIST_OCSP,
|
LIST_OCSP,
|
||||||
|
LIST_ALGS,
|
||||||
LIST_ALL
|
LIST_ALL
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -308,6 +309,8 @@ static void exit_usage(char *error)
|
|||||||
printf(" stroke listcacerts|listocspcerts|listaacerts|listacerts\n");
|
printf(" stroke listcacerts|listocspcerts|listaacerts|listacerts\n");
|
||||||
printf(" Show list of end entity certificates, ca info records and crls:\n");
|
printf(" Show list of end entity certificates, ca info records and crls:\n");
|
||||||
printf(" stroke listcerts|listcainfos|listcrls|listall\n");
|
printf(" stroke listcerts|listcainfos|listcrls|listall\n");
|
||||||
|
printf(" Show list of supported algorithms:\n");
|
||||||
|
printf(" stroke listalgs\n");
|
||||||
printf(" Reload authority and attribute certificates:\n");
|
printf(" Reload authority and attribute certificates:\n");
|
||||||
printf(" stroke rereadcacerts|rereadocspcerts|rereadaacerts|rereadacerts\n");
|
printf(" stroke rereadcacerts|rereadocspcerts|rereadaacerts|rereadacerts\n");
|
||||||
printf(" Reload secrets and crls:\n");
|
printf(" Reload secrets and crls:\n");
|
||||||
@@ -408,6 +411,7 @@ int main(int argc, char *argv[])
|
|||||||
case STROKE_LIST_CAINFOS:
|
case STROKE_LIST_CAINFOS:
|
||||||
case STROKE_LIST_CRLS:
|
case STROKE_LIST_CRLS:
|
||||||
case STROKE_LIST_OCSP:
|
case STROKE_LIST_OCSP:
|
||||||
|
case STROKE_LIST_ALGS:
|
||||||
case STROKE_LIST_ALL:
|
case STROKE_LIST_ALL:
|
||||||
res = list(token->kw, argc > 2 && strcmp(argv[2], "--utc") == 0);
|
res = list(token->kw, argc > 2 && strcmp(argv[2], "--utc") == 0);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ typedef enum {
|
|||||||
STROKE_LIST_CAINFOS,
|
STROKE_LIST_CAINFOS,
|
||||||
STROKE_LIST_CRLS,
|
STROKE_LIST_CRLS,
|
||||||
STROKE_LIST_OCSP,
|
STROKE_LIST_OCSP,
|
||||||
|
STROKE_LIST_ALGS,
|
||||||
STROKE_LIST_ALL,
|
STROKE_LIST_ALL,
|
||||||
STROKE_REREAD_SECRETS,
|
STROKE_REREAD_SECRETS,
|
||||||
STROKE_REREAD_CACERTS,
|
STROKE_REREAD_CACERTS,
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ listgroups, STROKE_LIST_GROUPS
|
|||||||
listcainfos, STROKE_LIST_CAINFOS
|
listcainfos, STROKE_LIST_CAINFOS
|
||||||
listcrls, STROKE_LIST_CRLS
|
listcrls, STROKE_LIST_CRLS
|
||||||
listocsp, STROKE_LIST_OCSP
|
listocsp, STROKE_LIST_OCSP
|
||||||
|
listalgs, STROKE_LIST_ALGS
|
||||||
listall, STROKE_LIST_ALL
|
listall, STROKE_LIST_ALL
|
||||||
rereadsecrets, STROKE_REREAD_SECRETS
|
rereadsecrets, STROKE_REREAD_SECRETS
|
||||||
rereadcacerts, STROKE_REREAD_CACERTS
|
rereadcacerts, STROKE_REREAD_CACERTS
|
||||||
|
|||||||
@@ -61,8 +61,10 @@ enum list_flag_t {
|
|||||||
LIST_CRLS = 0x0080,
|
LIST_CRLS = 0x0080,
|
||||||
/** list all ocsp cache entries */
|
/** list all ocsp cache entries */
|
||||||
LIST_OCSP = 0x0100,
|
LIST_OCSP = 0x0100,
|
||||||
|
/** list all supported algorithms */
|
||||||
|
LIST_ALGS = 0x0200,
|
||||||
/** all list options */
|
/** all list options */
|
||||||
LIST_ALL = 0x01FF,
|
LIST_ALL = 0x03FF,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum reread_flag_t reread_flag_t;
|
typedef enum reread_flag_t reread_flag_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user