]> WPIA git - cassiopeia.git/commitdiff
upd: add a shared_ptr, rename parse to parseCSR...
authorFelix Dörre <felix@dogcraft.de>
Sun, 16 Nov 2014 18:39:29 +0000 (19:39 +0100)
committerBenny Baumann <BenBE@geshi.org>
Sat, 24 Jan 2015 16:39:29 +0000 (17:39 +0100)
src/X509.cpp
src/X509.h
src/simpleOpensslSigner.cpp
src/util.cpp
src/util.h
test/src/X509Req.cpp

index 8bd8137f28295350fb275b1f9b74ea606e1f0e6f..d5f8bc50d52d33970ea436094c28cebb75d9c8ea 100644 (file)
@@ -52,7 +52,7 @@ std::shared_ptr<EVP_PKEY> X509Req::getPkey() {
     return pk;
 }
 
-std::shared_ptr<X509Req> X509Req::parse( std::string content ) {
+std::shared_ptr<X509Req> X509Req::parseCSR( std::string content ) {
     std::shared_ptr<BIO> in = std::shared_ptr<BIO>( BIO_new_mem_buf( const_cast<char*>( content.c_str() ), -1 ), BIO_free );
     X509_REQ* req = PEM_read_bio_X509_REQ( in.get(), NULL, NULL, NULL );
 
index dbc6d0a0df470a76a4dceea1691ddce034f85d1f..5f1b76fe282adeda0ccc7605ad8531494f5de62e 100644 (file)
@@ -15,7 +15,7 @@ private:
     X509Req( X509_REQ* csr );
     X509Req( std::string spkac );
 public:
-    static std::shared_ptr<X509Req> parse( std::string content );
+    static std::shared_ptr<X509Req> parseCSR( std::string content );
     static std::shared_ptr<X509Req> parseSPKAC( std::string content );
     int verify();
     std::shared_ptr<EVP_PKEY> getPkey();
index 1cc08149dba383ae3c6a3ea4fd7737780b7bc547..0096d5ec0457f67ca4f42058fbb8778124753254 100644 (file)
@@ -105,9 +105,12 @@ std::shared_ptr<BIGNUM> SimpleOpensslSigner::nextSerial( uint16_t profile ) {
         throw "Big number math failed while calcing serials.";
     }
 
-    char* serStr = BN_bn2hex( serial.get() );
-    writeFile( serStr, "serial" );
-    OPENSSL_free( serStr );
+    std::shared_ptr<char> serStr = std::shared_ptr<char>(
+        BN_bn2hex( serial.get() ),
+        []( char* ref ) {
+            OPENSSL_free( ref );
+        } );
+    writeFile( "serial", serStr.get() );
 
     return std::shared_ptr<BIGNUM>( BN_bin2bn( data.get(), len + 4 + 16 , 0 ), BN_free );
 }
@@ -122,7 +125,7 @@ std::shared_ptr<SignedCertificate> SimpleOpensslSigner::sign( std::shared_ptr<TB
     if( cert->csr_type == "SPKAC" ) {
         req = X509Req::parseSPKAC( cert->csr_content );
     } else if( cert->csr_type == "CSR" ) {
-        req = X509Req::parse( cert->csr_content );
+        req = X509Req::parseCSR( cert->csr_content );
     } else {
         throw "Error, unknown REQ rype " + ( cert->csr_type );
     }
index b174bb02d3fe30a7b67bd3dc65483d668ab6bc1e..13443af321f7f183cb5c907e744e98740c775bfc 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <fstream>
 
-void writeFile( const std::string& content, const std::string& name ) {
+void writeFile( const std::string& name, const std::string& content ) {
     std::ofstream file;
 
     file.open( name );
index b0d7fce7928459a8efb5a417a5450d915602fa7b..94ca64fa96b8117cc988916f28fabac34c05b2c4 100644 (file)
@@ -2,5 +2,5 @@
 
 #include <string>
 
-void writeFile( const std::string& content, const std::string& name );
+void writeFile( const std::string& name, const std::string& content );
 std::string readFile( const std::string& name );
index 1d230627c66c9d91e4f7bd02e063d7e0e647c640..c6c95ace66a95df140ef8bbc012330e0c13f23d9 100644 (file)
@@ -9,17 +9,17 @@ BOOST_AUTO_TEST_SUITE( TestX509Req )
 
 BOOST_AUTO_TEST_CASE( CSR ) {
     // Testing a valid CSR
-    std::shared_ptr<X509Req> req( X509Req::parse( readFile( "testdata/test.csr" ) ) );
+    std::shared_ptr<X509Req> req( X509Req::parseCSR( readFile( "testdata/test.csr" ) ) );
     BOOST_REQUIRE( req );
     BOOST_CHECK( req->verify() == 1 );
 
     // Testing a CSR, where the signature content has been tampered with
-    req = std::shared_ptr<X509Req>( X509Req::parse( readFile( "testdata/test_false_sig.csr" ) ) );
+    req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_false_sig.csr" ) ) );
     BOOST_REQUIRE( req );
     BOOST_CHECK( req->verify() == 0 );
 
     // Testing a CSR, where the signature OID is something strange
-    req = std::shared_ptr<X509Req>( X509Req::parse( readFile( "testdata/test_invalid_sig.csr" ) ) );
+    req = std::shared_ptr<X509Req>( X509Req::parseCSR( readFile( "testdata/test_invalid_sig.csr" ) ) );
     BOOST_REQUIRE( req );
     BOOST_CHECK( req->verify() < 0 );
 }