add_ext( caCert, target, NID_info_access, "OCSP;URI:http://ocsp.cacert.org" );
add_ext( caCert, target, NID_crl_distribution_points, "URI:http://crl.cacert.org/class3-revoke.crl" );
+ if( sans.size() == 0 ) {
+ return;
+ }
+
std::shared_ptr<GENERAL_NAMES> gens = std::shared_ptr<GENERAL_NAMES>(
sk_GENERAL_NAME_new_null(),
[]( GENERAL_NAMES * ref ) {
int main( int argc, const char* argv[] ) {
( void ) argc;
( void ) argv;
+ bool once = false;
+
+ if( argc == 2 && std::string( "--once" ) == std::string( argv[1] ) ) {
+ once = true;
+ }
+
std::ifstream config;
config.open( "config.txt" );
res->crt_name = fn;
jp->writeBack( job, res );
} catch( const char* c ) {
- std::cerr << c << std::endl;
+ std::cerr << "ERROR: " << c << std::endl;
+ return 2;
+ } catch( std::string c ) {
+ std::cerr << "ERROR: " << c << std::endl;
return 2;
}
} else {
return 1;
}
- if( !DAEMON ) {
+ if( !DAEMON || once ) {
return 0;
}
}
int err = mysql_real_query( this->conn.get(), query.c_str(), query.size() );
if( err ) {
- throw( std::string( "MySQL error: " ) + mysql_error( this->conn.get() ) ).c_str();
+ throw std::string( "MySQL error: " ) + mysql_error( this->conn.get() );
}
auto c = conn;
std::shared_ptr<TBSCertificate> MySQLJobProvider::fetchTBSCert( std::shared_ptr<Job> job ) {
std::shared_ptr<TBSCertificate> cert = std::shared_ptr<TBSCertificate>( new TBSCertificate() );
- std::string q = "SELECT CN, subject, md, profile, csr_name, csr_type FROM certs WHERE id='" + this->escape_string( job->target ) + "'";
+ std::string q = "SELECT md, profile, csr_name, csr_type FROM certs WHERE id='" + this->escape_string( job->target ) + "'";
int err = 0;
return std::shared_ptr<TBSCertificate>();
}
- cert->CN = std::string( row[0], row[0] + l[0] );
- cert->subj = std::string( row[1], row[1] + l[1] );
- cert->md = std::string( row[2], row[2] + l[2] );
- cert->profile = std::string( row[3], row[3] + l[3] );
- cert->csr = std::string( row[4], row[4] + l[4] );
- cert->csr_type = std::string( row[5], row[5] + l[5] );
+ cert->md = std::string( row[0], row[0] + l[0] );
+ cert->profile = std::string( row[1], row[1] + l[1] );
+ cert->csr = std::string( row[2], row[2] + l[2] );
+ cert->csr_type = std::string( row[3], row[3] + l[3] );
cert->SANs = std::vector<std::shared_ptr<SAN>>();
return std::shared_ptr<TBSCertificate>();
}
+ std::cout << "Fetching SANs" << std::endl;
+
while( ( row = mysql_fetch_row( res.get() ) ) ) {
unsigned long* l = mysql_fetch_lengths( res.get() );
cert->SANs.push_back( nSAN );
}
+ q = "SELECT name, value FROM certAvas WHERE certid='" + this->escape_string( job->target ) + "'";
+ std::tie( err, res ) = query( q );
+
+ if( err ) {
+ std::cout << mysql_error( this->conn.get() );
+ return std::shared_ptr<TBSCertificate>();
+
+ }
+
+ while( ( row = mysql_fetch_row( res.get() ) ) ) {
+ unsigned long* l = mysql_fetch_lengths( res.get() );
+
+ if( !l ) {
+ return std::shared_ptr<TBSCertificate>();
+ }
+
+ std::shared_ptr<AVA> nAVA = std::shared_ptr<AVA>( new AVA() );
+ nAVA->name = std::string( row[0], row[0] + l[0] );
+ nAVA->value = std::string( row[1], row[1] + l[1] );
+ cert->AVAs.push_back( nAVA );
+ }
+
return cert;
}
throw "malloc failure";
}
- std::shared_ptr<X509_NAME> subject = std::shared_ptr<X509_NAME>( subjectP, X509_NAME_free );
- const char* strdata = "commonName";
- X509_NAME_add_entry_by_NID( subject.get(), NID_commonName, MBSTRING_UTF8, ( unsigned char* )const_cast<char*>( strdata ), 10, -1, 0 ); // guard
- c.addRDN( NID_commonName, "common-Content" );
+ for( std::shared_ptr<AVA> a : cert->AVAs ) {
+ if( a->name == "CN" ) {
+ c.addRDN( NID_commonName, a->value );
+ } else if( a->name == "EMAIL" ) {
+ c.addRDN( NID_pkcs9_emailAddress, a->value );
+ } else {
+ throw "unknown AVA-type";
+ }
+ }
+
c.setIssuerNameFrom( caCert );
c.setPubkeyFrom( req );
std::shared_ptr<BIGNUM> ser = nextSerial();