#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import os
import subprocess
"""A class which creates certificates."""
# Allow relative path, but convert it to absolute path first.
# Set up the needed files.
# Set up the names of the needed directories.
# Set up the paths to the certificates that will be needed.
"""Convert a pem file to a human friendly text file."""
"-text"]
assert p.wait() == 0
"""Create a new CA cert."""
if not parent_loc:
if not ta_path:
if https:
assert p.wait() == 0
"-extensions", ext,
new_name),
"-batch"]
if expired:
elif future:
else:
assert p.wait() == 0
"""Create a new code signing cert."""
if not parent_loc:
if not ca_path:
if https:
assert p.wait() == 0
assert p.wait() == 0
if passphrase:
# Add a passphrase to the key just created using a new filename.
new_name),
assert p.wait() == 0
"-extensions", ext,
"-batch"]
if expired:
elif future:
elif expiring:
else:
assert p.wait() == 0
"""Make a new trust anchor."""
if https:
"-days", "1000",
"-sha256"]
assert p.wait() == 0
name))
try:
except:
name))
ca_path=None):
"""Revoke a certificate using the CA given."""
if not ca_dir:
if not cert_dir:
if not ca_path:
assert p.wait() == 0
"-crldays", "1000"]
assert p.wait() == 0
https_subj_str = "/C=US/ST=California/L=Santa Clara/O=pkg5/OU={0}/" \
"CN=localhost/emailAddress={1}"
openssl_conf = """\
HOME = .
RANDFILE = $ENV::HOME/.rnd
[ ca ]
default_ca = CA_default
[ CA_default ]
dir = {base_dir}
x509_extensions = usr_cert
unique_subject = no
default_md = sha256
preserve = no
policy = policy_match
# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
####################################################################
[ req ]
default_bits = 2048
default_keyfile = ./private/ca-key.pem
default_md = sha256
prompt = no
distinguished_name = root_ca_distinguished_name
x509_extensions = v3_ca
string_mask = nombstr
[ root_ca_distinguished_name ]
commonName = ta1
countryName = US
stateOrProvinceName = California
localityName = Santa Clara
0.organizationName = pkg5
emailAddress = ta1@pkg5
[ usr_cert ]
# These extensions are added when 'ca' signs a request.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always
[ v3_req ]
# Extensions to add to a certificate request.
basicConstraints = critical,CA:FALSE
keyUsage = critical, digitalSignature
[ v3_confused_cs ]
# Have CA be true, but don't have keyUsage allow certificate signing to created
# a confused certificate.
basicConstraints = critical,CA:true
keyUsage = critical, digitalSignature
[ v3_no_keyUsage ]
# The extensions to use for a code signing certificate without a keyUsage
# extension.
basicConstraints = critical,CA:FALSE
[ v3_ca ]
# Extensions for a typical CA.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true
keyUsage = critical, keyCertSign, cRLSign
[ v3_ca_lp4 ]
# Extensions for a typical CA.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true,pathlen:4
keyUsage = critical, keyCertSign, cRLSign
[ v3_ca_lp3 ]
# Extensions for a typical CA
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true,pathlen:3
keyUsage = critical, keyCertSign, cRLSign
[ v3_ca_lp2 ]
# Extensions for a typical CA.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true,pathlen:2
keyUsage = critical, keyCertSign, cRLSign
[ v3_ca_lp1 ]
# Extensions for a typical CA.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true,pathlen:1
keyUsage = critical, keyCertSign, cRLSign
[ v3_ca_lp0 ]
# Extensions for a typical CA.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true,pathlen:0
keyUsage = critical, keyCertSign, cRLSign
[ v3_ca_no_crl ]
# Extensions for a CA which cannot sign a CRL.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true
keyUsage = critical, keyCertSign
[ v3_ca_no_keyUsage ]
# Extensions for a CA without keyUsage information.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true
[ issuer_ext ]
# Used for a code signing cert with an unsupported critical extension.
basicConstraints = critical,CA:FALSE
issuerAltName = critical,issuer:copy
[ issuer_ext_ca ]
# Used for a CA cert with an unsupported critical extension.
basicConstraints = critical,CA:TRUE
issuerAltName = critical,issuer:copy
[ issuer_ext_keyUsage ]
# Used to test an extension with some more supported keyusage set.
basicConstraints = critical,CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment, dataEncipherment, keyAgreement, encipherOnly
[ invalid_ext ]
# Used to test an invalid extension. Cryptography complains that enciperOnly
# requires keyAgreement, so this is an invalid extension.
basicConstraints = critical,CA:FALSE
keyUsage = encipherOnly
[ crl_ext ]
# Used for testing certificate revocation.
basicConstraints = critical,CA:FALSE
crlDistributionPoints = URI:http://localhost:12001/file/0/ch1_ta4_crl.pem
[ ch5_ta1_crl ]
# Used for testing certificate revocation.
basicConstraints = critical,CA:FALSE
crlDistributionPoints = URI:http://localhost:12001/file/0/ch5_ta1_crl.pem
[ ch1.1_ta4_crl ]
# Used for testing certificate revocation.
basicConstraints = critical,CA:FALSE
crlDistributionPoints = URI:http://localhost:12001/file/0/ch1.1_ta4_crl.pem
[ ch1_ta1_crl ]
# Used for testing certificate revocation at the level of a chain certificate.
basicConstraints = critical,CA:FALSE
crlDistributionPoints = URI:http://localhost:12001/file/0/ch1_pubCA1_crl.pem
[ crl_ca ]
# Used for testing CA certificate revocation by a trust anchor.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:true
crlDistributionPoints = URI:http://localhost:12001/file/0/ta5_crl.pem
keyUsage = critical, keyCertSign, cRLSign
[ bad_crl ]
# Used for testing a CRL with a bad file format.
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:false
crlDistributionPoints = URI:http://localhost:12001/file/0/example_file
[ bad_crl_loc ]
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints = critical,CA:false
"""