Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
executable file 42 lines (28 sloc) 1.18 KB
#!/usr/bin/env bash
# Requires:
# * der2ascii/ascii2der tools by David Benjamin:
# * OpenSSL
set -eu -o pipefail
type der2ascii &>/dev/null || echo "Need der2ascii/ascii2der tools from"
if [[ ${#} -ne 1 ]] && [[ ${#} -ne 2 ]]; then
echo "Usage:"
echo " fakekey [certificate] [output]"
echo ""
echo "If [output] isn't given we'll write to fake.key."
exit 1
TMP="$(mktemp -d)"
[[ "${#}" -eq 2 ]] && out="${2}" || out="fake.key"
openssl x509 -noout -pubkey -in "${1}" | openssl pkey -outform der -pubin > "${TMP}/cert.der"
openssl genrsa 2048 | openssl pkey -outform der -out "${TMP}/newkey.der"
der2ascii -i "${TMP}/cert.der" -o "${TMP}/cert.ascii"
der2ascii -i "${TMP}/newkey.der" -o "${TMP}/newkey.ascii"
head -n 2 "${TMP}/newkey.ascii" > "${TMP}/fake.ascii"
grep INTEGER "${TMP}/cert.ascii" >> "${TMP}/fake.ascii"
tail -n +5 "${TMP}/newkey.ascii" >> "${TMP}/fake.ascii"
ascii2der -i "${TMP}/fake.ascii" -o "${TMP}/fake.der"
openssl pkey -inform der -in "${TMP}/fake.der" -out "${out}"
echo "checking ${out} (errors are to be expected!)"
openssl rsa -in "${out}" -check -noout
rm -rf "${TMP}"