Load certificate after enumeration
This commit is contained in:
@@ -70,32 +70,53 @@ static void find_certificates(private_pkcs11_creds_t *this,
|
|||||||
{CKA_LABEL, NULL, 0},
|
{CKA_LABEL, NULL, 0},
|
||||||
};
|
};
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
linked_list_t *raw;
|
||||||
certificate_t *cert;
|
certificate_t *cert;
|
||||||
|
struct {
|
||||||
|
chunk_t value;
|
||||||
|
chunk_t label;
|
||||||
|
} *entry;
|
||||||
|
|
||||||
|
raw = linked_list_create();
|
||||||
enumerator = this->lib->create_object_enumerator(this->lib,
|
enumerator = this->lib->create_object_enumerator(this->lib,
|
||||||
session, tmpl, countof(tmpl), attr, countof(attr));
|
session, tmpl, countof(tmpl), attr, countof(attr));
|
||||||
while (enumerator->enumerate(enumerator, &object))
|
while (enumerator->enumerate(enumerator, &object))
|
||||||
{
|
{
|
||||||
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
|
entry = malloc(sizeof(*entry));
|
||||||
BUILD_BLOB_ASN1_DER,
|
entry->value = chunk_clone(
|
||||||
chunk_create(attr[0].pValue, attr[0].ulValueLen),
|
chunk_create(attr[0].pValue, attr[0].ulValueLen));
|
||||||
BUILD_END);
|
entry->label = chunk_clone(
|
||||||
if (!cert)
|
chunk_create(attr[1].pValue, attr[1].ulValueLen));
|
||||||
{
|
raw->insert_last(raw, entry);
|
||||||
DBG1(DBG_CFG, " loading cert '%.*s' failed",
|
|
||||||
attr[1].ulValueLen, attr[1].pValue);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DBG1(DBG_CFG, " loaded %strusted cert '%.*s'",
|
|
||||||
trusted ? "" : "un", attr[1].ulValueLen, attr[1].pValue);
|
|
||||||
/* trusted certificates are also returned as untrusted */
|
|
||||||
this->untrusted->insert_last(this->untrusted, cert);
|
|
||||||
if (trusted)
|
|
||||||
{
|
|
||||||
this->trusted->insert_last(this->trusted, cert->get_ref(cert));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
while (raw->remove_first(raw, (void**)&entry) == SUCCESS)
|
||||||
|
{
|
||||||
|
cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
|
||||||
|
BUILD_BLOB_ASN1_DER, entry->value,
|
||||||
|
BUILD_END);
|
||||||
|
if (cert)
|
||||||
|
{
|
||||||
|
DBG1(DBG_CFG, " loaded %strusted cert '%.*s'",
|
||||||
|
trusted ? "" : "un", entry->label.len, entry->label.ptr);
|
||||||
|
/* trusted certificates are also returned as untrusted */
|
||||||
|
this->untrusted->insert_last(this->untrusted, cert);
|
||||||
|
if (trusted)
|
||||||
|
{
|
||||||
|
this->trusted->insert_last(this->trusted, cert->get_ref(cert));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DBG1(DBG_CFG, " loading cert '%.*s' failed",
|
||||||
|
entry->label.len, entry->label.ptr);
|
||||||
|
}
|
||||||
|
free(entry->value.ptr);
|
||||||
|
free(entry->label.ptr);
|
||||||
|
free(entry);
|
||||||
|
}
|
||||||
|
raw->destroy(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user