int main(void)
{
{
std::cout << "*** ERROR: Failed to generate CA key" << std::endl;
return 1;
}
{
std::cout << "*** WARNING: Failed to write CA key file" << std::endl;
}
ca_exts.
addKeyUsage(
"critical, cRLSign, digitalSignature, keyCertSign");
time_t t = time(nullptr);
std::cout << "--------------- CA Certificate ----------------" << std::endl;
std::cout << "-----------------------------------------------" << std::endl;
{
std::cout << "*** WARNING: Failed to write CA certificate file"
<< std::endl;
}
{
std::cout << "*** ERROR: Failed to generate server certificate key"
<< std::endl;
return 1;
}
{
std::cout << "*** WARNING: Failed to write CA key file" << std::endl;
}
"DNS:hostname.example.org"
", DNS:alias.example.org"
", DNS:localhost"
", IP:127.0.0.1"
", email:admin@example.org"
", URI:https://www.example.org"
", otherName:msUPN;UTF8:sb@sb.local");
std::cout << "--------- Certificate Signing Request ---------" << std::endl;
std::cout << "-----------------------------------------------" << std::endl;
{
std::cout << "*** WARNING: Failed to write CSR file" << std::endl;
}
std::cout << "The CSR verification "
<< (csr.
verify(cert_pkey) ?
"PASSED" :
"FAILED")
<< std::endl;
cert_exts.
addKeyUsage(
"critical, nonRepudiation, digitalSignature, keyEncipherment, keyAgreement");
std::cout << "------------- Server Certificate --------------" << std::endl;
std::cout << "-----------------------------------------------" << std::endl;
{
std::cout << "*** WARNING: Failed to write certificate file"
<< std::endl;
}
std::cout << "The certificate verification "
<< (cert.
verify(ca_pkey) ?
"PASSED" :
"FAILED")
<< std::endl;
return 0;
}
SSL context meant to be used with TcpConnection and friends.
Represent private and public keys.
Implements a representation of a X.509 certificate.
A class representing a certificate signing request.
void addExtensions(SslX509Extensions &exts)
Add extensions to this CSR.
const X509_NAME * subjectName(void) const
Return the subject name as a X509_NAME pointer.
bool setPublicKey(SslKeypair &pubkey)
Set the public key.
void print(const std::string &prefix="") const
Print the info in this CSR to std::cout.
SslKeypair publicKey(void) const
Get the public key.
SslX509Extensions extensions(void) const
Get the extensions in this CSR.
bool writePemFile(FILE *f)
Write the CSR data to a PEM file.
bool verify(SslKeypair &pubkey) const
Verify the signature of this CSR.
bool sign(SslKeypair &privkey)
Sign the CSR using the given private key.
bool addSubjectName(const std::string &field, const std::string &value)
Add a subject name component.
bool setVersion(long version)
Set the version of the request.
A class representing private and public keys.
bool writePrivateKeyFile(const std::string &filename)
Write key data to file on PEM format.
bool generate(unsigned int bits)
Generate a new RSA keypair.
A class representing the X.509 Subject Alternative Name extension.
A class representing X.509 extensions.
bool addExtKeyUsage(const std::string &eku)
Add extended key usage.
bool addSubjectAltNames(const std::string &san)
Add subject alternative names.
bool addExtension(const SslX509ExtSubjectAltName &san)
Add a subject alternative names object.
bool addBasicConstraints(const std::string &bc)
Add basic constraints extension.
bool addKeyUsage(const std::string &ku)
Add key usage.
A class representing an X.509 certificate.
void addIssuerName(const std::string &field, const std::string &value)
Add a name to the issuer distinguished name.
void print(const std::string &prefix="") const
Print this certificate to std::cout.
void setSerialNumber(long serial_number=-1)
Set the serial number of the certificate.
bool setPublicKey(SslKeypair &pkey)
Set the public key for this certificate.
bool verify(SslKeypair &keypair)
Verify that this certificate is signed by the given key.
const X509_NAME * subjectName(void) const
Get the subject distinguished name.
bool setSubjectName(const X509_NAME *name)
Set the subject distinguished name.
bool writePemFile(FILE *f)
Write this certificate to file in PEM format.
bool setIssuerName(const X509_NAME *name)
Set the issuer distinguished name.
void addExtensions(const SslX509Extensions &exts)
Add v3 extensions to this certificate.
bool sign(SslKeypair &pkey)
Sign this certificate using the given key.
const X509_NAME * issuerName(void) const
Get the issuer distinguished name.
void setNotBefore(std::time_t in_time)
Set the date and time from which this certificate is valid.
void setNotAfter(std::time_t in_time)
Set the date and time up to which this certificate is valid.
bool setVersion(long version)
Set the version of this certificate.