Created
October 3, 2019 19:07
-
-
Save almightyju/bafda22aaf8f14de082e4ae8577d8b3c to your computer and use it in GitHub Desktop.
Sophos XG LetsEncrypt API update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
xmlMsg = """ | |
<Request APIVersion="1702.1"> | |
<Login> | |
<Username>apiuser</Username> | |
<Password>Password</Password> | |
</Login> | |
<Set operation="update"> | |
<Certificate> | |
<Action>UploadCertificate</Action> | |
<Name>{Domain}</Name> | |
<Password>CertPassword</Password> | |
<CertificateFormat>pem</CertificateFormat> | |
<CertificateFile>cert.pem</CertificateFile> | |
<PrivateKeyFile>priv.key</PrivateKeyFile> | |
</Certificate> | |
</Set> | |
</Request> | |
""" | |
url = "https://FirewallIP:Port/webconsole/APIController" | |
certDirs = "/etc/letsencrypt/live" | |
domains = [d for d in os.listdir(certDirs) if os.path.isdir(os.path.join(certDirs, d))] | |
for d in domains: | |
reqXml = xmlMsg.format(Domain=d) | |
chainPem = os.path.join(certDirs, d, 'fullchain.pem') | |
privKey = os.path.join(certDirs, d, 'privkey.pem') | |
response = requests.post(url, files={ | |
'cert.pem': ('cert.pem', open(chainPem, 'rb'), 'application/octet-stream'), | |
'priv.key': ('priv.key', open(privKey, 'rb'), 'application/octet-stream'), | |
'reqxml': (None, reqXml, 'application/xml', {'charset': 'utf-8'}) | |
}, verify=False) | |
print(response.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment