std::string date = rev.second;
const unsigned char* pos = ( const unsigned char* ) date.data();
std::shared_ptr<ASN1_TIME> time( d2i_ASN1_TIME( NULL, &pos, date.size() ), ASN1_TIME_free );
- std::shared_ptr<ASN1_GENERALIZEDTIME> gtime( ASN1_TIME_to_generalizedtime( time.get(), 0 ) );
- std::string strdate( ( char* ) ASN1_STRING_data( gtime.get() ), ASN1_STRING_length( gtime.get() ) );
- if( strdate[strdate.size() - 1] != 'Z' ) {
- throw "Got invalid date?";
- }
-
- jp->writeBackRevocation( job, strdate.substr( 0, strdate.size() - 1 ) );
+ jp->writeBackRevocation( job, timeToString( time ) );
jp->finishJob( job );
} catch( const char* c ) {
std::cout << "Exception: " << c << std::endl;
[]( char* p ) {
OPENSSL_free( p );
} ); // OPENSSL_free is a macro...
+
+ extractTimes( pem, result );
+
result->serial = std::string( serStr.get() );
}
ASN1_TIME* tm = X509_get_notBefore( ca );
notBefore = std::shared_ptr<ASN1_TIME>( tm, ASN1_TIME_free );
}
+
+std::string timeToString( std::shared_ptr<ASN1_TIME> time ) {
+ std::shared_ptr<ASN1_GENERALIZEDTIME> gtime( ASN1_TIME_to_generalizedtime( time.get(), 0 ) );
+ std::string strdate( ( char* ) ASN1_STRING_data( gtime.get() ), ASN1_STRING_length( gtime.get() ) );
+
+ if( strdate[strdate.size() - 1] != 'Z' ) {
+ throw "Got invalid date?";
+ }
+
+ return strdate.substr( 0, strdate.size() - 1 );
+}
+
+void extractTimes( std::shared_ptr<X509> target, std::shared_ptr<SignedCertificate> cert ) {
+ cert->before = timeToString( std::shared_ptr<ASN1_TIME>( X509_get_notBefore( target.get() ), ASN1_TIME_free ) );
+ cert->after = timeToString( std::shared_ptr<ASN1_TIME>( X509_get_notAfter( target.get() ), ASN1_TIME_free ) );
+}
#pragma once
-#include <openssl/ssl.h>
+
#include <memory>
#include <string>
#include <vector>
#include <cinttypes>
+#include <openssl/ssl.h>
+
+#include "db/database.h"
+
class CAConfig {
public:
std::string path;
std::shared_ptr<EVP_PKEY> caKey;
std::shared_ptr<ASN1_TIME> notBefore;
CAConfig( std::string name );
-
};
struct Profile {
std::shared_ptr<SSL_CTX> generateSSLContext( bool server );
std::shared_ptr<BIO> openSerial( const std::string name );
+std::string timeToString( std::shared_ptr<ASN1_TIME> time );
+void extractTimes( std::shared_ptr<X509> source, std::shared_ptr<SignedCertificate> cert );
struct SignedCertificate {
std::string certificate;
std::string serial;
- uint32_t before;
- uint32_t after;
+ std::string before;
+ std::string after;
std::string pkHash;
std::string certHash;
std::string crt_name;
read_id = std::string( row[0], row[0] + l[0] );
}
- std::string q = "UPDATE certs SET crt_name='" + this->escape_string( res->crt_name ) + "', serial='" + this->escape_string( res->serial ) + "', caId = '" + this->escape_string( read_id ) + "', created=NOW() WHERE id='" + this->escape_string( job->target ) + "' LIMIT 1";
-
+ std::string q = "UPDATE certs SET crt_name='" + this->escape_string( res->crt_name ) + "', serial='" + this->escape_string( res->serial ) + "', caId = '" + this->escape_string( read_id ) + "', created='" + this->escape_string( res->before ) + "', expire='" + this->escape_string( res->after ) + "' WHERE id='" + this->escape_string( job->target ) + "' LIMIT 1";
// TODO write more thingies back
if( query( q ).first ) {