* 修改sanlist中CN以行为分割的读取方式

This commit is contained in:
fengweihao
2019-09-26 15:04:19 +08:00
parent dbb16ae0c3
commit d84461437c

View File

@@ -901,24 +901,14 @@ int add_cert_ctx(X509_NAME* name, char* ctx[], int num)
static void x509_set_subject(X509 *x509, char *subject)
{
#define SUBJECT_NAME_MAX 126
char seps[] = ",";
char *item = strtok(subject, seps);
char key[SUBJECT_NAME_MAX] = {0}, value[SUBJECT_NAME_MAX] = {0};
X509_NAME *name = X509_get_subject_name(x509);
while (item)
{
sscanf(item, " %[^=]=%s", key, value);
X509_NAME_add_entry_by_txt(name, key, MBSTRING_UTF8, (unsigned char*)value, -1, -1, 0);
item = strtok(NULL, seps);
}
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8, (unsigned char*)subject, -1, -1, 0);
free(subject);
}
static int x509_set_altname(X509 *crt, int type, const char *sanfile, char **subjectname)
{
int ret = 0;
int ret = 0, num = 0;
GENERAL_NAMES *gens = NULL;
GENERAL_NAME *gen = NULL;
ASN1_IA5STRING *ia5 = NULL;
@@ -931,23 +921,17 @@ static int x509_set_altname(X509 *crt, int type, const char *sanfile, char **sub
if (buff == NULL){
goto finish;
}
char seps1[] = "\n", seps[] = ";";
char *sanline=NULL, *host = NULL;
if (buff[0] != '\n')
{
char *subject = strtok(buff, seps1);
if (subject != NULL)
{
*subjectname = strdup(subject);
}
sanline = strtok(NULL, seps);
}else
{
sanline = strtok(buff+1, seps);
}
char *sanline = NULL, *host = NULL;
char seps[] = ";";
sanline = strtok(buff, seps);
while (sanline)
{
asprintf(&host, "%s", sanline);
if (num == 0)
{
*subjectname = host;
goto next;
}
gen = GENERAL_NAME_new();
if (gen == NULL)
goto out;
@@ -968,11 +952,13 @@ static int x509_set_altname(X509 *crt, int type, const char *sanfile, char **sub
sk_GENERAL_NAME_push(gens, gen);
gen = NULL;
free(host);
next:
sanline = strtok(NULL, seps);
if (sanline == NULL || strlen(sanline) == 1)
{
break;
}
num++;
}
if (!X509_add1_ext_i2d(crt, NID_subject_alt_name, gens, 0, 0))
goto out;