<s> import ctypes <EOL> from ctypes import windll <EOL> from ctypes import wintypes <EOL> class CryptoAPIException ( Exception ) : <EOL> def __init__ ( self ) : <EOL> message = self . _get_windows_error ( ) <EOL> super ( CryptoAPIException , self ) . __init__ ( message ) <EOL> def _get_windows_error ( self ) : <EOL> err_code = GetLastError ( ) <EOL> return "<STR_LIT>" % err_code <EOL> class SYSTEMTIME ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ( '<STR_LIT>' , wintypes . WORD ) , <EOL> ] <EOL> class FILETIME ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ] <EOL> class CERT_CONTEXT ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , ctypes . POINTER ( wintypes . BYTE ) ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , ctypes . c_void_p ) , <EOL> ( '<STR_LIT>' , wintypes . HANDLE ) , <EOL> ] <EOL> class CRYPTOAPI_BLOB ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , ctypes . POINTER ( wintypes . BYTE ) ) , <EOL> ] <EOL> class CRYPT_ALGORITHM_IDENTIFIER ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . LPSTR ) , <EOL> ( '<STR_LIT>' , CRYPTOAPI_BLOB ) , <EOL> ] <EOL> class CRYPT_KEY_PROV_PARAM ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , ctypes . POINTER ( wintypes . BYTE ) ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ] <EOL> class CRYPT_KEY_PROV_INFO ( ctypes . Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , wintypes . LPWSTR ) , <EOL> ( '<STR_LIT>' , wintypes . LPWSTR ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ( '<STR_LIT>' , ctypes . POINTER ( CRYPT_KEY_PROV_PARAM ) ) , <EOL> ( '<STR_LIT>' , wintypes . DWORD ) , <EOL> ] <EOL> AT_SIGNATURE = <NUM_LIT:2> <EOL> CERT_NAME_UPN_TYPE = <NUM_LIT:8> <EOL> CERT_SHA1_HASH_PROP_ID = <NUM_LIT:3> <EOL> CERT_STORE_ADD_REPLACE_EXISTING = <NUM_LIT:3> <EOL> CERT_STORE_PROV_SYSTEM = wintypes . LPSTR ( <NUM_LIT:10> ) <EOL> CERT_SYSTEM_STORE_CURRENT_USER = <NUM_LIT> <EOL> CERT_SYSTEM_STORE_LOCAL_MACHINE = <NUM_LIT> <EOL> CERT_X500_NAME_STR = <NUM_LIT:3> <EOL> CRYPT_MACHINE_KEYSET = <NUM_LIT:32> <EOL> CRYPT_NEWKEYSET = <NUM_LIT:8> <EOL> CRYPT_STRING_BASE64 = <NUM_LIT:1> <EOL> PKCS_7_ASN_ENCODING = <NUM_LIT> <EOL> PROV_RSA_FULL = <NUM_LIT:1> <EOL> X509_ASN_ENCODING = <NUM_LIT:1> <EOL> szOID_PKIX_KP_SERVER_AUTH = b"<STR_LIT>" <EOL> szOID_RSA_SHA1RSA = b"<STR_LIT>" <EOL> advapi32 = windll . advapi32 <EOL> crypt32 = windll . crypt32 <EOL> kernel32 = windll . kernel32 <EOL> advapi32 . CryptAcquireContextW . restype = wintypes . BOOL <EOL> advapi32 . CryptAcquireContextW . argtypes = [ wintypes . HANDLE , wintypes . LPCWSTR , <EOL> wintypes . LPCWSTR , wintypes . DWORD , <EOL> wintypes . DWORD ] <EOL> CryptAcquireContext = advapi32 . CryptAcquireContextW <EOL> advapi32 . CryptReleaseContext . restype = wintypes . BOOL <EOL> advapi32 . CryptReleaseContext . argtypes = [ wintypes . HANDLE , wintypes . DWORD ] <EOL> CryptReleaseContext = advapi32 . CryptReleaseContext <EOL> advapi32 . CryptGenKey . restype = wintypes . BOOL <EOL> advapi32 . CryptGenKey . argtypes = [ wintypes . HANDLE , <EOL> wintypes . DWORD , <EOL> wintypes . DWORD , <EOL> ctypes . POINTER ( wintypes . HANDLE ) ] <EOL> CryptGenKey = advapi32 . CryptGenKey <EOL> advapi32 . CryptDestroyKey . restype = wintypes . BOOL <EOL> advapi32 . CryptDestroyKey . argtypes = [ wintypes . HANDLE ] <EOL> CryptDestroyKey = advapi32 . CryptDestroyKey <EOL> crypt32 . CertStrToNameW . restype = wintypes . BOOL <EOL> crypt32 . CertStrToNameW . argtypes = [ wintypes . DWORD , wintypes . LPCWSTR , <EOL> wintypes . DWORD , ctypes . c_void_p , <EOL> ctypes . POINTER ( wintypes . BYTE ) , <EOL> ctypes . POINTER ( wintypes . DWORD ) , <EOL> ctypes . POINTER ( wintypes . LPCWSTR ) ] <EOL> CertStrToName = crypt32 . CertStrToNameW <EOL> kernel32 . GetSystemTime . restype = None <EOL> kernel32 . GetSystemTime . argtypes = [ ctypes . POINTER ( SYSTEMTIME ) ] <EOL> GetSystemTime = kernel32 . GetSystemTime <EOL> kernel32 . SystemTimeToFileTime . restype = wintypes . BOOL <EOL> kernel32 . SystemTimeToFileTime . argtypes = [ ctypes . POINTER ( SYSTEMTIME ) , <EOL> ctypes . POINTER ( FILETIME ) ] <EOL> SystemTimeToFileTime = kernel32 . SystemTimeToFileTime <EOL> kernel32 . FileTimeToSystemTime . restype = wintypes . BOOL <EOL> kernel32 . FileTimeToSystemTime . argtypes = [ ctypes . POINTER ( FILETIME ) , <EOL> ctypes . POINTER ( SYSTEMTIME ) ] <EOL> FileTimeToSystemTime = kernel32 . FileTimeToSystemTime <EOL> kernel32 . GetLastError . restype = wintypes . DWORD <EOL> kernel32 . GetLastError . argtypes = [ ] <EOL> GetLastError = kernel32 . GetLastError <EOL> crypt32 . CertCreateSelfSignCertificate . restype = ctypes . POINTER ( CERT_CONTEXT ) <EOL> crypt32 . CertCreateSelfSignCertificate . argtypes = [ <EOL> wintypes . HANDLE , <EOL> ctypes . POINTER ( CRYPTOAPI_BLOB ) , <EOL> wintypes . DWORD , <EOL> ctypes . POINTER ( CRYPT_KEY_PROV_INFO ) , <EOL> ctypes . POINTER ( CRYPT_ALGORITHM_IDENTIFIER ) , <EOL> ctypes . POINTER ( SYSTEMTIME ) , <EOL> ctypes . POINTER ( SYSTEMTIME ) , <EOL> ctypes . c_void_p ] <EOL> CertCreateSelfSignCertificate = crypt32 . CertCreateSelfSignCertificate <EOL> crypt32 . CertAddEnhancedKeyUsageIdentifier . restype = wintypes . BOOL <EOL> crypt32 . CertAddEnhancedKeyUsageIdentifier . argtypes = [ <EOL> ctypes . POINTER ( CERT_CONTEXT ) , <EOL> wintypes . LPCSTR ] <EOL> CertAddEnhancedKeyUsageIdentifier = crypt32 . CertAddEnhancedKeyUsageIdentifier <EOL> crypt32 . CertOpenStore . restype = wintypes . HANDLE <EOL> crypt32 . CertOpenStore . argtypes = [ wintypes . LPCSTR , wintypes . DWORD , <EOL> wintypes . HANDLE , wintypes . DWORD , <EOL> ctypes . c_void_p ] <EOL> CertOpenStore = crypt32 . CertOpenStore <EOL> crypt32 . CertAddCertificateContextToStore . restype = wintypes . BOOL <EOL> crypt32 . CertAddCertificateContextToStore . argtypes = [ <EOL> wintypes . HANDLE , <EOL> ctypes . POINTER ( CERT_CONTEXT ) , <EOL> wintypes . DWORD , <EOL> ctypes . POINTER ( CERT_CONTEXT ) ] <EOL> CertAddCertificateContextToStore = crypt32 . CertAddCertificateContextToStore <EOL> crypt32 . CryptStringToBinaryW . restype = wintypes . BOOL <EOL> crypt32 . CryptStringToBinaryW . argtypes = [ wintypes . LPCWSTR , <EOL> wintypes . DWORD , <EOL> wintypes . DWORD , <EOL> ctypes . POINTER ( wintypes . BYTE ) , <EOL> ctypes . POINTER ( wintypes . DWORD ) , <EOL> ctypes . POINTER ( wintypes . DWORD ) , <EOL> ctypes . POINTER ( wintypes . DWORD ) ] <EOL> CryptStringToBinaryW = crypt32 . CryptStringToBinaryW <EOL> crypt32 . CertAddEncodedCertificateToStore . restype = wintypes . BOOL <EOL> crypt32 . CertAddEncodedCertificateToStore . argtypes = [ <EOL> wintypes . HANDLE , <EOL> wintypes . DWORD , <EOL> ctypes . POINTER ( wintypes . BYTE ) , <EOL> wintypes . DWORD , <EOL> wintypes . DWORD , <EOL> ctypes . POINTER ( ctypes . POINTER ( CERT_CONTEXT ) ) ] <EOL> CertAddEncodedCertificateToStore = crypt32 . CertAddEncodedCertificateToStore <EOL> crypt32 . CertGetNameStringW . restype = wintypes . DWORD <EOL> crypt32 . CertGetNameStringW . argtypes = [ ctypes . POINTER ( CERT_CONTEXT ) , <EOL> wintypes . DWORD , <EOL> wintypes . DWORD , <EOL> ctypes . c_void_p , <EOL> wintypes . LPWSTR , <EOL> wintypes . DWORD ] <EOL> CertGetNameString = crypt32 . CertGetNameStringW <EOL> crypt32 . CertFreeCertificateContext . restype = wintypes . BOOL <EOL> crypt32 . CertFreeCertificateContext . argtypes = [ ctypes . POINTER ( CERT_CONTEXT ) ] <EOL> CertFreeCertificateContext = crypt32 . CertFreeCertificateContext <EOL> crypt32 . CertCloseStore . restype = wintypes . BOOL <EOL> crypt32 . CertCloseStore . argtypes = [ wintypes . HANDLE , wintypes . DWORD ] <EOL> CertCloseStore = crypt32 . CertCloseStore <EOL> crypt32 . CertGetCertificateContextProperty . restype = wintypes . BOOL <EOL> crypt32 . CertGetCertificateContextProperty . argtypes = [ <EOL> ctypes . POINTER ( CERT_CONTEXT ) , <EOL> wintypes . DWORD , <EOL> ctypes . c_void_p , <EOL> ctypes . POINTER ( wintypes . DWORD ) ] <EOL> CertGetCertificateContextProperty = crypt32 . CertGetCertificateContextProperty </s>
