-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from NethServer/export_custom_cert
Improve Custom Certificate Handling and Redis Storage
- Loading branch information
Showing
6 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
imageroot/actions/upload-certificate/23export_certificates
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import os | ||
import json | ||
import agent | ||
import sys | ||
import subprocess | ||
from base64 import b64decode | ||
|
||
|
||
module_id = os.environ['MODULE_ID'] | ||
node_id = os.environ['NODE_ID'] | ||
|
||
data = json.load(sys.stdin) | ||
|
||
# read and decode the base64 certificate and key from json payload | ||
cert = b64decode(data["certFile"]).decode() | ||
key = b64decode(data["keyFile"]).decode() | ||
|
||
# read the common name from the certificate | ||
result = subprocess.run( | ||
['openssl', 'x509', '-noout', '-subject', '-in', '/dev/stdin', '-nameopt', 'sep_multiline', '-nameopt', 'utf8'], | ||
input=cert, | ||
capture_output=True, | ||
text=True | ||
) | ||
|
||
subject = result.stdout | ||
domain = subject.split("\n")[1].split("CN=")[1] | ||
|
||
# save the certificate and key in redis | ||
rdb = agent.redis_connect(privileged=True) | ||
rkey = f'module/{module_id}/certificate/{domain}' | ||
rdb.hset(rkey, mapping={"cert": cert, "key": key, "custom": "true"}) | ||
|
||
# signal the certificate-updated event | ||
event_key = f'module/{module_id}/event/certificate-updated' | ||
event = {"rkey": rkey, "node": node_id, "module": module_id, "domain": domain, "custom": True} | ||
rdb.publish(event_key, json.dumps(event)) |
This file contains 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
This file contains 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
This file contains 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