Certificate

Certificate provides necessary functionality to create and read X509 Certificates.

Note, once a Certificate has been signed, it is immutable, and cannot be modified.

X509 Certificates are sometimes called SSL Certificates.

Example

auto newPkey = new PrivateKey(2048); // create new keypair
auto cert = new Certificate();
cert.privateKey = newPkey;
cert.serialNumber = 1;
cert.dateBeforeOffset = TimeSpan.zero;
cert.dateAfterOffset = TimeSpan.days(365); // cert is valid for one year
cert.setSubject("US", "State", "City", "Organization", "CN", "Organizational Unit", "Email");
cert.sign(cert, newPkey); // self signed cert
Stdout(newPkey.pemFormat).newline;
Stdout(cert.pemFormat).newline;

Constructors

this
this(X509* cert)
Undocumented in source.
this
this(const(ubyte)[] publicPemData)

Parses a X509 Certificate from the provided PEM encoded data.

this
this()

Creates a new and un-signed (empty) X509 certificate. Useful for generating X509 certificates programatically.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

dateAfter
char[] dateAfter()

Returns the dateAfter field of the certificate in ASN1_GENERALIZEDTIME.

dateAfterOffset
Certificate dateAfterOffset(TimeSpan t)

If the current date is "after" the date set here, the certificate will be invalid.

dateBefore
char[] dateBefore()

Returns the dateBefore field of the certificate in ASN1_GENERALIZEDTIME.

dateBeforeOffset
Certificate dateBeforeOffset(TimeSpan t)

If the current date is "before" the date set here, the certificate will be invalid.

opEquals
bool opEquals(Object obj)

Checks if the underlying data structur of the Certificate is equal

pemFormat
string pemFormat()

Returns the Certificate in a PEM encoded string.

privateKey
Certificate privateKey(PrivateKey key)

Sets the public/private keypair of an unsigned certificate.

serialNumber
Certificate serialNumber(uint serial)

Sets the serial number of the new unsigned certificate.

serialNumber
uint serialNumber()

Returns the serial number of the Certificate

setSubject
Certificate setSubject(const(char)[] country, const(char)[] stateProvince, const(char)[] city, const(char)[] organization, const(char)[] cn, const(char)[] organizationalUnit, const(char)[] email)

Sets the subject (who this certificate is for) of an unsigned certificate.

sign
Certificate sign(Certificate caCert, PrivateKey caKey)

Signs the unsigned Certificate with the specified CA X509 Certificate and it's corresponding public/private keypair.

subject
char[] subject()

Returns the Certificate subject in a multi-line string.

verify
bool verify(CertificateStore store)

Verifies that the Certificate was signed and issues by a CACert in the passed CertificateStore.

Variables

_cert
X509* _cert;
Undocumented in source.

Meta