TEST_F(CACertsTests, test_certificate_properties) { CFDataRef property; CFTypeRef oid; std::string prop_string; oid = kSecOIDCommonName; property = CreatePropertyFromCertificate(cert, oid); prop_string = genCommonNameProperty(property); EXPECT_EQ("localhost.localdomain", prop_string); CFRelease(property); oid = kSecOIDSubjectKeyIdentifier; property = CreatePropertyFromCertificate(cert, oid); prop_string = genKIDProperty(property); EXPECT_EQ("f2b99b00e0ee60d57c426ce3e64e3fdc6f6411c0", prop_string); CFRelease(property); oid = kSecOIDX509V1ValidityNotBefore; property = CreatePropertyFromCertificate(cert, oid); prop_string = stringFromCFNumber(property); EXPECT_EQ("430168336", prop_string); CFRelease(property); oid = kSecOIDBasicConstraints; property = CreatePropertyFromCertificate(cert, oid); prop_string = genCAProperty(property); EXPECT_EQ("1", prop_string); CFRelease(property); }
std::string genSHA1ForCertificate(X509* cert) { const EVP_MD* fprint_type = EVP_sha1(); unsigned char fprint[EVP_MAX_MD_SIZE] = {0}; unsigned int fprint_size = 0; if (X509_digest(cert, fprint_type, fprint, &fprint_size)) { return genKIDProperty(fprint, fprint_size); } return ""; }
TEST_F(CACertsTests, test_certificate_properties) { std::string subject, common_name, issuer; genCommonName(x_cert, subject, common_name, issuer); EXPECT_EQ("localhost.localdomain", common_name); OSX_OPENSSL(X509_check_ca(x_cert)); auto skid = genKIDProperty(x_cert->skid->data, x_cert->skid->length); EXPECT_EQ("f2b99b00e0ee60d57c426ce3e64e3fdc6f6411c0", skid); auto not_before = std::to_string(genEpoch(X509_get_notBefore(x_cert))); EXPECT_EQ("1408475536", not_before); auto ca = (CertificateIsCA(x_cert)) ? "1" : "0"; EXPECT_EQ("1", ca); }