0

I am trying to read the USB token certificate details like the day stated, the day end and subject, and other details from the certificate on the USB token I am using Botan 2.19 library and PKCS11 I have success in login and also set the bin and i got all details but i have two problem the first one i got issure in that format

"0B1\u001D0\u001B\u0006\u0003U\u0004\u0003\f\u0014Test CA Pilot1\u00140\u0012\u0006\u0003U\u0004\n\f\u000B Test\u000B0\t\u0006\u0003U\u0004\u0006\u0013\u0002EG"

while it should be

C = EG
O = Test
CN = Test CA Pilot

same thing for subject and the second problem is that i always got start date and end date empty string despite there is dates on the certificate my trial is

 Botan::PKCS11::AttributeContainer search_template;
search_template.add_numeric(Botan::PKCS11::AttributeType::Class, static_cast<unsigned long>(Botan::PKCS11::ObjectClass::Certificate));

auto found_objs = Botan::PKCS11::Object::search<Botan::PKCS11::Object>(m_session, search_template.attributes());

for (const Botan::PKCS11::Object& obj : found_objs)
{

    Botan::secure_vector<uint8_t> issuer = obj.get_attribute_value(Botan::PKCS11::AttributeType::Issuer);
    std::string issuer_str(issuer.begin(), issuer.end());
    qDebug() << "issuer: " << QString::fromUtf8(issuer);

    Botan::secure_vector<uint8_t> Label = obj.get_attribute_value(Botan::PKCS11::AttributeType::Label);
    std::string Label_str(reinterpret_cast<const char*>(Label.data()), Label.size());
    qDebug() << "Subject: " << QString::fromStdString(Label_str);


    Botan::secure_vector<uint8_t> SerialNumber = obj.get_attribute_value(Botan::PKCS11::AttributeType::SerialNumber);
    std::string SerialNumber_str(reinterpret_cast<const char*>(SerialNumber.data()), SerialNumber.size());
    qDebug() << "Subject: " << QString::fromStdString(SerialNumber_str);


    Botan::secure_vector<uint8_t> CertificateType = obj.get_attribute_value(Botan::PKCS11::AttributeType::CertificateType);
    std::string CertificateType_str(reinterpret_cast<const char*>(CertificateType.data()), CertificateType.size());
    qDebug() << "Subject: " << QString::fromStdString(CertificateType_str);


    Botan::secure_vector<uint8_t> subject_bytes = obj.get_attribute_value(Botan::PKCS11::AttributeType::Subject);
    std::string subject_str(reinterpret_cast<const char*>(subject_bytes.data()), subject_bytes.size());
    qDebug() << "Subject: " << QString::fromStdString(subject_str);

    Botan::secure_vector<uint8_t> start_date_bytes = obj.get_attribute_value(Botan::PKCS11::AttributeType::StartDate);
    std::string start_date_str(reinterpret_cast<const char*>(start_date_bytes.data()), start_date_bytes.size());
    qDebug() << "Validity Start Date: " << QString::fromStdString(start_date_str);

    Botan::secure_vector<uint8_t> end_date_bytes = obj.get_attribute_value(Botan::PKCS11::AttributeType::EndDate);
    std::string end_date_str(reinterpret_cast<const char*>(end_date_bytes.data()), end_date_bytes.size());
    qDebug() << "Validity End Date: " << QString::fromStdString(end_date_str);
}

can anyone help thanks in advance.

mr.alaa
  • 76
  • 3
  • 11

0 Answers0