certsvc_instance_free(instance);
}
+POSITIVE_TEST_CASE(T_certsvc_certificate_verify)
+{
+ const int MAXC = 3;
+ CertSvcCertificate certs[MAXC];
+ int result;
+ int status;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ makeCertificateFromFile(
+ instance,
+ CertChain::Signer::Path,
+ certs[0],
+ CertChain::Signer::SubjectCommonName);
+
+ makeCertificateFromFile(
+ instance,
+ CertChain::Intermediate::Path,
+ certs[1],
+ CertChain::Intermediate::SubjectCommonName);
+
+ makeCertificateFromFile(
+ instance,
+ CertChain::Root::Path,
+ certs[2],
+ CertChain::Root::SubjectCommonName);
+
+ result = certsvc_certificate_verify(certs[0], &certs[1], MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_SUCCESS);
+
+ result = certsvc_certificate_verify(certs[0], certs, MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_FAIL);
+
+ result = certsvc_certificate_verify(certs[0], certs, 1, certs, MAXC, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_FAIL);
+
+ result = certsvc_certificate_verify(certs[0], &certs[2], 1, certs, MAXC, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_SUCCESS);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], certs, MAXC, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_SUCCESS);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], &certs[2], 1, certs, MAXC, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_SUCCESS);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], certs, MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_FAIL);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], certs, 1, certs, MAXC,&status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, CERTSVC_FAIL);
+
+ for (int i = 0; i < MAXC; i++)
+ certsvc_certificate_free(certs[i]);
+
+ certsvc_instance_free(instance);
+}
+
+NEGATIVE_TEST_CASE(T_certsvc_certificate_verify_invalid_argument)
+{
+ const int MAXC = 3;
+ CertSvcCertificate certs[MAXC];
+ CertSvcCertificate cert;
+ int result;
+ int status = -1;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ makeCertificateFromFile(
+ instance,
+ CertChain::Signer::Path,
+ cert,
+ CertChain::Signer::SubjectCommonName);
+
+ certs[0].privateHandler = 10;
+ certs[0].privateInstance = instance;
+ certs[1].privateHandler = 11;
+ certs[1].privateInstance = instance;
+ certs[2].privateHandler = 12;
+ certs[2].privateInstance = instance;
+
+ result = certsvc_certificate_verify(certs[0], NULL, MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify(certs[0], &certs[1], MAXC - 1, NULL, 0, NULL);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+
+ result = certsvc_certificate_verify(certs[0], &certs[1], MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify(cert, &certs[1], MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify(cert, &cert, 1, &certs[1], MAXC - 1, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], NULL, MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], &certs[1], MAXC - 1, NULL, 0, NULL);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+
+ result = certsvc_certificate_verify_with_caflag(certs[0], &certs[1], MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify_with_caflag(cert, &certs[1], MAXC - 1, NULL, 0, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ result = certsvc_certificate_verify_with_caflag(cert, &cert, 1, &certs[1], MAXC - 1, &status);
+ BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, -1);
+
+ certsvc_certificate_free(cert);
+ certsvc_instance_free(instance);
+}
+
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file