| 1 | #!/usr/bin/env bash |
| 2 | # ========================================================================== |
| 3 | # _ _ _ ____ ____ _____ |
| 4 | # | | | (_) _ \ ___ _ __ / ___|___ _ _|_ _| __ __ _ ___ ___ _ __ |
| 5 | # | |_| | | |_) / _ \ '__| | / _ \| '_ \| || '__/ _` |/ __/ _ \ '__| |
| 6 | # | _ | | __/ __/ | | |__| (_) | | | | || | | (_| | (_| __/ | |
| 7 | # |_| |_|_|_| \___|_| \____\___/|_| |_|_||_| \__,_|\___\___|_| |
| 8 | # |
| 9 | # --- High-Performance Connectivity Tracer (HiPerConTracer) --- |
| 10 | # https://www.nntb.no/~dreibh/hipercontracer/ |
| 11 | # ========================================================================== |
| 12 | # |
| 13 | # High-Performance Connectivity Tracer (HiPerConTracer) |
| 14 | # Copyright (C) 2015-2026 by Thomas Dreibholz |
| 15 | # |
| 16 | # This program is free software: you can redistribute it and/or modify |
| 17 | # it under the terms of the GNU General Public License as published by |
| 18 | # the Free Software Foundation, either version 3 of the License, or |
| 19 | # (at your option) any later version. |
| 20 | # |
| 21 | # This program is distributed in the hope that it will be useful, |
| 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | # GNU General Public License for more details. |
| 25 | # |
| 26 | # You should have received a copy of the GNU General Public License |
| 27 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 | # |
| 29 | # Contact: [email protected] |
| 30 | |
| 31 | # Bash options: |
| 32 | set -euo pipefail |
| 33 | |
| 34 | |
| 35 | # ###### Usage ############################################################## |
| 36 | usage () { |
| 37 | local exitCode="$1" |
| 38 | echo >&2 "Usage: $0 encrypted_dbeaver_credentials_config_json plain_dbeaver_credentials_config_json [-h|--help] [-v|--version]" |
| 39 | exit "${exitCode}" |
| 40 | } |
| 41 | |
| 42 | |
| 43 | # ###### Version ############################################################ |
| 44 | version () { |
| 45 | echo "Decrypt-DBeaver-Configuration @BUILD_MAJOR@.@BUILD_MINOR@.@BUILD_PATCH@" |
| 46 | exit 0 |
| 47 | } |
| 48 | |
| 49 | |
| 50 | |
| 51 | # ###### Main program ####################################################### |
| 52 | |
| 53 | # ====== Handle arguments =================================================== |
| 54 | if (( BASH_VERSINFO[0] < 4 )) || (( (BASH_VERSINFO[0] == 4) && (BASH_VERSINFO[1] < 4) )) ; then |
| 55 | echo "ERROR: Bash 4.4 or higher is required, but Bash ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]} is installed!" |
| 56 | exit 1 |
| 57 | fi |
| 58 | UNAME="$(uname)" |
| 59 | case "${UNAME}" in |
| 60 | FreeBSD) |
| 61 | GETOPT="$(PATH="/usr/local/bin:${PATH}" command -v getopt || true)" |
| 62 | ;; |
| 63 | NetBSD) |
| 64 | GETOPT="$(PATH="/usr/pkg/bin:${PATH}" command -v getopt || true)" |
| 65 | ;; |
| 66 | OpenBSD) |
| 67 | GETOPT="$(command -v gnugetopt || true)" |
| 68 | ;; |
| 69 | Darwin) |
| 70 | GETOPT="$(env PATH="/opt/homebrew/opt/gnu-getopt/bin:${PATH}" command -v getopt || true)" |
| 71 | ;; |
| 72 | *) |
| 73 | GETOPT="$(command -v getopt || true)" |
| 74 | ;; |
| 75 | esac |
| 76 | if "${GETOPT}" -T >/dev/null 2>&1 || [[ $? -ne 4 ]]; then |
| 77 | echo >&2 "ERROR: Enhanced/GNU getopt is required!" |
| 78 | exit 1 |
| 79 | fi |
| 80 | options="$(${GETOPT} -o hv --long help,version -a -- "$@")" |
| 81 | # shellcheck disable=SC2181 |
| 82 | if [[ $? -ne 0 ]]; then |
| 83 | usage 1 |
| 84 | fi |
| 85 | |
| 86 | eval set -- "${options}" |
| 87 | while [ $# -gt 0 ] ; do |
| 88 | case "$1" in |
| 89 | -h | --help) |
| 90 | usage 0 |
| 91 | ;; |
| 92 | -v | --version) |
| 93 | version |
| 94 | ;; |
| 95 | --) |
| 96 | shift |
| 97 | break |
| 98 | ;; |
| 99 | *) |
| 100 | # This should not happen: wrong getopt parameters, or missing case? |
| 101 | echo >&2 "INTERNAL ERROR: Unhandled option $1!" |
| 102 | exit 1 |
| 103 | ;; |
| 104 | esac |
| 105 | shift |
| 106 | done |
| 107 | if [ $# -ne 2 ] ; then |
| 108 | usage 1 |
| 109 | fi |
| 110 | |
| 111 | INPUT_FILE="$1" |
| 112 | if [ "${INPUT_FILE}" == "-" ] ; then |
| 113 | INPUT_FILE="/dev/stdin" |
| 114 | fi |
| 115 | OUTPUT_FILE="$2" |
| 116 | if [ "${OUTPUT_FILE}" == "-" ] ; then |
| 117 | OUTPUT_FILE="/dev/stdout" |
| 118 | fi |
| 119 | |
| 120 | # ====== Process file ======================================================= |
| 121 | openssl aes-128-cbc -d \ |
| 122 | -K babb4a9f774ab853c96c2d653dfe544a -iv 00000000000000000000000000000000 \ |
| 123 | -in "${INPUT_FILE}" | dd bs=1 skip=16 status=none | jq . >"${OUTPUT_FILE}" |