a oe@sddlZddlZddlmZmZddlZddlmZmZm Z ddl TGdddej Z dZ dZejeeeed d d ZGd d d ej Zedkre dS)N)AnyIterator) TestSkippedfind_test_fixturetestmain)*c@seZdZddZddZdS)Cryptc CsZd}d}d}d}d}t|||d||}t||d||\}}||||||dS)N My test dataMy descriptionr win32cryptZCryptProtectDataZCryptUnprotectData assertEqual selfdataZentropyZdescflagsZpsZblobZgot_descZgot_datar;C:\Program Files\Certbot\pkgs\win32\test\test_win32crypt.py testSimple s  zCrypt.testSimplec CsZd}d}d}d}d}t|||d||}t||d||\}}||||||dS)Nr sMy test entropyr rr rrrr testEntropys  zCrypt.testEntropyN)__name__ __module__ __qualname__rrrrrrr s rZ LocalMachineZ CurrentUser) store_namestore_locationreturnccsTd}z8ttdd|tkrtnt|}|VW|durP|n|durN|0dS)zOpen a windows certificate store :param store_name: store name :param store_location: store location :return: handle to cert store Nr)r Z CertOpenStoreZCERT_STORE_PROV_SYSTEM_LOCAL_MACHINEZCERT_SYSTEM_STORE_LOCAL_MACHINEZCERT_SYSTEM_STORE_CURRENT_USERZCertCloseStore)rrhandlerrropen_windows_certstore-s   rc@s4eZdZddZddZddZddZd d Zd S) TestCertscCsPtt|d.}t|}tt|ttdWdS1sB0YdS)Nrbr) openr bytearrayreadr CryptQueryObjectZCERT_QUERY_OBJECT_BLOBCERT_QUERY_CONTENT_FLAG_CERTCERT_QUERY_FORMAT_FLAG_ALL)r file_namefbufrrr readCertFileGs zTestCerts.readCertFilecCs>d}ttt|ttd}||dt||dtdS)Nwin32crypt_testcert_base64.cerr FormatType ContentType) r r$ZCERT_QUERY_OBJECT_FILErr%r&r CERT_QUERY_FORMAT_BASE64_ENCODEDCERT_QUERY_CONTENT_CERT)rfilenamecertrrrtestReadCertFilesRszTestCerts.testReadCertFilesc Cs||}||d|||dtttdt}||dt}|t| | t| | z | Wnt yYn 0tdWdn1s0YdS)Nr,r-ZTempZContextz-should not be able to close the context twice)r*r r/r _CURRENT_USERZ CertAddCertificateContextToStoreZCERT_STORE_ADD_REPLACE_EXISTINGZ assertTruelenZCertEnumCertificatesInStoreZ assertFalseZCertEnumCTLsInStoreZCertFreeCertificateContext ValueError RuntimeError)rr0Zexpected_formatr1storecontextrrr checkCertFilecs    zTestCerts.checkCertFilecCs|dtdS)Nr+)r9r.rrrrtestCertBase64wszTestCerts.testCertBase64cCs|dtdS)Nzwin32crypt_testcert_bin.cer)r9ZCERT_QUERY_FORMAT_BINARYr:rrrtestCertBinary|szTestCerts.testCertBinaryN)rrrr*r2r9r;r<rrrrrFs  r__main__) contextlibZunittesttypingrrr Zpywin32_testutilrrrZ win32cryptconZTestCaserrr3contextmanagerstrrrrrrrrs: