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 switch for SMIME Extensions support #229

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion certipy/commands/parsers/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def add_subparser(subparsers: argparse._SubParsersAction) -> Tuple[str, Callable
action="store_true",
help="Create renewal request",
)

group.add_argument(
"-smime",
action="store",
help="Specify SMIME Extension that gets added to CSR eg: des, rc4, 3des, aes128, aes192, aes256",
)
group = subparser.add_argument_group("output options")
group.add_argument("-out", action="store", metavar="output file name")

Expand Down
3 changes: 3 additions & 0 deletions certipy/commands/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ def __init__(
scheme: str = None,
dynamic_endpoint: bool = False,
debug=False,
smime: str = None,
**kwargs
):
self.target = target
Expand All @@ -556,6 +557,7 @@ def __init__(
self.renew = renew
self.out = out
self.key = key
self.smime = smime

self.web = web
self.port = port
Expand Down Expand Up @@ -676,6 +678,7 @@ def request(self) -> bool:
key_size=self.key_size,
subject=self.subject,
renewal_cert=renewal_cert,
smime=self.smime,
)
self.key = key

Expand Down
36 changes: 36 additions & 0 deletions certipy/lib/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
szOID_NTDS_CA_SECURITY_EXT = asn1cms.ObjectIdentifier("1.3.6.1.4.1.311.25.2")
szOID_NTDS_OBJECTSID = asn1cms.ObjectIdentifier("1.3.6.1.4.1.311.25.2.1")

# https://learn.microsoft.com/en-us/windows/win32/api/certenroll/nn-certenroll-ix509extensionsmimecapabilities
smimedict = {
"des":"1.3.14.3.2.7",
"rc4":"1.2.840.113549.3.4",
"3des":"1.2.840.113549.1.9.16.3.6",
"aes128":"2.16.840.1.101.3.4.1.5",
"aes192":"2.16.840.1.101.3.4.1.25",
"aes256":"2.16.840.1.101.3.4.1.45",
}

class TaggedCertificationRequest(asn1core.Sequence):
_fields = [
("bodyPartID", asn1core.Integer),
Expand Down Expand Up @@ -334,6 +344,7 @@ def create_csr(
key_size: int = 2048,
subject: str = None,
renewal_cert: x509.Certificate = None,
smime: str = None,
) -> Tuple[x509.CertificateSigningRequest, rsa.RSAPrivateKey]:
if key is None:
logging.debug("Generating RSA key")
Expand Down Expand Up @@ -404,6 +415,31 @@ def create_csr(

cri_attributes.append(cri_attribute)

if smime:
asn1x509.ExtensionId._map.update(
{
"1.2.840.113549.1.9.15": "smime_capability",
}
)

asn1x509.Extension._oid_specs.update(
{
"smime_capability": asn1core.ObjectIdentifier,
}
)
# https://learn.microsoft.com/en-us/windows/win32/api/certenroll/nn-certenroll-ix509extensionsmimecapabilities
smime_extension = asn1x509.Extension(
{"extn_id": "1.2.840.113549.1.9.15", "extn_value": smimedict[smime]}
)

set_of_extensions = asn1csr.SetOfExtensions([[smime_extension]])

cri_attribute = asn1csr.CRIAttribute(
{"type": "extension_request", "values": set_of_extensions}
)

cri_attributes.append(cri_attribute)

if alt_sid:
if type(alt_sid) == str:
alt_sid = alt_sid.encode()
Expand Down