From a580d825aeebce0e149579eae41d530d779b0f91 Mon Sep 17 00:00:00 2001 From: hakril Date: Mon, 20 May 2024 19:00:06 +0200 Subject: [PATCH] More unicode compat / more fix --- tests/test_crypto.py | 4 ++-- windows/crypto/generation.py | 2 +- windows/pycompat.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 1e7d057..aad58b9 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -92,7 +92,7 @@ def rawpfx(): return b64decode(TEST_PFX) PFW_TEST_TMP_KEY_CONTAINER = "PythonForWindowsTMPContainerTest" -RANDOM_CERTIF_NAME = b"PythonForWindowsGeneratedRandomCertifTest" +RANDOM_CERTIF_NAME = "PythonForWindowsGeneratedRandomCertifTest" RANDOM_PFX_PASSWORD = "PythonForWindowsGeneratedRandomPFXPassword" @pytest.fixture() @@ -125,7 +125,7 @@ def randomkeypair(keysize=1024): crypt_algo.pszObjId = gdef.szOID_RSA_SHA256RSA.encode("ascii") # do something else (bytes in generated ctypes ?) # This is fucking dumb, there is no .format on bytes object... - certif_name = b"".join((b"CN=", RANDOM_CERTIF_NAME)) + certif_name = "".join(("CN=", RANDOM_CERTIF_NAME)) # Generate a self-signed certificate based on the given key-container and signature algorithme certif = windows.crypto.generation.generate_selfsigned_certificate(certif_name, key_info=KeyProvInfo, signature_algo=crypt_algo) # Add the newly created certificate to our TMP cert-store diff --git a/windows/crypto/generation.py b/windows/crypto/generation.py index dc38af7..0109e2b 100644 --- a/windows/crypto/generation.py +++ b/windows/crypto/generation.py @@ -13,7 +13,7 @@ def generate_selfsigned_certificate(name="CN=DEFAULT", prov=None, key_info=None, """ size = ULONG(len(name) + 0x100) buffer = (ctypes.c_ubyte * size.value)() - winproxy.CertStrToNameA(X509_ASN_ENCODING, name, CERT_OID_NAME_STR, None, buffer, size, None) + winproxy.CertStrToNameW(X509_ASN_ENCODING, name, CERT_OID_NAME_STR, None, buffer, size, None) blobname = CRYPT_DATA_BLOB(size.value, buffer) cert = winproxy.CertCreateSelfSignCertificate(prov, blobname, flags, key_info, signature_algo, None, None, None) return windows.crypto.Certificate.from_pointer(cert) diff --git a/windows/pycompat.py b/windows/pycompat.py index c30f29c..290681c 100644 --- a/windows/pycompat.py +++ b/windows/pycompat.py @@ -36,7 +36,7 @@ if is_py3: repr_encoding = sys.stdout.encoding or locale.getpreferredencoding() def urepr_encode(s): - return ustr.encode(repr_encoding, "backslashreplace") + return s.encode(repr_encoding, "backslashreplace") else: # py2.7 def str_from_ascii_function(s):