Featured image of post Verify And Cert In Python Requests

Verify And Cert In Python Requests

Understanding the cert and verify parameters in the requests library vaguely but enough to use

the delivery_man import requests as delivery_man is tasked with delivering the money to banks.

verify (Delivery Man’s Side)

Context

Before giving the money to the bank, the delivery_man must verify if the bank is legitimate or a scam.

verify is the task where the delivery_man compares if the bank’s certificate is in the valid certificates before handing over the money. There are 3 types of verification to validate the legitimacy of the bank:

  • verify=False: No need to verify! Just give the money to the bank without checking if it’s legit.
  • verify=True: Fetch valid certificates using a certificate authority from the cloud. DigiCert (https://www.digicert.com/) is one of the well-known certificate authorities.
  • verify='/local/path/digicert.pem': Fetch valid certificates using the provided cert path from the local system.

Code

verify=False The delivery_man will not check if https://www.bankofamerica.com certificate is valid or not

1
2
3
4
5
delivery_man.post(
    "https://www.bankofamerica.com/", 
    json={"id": "bill_gates", "money": 1000}, 
    verify=False
)

verify=True The delivery_man will check if https://www.bankofamerica.com certificate is in https://www.digicert.com/ or not

1
2
3
4
5
delivery_man.post(
    "https://www.bankofamerica.com/", 
    json={"id": "bill_gates", "money": 1000}, 
    verify=True
)

verify='/local/path/digicert.pem' The delivery_man will check if https://www.bankofamerica.com certificate is in /local/path/digicert.pem or not

1
2
3
4
5
delivery_man.post(
    "https://www.bankofamerica.com/", 
    json={"id": "bill_gates", "money": 1000}, 
    verify='/local/path/digicert.pem'
)

cert (Bank’s Side)

Context

Before receiving the money from the delivery_man, the bank has to verify if the delivery_man is legitimate or a scam.

cert is the task where the bank compares if the delivery_man’s certificate is in the valid certificates before accepting the money. There are 2 types of verification to validate the legitimacy of the delivery_man:

  • cert='/local/path/cert_and_key.pem': Cert and Key are combined into one file.
  • cert=('/local/path/cert.crt', '/local/path/private.key'): Cert and Key are 2 separate files.

Code

cert='/local/path/cert_and_key.pem' The bank will check if the delivery_man’s certificate is legit or not

1
2
3
4
5
delivery_man.post(
    "https://www.bankofamerica.com/", 
    json={"id": "bill_gates", "money": 1000}, 
    cert="/local/path/cert_and_key.pem"
)

cert=('/local/path/cert.crt', '/local/path/private.key') The bank will check if the delivery_man’s certificate is legit or not

1
2
3
4
5
delivery_man.post(
    "https://www.bankofamerica.com/", 
    json={"id": "bill_gates", "money": 1000}, 
    cert=("/local/path/cert.crt", "/local/path/private.key")
)
Made with the laziness 🦥
by a busy guy