mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Testing some crypto stuff
This commit is contained in:
@@ -946,3 +946,7 @@
|
||||
#define SACL_SECURITY_INFORMATION (0x00000008L)
|
||||
#define LABEL_SECURITY_INFORMATION (0x00000010L)
|
||||
#define MAXIMUM_ALLOWED (0x02000000L)
|
||||
|
||||
#define CERT_STORE_CERTIFICATE_CONTEXT 1
|
||||
#define CERT_STORE_CRL_CONTEXT 2
|
||||
#define CERT_STORE_CTL_CONTEXT 3
|
||||
|
||||
@@ -324,3 +324,21 @@ PCCTL_CONTEXT WINAPI CertEnumCTLsInStore(
|
||||
_In_ HCERTSTORE hCertStore,
|
||||
_In_ PCCTL_CONTEXT pPrevCtlContext
|
||||
);
|
||||
|
||||
PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(
|
||||
_In_ PCCTL_CONTEXT pCtlContext
|
||||
);
|
||||
|
||||
BOOL WINAPI CertFreeCTLContext(
|
||||
_In_ PCCTL_CONTEXT pCtlContext
|
||||
);
|
||||
|
||||
|
||||
BOOL WINAPI CryptUIDlgViewContext(
|
||||
_In_ DWORD dwContextType,
|
||||
_In_ PVOID pvContext,
|
||||
_In_ HWND hwnd,
|
||||
_In_ LPCWSTR pwszTitle,
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ PVOID pvReserved
|
||||
);
|
||||
@@ -813,6 +813,9 @@ Windef
|
||||
.. autodata:: SACL_SECURITY_INFORMATION
|
||||
.. autodata:: LABEL_SECURITY_INFORMATION
|
||||
.. autodata:: MAXIMUM_ALLOWED
|
||||
.. autodata:: CERT_STORE_CERTIFICATE_CONTEXT
|
||||
.. autodata:: CERT_STORE_CRL_CONTEXT
|
||||
.. autodata:: CERT_STORE_CTL_CONTEXT
|
||||
.. autodata:: CERT_QUERY_OBJECT_FILE
|
||||
.. autodata:: CERT_QUERY_OBJECT_BLOB
|
||||
.. autodata:: CERT_QUERY_CONTENT_CERT
|
||||
|
||||
@@ -110,4 +110,7 @@ def test_crypt_obj():
|
||||
x.signers_and_certs
|
||||
# TODO: Need some better ideas
|
||||
|
||||
def test_certificate_from_store():
|
||||
return windows.crypto.EHCERTSTORE.from_system_store("Root")
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from windows import winproxy
|
||||
import windows.generated_def as gdef
|
||||
import windows.crypto
|
||||
|
||||
@@ -32,6 +32,7 @@ CRYPT_OBJECT_FORMAT_TYPE = [
|
||||
CRYPT_OBJECT_FORMAT_TYPE_DICT = {x:x for x in CRYPT_OBJECT_FORMAT_TYPE}
|
||||
|
||||
## Move CryptObject to new .py ?
|
||||
|
||||
class CryptObject(object):
|
||||
"""Extract information from an CryptoAPI object.
|
||||
|
||||
@@ -64,8 +65,8 @@ class CryptObject(object):
|
||||
hMsg,
|
||||
None)
|
||||
|
||||
self.cert_store = hStore
|
||||
self.crypt_msg = hMsg
|
||||
self.cert_store = hStore if hStore else None
|
||||
self.crypt_msg = hMsg if hMsg else None
|
||||
self.encoding = dwEncoding
|
||||
self.content_type = CRYPT_OBJECT_FORMAT_TYPE_DICT.get(dwContentType.value, dwContentType)
|
||||
|
||||
@@ -82,6 +83,7 @@ class CryptObject(object):
|
||||
return '<{0} "{1}" content_type={2}>'.format(type(self).__name__, self.filename, self.content_type)
|
||||
|
||||
# TODO: rename to CertificateStore ?
|
||||
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa382037(v=vs.85).aspx
|
||||
class EHCERTSTORE(gdef.HCERTSTORE):
|
||||
"""A certificate store"""
|
||||
@property
|
||||
@@ -115,6 +117,13 @@ class EHCERTSTORE(gdef.HCERTSTORE):
|
||||
res = winproxy.CertOpenStore(gdef.CERT_STORE_PROV_FILENAME_A, DEFAULT_ENCODING, None, gdef.CERT_STORE_OPEN_EXISTING_FLAG, filename)
|
||||
return ctypes.cast(res, cls)
|
||||
|
||||
def yolo(self):
|
||||
x = winproxy.CertEnumCTLsInStore(self, None)
|
||||
title = None
|
||||
windows.winproxy.CryptUIDlgViewContext(gdef.CERT_STORE_CTL_CONTEXT, x, None, title, 0, None)
|
||||
|
||||
return x
|
||||
|
||||
|
||||
# See https://msdn.microsoft.com/en-us/library/windows/desktop/aa388136(v=vs.85).aspx
|
||||
@classmethod
|
||||
@@ -122,13 +131,13 @@ class EHCERTSTORE(gdef.HCERTSTORE):
|
||||
"""Create a new :class:`EHCERTSTORE` from system store``store_name``
|
||||
(see https://msdn.microsoft.com/en-us/library/windows/desktop/aa388136(v=vs.85).aspx)
|
||||
"""
|
||||
res = winproxy.CertOpenStore(CERT_STORE_PROV_SYSTEM_A, DEFAULT_ENCODING, None, CERT_SYSTEM_STORE_LOCAL_MACHINE | CERT_STORE_READONLY_FLAG, store_name)
|
||||
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)
|
||||
return ctypes.cast(res, cls)
|
||||
|
||||
@classmethod
|
||||
def new_in_memory(cls):
|
||||
"""Create a new temporary :class:`EHCERTSTORE` in memory"""
|
||||
res = winproxy.CertOpenStore(CERT_STORE_PROV_MEMORY, DEFAULT_ENCODING, None, 0, None)
|
||||
res = winproxy.CertOpenStore(gdef.CERT_STORE_PROV_MEMORY, DEFAULT_ENCODING, None, 0, None)
|
||||
return ctypes.cast(res, cls)
|
||||
|
||||
|
||||
@@ -277,6 +286,9 @@ class CertificateContext(gdef.PCCERT_CONTEXT):
|
||||
raise ValueError("CertDuplicateCertificateContext did not returned the argument (check doc)")
|
||||
return self
|
||||
|
||||
def view(self, title=None):
|
||||
return windows.winproxy.CryptUIDlgViewContext(gdef.CERT_STORE_CERTIFICATE_CONTEXT, self, None, title, 0, None)
|
||||
|
||||
def enum_properties(self):
|
||||
prop = 0
|
||||
res = []
|
||||
|
||||
@@ -864,6 +864,9 @@ DACL_SECURITY_INFORMATION = make_flag("DACL_SECURITY_INFORMATION", ( 0x00000004
|
||||
SACL_SECURITY_INFORMATION = make_flag("SACL_SECURITY_INFORMATION", ( 0x00000008 ))
|
||||
LABEL_SECURITY_INFORMATION = make_flag("LABEL_SECURITY_INFORMATION", ( 0x00000010 ))
|
||||
MAXIMUM_ALLOWED = make_flag("MAXIMUM_ALLOWED", ( 0x02000000 ))
|
||||
CERT_STORE_CERTIFICATE_CONTEXT = make_flag("CERT_STORE_CERTIFICATE_CONTEXT", 1)
|
||||
CERT_STORE_CRL_CONTEXT = make_flag("CERT_STORE_CRL_CONTEXT", 2)
|
||||
CERT_STORE_CTL_CONTEXT = make_flag("CERT_STORE_CTL_CONTEXT", 3)
|
||||
CERT_QUERY_OBJECT_FILE = make_flag("CERT_QUERY_OBJECT_FILE", 0x00000001)
|
||||
CERT_QUERY_OBJECT_BLOB = make_flag("CERT_QUERY_OBJECT_BLOB", 0x00000002)
|
||||
CERT_QUERY_CONTENT_CERT = make_flag("CERT_QUERY_CONTENT_CERT", 1)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -104,7 +104,7 @@ def construct_alpc_tower(object, syntax, protseq, endpoint, address):
|
||||
floor_0_rsh = TOWER_EMPTY_RHS
|
||||
floor_0 = craft_floor(floor_0_lsh, floor_0_rsh)
|
||||
# Floor 1
|
||||
floor_1_lsh = TOWER_PROTOCOL_IS_UUID + bytearray(object.Uuid) + struct.pack("<BB", object.VersMajor, object.VersMinor)
|
||||
floor_1_lsh = TOWER_PROTOCOL_IS_UUID + bytearray(syntax.Uuid) + struct.pack("<BB", syntax.VersMajor, syntax.VersMinor)
|
||||
floor_1_rsh = TOWER_EMPTY_RHS
|
||||
floor_1 = craft_floor(floor_1_lsh, floor_1_rsh)
|
||||
# Floor 2
|
||||
|
||||
@@ -217,6 +217,11 @@ class Crypt32Proxy(ApiProxy):
|
||||
APIDLL = "crypt32"
|
||||
default_error_check = staticmethod(zero_is_fail_error_check)
|
||||
|
||||
|
||||
class CryptUIProxy(ApiProxy):
|
||||
APIDLL = "cryptui"
|
||||
default_error_check = staticmethod(zero_is_fail_error_check)
|
||||
|
||||
class Shell32Proxy(ApiProxy):
|
||||
APIDLL = "shell32"
|
||||
default_error_check = staticmethod(zero_is_fail_error_check)
|
||||
@@ -1408,6 +1413,12 @@ def CryptDecodeObject(dwCertEncodingType, lpszStructType, pbEncoded, cbEncoded,
|
||||
return CryptDecodeObject.ctypes_function(dwCertEncodingType, lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, pcbStructInfo)
|
||||
|
||||
|
||||
# ## CryptUI ## #
|
||||
|
||||
@CryptUIProxy('CryptUIDlgViewContext')
|
||||
def CryptUIDlgViewContext(dwContextType, pvContext, hwnd, pwszTitle, dwFlags, pvReserved):
|
||||
return CryptUIDlgViewContext.ctypes_function(dwContextType, pvContext, hwnd, pwszTitle, dwFlags, pvReserved)
|
||||
|
||||
# ## User32 stuff ## #
|
||||
|
||||
EnumWindows = TransparentUser32Proxy('EnumWindows')
|
||||
|
||||
Reference in New Issue
Block a user