# Copyright (C) 2010, 2012 Internet Systems Consortium, Inc. ("ISC")
#
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# Generate a DNS RR from an x.509 certificate
# Currently only supports TLSA, but can be extended to support
# other DANE types such as SMIMEA in the future.
#
# Requires: openssl
Options:
-f <input format>: PEM | DLR
-n <name>: record name (default: _443._tcp)
-o <origin>: zone origin (default: none; name will be relative)
-m <matching type>: NONE (0) | SHA256 (1) | SHA512 (2)
-r <RR type>: TLSA
-s <selector>: FULL (0) | PK (1)
-t <ttl>: TTL of the TLSA record (default: none)
-u <certificate usage>: CA (0) | SERVICE (1) | TA (2) | DOMAIN (3)"
NM="_443._tcp"
CU=2
SELECTOR=0
MTYPE=1
IN=
TTL=
while getopts "xn:o:u:s:t:m:i:f:r:" c; do
case $c in
x) set -x; DEBUG=-x;;
esac
done
IN=$1
else
fi
if [ -n "$ORIGIN" ]; then
fi
[0123]) ;;
esac
[01]) ;;
esac
esac
esac
*) echo "invalid RR type" 1>&2; exit 1
esac
fi
else
fi) \
| $HASH \
| awk '
# format Association Data as in Appendix C of the DANE RFC
BEGIN {
leader = "\t\t\t\t\t";
}
/.+/ {
gsub(/ +/, "", $0);
buf = buf $0;
while (length(buf) >= 36) {
print leader substr(buf, 1, 36);
buf = substr(buf, 37);
}
}
END {
if (length(buf) > 34)
print leader buf "\n" leader ")";
else
print leader buf " )";
}'