]> WPIA git - cassiopeia.git/blob - test/src/X509Req.cpp
upd: move more code to remoteSigner
[cassiopeia.git] / test / src / X509Req.cpp
1 #include <iostream>
2
3 #include <boost/test/unit_test.hpp>
4
5 #include <openssl/err.h>
6
7 #include "X509.h"
8 #include "util.h"
9
10 BOOST_AUTO_TEST_SUITE( TestX509Req )
11
12 BOOST_AUTO_TEST_CASE( CSR ) {
13     // Testing a valid CSR
14     std::shared_ptr<X509Req> req( X509Req::parseCSR( readFile( "testdata/test.csr" ) ) );
15     BOOST_REQUIRE( req );
16     BOOST_CHECK( req->verify() == 1 );
17     BOOST_REQUIRE( ERR_peek_error() == 0 );
18
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" ) ) );
21     BOOST_REQUIRE( req );
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 );
27
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" ) ) );
30     BOOST_REQUIRE( req );
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 );
34 }
35
36 BOOST_AUTO_TEST_CASE( SPKAC ) {
37     // Testing a valid SPKAC
38     std::shared_ptr<X509Req> req( X509Req::parseSPKAC( readFile( "testdata/test.spkac" ) ) );
39     BOOST_REQUIRE( req );
40     BOOST_CHECK( req->verify() == 1 );
41
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" ) ) );
44     BOOST_REQUIRE( req );
45     BOOST_CHECK( req->verify() == 0 );
46
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" ) ) );
49     BOOST_REQUIRE( req );
50     BOOST_CHECK( req->verify() < 0 );
51 }
52
53 BOOST_AUTO_TEST_SUITE_END()