mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-19 19:33:38 +08:00
Fix cleanup bug
This commit is contained in:
@@ -315,6 +315,9 @@ int x509_key_generate(X509_KEY *key, int algor, const void *param, size_t paraml
|
|||||||
void x509_key_cleanup(X509_KEY *key)
|
void x509_key_cleanup(X509_KEY *key)
|
||||||
{
|
{
|
||||||
if (key) {
|
if (key) {
|
||||||
|
if (!key->algor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (key->algor) {
|
switch (key->algor) {
|
||||||
case OID_ec_public_key:
|
case OID_ec_public_key:
|
||||||
switch (key->algor_param) {
|
switch (key->algor_param) {
|
||||||
|
|||||||
@@ -338,22 +338,20 @@ static int test_x509_private_key_info_encrypt_to_pem(void)
|
|||||||
const uint8_t *attrs;
|
const uint8_t *attrs;
|
||||||
size_t attrslen;
|
size_t attrslen;
|
||||||
|
|
||||||
if (!(fp = fopen("test_x509_private_key_info_encrypt_to_pem.pem", "w"))) {
|
if (!(fp = tmpfile())) {
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (x509_private_key_info_encrypt_to_pem(&x509_keys[i], pass, fp) != 1) {
|
if (x509_private_key_info_encrypt_to_pem(&x509_keys[i], pass, fp) != 1) {
|
||||||
error_print();
|
error_print();
|
||||||
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
rewind(fp);
|
||||||
|
|
||||||
if (!(fp = fopen("test_x509_private_key_info_encrypt_to_pem.pem", "r"))) {
|
|
||||||
error_print();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (x509_private_key_info_decrypt_from_pem(&key, &attrs, &attrslen, pass, fp) != 1) {
|
if (x509_private_key_info_decrypt_from_pem(&key, &attrs, &attrslen, pass, fp) != 1) {
|
||||||
error_print();
|
error_print();
|
||||||
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@@ -373,28 +371,23 @@ static int test_x509_private_key_info_encrypt_to_pem(void)
|
|||||||
|
|
||||||
static int test_x509_private_key_info_decrypt_from_pem(void)
|
static int test_x509_private_key_info_decrypt_from_pem(void)
|
||||||
{
|
{
|
||||||
const char *file = "test_x509_private_key_info_decrypt_from_pem.pem";
|
|
||||||
const char *pass = "P@ssw0rd";
|
const char *pass = "P@ssw0rd";
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!(fp = fopen(file, "w"))) {
|
if (!(fp = tmpfile())) {
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < sizeof(tests)/sizeof(tests[0]) && tests[i].algor == OID_ec_public_key; i++) {
|
for (i = 0; i < sizeof(tests)/sizeof(tests[0]) && tests[i].algor == OID_ec_public_key; i++) {
|
||||||
if (x509_private_key_info_encrypt_to_pem(&x509_keys[i], pass, fp) != 1) {
|
if (x509_private_key_info_encrypt_to_pem(&x509_keys[i], pass, fp) != 1) {
|
||||||
error_print();
|
error_print();
|
||||||
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(fp);
|
rewind(fp);
|
||||||
|
|
||||||
if (!(fp = fopen(file, "r"))) {
|
|
||||||
error_print();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int ret;
|
int ret;
|
||||||
X509_KEY key;
|
X509_KEY key;
|
||||||
@@ -403,6 +396,7 @@ static int test_x509_private_key_info_decrypt_from_pem(void)
|
|||||||
|
|
||||||
if ((ret = x509_private_key_info_decrypt_from_pem(&key, &attrs, &attrslen, pass, fp)) < 0) {
|
if ((ret = x509_private_key_info_decrypt_from_pem(&key, &attrs, &attrslen, pass, fp)) < 0) {
|
||||||
error_print();
|
error_print();
|
||||||
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
} else if (ret == 0) {
|
} else if (ret == 0) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -93,8 +93,7 @@ int tlcp_client_main(int argc, char *argv[])
|
|||||||
if (!strcmp(*argv, "-help")) {
|
if (!strcmp(*argv, "-help")) {
|
||||||
printf("usage: gmssl %s %s\n\n", prog, usage);
|
printf("usage: gmssl %s %s\n\n", prog, usage);
|
||||||
printf("%s\n", help);
|
printf("%s\n", help);
|
||||||
ret = 0;
|
return 0;
|
||||||
goto end;
|
|
||||||
} else if (!strcmp(*argv, "-host")) {
|
} else if (!strcmp(*argv, "-host")) {
|
||||||
if (--argc < 1) goto bad;
|
if (--argc < 1) goto bad;
|
||||||
host = *(++argv);
|
host = *(++argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user