fix: 🚑 Fix broken cert/key requests

master
Keith Irwin 2023-12-30 19:02:35 -07:00
parent beea0a81d6
commit 12b2c4c1ae
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
3 changed files with 14 additions and 14 deletions

View File

@ -87,9 +87,9 @@ To prevent this, a token is generated on the server and sent to the user when re
- **REQUEST:** `GET /ssl`
- **FILE:** `back/lib/dashboard/ssl`
- **QUERYSTRING:** `?host=myhostname&ext=crt`
- **QUERYSTRING:** `?host=myhostname&type=cert`
- `host`: get file for which host?
- `ext`: `crt` for certs or `key` for keys
- `type`: `cert` for certs or `key` for keys
- **RESPONSE:** The requested SSL certificate or key file
## 2. Admin service

View File

@ -2,25 +2,25 @@
# FILE: dashboard/ssl
# DESCRIPTION: Get a user's SSL certs and keys
# USAGE: ssl remote_ip querystring
# QUERYSTRING: ?host=$hostname&ext=crt
# QUERYSTRING: ?host=$hostname&type=cert
source /etc/wagon/config
ip="${1}"; qs="$(<<<"${2}" tr '&' '\n' | sed 's/?//')"
# Parse querystring
hostname="$(<<<"${qs}" grep -oP 'host=(.*)' | sed 's/^host=//' | xargs)"
ext="$(<<<"${qs}" grep -oP 'ext=(.*)' | sed 's/^ext=//' | xargs)"
type="$(<<<"${qs}" grep -oP 'type=(.*)' | sed 's/^type=//' | xargs)"
if ! file="${hostname:?}/server.${ext:?}"; then
printf 'ERROR! Hostname "%s" or extension "%s" missing!\n' "${hostname}" "${ext}" >&2
printf 'Hostname or extension missing!\n' | /usr/lib/wagon/http_res 400; exit
else
printf 'User %s requested SSL file %s\n' "${ip}" "${file}" >&2
# Make sure type is 'cert' or 'key'
if [ "${type}" != 'cert' ] && [ "${type}" != 'key' ]; then
printf 'Invalid type: %s\n' "${type}" | tee >(cat 1>&2) | /usr/lib/wagon/http_res 400; exit
fi
# Make sure extension is 'crt' or 'key'
if [ "${ext}" != 'crt' ] && [ "${ext}" != 'key' ]; then
printf 'Invalid extension: %s\n' "${ext}" | tee >(cat 1>&2) | /usr/lib/wagon/http_res 400; exit
if ! file="${hostname:?}/${type:?}.pem"; then
printf 'ERROR! Hostname "%s" or type "%s" missing!\n' "${hostname}" "${type}" >&2
printf 'Hostname or type missing!\n' | /usr/lib/wagon/http_res 400; exit
else
printf 'User %s requested SSL file %s\n' "${ip}" "${file}" >&2
fi
# Get username

View File

@ -9,8 +9,8 @@ function Peer(data) {
this.cantDelete = data.cantDelete
this.isDeleting = ko.observable(false)
this.deleteText = ko.computed(() => this.isDeleting()?'Deleting...':'Delete')
this.crtHref = ko.computed(() => `${API_URL}/ssl?host=${this.name}&ext=crt`)
this.keyHref = ko.computed(() => `${API_URL}/ssl?host=${this.name}&ext=key`)
this.crtHref = ko.computed(() => `${API_URL}/ssl?host=${this.name}&type=cert`)
this.keyHref = ko.computed(() => `${API_URL}/ssl?host=${this.name}&type=key`)
}
function PeerList() {