Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CRL examples #120

Merged
merged 6 commits into from
Nov 28, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Generate CRL certificates
shoracek committed Nov 24, 2021
commit 7dad57dad4ff5f9898c83a46d9b122c05c55c45e
87 changes: 87 additions & 0 deletions validation/certs/scripts/chains/cert_revoked/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import asn1tools
from utils import x509
from utils import io
from utils import misc
from utils import crypto

VALID_ASN_FILE = 'valid.asn'
EXPORTED_KEY_NAME = 'key.pem'
EXPORTED_CHAIN_NAME = 'chain.pem'
EXPORTED_CRL_NAME = 'crl.der'


def main():
args = misc.parse_arguments()

# Compile the ASN.1 specification
asn = asn1tools.compile_files(args.asn_dir + VALID_ASN_FILE, 'der')

# Import the root private key and cert
root_privkey = io.import_rsa_private_key(args.root_key_file)
root_pubkey = root_privkey.publickey()

# Generate an RSA public key pair for intermediate CA
(sub_privkey, sub_pubkey) = crypto.new_rsa_keypair(2048)

# Encode intermediate tbsCertificate
sub_tbs = x509.default_tbs(issuer_public_key=root_pubkey,
subject_public_key=sub_pubkey,
issuer_cn='root',
subject_cn='intermediate',
is_ca=True,
additional_extensions=[],
asn=asn)
sub_tbs_der = asn.encode('TBSCertificate', sub_tbs)

# Sign the intermediate tbsCertificate
sub_sig = crypto.rsa_sha256_sign(root_privkey, sub_tbs_der)

# Encode the intermediate CA Certificate
sub_cert_der = x509.certificate(sub_tbs, sub_sig, asn)

# Generate an RSA public key pair for end entity certificate
(end_privkey, end_pubkey) = crypto.new_rsa_keypair(2048)

# Encode end entity tbsCertificate
end_tbs = x509.default_tbs(issuer_public_key=sub_pubkey,
subject_public_key=end_pubkey,
issuer_cn='intermediate',
subject_cn='localhost',
is_ca=False,
additional_extensions=[x509.crl_distribution_points(['http://localhost:49999/crl.der'], asn)],
asn=asn)
end_tbs_der = asn.encode('TBSCertificate', end_tbs)

# Sign the end entity tbsCertificate
end_sig = crypto.rsa_sha256_sign(sub_privkey, end_tbs_der)

# Encode the end entity Certificate
end_cert_der = x509.certificate(end_tbs, end_sig, asn)

# Create the CRL entry
crl_entry_tbs = x509.revoked_certificate(end_tbs['serialNumber'],
('generalTime', misc.current_time()))
# Create the CRL
crl_tbs = x509.default_tbs_crl(issuer_public_key=sub_pubkey,
issuer_cn='intermediate',
number=1,
revoked=[crl_entry_tbs],
additional_extensions=[],
asn=asn)
crl_tbs_der = asn.encode('TBSCertList', crl_tbs)
crl_sig = crypto.rsa_sha256_sign(sub_privkey, crl_tbs_der)
crl_der = x509.certificate_list(crl_tbs, crl_sig, asn)

# Write the chain into file
io.export_chain([end_cert_der, sub_cert_der],
args.build_dir + EXPORTED_CHAIN_NAME)

# Write the CRL into file
io.export_crl(crl_der, args.build_dir + EXPORTED_CRL_NAME)

# Export the private key
io.export_private_key(end_privkey, args.build_dir + EXPORTED_KEY_NAME)


if __name__ == "__main__":
main()
15 changes: 15 additions & 0 deletions validation/certs/scripts/chains/cert_revoked/vconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
servers:
main: {}

verify:
openssl:
options:
flags: "--check_crl"
gnutls:
options: {}
mbedtls:
options: {}
botan:
options: {}
openjdk:
options: {}
88 changes: 88 additions & 0 deletions validation/certs/scripts/chains/crl_has_expired/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import asn1tools
from utils import x509
from utils import io
from utils import misc
from utils import crypto

VALID_ASN_FILE = 'valid.asn'
EXPORTED_KEY_NAME = 'key.pem'
EXPORTED_CHAIN_NAME = 'chain.pem'
EXPORTED_CRL_NAME = 'crl.der'


def main():
args = misc.parse_arguments()

# Compile the ASN.1 specification
asn = asn1tools.compile_files(args.asn_dir + VALID_ASN_FILE, 'der')

# Import the root private key and cert
root_privkey = io.import_rsa_private_key(args.root_key_file)
root_pubkey = root_privkey.publickey()

# Generate an RSA public key pair for intermediate CA
(sub_privkey, sub_pubkey) = crypto.new_rsa_keypair(2048)

# Encode intermediate tbsCertificate
sub_tbs = x509.default_tbs(issuer_public_key=root_pubkey,
subject_public_key=sub_pubkey,
issuer_cn='root',
subject_cn='intermediate',
is_ca=True,
additional_extensions=[],
asn=asn)
sub_tbs_der = asn.encode('TBSCertificate', sub_tbs)

# Sign the intermediate tbsCertificate
sub_sig = crypto.rsa_sha256_sign(root_privkey, sub_tbs_der)

# Encode the intermediate CA Certificate
sub_cert_der = x509.certificate(sub_tbs, sub_sig, asn)

# Generate an RSA public key pair for end entity certificate
(end_privkey, end_pubkey) = crypto.new_rsa_keypair(2048)

# Encode end entity tbsCertificate
end_tbs = x509.default_tbs(issuer_public_key=sub_pubkey,
subject_public_key=end_pubkey,
issuer_cn='intermediate',
subject_cn='localhost',
is_ca=False,
additional_extensions=[x509.crl_distribution_points(['http://localhost:49999/crl.der'], asn)],
asn=asn)
end_tbs_der = asn.encode('TBSCertificate', end_tbs)

# Sign the end entity tbsCertificate
end_sig = crypto.rsa_sha256_sign(sub_privkey, end_tbs_der)

# Encode the end entity Certificate
end_cert_der = x509.certificate(end_tbs, end_sig, asn)

# Create the CRL entry
crl_entry_tbs = x509.revoked_certificate(end_tbs['serialNumber'],
('generalTime', misc.current_time()))
# Create the CRL
crl_tbs = x509.default_tbs_crl(issuer_public_key=sub_pubkey,
issuer_cn='intermediate',
number=1,
revoked=[crl_entry_tbs],
additional_extensions=[],
asn=asn)
crl_tbs['nextUpdate'] = ('generalTime', misc.current_time_offset(0))
crl_tbs_der = asn.encode('TBSCertList', crl_tbs)
crl_sig = crypto.rsa_sha256_sign(sub_privkey, crl_tbs_der)
crl_der = x509.certificate_list(crl_tbs, crl_sig, asn)

# Write the chain into file
io.export_chain([end_cert_der, sub_cert_der],
args.build_dir + EXPORTED_CHAIN_NAME)

# Write the CRL into file
io.export_crl(crl_der, args.build_dir + EXPORTED_CRL_NAME)

# Export the private key
io.export_private_key(end_privkey, args.build_dir + EXPORTED_KEY_NAME)


if __name__ == "__main__":
main()
15 changes: 15 additions & 0 deletions validation/certs/scripts/chains/crl_has_expired/vconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
servers:
main: {}

verify:
openssl:
options:
flags: "--check_crl"
gnutls:
options: {}
mbedtls:
options: {}
botan:
options: {}
openjdk:
options: {}
88 changes: 88 additions & 0 deletions validation/certs/scripts/chains/crl_not_yet_valid/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import asn1tools
from utils import x509
from utils import io
from utils import misc
from utils import crypto

VALID_ASN_FILE = 'valid.asn'
EXPORTED_KEY_NAME = 'key.pem'
EXPORTED_CHAIN_NAME = 'chain.pem'
EXPORTED_CRL_NAME = 'crl.der'


def main():
args = misc.parse_arguments()

# Compile the ASN.1 specification
asn = asn1tools.compile_files(args.asn_dir + VALID_ASN_FILE, 'der')

# Import the root private key and cert
root_privkey = io.import_rsa_private_key(args.root_key_file)
root_pubkey = root_privkey.publickey()

# Generate an RSA public key pair for intermediate CA
(sub_privkey, sub_pubkey) = crypto.new_rsa_keypair(2048)

# Encode intermediate tbsCertificate
sub_tbs = x509.default_tbs(issuer_public_key=root_pubkey,
subject_public_key=sub_pubkey,
issuer_cn='root',
subject_cn='intermediate',
is_ca=True,
additional_extensions=[],
asn=asn)
sub_tbs_der = asn.encode('TBSCertificate', sub_tbs)

# Sign the intermediate tbsCertificate
sub_sig = crypto.rsa_sha256_sign(root_privkey, sub_tbs_der)

# Encode the intermediate CA Certificate
sub_cert_der = x509.certificate(sub_tbs, sub_sig, asn)

# Generate an RSA public key pair for end entity certificate
(end_privkey, end_pubkey) = crypto.new_rsa_keypair(2048)

# Encode end entity tbsCertificate
end_tbs = x509.default_tbs(issuer_public_key=sub_pubkey,
subject_public_key=end_pubkey,
issuer_cn='intermediate',
subject_cn='localhost',
is_ca=False,
additional_extensions=[x509.crl_distribution_points(['http://localhost:49999/crl.der'], asn)],
asn=asn)
end_tbs_der = asn.encode('TBSCertificate', end_tbs)

# Sign the end entity tbsCertificate
end_sig = crypto.rsa_sha256_sign(sub_privkey, end_tbs_der)

# Encode the end entity Certificate
end_cert_der = x509.certificate(end_tbs, end_sig, asn)

# Create the CRL entry
crl_entry_tbs = x509.revoked_certificate(end_tbs['serialNumber'],
('generalTime', misc.current_time()))
# Create the CRL
crl_tbs = x509.default_tbs_crl(issuer_public_key=sub_pubkey,
issuer_cn='intermediate',
number=1,
revoked=[crl_entry_tbs],
additional_extensions=[],
asn=asn)
crl_tbs['thisUpdate'] = ('generalTime', misc.current_time_offset(364))
crl_tbs_der = asn.encode('TBSCertList', crl_tbs)
crl_sig = crypto.rsa_sha256_sign(sub_privkey, crl_tbs_der)
crl_der = x509.certificate_list(crl_tbs, crl_sig, asn)

# Write the chain into file
io.export_chain([end_cert_der, sub_cert_der],
args.build_dir + EXPORTED_CHAIN_NAME)

# Write the CRL into file
io.export_crl(crl_der, args.build_dir + EXPORTED_CRL_NAME)

# Export the private key
io.export_private_key(end_privkey, args.build_dir + EXPORTED_KEY_NAME)


if __name__ == "__main__":
main()
15 changes: 15 additions & 0 deletions validation/certs/scripts/chains/crl_not_yet_valid/vconfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
servers:
main: {}

verify:
openssl:
options:
flags: "--check_crl"
gnutls:
options: {}
mbedtls:
options: {}
botan:
options: {}
openjdk:
options: {}
Loading