我想在 iOS 中使用 openSSL 从 SSL 证书中提取颁发者 CN(通用名称)。我正在使用链接http://pastebin.com/Vn797Sc0从证书中提取信息。我正在获取发行人名称,但无法在 iOS 中提取发行人通用名称(通用名称)。提前致谢
问问题
2621 次
2 回答
3
您可以在链接的代码中提取通用名称,例如组织字段(未测试)
static NSString * CertificateGetIssuerCommonName(X509 *certificateX509) {
NSString *issuerCN = nil;
if (certificateX509 != NULL) {
X509_NAME *issuerX509Name = X509_get_issuer_name(certificateX509);
if (issuerX509Name != NULL) {
int nid = OBJ_txt2nid("CN");
int index = X509_NAME_get_index_by_NID(issuerX509Name, nid, -1);
if (index != -1) {
X509_NAME_ENTRY *issuerNameCommonName = X509_NAME_get_entry(issuerX509Name, index);
if (issuerNameEntry) {
ASN1_STRING *issuerCNASN1 = X509_NAME_ENTRY_get_data(issuerNameEntry);
if (issuerCNASN1 != NULL) {
unsigned char *issuerCName = ASN1_STRING_data(issuerCNASN1);
issuerCN = [NSString stringWithUTF8String:(char *)issuerCName];
}
}
}
}
}
return issuerCN;
}
于 2013-10-11T15:33:32.783 回答
2
static NSString * CertificateGetIssuerName(X509 *certificateX509)
{
NSString *issuer = nil;
if (certificateX509 != NULL) {
X509_NAME *issuerX509Name = X509_get_issuer_name(certificateX509);
if (issuerX509Name != NULL) {
//NID_commonName extract the common name of the issuer
int index = X509_NAME_get_index_by_NID(issuerX509Name, NID_commonName, -1);
X509_NAME_ENTRY *issuerNameEntry = X509_NAME_get_entry(issuerX509Name, index);
if (issuerNameEntry) {
ASN1_STRING *issuerNameASN1 = X509_NAME_ENTRY_get_data(issuerNameEntry);
if (issuerNameASN1 != NULL) {
unsigned char *issuerName = ASN1_STRING_data(issuerNameASN1);
issuer = [NSString stringWithUTF8String:(char *)issuerName];
}
}
}
}
return issuer;
}
于 2013-10-15T09:53:50.267 回答