Verifying peer in SSL using python

后端 未结 3 675
花落未央
花落未央 2020-12-30 11:29

I was trying to find out how I can go about verifying a self-signed certificate by a server in python. I could not find much data in google. I also want to make sure that th

3条回答
  •  我在风中等你
    2020-12-30 12:04

    I assume you use some OpenSSL binding. I see 2 ways to solve your problem.

    1. You can add your certificate to openssl directory (run openssl version -d to see it for your system). This will affect all programs using openssl on your machine.
    2. Load certificate and add it run-time (the code sketch below is for PyOpenSSL, but it should be similar for other bindings):

    .

    x509 = OpenSSL.crypto.load_certificate(...)
    ctx = OpenSSL.SSL.Context(...)
    store = ctx.get_cert_store()
    store.add_cert(x509)
    ctx.set_verify(VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT, ...)
    

提交回复
热议问题