提交 1efd98f9 编写于 作者: P Paul Yang 提交者: Matt Caswell
上级 09ddb878
...@@ -45,85 +45,61 @@ static int test_x509_check_cert_pkey(const char *c, const char *k, ...@@ -45,85 +45,61 @@ static int test_x509_check_cert_pkey(const char *c, const char *k,
if (strcmp(e, "ok") == 0) { if (strcmp(e, "ok") == 0) {
expected = 1; expected = 1;
} else if (strcmp(e, "failed") == 0) { } else if (strcmp(e, "failed") == 0) {
expected = 2; expected = 0;
} else { } else {
TEST_error("invalid 'expected'"); TEST_error("invalid 'expected'");
goto failed; goto failed;
} }
/* process private key */ /* process private key */
bio = BIO_new_file(k, "r"); if (!TEST_ptr(bio = BIO_new_file(k, "r")))
if (bio == NULL) {
TEST_error("create BIO for private key failed");
goto failed; goto failed;
}
pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL); if (!TEST_ptr(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)))
if (pkey == NULL) {
TEST_error("read PEM private key failed");
goto failed; goto failed;
}
BIO_free(bio); BIO_free(bio);
/* process cert or cert request, use the same local var */ /* process cert or cert request, use the same local var */
bio = BIO_new_file(c, "r"); if (!TEST_ptr(bio = BIO_new_file(c, "r")))
if (bio == NULL) {
TEST_error("create BIO for cert or cert req failed");
goto failed; goto failed;
}
switch (type) { switch (type) {
case 1: case 1:
x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL); x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL);
if (x509 == NULL) { if (x509 == NULL) {
TEST_error("read PEM x509 failed"); TEST_error("read PEM x509 failed");
goto failed;
}
result = X509_check_private_key(x509, pkey);
break;
case 2:
x509_req = PEM_read_bio_X509_REQ(bio, NULL, NULL, NULL);
if (x509_req == NULL) {
TEST_error("read PEM x509 req failed");
goto failed;
}
result = X509_REQ_check_private_key(x509_req, pkey);
break;
default:
/* should never be here */
break;
}
if (expected == 1) {
/* expected == 1 means we expect an "ok" */
if (!TEST_int_eq(result, 1)) {
TEST_error("check private key: expected: 1, got: %d", result);
goto failed; goto failed;
} }
} else {
if (!TEST_int_eq(result, 0)) { result = X509_check_private_key(x509, pkey);
TEST_error("check private key: expected: 0, got: %d", result); break;
case 2:
x509_req = PEM_read_bio_X509_REQ(bio, NULL, NULL, NULL);
if (x509_req == NULL) {
TEST_error("read PEM x509 req failed");
goto failed; goto failed;
} }
result = X509_REQ_check_private_key(x509_req, pkey);
break;
default:
/* should never be here */
break;
} }
out: if (!TEST_int_eq(result, expected)) {
if (bio) TEST_error("check private key: expected: %d, got: %d", expected, result);
BIO_free(bio); goto failed;
if (x509) }
X509_free(x509);
if (x509_req)
X509_REQ_free(x509_req);
if (pkey)
EVP_PKEY_free(pkey);
return ret;
failed:
ret = 1; ret = 1;
goto out; failed:
BIO_free(bio);
X509_free(x509);
X509_REQ_free(x509_req);
EVP_PKEY_free(pkey);
return ret;
} }
int test_main(int argc, char **argv) int test_main(int argc, char **argv)
...@@ -134,5 +110,5 @@ int test_main(int argc, char **argv) ...@@ -134,5 +110,5 @@ int test_main(int argc, char **argv)
return 1; return 1;
} }
return test_x509_check_cert_pkey(argv[1], argv[2], argv[3], argv[4]); return !test_x509_check_cert_pkey(argv[1], argv[2], argv[3], argv[4]);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册