我想在iOS中使用openSSL从SSL证书中提取Issuer CN(公共名称)。我使用链接http://pastebin.com/Vn797Sc0从证书中提取信息。我正在获取发行者名称,但无法在iOS中提取颁发者公用名(公用名)。提前致谢
答案 0 :(得分:2)
您可以在链接的代码中提取公共名称,例如“组织”字段(未测试)
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;
}
答案 1 :(得分: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;
}