[pywin32-checkins] /hgroot/pywin32/pywin32: Release thread lock when calling PyCERT...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2013-12-08 18:49:12
|
changeset c36870fc25f0 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=c36870fc25f0 summary: Release thread lock when calling PyCERT_CONTEXT methods, update some constants diffstat: win32/Lib/win32cryptcon.py | 28 ++++++++++- win32/src/win32crypt/PyCERT_CONTEXT.cpp | 89 +++++++++++++++++++++++++------- 2 files changed, 96 insertions(+), 21 deletions(-) diffs (235 lines): diff -r 902851ec4db0 -r c36870fc25f0 win32/Lib/win32cryptcon.py --- a/win32/Lib/win32cryptcon.py Sat Dec 07 18:08:31 2013 -0500 +++ b/win32/Lib/win32cryptcon.py Sun Dec 08 13:47:19 2013 -0500 @@ -1149,6 +1149,8 @@ CMSG_OID_IMPORT_KEY_TRANS_FUNC = "CryptMsgDllImportKeyTrans" CMSG_OID_IMPORT_KEY_AGREE_FUNC = "CryptMsgDllImportKeyAgree" CMSG_OID_IMPORT_MAIL_LIST_FUNC = "CryptMsgDllImportMailList" + +# Certificate property id's used with CertGetCertificateContextProperty CERT_KEY_PROV_HANDLE_PROP_ID = 1 CERT_KEY_PROV_INFO_PROP_ID = 2 CERT_SHA1_HASH_PROP_ID = 3 @@ -1185,10 +1187,34 @@ CERT_ARCHIVED_KEY_HASH_PROP_ID = 65 CERT_AUTO_ENROLL_RETRY_PROP_ID = 66 CERT_AIA_URL_RETRIEVED_PROP_ID = 67 -CERT_FIRST_RESERVED_PROP_ID = 68 +CERT_AUTHORITY_INFO_ACCESS_PROP_ID = 68 +CERT_BACKED_UP_PROP_ID = 69 +CERT_OCSP_RESPONSE_PROP_ID = 70 +CERT_REQUEST_ORIGINATOR_PROP_ID = 71 +CERT_SOURCE_LOCATION_PROP_ID = 72 +CERT_SOURCE_URL_PROP_ID = 73 +CERT_NEW_KEY_PROP_ID = 74 +CERT_OCSP_CACHE_PREFIX_PROP_ID = 75 +CERT_SMART_CARD_ROOT_INFO_PROP_ID = 76 +CERT_NO_AUTO_EXPIRE_CHECK_PROP_ID = 77 +CERT_NCRYPT_KEY_HANDLE_PROP_ID = 78 +CERT_HCRYPTPROV_OR_NCRYPT_KEY_HANDLE_PROP_ID = 79 +CERT_SUBJECT_INFO_ACCESS_PROP_ID = 80 +CERT_CA_OCSP_AUTHORITY_INFO_ACCESS_PROP_ID = 81 +CERT_CA_DISABLE_CRL_PROP_ID = 82 +CERT_ROOT_PROGRAM_CERT_POLICIES_PROP_ID = 83 +CERT_ROOT_PROGRAM_NAME_CONSTRAINTS_PROP_ID = 84 +CERT_SUBJECT_OCSP_AUTHORITY_INFO_ACCESS_PROP_ID = 85 +CERT_SUBJECT_DISABLE_CRL_PROP_ID = 86 +CERT_CEP_PROP_ID = 87 +CERT_SIGN_HASH_CNG_ALG_PROP_ID = 89 +CERT_SCARD_PIN_ID_PROP_ID = 90 +CERT_SCARD_PIN_INFO_PROP_ID = 91 +CERT_FIRST_RESERVED_PROP_ID = 92 CERT_LAST_RESERVED_PROP_ID = 0x00007FFF CERT_FIRST_USER_PROP_ID = 0x00008000 CERT_LAST_USER_PROP_ID = 0x0000FFFF + szOID_CERT_PROP_ID_PREFIX = "1.3.6.1.4.1.311.10.11." szOID_CERT_KEY_IDENTIFIER_PROP_ID = "1.3.6.1.4.1.311.10.11.20" szOID_CERT_ISSUER_SERIAL_NUMBER_MD5_HASH_PROP_ID = \ diff -r 902851ec4db0 -r c36870fc25f0 win32/src/win32crypt/PyCERT_CONTEXT.cpp --- a/win32/src/win32crypt/PyCERT_CONTEXT.cpp Sat Dec 07 18:08:31 2013 -0500 +++ b/win32/src/win32crypt/PyCERT_CONTEXT.cpp Sun Dec 08 13:47:19 2013 -0500 @@ -224,12 +224,14 @@ PyObject *PyCERT_CONTEXT::PyCertFreeCertificateContext (PyObject *self, PyObject *args) { PCCERT_CONTEXT pccert_context=((PyCERT_CONTEXT *)self)->GetPCCERT_CONTEXT(); - if (CertFreeCertificateContext (pccert_context)){ - Py_INCREF(Py_None); - return Py_None; - } - PyWin_SetAPIError("CertFreeCertificateContext"); - return NULL; + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertFreeCertificateContext (pccert_context); + Py_END_ALLOW_THREADS + if (!bsuccess) + return PyWin_SetAPIError("CertFreeCertificateContext"); + Py_INCREF(Py_None); + return Py_None; } // @pymethod [int,...]|PyCERT_CONTEXT|CertEnumCertificateContextProperties|Lists property ids for the certificate @@ -242,7 +244,9 @@ if (ret==NULL) return NULL; while (TRUE){ + Py_BEGIN_ALLOW_THREADS dwPropId=CertEnumCertificateContextProperties(pccert_context, dwPropId); + Py_END_ALLOW_THREADS if (dwPropId==0) break; ret_item=PyLong_FromUnsignedLong(dwPropId); @@ -272,8 +276,12 @@ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|k:CryptAcquireCertificatePrivateKey", keywords, &flags)) // @pyparm int|Flags|0|Combination of CRYPT_ACQUIRE_*_FLAG constants return NULL; - if (!CryptAcquireCertificatePrivateKey(pccert_context, flags, reserved, - &hcryptprov, &keyspec, &callerfree)) + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CryptAcquireCertificatePrivateKey(pccert_context, flags, reserved, + &hcryptprov, &keyspec, &callerfree); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CryptAcquireCertificatePrivateKey"); /* If callerfree returns false, CSP handle shouldn't be freed, so increase its refcount since @@ -297,13 +305,19 @@ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|k:CertGetEnhancedKeyUsage", keywords, &flags)) // @pyparm int|Flags|0|CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG, CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG, or 0 return NULL; - if (!CertGetEnhancedKeyUsage(pccert_context, flags, pceu, &bufsize)) + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertGetEnhancedKeyUsage(pccert_context, flags, pceu, &bufsize); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CertGetEnhancedKeyUsage"); pceu=(PCERT_ENHKEY_USAGE)malloc(bufsize); if (pceu==NULL) return PyErr_Format(PyExc_MemoryError, "Failed to allocate %d bytes", bufsize); - - if (!CertGetEnhancedKeyUsage(pccert_context, flags, pceu, &bufsize)) + Py_BEGIN_ALLOW_THREADS + bsuccess = CertGetEnhancedKeyUsage(pccert_context, flags, pceu, &bufsize); + Py_END_ALLOW_THREADS + if (!bsuccess) PyWin_SetAPIError("CertGetEnhancedKeyUsage"); else ret=PyWinObject_FromCTL_USAGE(pceu); @@ -318,7 +332,11 @@ PCCERT_CONTEXT pccert_context=((PyCERT_CONTEXT *)self)->GetPCCERT_CONTEXT(); DWORD buf; DWORD bufsize=sizeof(DWORD); - if (!CertGetIntendedKeyUsage(pccert_context->dwCertEncodingType, pccert_context->pCertInfo, (BYTE *)&buf, bufsize)) + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertGetIntendedKeyUsage(pccert_context->dwCertEncodingType, pccert_context->pCertInfo, (BYTE *)&buf, bufsize); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CertGetIntendedKeyUsage"); return PyLong_FromUnsignedLong(buf); } @@ -334,12 +352,21 @@ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|k:CertSerializeCertificateStoreElement", keywords, &flags)) // @pyparm int|Flags|0|Reserved, use only 0 if passed in return NULL; - if (!CertSerializeCertificateStoreElement(pccert_context, flags, buf, &bufsize)) + + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertSerializeCertificateStoreElement(pccert_context, flags, buf, &bufsize); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CertSerializeCertificateStoreElement"); buf=(BYTE *)malloc(bufsize); if (buf==NULL) return PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", bufsize); - if (!CertSerializeCertificateStoreElement(pccert_context, flags, buf, &bufsize)) + + Py_BEGIN_ALLOW_THREADS + bsuccess = CertSerializeCertificateStoreElement(pccert_context, flags, buf, &bufsize); + Py_END_ALLOW_THREADS + if (!bsuccess) PyWin_SetAPIError("CertSerializeCertificateStoreElement"); else ret=PyString_FromStringAndSize((char *)buf, bufsize); @@ -362,7 +389,11 @@ return NULL; if (!PyWinObject_AsCERT_CONTEXT(obissuer, &issuer, TRUE)) return NULL; - if (!CertVerifySubjectCertificateContext(pccert_context, issuer, &flags)) + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertVerifySubjectCertificateContext(pccert_context, issuer, &flags); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CertVerifySubjectCertificateContext"); return PyLong_FromUnsignedLong(flags); } @@ -371,7 +402,11 @@ PyObject *PyCERT_CONTEXT::PyCertDeleteCertificateFromStore(PyObject *self, PyObject *args) { PCCERT_CONTEXT pcert_context=((PyCERT_CONTEXT *)self)->GetPCCERT_CONTEXT(); - if (!CertDeleteCertificateFromStore(pcert_context)) + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertDeleteCertificateFromStore(pcert_context); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CertDeleteCertificateFromStore"); Py_INCREF(Py_None); return Py_None; @@ -391,7 +426,11 @@ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "k:CertGetCertificateContextProperty", keywords, &dwPropId)) // @pyparm int|PropId||One of the CERT_*_PROP_ID constants return NULL; - if (!CertGetCertificateContextProperty(pccert_context, dwPropId, pvData, &pcbData)){ + BOOL bsuccess; + Py_BEGIN_ALLOW_THREADS + bsuccess = CertGetCertificateContextProperty(pccert_context, dwPropId, pvData, &pcbData); + Py_END_ALLOW_THREADS + if (!bsuccess){ PyWin_SetAPIError("CertGetCertificateContextProperty"); return NULL; } @@ -401,7 +440,10 @@ if (pvData==NULL) return PyErr_Format(PyExc_MemoryError,"CertGetCertificateContextProperty: unable to allocate %d bytes", pcbData); ZeroMemory(pvData, pcbData); - if (!CertGetCertificateContextProperty(pccert_context, dwPropId, pvData, &pcbData)){ + Py_BEGIN_ALLOW_THREADS + bsuccess = CertGetCertificateContextProperty(pccert_context, dwPropId, pvData, &pcbData); + Py_END_ALLOW_THREADS + if (!bsuccess){ PyWin_SetAPIError("CertGetCertificateContextProperty"); free(pvData); return NULL; @@ -494,9 +536,13 @@ &flags)) // @pyparm int|Flags|0|Combination of CERT_SET_* flags return NULL; + BOOL bsuccess; // When Data is None, property is to be deleted so no conversion necessary if (obData==Py_None){ - if (!CertSetCertificateContextProperty(pccert_context, prop, flags, NULL)) + Py_BEGIN_ALLOW_THREADS + bsuccess = CertSetCertificateContextProperty(pccert_context, prop, flags, NULL); + Py_END_ALLOW_THREADS + if (!bsuccess) return PyWin_SetAPIError("CertSetCertificateContextProperty"); else{ Py_INCREF(Py_None); @@ -577,7 +623,10 @@ goto cleanup; } - if (!CertSetCertificateContextProperty(pccert_context, prop, flags, pvData)) + Py_BEGIN_ALLOW_THREADS + bsuccess = CertSetCertificateContextProperty(pccert_context, prop, flags, pvData); + Py_END_ALLOW_THREADS + if (!bsuccess) PyWin_SetAPIError("CertSetCertificateContextProperty"); else{ Py_INCREF(Py_None); |