Created
August 22, 2016 17:58
-
-
Save trapexit/82db860d42f7ea5f176e77253fb05b15 to your computer and use it in GitHub Desktop.
Extract certs and keys from OpenVPN ovpn file
This file contains hidden or 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
#!/bin/bash | |
OVPN_FILE="${1}" | |
OUTPUT_PREFIX="${2}" | |
if [ ! -e "${OVPN_FILE}" ]; then | |
echo "File not found: ${OVPN_FILE}" | |
exit 1 | |
fi | |
if [ "${OUTPUT_PREFIX}" == "" ]; then | |
OUTPUT_PREFIX=$(date '+%s') | |
fi | |
awk '/<ca>/{flag=1;next}/<\/ca>/{flag=0}flag' "${OVPN_FILE}" > "${OUTPUT_PREFIX}-ca.crt" | |
awk '/<cert>/{flag=1;next}/<\/cert>/{flag=0}flag' "${OVPN_FILE}" > "${OUTPUT_PREFIX}-client.crt" | |
awk '/<key>/{flag=1;next}/<\/key>/{flag=0}flag' "${OVPN_FILE}" > "${OUTPUT_PREFIX}-client.key" | |
openssl pkcs12 -export \ | |
-in "${OUTPUT_PREFIX}-client.crt" \ | |
-inkey "${OUTPUT_PREFIX}-client.key" \ | |
-out "${OUTPUT_PREFIX}-client.p12" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment