Last active
February 10, 2023 04:22
-
-
Save brianddk/8ffa0734fc9ff4d616df to your computer and use it in GitHub Desktop.
Extract Key Data from GPG
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
| enc_oaep_bi_552_by_27_ch_69.txt | |
| enc_pkcs_bi_552_by_58_ch_69.txt | |
| enc_oaep_bi_528_by_24_ch_66.txt | |
| enc_pkcs_bi_528_by_55_ch_66.txt | |
| b64 = ceil ( cipher * 4/3 ) | |
| cipher = bits / 8 | |
| bits = 8 * (text + pack) | |
| pack = 11 #pkcs | |
| pack = 42 #oaep |
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
| function mkP12 { | |
| echo 'Making P12' 1>&3 | |
| openssl pkcs12 -export -nocerts -inkey <(mkPrivKey) -password pass:"$locKeyPass" | |
| echo 'Made P12' 1>&3 | |
| } | |
| function gptImp { | |
| echo 'Importing with gpg-protect-tool' 1>&3 | |
| gpg-protect-tool -P "$locKeyPass" --store --force --p12-import - | |
| echo 'Imported with gpg-protect-tool' 1>&3 | |
| } | |
| function mkPrivKey { | |
| echo "Making $locBits bit Private Key" 1>&3 | |
| openssl genrsa $locBits | |
| echo "Made $locBits bit Private Key" 1>&3 | |
| } | |
| function errCat { | |
| echo "Catting to STDERR" 1>&3 | |
| cat 1>&2 | |
| echo "Catted to STDERR" 1>&3 | |
| } | |
| function cleanKgrip { | |
| echo "Cleaning Keygrip without Cert" 1>&3 | |
| local locArray="init" | |
| IFS=":" read -ra locArray <<< "$locKeygrip" | |
| locKeygrip=$(echo -n ${locArray[2]} | tr -d '[[:space:]]') | |
| echo "Cleaned Keygrip without Cert" 1>&3 | |
| } | |
| function _main { | |
| echo "Begin main" | |
| local locKeyPass="init" | |
| local locVerPass="init_" | |
| local locBits="init" | |
| local locKeygrip="init" | |
| echo "Enter how many bits wide you want this key." | |
| echo -n "Bits: " | |
| read locBits | |
| echo "Enter a password for this key. You will be prompted again, sorry." | |
| echo -n "Password: " | |
| read -s locKeyPass | |
| echo "" | |
| echo -n "Verify: " | |
| read -s locVerPass | |
| echo "" | |
| if [ "$locKeyPass" != "$locVerPass" ]; then | |
| echo "ERR: password mismatch" | |
| exit 1 | |
| fi | |
| exec 3>&2 # copy fd2 to fd3 | |
| exec 2> err.log # copy err.log to 2 | |
| locKeygrip=$(mkP12 | gptImp 2>&1 | tee >(errCat) | grep keygrip) | |
| cleanKgrip | |
| unset locKeyPass | |
| unset locVerPass | |
| unset locBits | |
| #unset locKeygrip | |
| exec 2>&3 # copy fd3 to fd2 | |
| exec 3>&- # close fd3 | |
| echo "End main: $locKeygrip" | |
| } | |
| _main |
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
| 1) Create a key in Openssl (openssl genrsa) | |
| 2) Dump Key matter (https://www.openssl.org/docs/apps/asn1parse.html) | |
| 3) Import it into GpgSM (http://www.sysmic.org/dotclear/index.php?post/2010/03/24/Convert-keys-betweens-GnuPG%2C-OpenSsh-and-OpenSSL) | |
| 4) Import into gpg (gpg --edit-key addkey {from existing fingerprint}) | |
| 5) Dump Key matter (gpg --export {keyid} | gpg --list-packets --debug-all) | |
| 6) Export to OpenSSL (http://www.sysmic.org/dotclear/index.php?post/2010/03/24/Convert-keys-betweens-GnuPG%2C-OpenSsh-and-OpenSSL) | |
| 7) Dump Key matter (https://www.openssl.org/docs/apps/asn1parse.html) | |
| PublicKey: https://tools.ietf.org/html/rfc2313#section-7.1 | |
| PrivateKey: https://tools.ietf.org/html/rfc2313#section-7.2 | |
| gpg-protect-tool --armor -u %appdata%\gnupg\private-keys-v1.d\{keygrip}.key ^ | |
| | gpg-protect-tool.exe --p12-export -P {pipepass} ^ | |
| | openssl pkcs12 -nodes -nocerts -passin pass:pipepass ^ | |
| | openssl asn1parse -strparse 22 | |
| >gpgsm --debug-all --import priv_528.p12 2>&1 | findstr /i keygrip | |
| <gpgsm: DBG: keygrip= 2D C1 91 45 6D BD CD 97 F1 33 17 B1 DF 78 61 A9 0E 11 BE AE | |
| gpg --expert --edit-key TestKey addkey 13 2DC191456DBDCD97F13317B1DF7861A90E11BEAE s q 0 y y save | |
| scripting edit-key | |
| https://lists.gnupg.org/pipermail/gnupg-devel/2002-April/018255.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment