mirror of
https://github.com/moepman/acertmgr.git
synced 2025-01-01 04:21:51 +01:00
tools: remove six dependency
Always decode string if the functions is available, assume normal string otherwise
This commit is contained in:
parent
b5bac4870a
commit
1f5ef9322b
@ -12,7 +12,7 @@ Requirements
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* Python (2.7+ and 3.5+ should work)
|
* Python (2.7+ and 3.5+ should work)
|
||||||
* cryptography (includes the required six and optional idna module)
|
* cryptography (includes the optional idna module)
|
||||||
|
|
||||||
Optional packages (required to use specified features)
|
Optional packages (required to use specified features)
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
|
@ -14,7 +14,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import six
|
|
||||||
from cryptography import x509
|
from cryptography import x509
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes, serialization
|
from cryptography.hazmat.primitives import hashes, serialization
|
||||||
@ -92,14 +91,11 @@ def is_cert_valid(cert, ttl_days):
|
|||||||
# @param must_staple whether or not the certificate should include the OCSP must-staple flag
|
# @param must_staple whether or not the certificate should include the OCSP must-staple flag
|
||||||
# @return the CSR in pyopenssl format
|
# @return the CSR in pyopenssl format
|
||||||
def new_cert_request(names, key, must_staple=False):
|
def new_cert_request(names, key, must_staple=False):
|
||||||
# TODO: There has to be a better way to ensure correct text type (why typecheck, cryptography?)
|
primary_name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME,
|
||||||
primary_name = x509.Name([x509.NameAttribute(
|
names[0].decode('utf-8') if getattr(names[0], 'decode', None) else
|
||||||
NameOID.COMMON_NAME,
|
names[0])])
|
||||||
names[0] if isinstance(names[0], six.text_type) else names[0].decode('utf-8'))
|
all_names = x509.SubjectAlternativeName(
|
||||||
])
|
[x509.DNSName(name.decode('utf-8') if getattr(name, 'decode', None) else name) for name in names])
|
||||||
all_names = x509.SubjectAlternativeName([x509.DNSName(
|
|
||||||
name if isinstance(name, six.text_type) else name.decode('utf-8')
|
|
||||||
) for name in names])
|
|
||||||
req = x509.CertificateSigningRequestBuilder()
|
req = x509.CertificateSigningRequestBuilder()
|
||||||
req = req.subject_name(primary_name)
|
req = req.subject_name(primary_name)
|
||||||
req = req.add_extension(all_names, critical=False)
|
req = req.add_extension(all_names, critical=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user