* 修改sanlist中CN以行为分割的读取方式
This commit is contained in:
38
src/x509.c
38
src/x509.c
@@ -901,24 +901,14 @@ int add_cert_ctx(X509_NAME* name, char* ctx[], int num)
|
|||||||
|
|
||||||
static void x509_set_subject(X509 *x509, char *subject)
|
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);
|
X509_NAME *name = X509_get_subject_name(x509);
|
||||||
while (item)
|
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8, (unsigned char*)subject, -1, -1, 0);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
free(subject);
|
free(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x509_set_altname(X509 *crt, int type, const char *sanfile, char **subjectname)
|
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_NAMES *gens = NULL;
|
||||||
GENERAL_NAME *gen = NULL;
|
GENERAL_NAME *gen = NULL;
|
||||||
ASN1_IA5STRING *ia5 = 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){
|
if (buff == NULL){
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
char seps1[] = "\n", seps[] = ";";
|
char *sanline = NULL, *host = NULL;
|
||||||
char *sanline=NULL, *host = NULL;
|
char seps[] = ";";
|
||||||
if (buff[0] != '\n')
|
sanline = strtok(buff, seps);
|
||||||
{
|
|
||||||
char *subject = strtok(buff, seps1);
|
|
||||||
if (subject != NULL)
|
|
||||||
{
|
|
||||||
*subjectname = strdup(subject);
|
|
||||||
}
|
|
||||||
sanline = strtok(NULL, seps);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
sanline = strtok(buff+1, seps);
|
|
||||||
}
|
|
||||||
while (sanline)
|
while (sanline)
|
||||||
{
|
{
|
||||||
asprintf(&host, "%s", sanline);
|
asprintf(&host, "%s", sanline);
|
||||||
|
if (num == 0)
|
||||||
|
{
|
||||||
|
*subjectname = host;
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
gen = GENERAL_NAME_new();
|
gen = GENERAL_NAME_new();
|
||||||
if (gen == NULL)
|
if (gen == NULL)
|
||||||
goto out;
|
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);
|
sk_GENERAL_NAME_push(gens, gen);
|
||||||
gen = NULL;
|
gen = NULL;
|
||||||
free(host);
|
free(host);
|
||||||
|
next:
|
||||||
sanline = strtok(NULL, seps);
|
sanline = strtok(NULL, seps);
|
||||||
if (sanline == NULL || strlen(sanline) == 1)
|
if (sanline == NULL || strlen(sanline) == 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
num++;
|
||||||
}
|
}
|
||||||
if (!X509_add1_ext_i2d(crt, NID_subject_alt_name, gens, 0, 0))
|
if (!X509_add1_ext_i2d(crt, NID_subject_alt_name, gens, 0, 0))
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
Reference in New Issue
Block a user