SimpleOpensslSigner::~SimpleOpensslSigner() {
}
-std::shared_ptr<BIGNUM> SimpleOpensslSigner::nextSerial() {
+std::shared_ptr<BIGNUM> SimpleOpensslSigner::nextSerial( uint16_t profile ) {
std::ifstream serialif( "serial" );
std::string res;
serialif >> res;
std::shared_ptr<unsigned char> data = std::shared_ptr<unsigned char>( ( unsigned char* ) malloc( BN_num_bytes( serial.get() ) + 20 ), free );
int len = BN_bn2bin( serial.get(), data.get() );
+
data.get()[len] = 0x0;
- data.get()[len + 1] = 0x0; // profile id
- data.get()[len + 2] = 0x0;
- data.get()[len + 3] = 0x0; // signer id
+ data.get()[len + 1] = 0x0; // signer id
+
+ data.get()[len + 2] = profile >> 8;
+ data.get()[len + 3] = profile & 0xFF; // profile id
if( !RAND_bytes( data.get() + len + 4, 16 ) || !BN_add_word( serial.get(), 1 ) ) {
throw "Big number math failed while calcing serials.";
c.addRDN( NID_commonName, a->value );
} else if( a->name == "EMAIL" ) {
c.addRDN( NID_pkcs9_emailAddress, a->value );
+ } else if( a->name == "C" ) {
+ c.addRDN( NID_countryName, a->value );
+ } else if( a->name == "L" ) {
+ c.addRDN( NID_localityName, a->value );
+ } else if( a->name == "ST" ) {
+ c.addRDN( NID_stateOrProvinceName, a->value );
+ } else if( a->name == "O" ) {
+ c.addRDN( NID_organizationName, a->value );
+ } else if( a->name == "OU" ) {
+ c.addRDN( NID_organizationalUnitName, a->value );
} else {
throw "unknown AVA-type";
}
c.setIssuerNameFrom( caCert );
c.setPubkeyFrom( req );
- std::shared_ptr<BIGNUM> ser = nextSerial();
+ long int profile = strtol( cert->profile.c_str(), 0, 10 );
+
+ if( profile > 0xFFFF || profile < 0 || ( profile == 0 && cert->profile != "0" ) ) {
+ throw "invalid profile id";
+ }
+
+ std::shared_ptr<BIGNUM> ser = nextSerial( profile );
c.setSerialNumber( ser.get() );
c.setTimes( 0, 60 * 60 * 24 * 10 );
c.setExtensions( caCert, cert->SANs );
- std::shared_ptr<SignedCertificate> output = c.sign( caKey );
+ std::shared_ptr<SignedCertificate> output = c.sign( caKey, cert->md );
return output;
}