mirror of
https://github.com/SnowMB/traefik-certificate-extractor.git
synced 2025-09-19 05:34:31 +08:00
Compare commits
3 Commits
v1.0.0
...
feature-cl
Author | SHA1 | Date | |
---|---|---|---|
|
fec384f6e7 | ||
|
0f77fa2960 | ||
|
6aa38b7a93 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
certs/
|
certs/
|
||||||
|
certs_flat/
|
||||||
data/
|
data/
|
||||||
|
|
||||||
# Python ignores
|
# Python ignores
|
||||||
|
15
README.md
15
README.md
@@ -5,6 +5,7 @@ Tool to extract Let's Encrypt certificates from Traefik's ACME storage file.
|
|||||||
## Installation
|
## Installation
|
||||||
```
|
```
|
||||||
git clone https://github.com/DanielHuisman/traefik-certificate-extractor
|
git clone https://github.com/DanielHuisman/traefik-certificate-extractor
|
||||||
|
cd traefik-certificate-extractor
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -13,6 +14,13 @@ python3 extractor.py [directory]
|
|||||||
```
|
```
|
||||||
Default directory is `./data`. The output directory is `./certs`.
|
Default directory is `./data`. The output directory is `./certs`.
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
There is a Docker image available for this tool: [danielhuisman/traefik-certificate-extractor](https://hub.docker.com/r/danielhuisman/traefik-certificate-extractor/).
|
||||||
|
Example run:
|
||||||
|
```
|
||||||
|
docker run --name extractor -d -v /srv/extractor/data:/app/data -v /srv/extractor/certs:/app/certs danielhuisman/traefik-certificate-extractor
|
||||||
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
```
|
```
|
||||||
certs/
|
certs/
|
||||||
@@ -26,4 +34,11 @@ certs/
|
|||||||
chain.pem
|
chain.pem
|
||||||
fullchain.pem
|
fullchain.pem
|
||||||
privkey.pem
|
privkey.pem
|
||||||
|
certs_flat/
|
||||||
|
example.com.crt
|
||||||
|
example.com.key
|
||||||
|
example.com.chain.pem
|
||||||
|
sub.example.nl.crt
|
||||||
|
sub.example.nl.key
|
||||||
|
sub.example.nl.chain.pem
|
||||||
```
|
```
|
||||||
|
29
extractor.py
29
extractor.py
@@ -3,6 +3,7 @@ import os
|
|||||||
import errno
|
import errno
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import argparse
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
@@ -53,18 +54,44 @@ class Handler(FileSystemEventHandler):
|
|||||||
with open(directory + 'fullchain.pem', 'w') as f:
|
with open(directory + 'fullchain.pem', 'w') as f:
|
||||||
f.write(fullchain)
|
f.write(fullchain)
|
||||||
|
|
||||||
|
# Write private key, certificate and chain to flat files
|
||||||
|
directory = 'certs_flat/'
|
||||||
|
|
||||||
|
with open(directory + c['Certificate']['Domain'] + '.key', 'w') as f:
|
||||||
|
f.write(privatekey)
|
||||||
|
with open(directory + c['Certificate']['Domain'] + '.crt', 'w') as f:
|
||||||
|
f.write(fullchain)
|
||||||
|
with open(directory + c['Certificate']['Domain'] + '.chain.pem', 'w') as f:
|
||||||
|
f.write(chain)
|
||||||
|
|
||||||
|
if c['Domains']['SANs']:
|
||||||
|
for name in c['Domains']['SANs']:
|
||||||
|
with open(directory + name + '.key', 'w') as f:
|
||||||
|
f.write(privatekey)
|
||||||
|
with open(directory + name + '.crt', 'w') as f:
|
||||||
|
f.write(fullchain)
|
||||||
|
with open(directory + name + '.chain.pem', 'w') as f:
|
||||||
|
f.write(chain)
|
||||||
|
|
||||||
print('Extracted certificate for: ' + c['Domains']['Main'] + (', ' + ', '.join(c['Domains']['SANs']) if c['Domains']['SANs'] else ''))
|
print('Extracted certificate for: ' + c['Domains']['Main'] + (', ' + ', '.join(c['Domains']['SANs']) if c['Domains']['SANs'] else ''))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description='Tool to extract Let\'s Encrypt certificates from Traefik\'s ACME storage file.')
|
||||||
|
|
||||||
# Determine path to watch
|
# Determine path to watch
|
||||||
path = sys.argv[1] if len(sys.argv) > 1 else './data'
|
path = sys.argv[1] if len(sys.argv) > 1 else './data'
|
||||||
|
|
||||||
# Create output directory if it doesn't exist
|
# Create output directories if it doesn't exist
|
||||||
try:
|
try:
|
||||||
os.makedirs('certs')
|
os.makedirs('certs')
|
||||||
except OSError as error:
|
except OSError as error:
|
||||||
if error.errno != errno.EEXIST:
|
if error.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
try:
|
||||||
|
os.makedirs('certs_flat')
|
||||||
|
except OSError as error:
|
||||||
|
if error.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
|
||||||
# Create event handler and observer
|
# Create event handler and observer
|
||||||
event_handler = Handler()
|
event_handler = Handler()
|
||||||
|
Reference in New Issue
Block a user