Windows 인증서 관리자-> 신뢰할 수있는 루트 인증 기관에 API.crt가 저장되어 있습니다. 목록에 인증서 이름이 'localhost'로 표시됩니다.
아래 코드를 실행하면 load_verify_locations()
기능 에 인증서 경로를 제공하면 작동 합니다.
그러나 Windows 인증서 관리자에서 인증서를 검색하고 실제 인증서를 제공하면 작동하지 않습니다. 누구든지이 작업을 도와 줄 수 있습니다.
import wincertstore
import ssl
for storename in ("CA", "ROOT"):
with wincertstore.CertSystemStore(storename) as store:
for cert in store.itercerts(usage=wincertstore.SERVER_AUTH):
if cert.get_name() == 'localhost': #name of cert
mycert = cert.get_pem()
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_REQUIRED
context.load_verify_locations("C:/API.crt") ##Works if certificate is stored locally
context.load_verify_locations(mycert) ## Does not Works if certificate is passed.
Traceback (most recent call last):
File "test.py", line 14, in <module>
context.load_verify_locations(mycert) ## Does not Works if certificate is passed.
FileNotFoundError: [Errno 2] No such file or directory
이 SSLContext.load_verify_locations()
메서드는 세 가지 키워드 인수를 사용합니다.
cafile
PEM 형식의 연결된 CA 인증서 파일 경로
capath
PEM 형식의 여러 CA 인증서를 포함하는 디렉토리 경로
cadata
하나 이상의 PEM 인코딩 인증서 의 ASCII 문자열 또는 DER 인코딩 인증서의 바이트 류 객체
로 인해 mycert = cert.get_pem()
, mycert
은 IS ASCII의 PEM 문자열 해당 인증서가 아닌의 경로 인증서에가.
두 호출 모두에서 매개 변수를 위치로 전달하므로 첫 번째 키워드 인수 ( cafile
)에 할당됩니다 . 첫 번째 호출에서 인수는 실제로 파일 경로이므로 예상대로 작동합니다. 두 번째에서는 파일 경로가 아니므로 FileNotFoundError
.
두 번째 호출을 context.load_verify_locations(cdata=mycert)
로 변경 하여 인수가 PEM 문자열임을 지정하면 작동 할 것으로 의심됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다