Добрый день. Стоит следующая задача. Дан список отозванных сертификатов в кодировке PEM. Необходимо из него выбрать id отзываемых ключей.
Какой функцией это можно сделать ? Пишу на с++ в связке с openssl .
Пока разобрался лишь с тем как из обычного сертификата выдирать id ключа.
Спасибо ! Разобрался почитав доки. Вот что получилось
bool get_sn_from_coc(const std::string & file , std::vector<std::string> & key_id_storage)
{
key_id_storage.clear();
BIO *bio;
const char * file_name = file.c_str();
X509_REVOKED * r = NULL;
//--------------------------------------------------------------
//open file
if (file_name == NULL)
{
std::string msg ="file name is empty";
throw sos_exception(msg.c_str());
}
else
{
bio = BIO_new_file(file_name, "r");
}
if (bio == NULL)
{
std::string msg ="Error open file ";
msg.append(file);
throw sos_exception(msg.c_str());
}
//--------------------------------------------------------------
STACK_OF(X509_INFO) *xis = PEM_X509_INFO_read_bio(bio, NULL,NULL, NULL);
//--------------------------------------------------------------
if (xis ==NULL )
{
std::string msg ="Error read bio file ";
msg.append(file);
throw sos_exception(msg.c_str());
}
BIO_free(bio);
//--------------------------------------------------------------
X509_INFO *xi =NULL;
for(int i = 0; i < sk_X509_INFO_num(xis); i++)
{
xi = sk_X509_INFO_value (xis, i);
//do paranoi check :)
if (xi ==NULL )
{
std::string msg ="Error read X509_INFO_value from file ";
msg.append(file);
throw sos_exception(msg.c_str());
}
if (xi->crl ==NULL )
{
std::string msg ="Error read X509_INFO_value (xi->crl) from file ";
msg.append(file);
throw sos_exception(msg.c_str());
}
if (xi->crl->crl ==NULL )
{
std::string msg ="Error read X509_INFO_value (xi->crl->crl) from file ";
msg.append(file);
throw sos_exception(msg.c_str());
}
//--------------------------------------------------------------
if (xi->crl->crl->revoked !=NULL)
{
while (sk_X509_REVOKED_num(xi->crl->crl->revoked))
{
r=sk_X509_REVOKED_shift(xi->crl->crl->revoked);
ASN1_INTEGER * serialNumber = r->serialNumber;
if (serialNumber!=NULL)
{
std::ostringstream out;
for (int i = 0 ; i <serialNumber->length ; ++i)
out << std::hex<< (serialNumber->data[i]&255);
std::string str_key_id = out.str();
key_id_storage.push_back(str_key_id);
X509_REVOKED_free(r);
}
}
}
}
//--------------------------------------------------------------
return true;
}