Initial commit.

This commit is contained in:
Erik C. Thauvin 2019-04-29 20:14:29 -07:00
commit 8a91146fae
14 changed files with 360 additions and 0 deletions

2
.editorconfig Normal file
View file

@ -0,0 +1,2 @@
[*]
insert_final_newline=true

5
.gitattributes vendored Normal file
View file

@ -0,0 +1,5 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# batch files are specific to windows and always crlf
*.bat eol=crlf

84
.gitignore vendored Normal file
View file

@ -0,0 +1,84 @@
__pycache__
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json
!.vscode/tasks.json
!gradle-wrapper.jar
.classpath
.DS_Store
.gradle
.history
.idea_modules/
.idea/**/contentModel.xml
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/dataSources/
.idea/**/dbnavigator.xml
.idea/**/dictionaries
.idea/**/dynamic.xml
.idea/**/gradle.xml
.idea/**/libraries
.idea/**/mongoSettings.xml
.idea/**/shelf
.idea/**/sqlDataSources.xml
.idea/**/tasks.xml
.idea/**/uiDesigner.xml
.idea/**/usage.statistics.xml
.idea/**/workspace.xml
.idea/caches/build_file_checksums.ser
.idea/httpRequests
.idea/replstate.xml
.kobalt
.mtj.tmp/
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.nb-gradle
.project
.scannerwork
.settings
.vscode/*
*.class
*.code-workspace
*.ctxt
*.ear
*.iws
*.jar
*.log
*.nar
*.rar
*.sublime-*
*.tar.gz
*.war
*.zip
atlassian-ide-plugin.xml
bin/
build/
cmake-build-*/
com_crashlytics_export_strings.xml
crashlytics-build.properties
crashlytics.properties
dependency-reduced-pom.xml
deploy/
dist/
ehthumbs.db
fabric.properties
gen/
gradle.properties
hs_err_pid*
kobaltBuild
kobaltw*-test
lib/kotlin*
libs/
local.properties
out/
pom.xml.next
pom.xml.releaseBackup
pom.xml.tag
pom.xml.versionsBackup
proguard-project.txt
project.properties
release.properties
target/
test-output
Thumbs.db
venv

View file

@ -0,0 +1,6 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="&amp;#36;file.fileName&#10;&#10;Copyright (c) &amp;#36;today.year, Erik C. Thauvin (erik@thauvin.net)&#10;All rights reserved.&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are met:&#10;&#10; Redistributions of source code must retain the above copyright notice, this&#10; list of conditions and the following disclaimer.&#10;&#10; Redistributions in binary form must reproduce the above copyright notice,&#10; this list of conditions and the following disclaimer in the documentation&#10; and/or other materials provided with the distribution.&#10;&#10; Neither the name of this project nor the names of its contributors may be&#10; used to endorse or promote products derived from this software without&#10; specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;&#10;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&#10;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&#10;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE&#10;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&#10;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&#10;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER&#10;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&#10;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&#10;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." />
<option name="myName" value="Erik's Copyright Notice" />
</copyright>
</component>

7
.idea/copyright/profiles_settings.xml generated Normal file
View file

@ -0,0 +1,7 @@
<component name="CopyrightManager">
<settings default="Erik's Copyright Notice">
<module2copyright>
<element module="All" copyright="Erik's Copyright Notice" />
</module2copyright>
</settings>
</component>

6
.idea/encodings.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

7
.idea/misc.xml generated Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (namesilo-letsencrypt)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/namesilo-letsencrypt.iml" filepath="$PROJECT_DIR$/.idea/namesilo-letsencrypt.iml" />
</modules>
</component>
</project>

13
.idea/namesilo-letsencrypt.iml generated Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

12
LICENSE.md Normal file
View file

@ -0,0 +1,12 @@
### Copyright &copy; 2019, Erik C. Thauvin ([erik@thauvin.net](mailto:erik@thauvin.net))
#### All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of this project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*

45
README.md Normal file
View file

@ -0,0 +1,45 @@
# NameSilo Let's Encrypt
Python scripts (hook) to automate obtaining [Let's Encrypt](https://letsencrypt.org/) certificates,
using [Certbot](https://certbot.eff.org/) DNS-01 challenge validation for domains DNS hosted on
[NameSilo](https://www.namesilo.com/).
## Configuration
Add you [NameSilo API key](https://www.namesilo.com/account_api.php)
to the top of the `config.py` file:
```python
# Get your API Key from: https://www.namesilo.com/account_api.php
apikey = "YOUR_API_KEY"
```
Alternatively, the API key can be set in the `NAMESILO_API` environment variable.
## Using with Certbot
To issue a new certificate using the hook scripts, try something like:
<pre>
certbot certonly --manual --email you@example.com \
--agree-tos --manual-public-ip-logging-ok \
--preferred-challenges=dns \
--manual-auth-hook <em>/path/to/authenticator.py</em> \
--manual-cleanup-hook <em>/path/to/cleanup.py</em> \
-d *.example.com -d example.com
</pre>
Or to renew an existing certificate:
<pre>
certbot renew --manual --email you@example.com \
--agree-tos --manual-public-ip-logging-ok \
--preferred-challenges=dns \
--manual-auth-hook <em>/path/to/authenticator.py</em> \
--manual-cleanup-hook <em>/path/to/cleanup.py</em> \
-d *.example.com -d example.com
</pre>
Please note that NameSilo DNS propagation takes up to **15 minutes**,
so the scripts will wait 16 minutes before completing.

83
authenticator.py Normal file
View file

@ -0,0 +1,83 @@
#!/usr/bin/env python3.7
# authenticator.py
#
# Copyright (c) 2019, Erik C. Thauvin (erik@thauvin.net)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of this project nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import tempfile
import time
import urllib.request
import untangle
from config import apikey
domain = os.environ['CERTBOT_DOMAIN']
validation = os.environ['CERTBOT_VALIDATION']
tmpdir = os.path.join(tempfile.gettempdir(), f"CERTBOT_{domain}")
if "NAMESILO_API" in os.environ:
apikey = os.environ['NAMESILO_API']
url = f"https://www.namesilo.com/api/dnsAddRecord?\
version=1&type=xml&key={apikey}&domain={domain}&rrtype=TXT\
&rrhost=_acme-challenge&rrvalue={validation}&rrttl=3600"
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': ('Mozilla/5.0 (X11; CrOS x86_64 11647.154.0) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/73.0.3683.114 Safari/537.36')
}
)
with urllib.request.urlopen(req) as response:
html = response.read()
xml = untangle.parse(str(html, 'utf-8'))
if not os.path.exists(tmpdir):
os.mkdir(tmpdir, 0o700)
if xml.namesilo.reply.code.cdata == '300':
f = open(os.path.join(tmpdir, "RECORD_ID"), "a+")
print(xml.namesilo.reply.record_id.cdata, file=f)
f.close()
else:
print("{}: {} ({})".format(domain,
xml.namesilo.reply.detail.cdata,
xml.namesilo.reply.code.cdata), file=sys.stderr)
sys.exit(1)
# Sleep 16 minutes
time.sleep(960)

80
cleanup.py Normal file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env python3.7
# cleanup.py
#
# Copyright (c) 2019, Erik C. Thauvin (erik@thauvin.net)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of this project nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import os
import sys
import tempfile
import urllib.request
import untangle
from config import apikey
domain = os.environ['CERTBOT_DOMAIN']
tmpdir = os.path.join(tempfile.gettempdir(), f"CERTBOT_{domain}")
if "NAMESILO_API" in os.environ:
apikey = os.environ['NAMESILO_API']
url = f"https://www.namesilo.com/api/dnsDeleteRecord\
?version=1&type=xml&key={apikey}&domain={domain}&rrid="
def getrequest(record_id):
return urllib.request.Request(
url + record_id,
data=None,
headers={
'User-Agent': ('Mozilla/5.0 (X11; CrOS x86_64 11647.154.0) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/73.0.3683.114 Safari/537.36')
}
)
idFile = os.path.join(tmpdir, "RECORD_ID")
if os.path.isfile(idFile):
f = open(idFile, "r")
for line in f:
with urllib.request.urlopen(getrequest(line.rstrip())) as response:
html = response.read()
xml = untangle.parse(str(html, 'utf-8'))
if xml.namesilo.reply.code.cdata != '300':
print("{}: {} ({})".format(
domain,
xml.namesilo.reply.detail.cdata,
xml.namesilo.reply.code.cdata), file=sys.stderr)
if xml.namesilo.reply.code.cdata != '280':
sys.exit(1)
f.close()
os.remove(idFile)

2
config.py Normal file
View file

@ -0,0 +1,2 @@
# Get your API Key from: https://www.namesilo.com/account_api.php
apikey = "YOUR_API_KEY"