Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend require() to allow plaintext to variable #3190

Open
Sibul2k opened this issue Nov 3, 2024 · 0 comments
Open

Extend require() to allow plaintext to variable #3190

Sibul2k opened this issue Nov 3, 2024 · 0 comments

Comments

@Sibul2k
Copy link

Sibul2k commented Nov 3, 2024

Is your feature request related to a problem? Please describe.
As discussed on the mailing list between Tom and me. Topic: "Generation of correct TLSA record variables - How?"
My issue basically could be solved by an monstrocity of escaped ", " and ' combinations. It's not readable code. It would be way more easy, if the project would allow an easy option to load plaintext from files into a variable.

Describe the solution you'd like

------ ./somefile.txt ------
CNAME("foo", "foo.example.com."),

------ ./dnscontrol.js -------

[...]
var FOO = require(./somefile.txt)

D("example.com", REG_MY_PROVIDER,
   [..],
   FOO,
END);
[...]

Result:
CNAME foo.example.com was added to D()

Describe alternatives you've considered
I had to generate this:

var  EXAMPLE_MAIL_DOMAIN_TLSA = require("/opt/dnscontrol/TLSA-25-mail.example.com.json");
var  EXAMPLE_MAIL_DOMAIN_TLSA3 = TLSA("\"_" +  EXAMPLE_MAIL_DOMAIN_TLSA["port"] + "._tcp." + EXAMPLE_MAIL_DOMAIN_TLSA["domain"] + ".\"", 3, 1, 1, "\"" +  EXAMPLE_MAIL_DOMAIN_TLSA["cert_hash"] + "\"");
var  EXAMPLE_MAIL_DOMAIN_TLSA2 = TLSA("\"_" +  EXAMPLE_MAIL_DOMAIN_TLSA["port"] + "._tcp." +  EXAMPLE_MAIL_DOMAIN_TLSA["domain"] + ".\"", 2, 1, 1, "\"" +  EXAMPLE_MAIL_DOMAIN_TLSA["root_ca_hash"] + "\"");

where all the variable parts I generated with some other script had to be reconstructed from json. I could have altered the generation of the script to just the plaintext TLSA() string.

Additional context
Should be sufficient, I hope.

Just for reference: My TLSA() script to generate the variables, if someone cares to do DANE as well. Could be altered to read the certificate file instead or talk to a webserver, not mail by changing the openssl options.

-------- ./get_smtp_tls_hash.sh -----------------

#!/bin/bash

# Defaults
PORT=25
DOMAIN=""

# get CLI-Options
while getopts "d:p:" opt; do
  case $opt in
    d) DOMAIN="$OPTARG" ;;
    p) PORT="$OPTARG" ;;
    *) echo "Usage: $0 -d <domain> [-p <port>]" && exit 1 ;;
  esac
done

# Check if DOMAIN exists
if [[ -z "$DOMAIN" ]]; then
  echo "Error: Domain (-d) is required."
  exit 1
fi

# get live certificat information
CERTIFICATE=$(echo | openssl s_client -starttls smtp -connect ${DOMAIN}:${PORT} 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p')
ROOT_CA=$(echo "$CERTIFICATE" | openssl x509 -noout -issuer -next_serial)

# SHA256-Hash calculation
CERT_HASH=$(echo "$CERTIFICATE" | openssl x509 -noout -pubkey | openssl sha256 | awk '{print $2}')
ROOT_CA_HASH=$(echo "$ROOT_CA" | openssl sha256 | awk '{print $2}')

# Generate TLSA() records
#  echo "TLSA(\"_${PORT}._tcp.${DOMAIN}.\", 3, 1, 1, \"${CERT_HASH}\")" > ./TLSA-${PORT}-3-${DOMAIN}.txt
#  echo "TLSA(\"_${PORT}._tcp.${DOMAIN}.\", 2, 1, 1, \"${ROOT_CA_HASH}\")" > ./TLSA-${PORT}-2-${DOMAIN}.txt

# Generate as JSON
echo '{
  "port": "'${PORT}'",
  "domain": "'${DOMAIN}'",
  "cert_hash": "'${CERT_HASH}'",
  "root_ca_hash": "'${ROOT_CA_HASH}'"
}' > ./TLSA-${PORT}-${DOMAIN}.json


Thank you for considering this request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant