
An X509 certificate is made up of several key components, including the certificate's version number, serial number, and issuer's name.
The version number, as we've seen in our example, is always 3.
The serial number is a unique identifier assigned to each certificate, and in our example, it's 1234567890.
This serial number helps ensure that each certificate is unique and can be tracked.
The issuer's name is the entity that issued the certificate, and in our example, it's a company called "Example Corporation".
The issuer's name is usually the organization that issued the certificate, and it's often used to verify the certificate's authenticity.
Introduction
X.509 certificates are a crucial part of online security, used to verify the identity of websites and organizations.
They're essentially digital documents that contain a public key and some identifying information about the owner of the key.
A typical X.509 certificate is issued by a trusted Certificate Authority (CA) and contains a serial number, the subject's public key, and the CA's digital signature.
These certificates are used to establish trust between a web server and a client's browser, ensuring a secure connection.
In the digital world, X.509 certificates are the backbone of secure communication, enabling encryption and authentication.
They're used in various applications, including SSL/TLS, code signing, and email encryption.
A valid X.509 certificate is essential for a secure online experience, and they're used by millions of websites and organizations worldwide.
I've seen firsthand how a secure connection can make a big difference in online transactions and sensitive data exchange.
Readers also liked: Managed Certificates Azure
Key Types and Sizes
RSA keys have a lower limit of 384 bit (not generated) and a successfully tested upper limit of 16384 bit.
OpenSSL limits the RSA keysize per crypto/rsa/rsa.h, and starting with 32k keys, a default compilation of OpenSSL starts to fail verifying the signature.
RSA keys can have any size in bits within the valid range, but the typical hex-boundaries are 512, 1024, 2048, etc. For example, a certificate with a "evil" key length of 999bit is possible.
Explore further: Openssl Get Server Certificate
Here's a breakdown of the RSA key sizes tested:
ECC keys are also possible, and one example certificate has been generated using a 571 bit ECC key, which is one of the highest possible key sizes according to RFC 5480.
Key Sizes
Key sizes play a crucial role in determining the strength and security of a certificate. The smallest possible RSA key size is not explicitly mentioned, but it's known that the smallest successfully tested size is 512 bit.
In reality, most modern certificates use larger key sizes for added protection. For instance, 2048 bit has become a standard, and 4096 bit is not uncommon.
The largest RSA key size that can be successfully tested is 16384 bit, although it's worth noting that OpenSSL limits the RSA keysize to a certain point. This means that attempting to create a certificate with a key size above this limit can result in errors.
Here's a summary of the key sizes mentioned in the article:
Key sizes don't necessarily have to be aligned to typical hex-boundaries, but can have any size in bits within the valid range. For example, a certificate with a "non-standard" key length of 999 bit can be created.
In fact, attempting to create a certificate with a key size above 16384 bit can result in errors due to OpenSSL's limitations. This is evident in the example where a 32k RSA key fails to verify the signature and is unable to sign the certificate request.
ECC Keys, 571 Bit
Elliptic Curve Cryptography (ECC) keys are a type of key that's relatively new and not yet widely used. One example of an ECC key is the 571 bit key.
This key type is considered cutting edge and is rarely used. According to the strength rating in RFC 5480, one example certificate has been generated using one of the highest possible key sizes.

An example certificate using this key type is the sect571r1 certificate. It's a 570 ECC cert in DER format, taking up 610 bytes of space.
Here's a breakdown of the sect571r1 certificate:
- Certificate: 570 ECC cert in DER format, 610 bytes
- Certificate request: 570 ECC cert in PEM format, 883 bytes
- ECC key pair: 570 ECC csr in DER format, 424 bytes and 570 ECC csr in PEM format, 647 bytes
- ECC key: 570 ECC key in DER format, 241 bytes and 570 ECC key in PEM format, 390 bytes
Certificate Structure
The structure of certificates is defined in RFC 5280, which outlines the Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile.
ASN.1 (Abstract Syntax Notation One) is used to represent the data structure of a certificate in an abstract way. Specifications related to ASN.1 are defined in the X.680 series.
DER (Distinguished Encoding Rules) is one of the many specifications used to build a byte sequence from a data structure represented in ASN.1. This byte sequence can then be converted into text data using BASE64 (RFC 4648).
Bundles
Bundles are a crucial part of certificate management, and understanding how they work is essential for secure online transactions.
OpenSSL PKCS12 creation examples can be used to create certificate bundles without a signing certificate, as seen in the example where the password is set to "test".
A PKCS12 certificate bundle can contain multiple certificates, including private keys, and is often used to manage certificates in a single file.
In the example provided, the OpenSSL PKCS12 creation example is used without a signing certificate, which is a key aspect of bundle creation.
Certificate bundles can be created using OpenSSL, and the PKCS12 format is a common choice for this purpose.
Take a look at this: Openssl Certificate Generation
Chain
A certificate chain is formed when multiple certificates are connected, each one verifying the authenticity of the previous one.
Certificates are connected in a chain because each one relies on another to verify its digital signature.
The origin of the chain is a self-signed certificate, also known as a root certificate, which has to be installed in advance as a trusted certificate.
A self-signed certificate is made by self-signing the public key with the paired private key, and the issuer and subject of a self-signed certificate are identical.
The number of intermediate certificates in a chain can be 2 or more, each one verifying the authenticity of the previous one until reaching the root certificate.
Certificates in a chain are connected in a hierarchical structure, with the root certificate at the top and the intermediate certificates below it.
Structure
The structure of a certificate is defined in RFC 5280, which outlines the Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile.
RFC 5280 defines the certificate structure in ASN.1, a notation to represent data structures in an abstract way.
ASN.1 does not define how to embody abstract structures into a specific byte sequence, so another specification is necessary to build a byte sequence from a data structure represented in ASN.1.
Specifications like DER, XER, and JER are used to build a byte sequence from a data structure represented in ASN.1.
DER is used to convert the information into a byte sequence, which becomes binary data.

BASE64 is used to convert the binary data into text data, as it is not suitable to directly display binary data.
BASE64 is defined in RFC 4648.
PEM is a rule used to add information to the text data, such as specifying what the data represents, by using a specific format.
The PEM format includes lines like "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" to indicate the start and end of the certificate.
Encrypted AES Extension
The Encrypted AES Extension is identified by the OID 1.3.6.1.4.1.294.1.66. This extension contains information about a TIFEK(public) encrypted, BMPK(priv) signed AES-256 key.
In the case of Keywriter, the software revision SYSFW and Keywriter: software revision SYSFW WP, RP, OVRD should be same, as these two swrev fields are clubbed together.
Certificate Details
A certificate contains more than just the owner's information. There are four groups of information details inside a certificate.
The subject field holds the distinguished name of the entity associated with the public key, defined in RFC 4514. This field is crucial for identifying the certificate owner.
A distinguished name consists of attributes, such as UID, OU, and CN, which are listed in the specification. The following are examples of distinguished names: UID=jsmith,DC=example,DC=net, OU=Sales+CN=J. Smith,DC=example,DC=net, and CN=James "Jim" Smith\, III,DC=example,DC=net.
Traditionally, a certificate for a website contains the hostname of the server as the value of the CN attribute of the subject distinguished name. The subject field of the certificate for Authlete, Inc.'s website holds a distinguished name whose value is CN=*.authlete.com.
Here are some key properties of a certificate:
Subject
The subject field in a certificate is a crucial piece of information that tells us about the entity associated with the public key. It contains the distinguished name of the entity.
A distinguished name is a way to represent a name as a string, and it's defined in RFC 4514. According to the specification, a distinguished name can have attribute names like UID, OU, and CN.
In the examples provided, we can see different forms of distinguished names. For instance, the first example is UID=jsmith,DC=example,DC=net. The second example is a bit more complex, with OU=Sales+CN=J. Smith,DC=example,DC=net. And the third example has a fancy name, CN=James "Jim" Smith\, III,DC=example,DC=net.
You might enjoy: Print Names
A distinguished name typically consists of attributes, like the ones mentioned above. And in the case of a certificate for a website, the value of the CN (common name) attribute is usually the hostname of the server.
For example, the certificate for the website of Authlete, Inc. has a subject field that holds a distinguished name with the value CN=*.authlete.com.
Here are some key properties of the subject field:
- Serial number: a unique identifier for the certificate
- Thumbprint: a unique identifier for the certificate
- Subject key identifier: an identifier for the public key associated with the subject
These properties can be accessed using code, as shown in the example.
Subject Alternative Name
The Subject Alternative Name, or SAN, is a game-changer for certificates. It allows for multiple subjects to be specified and other identifiers than the hostname to be used.
A certificate has a special place to hold extended data, and that's where the SAN extension comes in. This extension is defined in Section 4.2.1.6 of RFC 5280.
The SAN extension is particularly useful when you need to specify multiple DNS names, like *.authlete.com and authlete.com.
Information for Authority
A certificate authority stores additional information inside a certificate, which is useful for those who receive the certificate to know how to contact the issuing authority for more information.
This information can include the location of the Certificate Revocation List (CRL) and the Online Certificate Status Protocol (OCSP) endpoint.
The Certificate Revocation List (CRL) is a list of certificates that have been revoked, and it's used to verify the status of a certificate.
The Online Certificate Status Protocol (OCSP) endpoint is a URL that can be used to check the status of a certificate in real-time.
Certificate authorities may also include a URL for their Certificate Policies document, which outlines the policies and procedures for issuing certificates.
Some certificate authorities may also include a URL for their CACertificate, which can be used to verify the identity of the authority.
Here are some common information details that can be found for the Certificate Authority:
These URLs can be used to verify the status of a certificate and to contact the certificate authority for more information.
Generation
To generate a self-signed X.509 certificate, you'll need to use a tool like OpenSSL or a library like DidiSoft.OpenSsl.
The OpenSSL command to generate a self-signed certificate is req -x509, which generates a self-signed X.509 certificate instead of a Certificate Signing Request (CSR).
The subject distinguished name for the certificate is specified with the -subj option, and if not given, the OpenSSL command will prompt you to input a subject distinguished name interactively.
You can specify a valid period in days using the -days option, and if no valid period is given, 30 days is used as the default value.
Here are the basic options for the OpenSSL command:
- req -x509 : generates a self-signed X.509 certificate
- -key private_key.pem : specifies the private key for signing and the target public key
- -subj /CN=client.example.com : specifies a subject distinguished name
- -days : specifies a valid period in days
In C# using DidiSoft.OpenSsl, you can generate a self-signed certificate with the following code:
```csharp
OpenSslRsa rsa = new OpenSslRsa();
KeyPair keypair = rsa.GenerateRsaKeyPair(KeyLength.Length2048);
X509Name certificateProperties = new X509Name() { CN = "My Test Name" };
Certificate cert = Certificate.CreateSelfSignedCertificate(keypair.Public, keypair.Private, certificateProperties);
```
This code generates a self-signed certificate with the specified common name and key pair.
Certificate Security and Interoperability
Interoperability with X509Certificate2 is a key feature of the library, allowing seamless integration with default .NET cryptography code.
The X509Certificate2 class can hold a private key, making it a valuable asset in certificate creation and management.
You can create certificates to and from the System.Security.Cryptography.X509Certificate and System.Security.Cryptography.X509Certificate2 class instances using the DidiSoft.OpenSsl.X509.Certificate class.
The value of the X509Certificate2 class lies in its ability to store the corresponding private key.
Here are the key benefits of using X509Certificate2:
To create a self-signed certificate with a private key, you can use the DidiSoft.OpenSsl.X509.Certificate.CreateSelfSignedCertificate method, as shown in the example.
By using the ToX509Certificate2 method, you can easily convert the certificate to an X509Certificate2 instance, including the private key.
Featured Images: pexels.com


