|
6 | 6 | import windows.generated_def as gdef |
7 | 7 |
|
8 | 8 | from windows.crypto import DEFAULT_ENCODING |
9 | | -from windows.pycompat import urepr_encode |
| 9 | +from windows.pycompat import urepr_encode, unicode_type |
10 | 10 |
|
11 | 11 | import windows.crypto.cryptmsg |
12 | 12 |
|
@@ -58,7 +58,8 @@ def __init__(self, filename, content_type=gdef.CERT_QUERY_CONTENT_FLAG_ALL): |
58 | 58 | gdef.LPWSTR(filename), |
59 | 59 | # filename, |
60 | 60 | content_type, |
61 | | - gdef.CERT_QUERY_FORMAT_FLAG_BINARY, |
| 61 | + # gdef.CERT_QUERY_FORMAT_FLAG_BINARY, |
| 62 | + gdef.CERT_QUERY_FORMAT_FLAG_ALL, |
62 | 63 | 0, |
63 | 64 | dwEncoding, |
64 | 65 | dwContentType, |
@@ -149,15 +150,19 @@ def from_system_store(cls, store_name): |
149 | 150 | """Create a new :class:`CertificateStore` from system store ``store_name`` |
150 | 151 | (see `System Store Locations <https://msdn.microsoft.com/en-us/library/windows/desktop/aa388136(v=vs.85).aspx>`_) |
151 | 152 | """ |
152 | | - res = winproxy.CertOpenStore(gdef.CERT_STORE_PROV_SYSTEM_A, DEFAULT_ENCODING, None, gdef.CERT_SYSTEM_STORE_LOCAL_MACHINE | gdef.CERT_STORE_READONLY_FLAG, store_name) |
| 153 | + if not isinstance(store_name, unicode_type): |
| 154 | + raise ValueError("store_name should be an unicode string not {0}".format(type(store_name))) |
| 155 | + res = winproxy.CertOpenStore(gdef.CERT_STORE_PROV_SYSTEM_W, DEFAULT_ENCODING, None, gdef.CERT_SYSTEM_STORE_LOCAL_MACHINE | gdef.CERT_STORE_READONLY_FLAG, store_name) |
153 | 156 | return ctypes.cast(res, cls) |
154 | 157 |
|
155 | 158 | @classmethod |
156 | 159 | def from_user_store(cls, store_name, user=True): |
157 | 160 | """Create a new :class:`CertificateStore` from system store ``store_name`` |
158 | 161 | (see `System Store Locations <https://msdn.microsoft.com/en-us/library/windows/desktop/aa388136(v=vs.85).aspx>`_) |
159 | 162 | """ |
160 | | - res = winproxy.CertOpenStore(gdef.CERT_STORE_PROV_SYSTEM_A, DEFAULT_ENCODING, None, gdef.CERT_SYSTEM_STORE_CURRENT_USER | gdef.CERT_STORE_READONLY_FLAG, store_name) |
| 163 | + if not isinstance(store_name, unicode_type): |
| 164 | + raise ValueError("store_name should be an unicode string not {0}".format(type(store_name))) |
| 165 | + res = winproxy.CertOpenStore(gdef.CERT_STORE_PROV_SYSTEM_W, DEFAULT_ENCODING, None, gdef.CERT_SYSTEM_STORE_CURRENT_USER | gdef.CERT_STORE_READONLY_FLAG, store_name) |
161 | 166 | return ctypes.cast(res, cls) |
162 | 167 |
|
163 | 168 | @classmethod |
@@ -442,6 +447,19 @@ def get_property(self, prop): |
442 | 447 | windows.winproxy.CertGetCertificateContextProperty(self, prop, buf, datasize) |
443 | 448 | return bytearray(buf) |
444 | 449 |
|
| 450 | + def get_private_key(self, flags): |
| 451 | + """Tmp API: return value will change""" |
| 452 | + keyhandle = gdef.HCRYPTPROV_OR_NCRYPT_KEY_HANDLE() |
| 453 | + keyspec = gdef.DWORD() |
| 454 | + must_free_handle = gdef.BOOL() |
| 455 | + windows.winproxy.CryptAcquireCertificatePrivateKey(self, flags, None, keyhandle, keyspec, must_free_handle) |
| 456 | + return (keyhandle, keyspec, must_free_handle) |
| 457 | + |
| 458 | + @property |
| 459 | + def private_key(self): |
| 460 | + """Tmp API: return value will change""" |
| 461 | + return self.get_private_key(flags=gdef.CRYPT_ACQUIRE_COMPARE_KEY_FLAG | gdef.CRYPT_ACQUIRE_ALLOW_NCRYPT_KEY_FLAG | gdef.CRYPT_ACQUIRE_USE_PROV_INFO_FLAG) |
| 462 | + |
445 | 463 |
|
446 | 464 | @property |
447 | 465 | def encoded(self): |
|
0 commit comments