Search K
Appearance
Appearance
Other ways to support HackTricks:
Use Trickest to easily build and automate workflows powered by the world's most advanced community tools.
Get Access Today:
A public key certificate is a digital ID used in cryptography to prove someone owns a public key. It includes the key's details, the owner's identity (the subject), and a digital signature from a trusted authority (the issuer). If the software trusts the issuer and the signature is valid, secure communication with the key's owner is possible.
Certificates are mostly issued by certificate authorities (CAs) in a public-key infrastructure (PKI) setup. Another method is the web of trust, where users directly verify each otherโs keys. The common format for certificates is X.509, which can be adapted for specific needs as outlined in RFC 5280.
In x509 certificates, several fields play critical roles in ensuring the certificate's validity and security. Here's a breakdown of these fields:
# Example of accessing and using x509 certificate fields programmatically:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
# Load an x509 certificate (assuming cert.pem is a certificate file)
with open("cert.pem", "rb") as file:
cert_data = file.read()
certificate = x509.load_pem_x509_certificate(cert_data, default_backend())
# Accessing fields
serial_number = certificate.serial_number
issuer = certificate.issuer
subject = certificate.subject
public_key = certificate.public_key()
print(f"Serial Number: {serial_number}")
print(f"Issuer: {issuer}")
print(f"Subject: {subject}")
print(f"Public Key: {public_key}")
OCSP (RFC 2560) involves a client and a responder working together to check if a digital public-key certificate has been revoked, without needing to download the full CRL. This method is more efficient than the traditional CRL, which provides a list of revoked certificate serial numbers but requires downloading a potentially large file. CRLs can include up to 512 entries. More details are available here.
Certificate Transparency helps combat certificate-related threats by ensuring the issuance and existence of SSL certificates are visible to domain owners, CAs, and users. Its objectives are:
Certificate logs are publicly auditable, append-only records of certificates, maintained by network services. These logs provide cryptographic proofs for auditing purposes. Both issuance authorities and the public can submit certificates to these logs or query them for verification. While the exact number of log servers is not fixed, it's expected to be less than a thousand globally. These servers can be independently managed by CAs, ISPs, or any interested entity.
To explore Certificate Transparency logs for any domain, visit https://crt.sh/.
Different formats exist for storing certificates, each with its own use cases and compatibility. This summary covers the main formats and provides guidance on converting between them.
PEM conversions are essential for compatibility:
openssl x509 -in certificatename.cer -outform PEM -out certificatename.pem
openssl x509 -outform der -in certificatename.pem -out certificatename.der
openssl x509 -inform der -in certificatename.der -out certificatename.pem
openssl crl2pkcs7 -nocrl -certfile certificatename.pem -out certificatename.p7b -certfile CACert.cer
openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.pem
PFX conversions are crucial for managing certificates on Windows:
openssl pkcs12 -in certificatename.pfx -out certificatename.pem
openssl pkcs12 -in certificatename.pfx -nocerts -nodes -out certificatename.pem
openSSL pkcs8 -in certificatename.pem -topk8 -nocrypt -out certificatename.pk8
openssl pkcs7 -print_certs -in certificatename.p7b -out certificatename.cer
openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile cacert.cer
Use Trickest to easily build and automate workflows powered by the world's most advanced community tools.
Get Access Today:
Other ways to support HackTricks: