leslie-tsang commented on pull request #6498:
URL: https://github.com/apache/apisix/pull/6498#issuecomment-1057786886


   The change from `if len(sys.argv) <= 4` to `if len(sys.argv) < 4` in 
**<ins>ssl.py</ins>** don't have the desired effect.
   
   There is another [conditional 
judgment](https://github.com/apache/apisix/blob/ce8227aaf7e4f0b8aab6274c38deda6e7c243c9d/docs/en/latest/mtls.md?plain=1#L121)
 `if len(sys.argv) >= 5` will prevent the request execution.
   
   ```patch
   #!/usr/bin/env python
   # coding: utf-8
   # save this file as ssl.py
   import sys
   # sudo pip install requests
   import requests
   - if len(sys.argv) <= 4:
   + if len(sys.argv) < 4:
       print("bad argument")
       sys.exit(1)
   with open(sys.argv[1]) as f:
       cert = f.read()
   with open(sys.argv[2]) as f:
       key = f.read()
   sni = sys.argv[3]
   api_key = "edd1c9f034335f136f87ad84b625c8f1" # Change it
   reqParam = {
       "cert": cert,
       "key": key,
       "snis": [sni],
   }
   if len(sys.argv) >= 5:
       print("Setting mTLS")
       reqParam["client"] = {}
       with open(sys.argv[4]) as f:
           clientCert = f.read()
           reqParam["client"]["ca"] = clientCert
       if len(sys.argv) >= 6:
           reqParam["client"]["depth"] = int(sys.argv[5])
   resp = requests.put("http://127.0.0.1:9080/apisix/admin/ssl/1";, 
json=reqParam, headers={
       "X-API-KEY": api_key,
   })
   print(resp.status_code)
   print(resp.text)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to