3 #include <boost/test/unit_test.hpp>
5 #include <openssl/err.h>
10 BOOST_AUTO_TEST_SUITE( TestX509Req )
12 BOOST_AUTO_TEST_CASE( CSR ) {
13 // Testing a valid CSR
14 std::shared_ptr<X509Req> req( X509Req::parseCSR( readFile( "testdata/test.csr" ) ) );
16 BOOST_CHECK( req->verify() == 1 );
17 BOOST_REQUIRE( ERR_peek_error() == 0 );
19 // Testing a CSR, where the signature content has been tampered with
20 req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_false_sig.csr" ) ) );
22 BOOST_CHECK( req->verify() == 0 );
23 BOOST_REQUIRE( ERR_get_error() != 0 ); // RSA_padding_check_PKCS1_type_1:block type is not 01
24 BOOST_REQUIRE( ERR_get_error() != 0 ); // RSA_EAY_PUBLIC_DECRYPT:padding check failed
25 BOOST_REQUIRE( ERR_get_error() != 0 ); // ASN1_item_verify:EVP lib
26 BOOST_REQUIRE( ERR_get_error() == 0 );
28 // Testing a CSR, where the signature OID is something strange
29 req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_invalid_sig.csr" ) ) );
31 BOOST_CHECK( req->verify() < 0 );
32 BOOST_REQUIRE( ERR_get_error() != 0 ); // ASN1_item_verify:unknown signature algorithm
33 BOOST_REQUIRE( ERR_get_error() == 0 );
36 BOOST_AUTO_TEST_CASE( SPKAC ) {
37 // Testing a valid SPKAC
38 std::shared_ptr<X509Req> req( X509Req::parseSPKAC( readFile( "testdata/test.spkac" ) ) );
40 BOOST_CHECK( req->verify() == 1 );
42 // Testing a SPKAC, where the signature content has been tampered with
43 req = std::shared_ptr<X509Req>( X509Req::parseSPKAC( readFile( "testdata/test_false_sig.spkac" ) ) );
45 BOOST_CHECK( req->verify() == 0 );
47 // Testing a SPKAC, where the signature OID is something strange
48 req = std::shared_ptr<X509Req>( X509Req::parseSPKAC( readFile( "testdata/test_invalid_sig.spkac" ) ) );
50 BOOST_CHECK( req->verify() < 0 );
53 BOOST_AUTO_TEST_SUITE_END()