-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibkeyrng
1876 lines (1855 loc) · 81.3 KB
/
libkeyrng
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#################################################
############### GENERAL FUNCTIONS ###############
#################################################
#--------------
## CENTERING ##
#--------------
echo_c (){
w=$(stty size | cut -d" " -f2)
l=${#1}
printf "%"$((l+(w-l)/2))"s\n" "$1"; }
#--------------
## FIRST RUN ##
#--------------
firstrun (){
REDO=$(gpg --homedir gpg-KeyRNG/ --list-keys | grep -c KeyRNG)
if [ "$REDO" -gt "0" ]; then gpg --homedir gpg-KeyRNG/ --delete-secret-keys KeyRNG && gpg --homedir gpg-KeyRNG/ --delete-keys KeyRNG; fi
clear; echo ""; echo_c "GENERATING GPG MASTER KEY."; echo ""
echo_c "THIS KEY WILL AUTOMATICALLY ENCRYPT/DECRYPT YOUR BTC PRIVKEYS/SEEDS."; echo ""
read -s -p "Create a strong passphrase for this key: " pw; echo ""
read -s -p "Repeat: " cpw
while [[ "$pw" != "$cpw" ]]; do echo "Passwords don't match."; echo ""
read -s -p "Create a strong passphrase for this key: " pw; echo ""
read -s -p "Repeat: " cpw
done
echo -e "\nGenerating key..."
echo -e "Key-Type: 1\nKey-Length: 4096\nSubkey-Type: 1\nSubkey-Length: 4096\nPassphrase: "$pw"\nName-Real: KeyRNG\nExpire-Date: 0\nCreation-Date:1984-01-01\n" | gpg --homedir gpg-KeyRNG/ --quiet --batch --gen-key
unset pw; unset cpw; chown -R "$USER" gpg-KeyRNG/
chown -R "$USER" gpg-KeyRNG/*; chmod -R 0600 gpg-KeyRNG/gpg.conf; clear; }
#------------
## QUITING ##
#------------
badquit (){
clear; echo ""; echo_c "BAD QUIT"; echo ""
echo -e "\nI suggest quitting by using the "FAST LOCK UP" or "SECURE LOCK UP" option on any menu."
read -p "Do you still want to quit now? (Y/no) " rly
if [[ "$rly" = "Y" ]]; then
exit 0
fi; }
#------------------
## SECURE-DELETE ##
#------------------
secdelete (){
echo "Cleaning up..."
HAS_SRM=$(ls /usr/bin/ /usr/sbin/ /usr/local/bin/ | grep -c srm)
if [[ "$HAS_SRM" -gt "0" ]]; then
srm -d -r "$DEL"
else
shred -u -z "$DEL"
fi; }
#-----------
## LOCKUP ##
#-----------
lockup (){
clear; echo ""; echo_c "SECURE LOCKUP"; echo ""
echo "Locking up, choose a unique password to lock all files with."; echo ""
read -s -p "Set lockup password: " pw
pw=$(echo -n "$pw" | shasum -t -a 512 | cut -b -128)
echo ""; read -s -p "Once more:" chkpw
chkpw=$(echo -n "$chkpw" | shasum -t -a 512 | cut -b -128)
while [[ "$pw" != "$chkpw" ]]; do echo ""; echo "PASSPHRASES DON'T MATCH!"; echo ""
read -s -p "Set lockup Password: " pw
pw=$(echo -n "$pw" | shasum -t -a 512 | cut -b -128)
echo ""
read -s -p "Once more:" chkpw
chkpw=$(echo -n "$chkpw" | shasum -t -a 512 | cut -b -128)
done
rm -rf checksum; touch checksum
chmod 0600 checksum
cat keyrng | shasum -t -a 512 | cut -b -128 > checksum
tar -cf KeyRNG.tar.gz gpg-KeyRNG/ btc-KeyRNG/ pybtctools/ libkeyrng
gpg --quiet --output KeyRNG.gpg --passphrase "$pw" --cipher-algo aes256 --symmetric KeyRNG.tar.gz
gpg --quiet --passphrase "$pw" --cipher-algo aes256 --symmetric checksum
unset pw; unset chkpw;
echo "Cleaning temp files..."
hsrm=$(ls /usr/bin/ /usr/sbin/ /usr/local/bin/ /home/"$USER"/bin/ | grep -c srm)
if [[ "$hsrm" -gt "0" ]]; then
srm -drv btc-KeyRNG/*.seed btc-KeyRNG/*.addr temp/ checksum *-KeyRNG/ *.tar.gz
rm -rf libkeyrng pybtctools
else
find btc-KeyRNG/ -depth -type f -exec shred -u -z {}
find *-KeyRNG -depth -type f -exec shred -u -z {}
find temp/ -depth -type f -exec shred -u -z {}
shred -vuz *.tar.gz checksum
rm -rf temp/ *-KeyRNG/ libkeyrng pybtctools/
fi
exit 0; }
#-----------------
## FAST LOCKUP ##
#-----------------
fastlockup (){
echo ""
echo "Locking up, choose a unique password to lock all files with."
ech ""
read -s -p "Set lockup password: " pw
pw=$(echo -n "$pw" | shasum -t -a 512 | cut -b -128)
echo ""
read -s -p "Once more:" chkpw
chkpw=$(echo -n "$chkpw" | shasum -t -a 512 | cut -b -128)
while [[ "$pw" != "$chkpw" ]]; do echo ""; echo "PASSPHRASES DON'T MATCH!"; echo ""
read -s -p "Set lockup Password: " pw
pw=$(echo -n "$pw" | shasum -t -a 512 | cut -b -128)
echo ""
read -s -p "Once more:" chkpw
chkpw=$(echo -n "$chkpw" | shasum -t -a 512 | cut -b -128)
done
rm -rf checksum
touch checksum
chmod 0600 checksum
cat keyrng | shasum -t -a 512 | cut -b -128 > checksum
tar -cf KeyRNG.tar.gz btc-KeyRNG/ gpg-KeyRNG/ pybtctools/ libkeyrng
gpg --output KeyRNG.gpg --quiet --passphrase "$pw" --cipher-algo aes256 --symmetric KeyRNG.tar.gz
gpg --quiet --passphrase "$pw" --cipher-algo aes256 --symmetric checksum
unset pw; unset chkpw
rm -rf *-KeyRNG/ pybtctools/ libkeyrng *.tar.gz temp/ checksum
exit 0; }
###########################################################
############## GNUPG GENERAL KEY MANAGEMENT ###############
###########################################################
#---------------------
## GENERATE NEW KEY ##
#---------------------
genkey (){
clear; echo ""; echo_c "GENERATE A NEW GNUGP KEY PAIR"; echo ""
gpg --homedir gpg-KeyRNG/ --gen-key; clear; }
#--------------------------
## LIST FULL KEY DETAILS ##
#--------------------------
listfullkeydetails (){
clear; echo ""; echo_c "LIST FULL PUBLIC KEY DETAILS"; echo ""
echo "Press enter to see a list of possible recipients by UID."
echo "Use up/down arrows to navigate. Press "q" when your finished."
gpg --quiet --homedir gpg-KeyRNG/ --list-keys | grep -e "uid" -e "fingerprint" -e "0x" | sed -e 's| ||g' | less; clear; }
#------------------
## LIST KEY UIDS ##
#------------------
listkeyuids (){
clear; echo ""; echo_c "LIST PUBLIC KEYS BY UID"; echo ""
echo "Press enter to see a list of possible recipients by UID."
read -p "Use up/down arrows to navigate. Press "q" when your finished."
gpg --quiet --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less; clear; }
#---------------------------------
## LIST FULL SECRET KEY DETAILS ##
#---------------------------------
listfullseckey (){
clear; echo ""; echo_c "LIST ALL SECRET KEY DETAILS"; echo""
echo "Press enter to see a list of possible recipients by UID."
echo "Use up/down arrows to navigate. Press "q" when your finished."
gpg --homedir gpg-KeyRNG/ --list-secret-keys | grep -e "uid" -e "fingerprint" -e "0x" | sed -e 's| ||g' | less; clear; }
#-------------------------
## LIST SECRET KEY UIDS ##
#-------------------------
listseckeyuid (){
clear; echo ""; echo_c "LIST SECRET KEYS"; echo ""
echo "Press enter to see a list of possible recipients by UID."
echo "Use up/down arrows to navigate. Press "q" when your finished."
gpg --homedir gpg-KeyRNG/ --list-secret-keys | grep "uid" | cut -b 21- | less; clear; }
#-------------------------
## IMPORT KEY FROM FILE ##
#-------------------------
importkeyfile (){
clear; echo ""; echo_c "IMPORT A KEY FROM A FILE"; echo ""
echo "What file to import to KeyRNG?"
read $kf
gpg --homedir gpg-KeyRNG/ --import "$kf"
gpg --homedir gpg-KeyRNG/ --list-keys "$kf" | grep "fingerprint" | cut -b 25- | tr -d " " | sed 's|$|\:6\:|' | gpg --homedir gpg-KeyRNG/ --no-permission-warning --quiet --import-owner-trust; clear; }
#------------------------------
## IMPORT KEY FROM CLIPBOARD ##
#------------------------------
importkeyclip (){
clear; echo ""; echo_c "IMPORT A KEY FROM THE CLIPBOARD"; echo ""
echo ""; read -p "Press enter when you are ready to paste a key to import."
rm -rf temp/temp
nano temp/temp
gpg --homedir gpg-KeyRNG/ --import temp/temp
gpg --homedir gpg-KeyRNG/ --list-keys $(cat temp/temp) | grep "fingerprint" | cut -b 25- | tr -d " " | sed 's|$|\:6\:|' | gpg --homedir gpg-KeyRNG/ --no-permission-warning --quiet --import-owner-trust
DEL=temp/temp; secdelete; clear; }
#--------------------------------
## IMPORT KEY FROM ANOTHER GPG ##
#--------------------------------
importkeyfromgpg (){
clear; echo ""; echo_c "IMPORT A PUBLIC KEY FROM ANOTHER GNUPG KEYRING"; echo ""
echo "From defualt /home/"$USER"/.gnupg file? (y/no)"
read IS_DEFAULT_GPG
if [[ "$DEFAULT_GPG" = "no" ]]; then
echo "Please give the full path to the gnupg file:"
read DEFAULT_GPG
else
DEFAULT_GPG=/home/"$USER"/.gnupg/
fi
echo "List keys from "$DEFAULT_GPG"? (y/no)"
read LIST_KEYS
if [ "$LIST_KEYS" != "no" ]; then
echo "Press enter to see a list of possible recipients by UID."
echo "Use up/down arrows to navigate. Press "q" when finished."
read
gpg --homedir "$DEFAULT_GPG" --list-keys --keyid-format 0xlong | less
fi
echo "What key UID do you want to import to KeyRNG?"
read IMPORT_KEY
gpg --homedir "$DEFAULT_GPG" --export "$IMPORT_KEY" | gpg --homedir gpg-KeyRNG/ --quiet --import -
gpg --homedir gpg-KeyRNG/ --list-keys "$IMPORT_KEY" | grep "fingerprint" | cut -b 25- | tr -d " " | sed 's|$|\:6\:|' | gpg --homedir gpg-KeyRNG/ --no-permission-warning --quiet --import-owner-trust; }
#--------------------------------------------
## IMPORT ALL PUBLIC KEYS FROM ANOTHER GPG ##
#--------------------------------------------
gpgimportallpub (){
clear; echo ""; echo_c "IMPORT ALL PUBLIC KEYS FROM ANOTHER GNUPG KEYRING"; echo ""
read -p "Import all public keys from default location (/home/"$USER"/.gnupg/)? (y/no) " used
if [[ "$used" != "no" ]]; then
gpgh=/home/"$USER"/.gnupg/
else
read -p "Give the path and folder name. " gpgh
fi
rm -rf temp/temp
gpg --homedir $(echo "$gpgh") --no-permission-warning --list-keys --keyid-format 0xlong | grep "0x" | cut -b 13- | cut -b -19 > temp/temp
lines=$(grep -c "0x" temp/temp)
if [ "$lines" -gt "0" ]; then
cat temp/temp | xargs -I{} -d"\n" gpg --no-permission-warning --homedir $(echo "$gpgh") --export {} | gpg --no-permission-warning --homedir gpg-KeyRNG/ --import
gpg --homedir gpg-KeyRNG/ --list-keys | grep "fingerprint" | cut -b 25- | tr -d " " | sed 's|$|\:6\:|' | gpg --homedir gpg-KeyRNG/ --import-ownertrust
fi
DEL=temp/temp; secdelete; clear; }
#---------------------------------------
## IMPORT SECRET KEY FROM ANOTHER GPG ##
#---------------------------------------
importseckeyfromgpg (){
clear; echo ""; echo_c "IMPORT SECRET KEY FROM ANOTHER GNUPG KEYRING"; echo ""
read -p "From defualt /home/"$USER"/.gnupg file? (y/no) " idg
if [[ "$idg" = "no" ]]; then
read -p "Please give the full path to the gnupg file: " gpgh
else
gpgh=/home/"$USER"/.gnupg/
fi
read -p "List keys from "$gpgh"? (y/no) " lk
if [ "$lk" != "no" ]; then
echo "Press enter to see a list of possible recipients by UID."
read -p "Use up/down arrows to navigate. Press "q" when finished."
gpg --homedir "$gpgh" --list-secret-keys --keyid-format 0xlong | less
fi
echo "What key UID do you want to import to KeyRNG?"
read ik
gpg --quiet --no-permission-warning --homedir "$gpgh" --export "$ik" | gpg --homedir gpg-KeyRNG/ --import; clear; }
#---------------------------------------------
## IMPORT ALL PRIVATE KEYS FROM ANOTHER GPG ##
#---------------------------------------------
gpgimportallsec (){
clear; echo ""; echo_c "IMPORT ALL PRIVATE KEYS FROM ANOTHER GNUPG KEYRING"; echo ""
read -p "Import all secret keys from default location (/home/"$USER"/.gnupg/)? (y/no) " d
if [[ "$d" != "no" ]]; then
gpgh=/home/"$USER"/.gnupg/
else
read -p "Give path to GnuPG folder to import all secret keys from. " gpgh
fi
rm -rf temp/temp
gpg --quiet --homedir "$gpgh" --no-permission-warning --list-secret-keys --keyid-format 0xlong | grep "0x" | cut -b 13- | cut -b -19 > temp/temp
l=$(grep -c "0x" temp/temp)
if [ "$l" -gt "0" ]; then
cat temp/temp | xargs -I{} -d"\n" gpg --homedir "$gpgh" --export-secret-keys {} | gpg --no-permission-warning --homedir gpg-KeyRNG/ --import
fi
DEL=temp/temp; secdelete; }
#----------------------
## EXPORT PUBLIC KEY ##
#----------------------
exportpubkey (){
clear; echo ""; echo_c "EXPORT PUBLIC KEY HERE"; echo ""
echo "Press enter to see a list of your public keys. Press "q" when finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less
read -p "Enter the UID you would like to export. " exp
gpg --homedir gpg-KeyRNG/ --armor --export "$exp"; clear; }
#------------------------------
## EXPORT PUBLIC KEY TO FILE ##
#------------------------------
exportpubkeyfile (){
clear; echo ""; echo_c "EXPORT PUBLIC KEY TO A FILE"; echo ""
read -p "Press enter to see a list of your public keys. Press "q" when finished."
gpg --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less
read -p "Enter the UID you would like to export. " exp
echo "What file to write to?"
read file
gpg --homedir gpg-KeyRNG/ --armor --output "$file" --export "$exp"; clear; }
#----------------------
## EXPORT SECRET KEY ##
#----------------------
exportseckey (){
clear; echo ""; echo_c "EXPORT SECRET KEY HERE"; echo ""
read -p "Press enter to see a list of your secret keys. Press "q" when finished."
gpg --homedir gpg-KeyRNG/ --list-secret-keys | grep "uid" | cut -b 21- | less
read -p "Enter the UID you would like to export. " exp
gpg --homedir gpg-KeyRNG/ --armor --export "$exp"; clear; }
#------------------------------
## EXPORT SECRET KEY TO FILE ##
#------------------------------
exportseckeyfile (){
clear; echo ""; echo_c "EXPORT SECRET KEY TO A FILE"; echo ""
read -p "Press enter to see a list of your public keys. Press "q" when finished."
gpg --homedir gpg-KeyRNG/ --list-secret-keys | grep "uid" | cut -b 21- | less
read -p "Enter the UID you would like to export. " exp
read -p "What file to write to? " sec
gpg --homedir gpg-KeyRNG/ --armor --output "$sec" --export "$exp"; clear; }
#---------------------------
## SEND KEYS TO KEYSERVER ##
#---------------------------
sendkeyserv (){
clear; echo ""; echo_c "SEND KEYS TO SERVER"; echo ""; read -p "Send all keys? (Y/no) " a
if [[ "$a" = "Y" ]]; then
gpg --homedir gpg-KeyRNG/ --list-keys | grep "0x" | cut -b 13- | cut -b -19 > temp/temp
cat temp/temp | xargs -I{} -d"\n" gpg --homedir gpg-KeyRNG --send-keys {}
DEL=temp/temp; secdelete
else
echo "Copy the key ID starting with "0x...", press "q" when finished."
read "Press enter to see a list of your public keys."
gpg --homedir gpg-KeyRNG/ --list-keys | less
read -p "Enter the UID you would like to send to the keyserver. " key
gpg --homedir gpg-KeyRNG/ --send-keys "$key"
fi; clear; }
#-----------------------------
## RECEIVE KEYS FROM SERVER ##
#-----------------------------
recvkeyserv (){
clear; echo_c "RECEIVE KEYS FROM SERVER"; echo ""
read -p "Please enter the UID you would like to receive from the keyserver. " key
gpg --homedir gpg-KeyRNG/ --recv-keys "$key"
gpg --homedir gpg-KeyRNG/ --list-keys "$key" | grep "fingerprint" | cut -b 25- | tr -d " " | sed 's|$|\:6\:|' | gpg --homedir gpg-KeyRNG/ --no-permission-warning --quiet --import-owner-trust; clear; }
#---------------------------------------
## REFRESH KEYS/FIX OWNER PERMISSIONS ##
#---------------------------------------
refreshkeys (){
clear; echo ""; echo_c "REFRESH KEYS AND FIX OWNER PERMISSIONS"; echo ""
read -p "Refresh all keys? (y/no) " a
if [[ "$a" != "no" ]]; then
gpg --homedir gpg-KeyRNG/ --quiet --refresh-keys
gpg --homedir gpg-KeyRNG/ --list-keys | grep "0x" | cut -b 13- | cut -b -19 > temp/temp
LINES=$(grep -c "0x" temp/temp)
if [ "$LINES" -gt "0" ]; then
cat temp/temp | xargs -I{} -d"\n" gpg --homedir gpg-KeyRNG --list-keys {} | grep "fingerprint" | cut -b 25- | tr -d " " | sed 's|$|\:6\:|' | gpg --homedir gpg-KeyRNG/ --no-permission-warning --quiet --import-owner-trust
echo "Shredding temp file..."
DEL=temp/temp; secdelete
fi
else read -p "What key to refresh? " id; gpg --homedir gpg-KeyRNG/ --quiet --refresh-keys "$id"
fi; clear; }
#########################################################
############### ENCRYPTION AND DECRYPTION ###############
#########################################################
#-------------------
## ENCRYPT A FILE ##
#-------------------
encryptfile ()
{
echo "What file?"
read EFILE
echo "Sign message? (Y/no)"
read SIGN
if [ "$SIGN" = "Y" ]; then
echo "See private keys to sign with? (y/no)"
read SHOW_PRIV
if [[ "$SHOW_PRIV" != "no" ]]; then
echo "Copy the UID you would like to sign with."
echo "Press enter to see a list of signing keys."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "sig"
echo "Paste UID to sign with:"
read PRIVKEY
else
echo "Paste UID to sign with:"
read PRIVKEY
fi
fi
echo "See UIDS of possible recipients? (y/no)"
read SHOW_UIDS
if [ "$SHOW_UIDS" != "no" ]; then
echo "Press enter to see a list of possible recipients by uid."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less
fi
echo "What recipient?"
read MSG_RECP
echo "Another recipient (yourself possibly)? (y/no)"
read IF_MSG_RECP_TWO
if [[ "$IF_MSG_RECP_TWO" != "no" ]]; then
echo "See UID list again? (y/no)"
read SHOW_UIDS
if [ "$SHOW_UIDS" != "no" ]; then
echo "Press enter to see a list of possible recipients by uid."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less
fi
echo "Second recipient?"
read MSG_RECP_TWO
fi
if [[ "$SIGN" != "Y" ]]; then
if [[ "$IF_MSG_RECP_TWO" = "no" ]]; then
gpg --homedir gpg-KeyRNG/ --armor --recipient "$MSG_RECP" --output temp/newmsg.asc --encrypt "$EFILE"
else
echo "Do you want the second recipient hidden? (y/no)"
read HIDE_RECP_TWO
if [ "$HIDE_RECP_TWO" != "no" ]; then
gpg --homedir gpg-KeyRNG/ --armor --hidden-recipient "$MSG_RECP_TWO" --recipient "$MSG_RECP" --output temp/newmsg.asc --encrypt "$EFILE"
fi
gpg --homedir gpg-KeyRNG/ --armor --recipient "$MSG_RECP" --recipient "$MSG_RECP_TWO" --output temp/newmsg.asc --encrypt "$EFILE"
fi
else
if [[ "$IF_MSG_RECP_TWO" = "no" ]]; then
gpg --homedir gpg-KeyRNG/ --local-user "$PRIVKEY" --sign --armor --recipient "$MSG_RECP" --output temp/newmsg.asc --encrypt "$EFILE"
else
echo "Do you want the second recipient hidden? (y/no)"
read HIDE_RECP_TWO
if [ "$HIDE_RECP_TWO" != "no" ]; then
gpg --homedir gpg-KeyRNG/ --local-user "$PRIVKEY" --sign --armor --hidden-recipient "$MSG_RECP_TWO" --recipient "$MSG_RECP" --output temp/newmsg.asc --encrypt "$EFILE"
fi
gpg --homedir gpg-KeyRNG/ --local-user "$PRIVKEY" --sign --armor --recipient "$MSG_RECP" --recipient "$MSG_RECP_TWO" --output temp/newmsg.asc --encrypt "$EFILE"
fi
fi
echo "File is stored temporarily at KeyRNG/temp/newmsg.asc."
echo "Would you like to print it now? (y/no)"
read CAT_EFILE
if [ "$CAT_EFILE" != "no" ]; then
cat temp/newmsg.asc
echo "Destroy now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
DEL=temp/newmsg.asc
secdelete
fi
fi
}
#--------------------------
## ENCRYPT A NEW MESSAGE ##
#--------------------------
encryptnewmsg ()
{
echo "Press enter to type message."
rm -rf temp/newmsg
nano temp/newmsg
echo "Sign message? (Y/no)"
read SIGN
if [ "$SIGN" = "Y" ]; then
echo "See private keys to sign with? (y/no)"
read SHOW_PRIV
if [[ "$SHOW_PRIV" != "no" ]]; then
echo "Copy the UID you would like to sign with."
echo "Press enter to see a list of signing keys."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "sig"
echo "Give UID to sign with:"
read PRIVKEY
else
echo "Give UID to sign with:"
read PRIVKEY
fi
fi
echo "See UIDS of possible recipients? (y/no)"
read SHOW_UIDS
if [ "$SHOW_UIDS" != "no" ]; then
echo "Press enter to see a list of possible recipients by UID."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less
fi
echo "What recipient?"
read NEWMSG_RECP
echo "Another recipient (yourself possibly)? (y/no)"
read IF_NEWMSG_RECP_TWO
if [ "$IF_NEWMSG_RECP_TWO" != "no" ]; then
echo "See UID list again? (y/no)"
read SHOW_UIDS
if [ "$SHOW_UIDS" != "no" ]; then
echo "Press enter to see a list of possible recipients by UID."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
gpg --homedir gpg-KeyRNG/ --list-keys | grep "uid" | cut -b 21- | less
fi
echo "Second recipient UID?"
read NEWMSG_RECP_TWO
echo "Do you want the second recipient hidden? (y/no)"
read HIDE_RECP_TWO
if [[ "$SIGN" != "Y" ]]; then
if [[ "$HIDE_RECP_TWO" != "no" ]]; then
gpg --homedir gpg-KeyRNG/ --armor --recipient "$NEWMSG_RECP" --hidden-recipient "$NEWMSG_RECP_TWO" --yes --output temp/newmsg.asc --encrypt temp/newmsg
else
gpg --homedir gpg-KeyRNG/ --armor --recipient "$NEWMSG_RECP" --recipient "$NEWMSG_RECP_TWO" --yes --output temp/newmsg.asc --encrypt temp/newmsg
fi
else
if [[ "$HIDE_RECP_TWO" != "no" ]]; then
gpg --homedir gpg-KeyRNG/ --local-user "$PRIVKEY" --sign --armor --recipient "$NEWMSG_RECP" --hidden-recipient "$NEWMSG_RECP_TWO" --yes --output temp/newmsg.asc --encrypt temp/newmsg
else
gpg --homedir gpg-KeyRNG/ --local-user "$PRIVKEY" --sign --armor --recipient "$NEWMSG_RECP" --recipient "$NEWMSG_RECP_TWO" --yes --output temp/newmsg.asc --encrypt temp/newmsg
fi
fi
else
if [[ "$SIGN" != "Y" ]]; then
gpg --homedir gpg-KeyRNG/ --armor --recipient "$NEWMSG_RECP" --yes --output temp/newmsg.asc --encrypt temp/newmsg
else
gpg --homedir gpg-KeyRNG/ --local-user "$PRIVKEY" --sign --armor --recipient "$NEWMSG_RECP" --yes --output temp/newmsg.asc --encrypt temp/newmsg
fi
fi
echo "File is stored temporarily at KeyRNG/temp/newmsg.asc"
echo "Would you like to destroy the original, unencrypted message? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
echo "Would you like to print it now? (y/no)"
read CAT_EFILE
if [ "$CAT_EFILE" != "no" ]; then
cat temp/newmsg.asc
echo "Destroy now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
DEL=temp/newmsg.asc
secdelete
fi
fi
}
#-----------------
## DECRYPT FILE ##
#-----------------
decryptfile ()
{
echo "Which file?"
read DFILE
echo "Is this encrypted to a hidden UID? (y/no)"
read IS_HIDDEN_UID
if [[ "$IS_HIDDEN_UID" != "no" ]]; then
echo "Do you know the UID it is encrypted to? (y/no)"
read KNOW_UID
if [[ "$KNOW_UID" = "no" ]]; then
echo "Press enter to try all secret keys."
read
rm -rf temp/newmsg
gpg --homedir gpg-KeyRNG/ --try-all-secrets --output temp/newmsg --decrypt "$DFILE"
echo "File is stored temporarily at KeyRNG/temp/newmsg."
echo "Do you want to print it now? (y/no)"
read PRINT_NOW
if [ "$PRINT_NOW" != "no" ]; then
echo "Press enter to see message."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
cat temp/newmsg | less
echo "Destroy message now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
fi
else
echo "What UID?"
read HIDDEN_UID
gpg --homedir gpg-KeyRNG/ --local-user "$HIDDEN_ID" --output temp/newmsg --decrypt "$DFILE"
echo "File is stored temporarily at KeyRNG/temp/newmsg."
echo "Do you want to print it now? (y/no)"
read PRINT_NOW
if [ "$PRINT_NOW" != "no" ]; then
echo "Press enter to see message."
echo "Use up/down arrows to navigate. Press "q" when your finished."
read
cat temp/newmsg | less
echo "Destroy message now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
fi
fi
else
gpg --homedir gpg-KeyRNG/ --local-user "$HIDDEN_ID" --output temp/newmsg --decrypt "$DFILE"
echo "File is stored temporarily at KeyRNG/temp/newmsg."
echo "Do you want to print it now? (y/no)"
read PRINT_NOW
if [ "$PRINT_NOW" != "no" ]; then
echo "Press enter to see message."
echo "Use up/down arrows to navigate. Press "q" when finished."
read
cat temp/newmsg | less
echo "Destroy message now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
fi
fi
}
#---------------------------
## DECRYPT FROM CLIPBOARD ##
#---------------------------
decryptclip ()
{
echo "Press enter when you are ready to paste the message."
read
rm -rf temp/newmsg
nano temp/newmsg
DFILE=temp/newmsg
echo "Is this encrypted to a hidden UID? (y/no)"
read IS_HIDDEN_UID
if [[ "$IS_HIDDEN_UID" != "no" ]]; then
echo "Do you know the UID it is encrypted to? (y/no)"
read KNOW_UID
if [[ "$KNOW_UID" = "no" ]]; then
echo "Press enter to try all secret keys."
read
rm -rf temp/newmsg
gpg --homedir gpg-KeyRNG/ --try-all-secrets --output temp/newmsg --yes --decrypt "$DFILE"
echo "File is stored temporarily at KeyRNG/temp/newmsg."
echo "Do you want to print it now? (y/no)"
read PRINT_NOW
if [ "$PRINT_NOW" != "no" ]; then
echo "Press enter to see message."
echo "Use up/down arrows to navigate. Press "q" when finished."
read
cat temp/newmsg | less
echo "Destroy message now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
fi
else
echo "What UID?"
read HIDDEN_UID
gpg --homedir gpg-KeyRNG/ --local-user "$HIDDEN_ID" --yes --output temp/newmsg --decrypt "$DFILE"
echo "File is stored temporarily at KeyRNG/temp/newmsg."
echo "Do you want to print it now? (y/no)"
read PRINT_NOW
if [ "$PRINT_NOW" != "no" ]; then
echo "Press enter to see message."
echo "Use up/down arrows to navigate. Press "q" when finished."
read
cat temp/newmsg | less
echo "Destroy message now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
fi
fi
else
gpg --homedir gpg-KeyRNG/ --local-user "$HIDDEN_ID" --output temp/newmsg --yes --decrypt "$DFILE"
echo "File is stored temporarily at KeyRNG/temp/newmsg."
echo "Do you want to print it now? (y/no)"
read PRINT_NOW
if [ "$PRINT_NOW" != "no" ]; then
echo "Press enter to see message."
echo "Use up/down arrows to navigate. Press "q" when finished."
read
cat temp/newmsg | less
echo "Destroy message now? (y/no)"
read DESTROY
if [ "$DESTROY" != "no" ]; then
echo "Shredding temp file..."
DEL=temp/newmsg
secdelete
fi
fi
fi
}
#-----------------------------
## GPG CLEARSIGN FROM FILE ##
#-----------------------------
csignfile (){
clear; echo ""; echo_c "CLEARSIGN FILE"; echo ""; read -p "File to sign:" f
echo ""; read -p "See private keys to sign with? (y/no) " see
if [ "$see" != "no" ]; then
echo "Copy the UID you would like to sign with."
echo "Press enter to see a list of possible recipients by uid."
read -p "Use up/down arrows to navigate. Press "q" when finished."
gpg --homedir gpg-KeyRNG/ --list-secret-keys | grep -e "uid" -e "fingerprint" -e "0x" | sed -e 's| ||g' | less
fi
read -p "Give UID to sign with: " priv
gpg --homedir gpg-KeyRNG/ --local-user "$priv" --yes --armor --output "$f".asc --clearsign "$f"
echo "Signed file is stored at "$FILE".asc."
read -p "Do you want to copy the file to another location? (Y/no) " c
if [ "$c" = "Y" ]; then
read -p "Path to copy to: " p
cp "$f".asc "$p"
fi
read -p "Show the signed document here? (Y/no) " s
if [ "$SHOW" = "Y" ]; then
cat "$FILE".asc
fi; clear; }
#------------------------------
## GPG CLEARSIGN NEW MESSAGE ##
#------------------------------
csignnew (){
clear; echo ""; echo_c "CLEARSIGN A NEW MESSAGE"; echo ""
read -p "Press enter to type new message to clearsign."
rm -rf temp/newmsg
nano temp/newmsg
f=temp/newmsg
read -p "See private keys to sign with? (y/no) " see
if [ "$see" != "no" ]; then
echo "Copy the UID you would like to sign with."
echo "Press enter to see a list of possible recipients by uid."
read -p "Use up/down arrows to navigate. Press "q" when finished."
gpg --homedir gpg-KeyRNG/ --list-secret-keys | grep -e "uid" -e "fingerprint" -e "0x" | sed -e 's| ||g' | less
fi
read -p "Input UID to sign with: " priv
gpg --homedir gpg-KeyRNG/ --local-user "$priv" --yes -a -o "$f".asc --clearsign "$f"
echo "Signed file is stored at "$f".asc."
echo "This file will be deleted when you do the LOCK UP! option."
read -p "Do you want to copy the file to another location? (Y/no) " c
if [ "$c" = "Y" ]; then
echo "Path to copy to:"
read p
cp "$f".asc "$p"
fi
read -p "Show the signed document here? (Y/no) " s
if [ "$s" = "Y" ]; then
cat "$f".asc
fi; clear; }
#------------------------------
## GPG VERIFY FILE SIGNATURE ##
#------------------------------
gpgfileverify (){
clear; echo ""; echo_c "VERIFY GNUPG SIGNATURE FROM FILE"; echo ""
read -p "Which file to verify?" f
gpg --homedir gpg-KeyRNG/ --verify "$f"; clear; }
#------------------------------------
## GPG VERIFY CLIPBOARD SIGNATURE ##
#------------------------------------
gpgclipverify (){
clear; echo ""; echo_c "VERIFY GNUPG SIGNATURE FROM CLIPBOARD"; echo ""
read -p "Press enter to paste GPG clearsigned message."
rm -rf temp/newmsg; nano temp/newmsg
f=temp/newmsg
gpg --homedir gpg-KeyRNG/ --verify "$f"; clear; }
#########################################################
############### GENERAL BITCOIN FUNCTIONS ###############
#########################################################
#-------------------------
## BITCOIN SIGN MESSAGE ##
#-------------------------
btcsign ()
{
echo "This isn't working too well yet."
echo "Once you hit enter your message is finished. So, yeah..."
echo "Type the message you would like to sign."
echo "Press enter when finished."
read MSG
echo "See a list of your addresses and private keys to sign with? (y/no)"
read SEE
if [ "$SEE" != "no" ]; then
echo "Press enter to see addresses and private keys."
echo "Please copy the private key you would like to sign with."
echo "Use up/down arrows to navigate. Press "q" when finished."
read
cat btc-KeyRNG/*.addr | grep ":" | less
fi
echo "Paste privkey"
read PRIVKEY
SIG=$(pybtctools/pybtctool ecdsa_sign "$MSG" "$PRIVKEY")
echo -e "-----BEGIN BITCOIN SIGNED MESSAGE-----\n" > temp/btcmsg
echo -n ""$MSG"\n" >> temp/btcmsg
echo -e "\n-----BEGIN BITCOIN SIGNATURE-----\n" >> temp/btcmsg
echo -n "$SIG" >> temp/btcmsg
echo -e "\n\n-----END BITCOIN SIGNATURE-----" >> temp/btcmsg
echo "\nMessage and signature are temporarily save at KeyRNG/temp/btcmsg."
echo "Press enter to see signed message."
read
cat temp/btcmsg
echo "Destroy message now? (Y/no)"
read DESTROY
if [ "$DESTROY" = "Y" ]; then
DEL=temp/btcmsg
secdelete
fi
clear
echo "Press enter to go back to BITCOIN MENU."
read
}
#-----------------------------------
## SHOW ALL ADDRESSES AND PUBKEYS ##
#-----------------------------------
showalladdr (){
clear; echo ""; echo_c "SHOW ALL BITCOIN ADDRESS AND PUBLIC KEYS"; echo ""
echo "Press enter to see all addresses and pubkeys."
read -p "Use up/down arrows to navigate. Press "q" when finished."
cat btc-KeyRNG/*.addr | grep -e "Address" -e "Pubkey" | less; clear; }
#---------------------------------
## IMPORT A BITCOIN PRIVATE KEY ##
#---------------------------------
importbitpriv (){
keyrng=$(gpg --homedir gpg-KeyRNG/ --list-keys KeyRNG | grep pub | tr -d "pub" | cut -b 10- | cut -b -18)
clear; echo ""; echo_c "IMPORT A BITCOIN PRIVATE KEY"; echo ""
read -p "Input private key to import: " pk
pub=$(pybtctools/pybtctool privtopub $(echo -n "$pk"))
addr=$(pybtctools/pybtctool pubtoaddr $(echo -n "$pub"))
echo ""
echo "Address: "$addr""
echo "Pubkey: "$pub""
read -p "Import (y/no) " im
if [ "$im" != "no" ]; then
hf=$(ls btc-KeyRNG/ | grep -c "import.priv")
if [[ "$hf" -lt "1" ]]; then
touch btc-KeyRNG/import.priv; touch btc-KeyRNG/import.addr
chown -R "$USER" btc-KeyRNG/*; chmod 0600 btc-KeyRNG/import*
echo_c "-----------------------------------------------" > btc-KeyRNG/import.priv
echo_c "| I M P O R T E D P R I V A T E K E Y S |" >> btc-KeyRNG/import.priv
echo_c "-----------------------------------------------" >> btc-KeyRNG/import.priv
echo -e "\n\nImported Address 1: "$addr"\nImported Privkey 1: "$pk"\n---" >> btc-KeyRNG/import.priv
gpg --homedir gpg-KeyRNG/ --yes -q -o btc-KeyRNG/import.priv.gpg -ae -r "$keyrng" btc-KeyRNG/import.priv; DEL=btc-KeyRNG/import.priv; secdelete
echo_c "-----------------------------------------------------------------" > btc-KeyRNG/import.addr
echo_c "| I M P O R T E D A D D R E S S E S / P U B L I C K E Y S |" >> btc-KeyRNG/import.addr
echo_c "-----------------------------------------------------------------" >> btc-KeyRNG/import.addr
echo -e "\n\nImported Address 1: "$addr"\nImported Pubkey 1: "$pub"" >> btc-KeyRNG/import.addr
else
num=$(cat btc-KeyRNG/import.addr | grep -c "Pubkey")
num=$(expr $num + 1)
gpg --homedir gpg-KeyRNG/ -q --yes -o btc-KeyRNG/import.priv -d btc-KeyRNG/import.priv.gpg && rm -rf btc-KeyRNG/import.priv.gpg
echo -e "\n\nImported Address "$num": "$addr"\nImported Privkey "$num": "$pk"\n---" >> btc-KeyRNG/import.priv
gpg --homedir gpg-KeyRNG/ --yes -q -o btc-KeyRNG/import.priv.gpg -ae -r "$keyrng" btc-KeyRNG/import.priv; DEL=btc-KeyRNG/import.priv; secdelete
echo -e "\n\nImported Address "$num": "$addr"\nImported Pubkey "$num": "$pub"" >> btc-KeyRNG/import.addr
fi
fi
echo ""; read -p "Press enter to return to ADDRESS MANAGEMENT MENU."; clear; }
################################################################
############### STANDARD BTC ADDRESS MANAGEMENT ################
################################################################
#---------------------------
## CHECK FOR PRIVATE KEYS ##
#---------------------------
haspriv (){
kr=$(gpg --homedir gpg-KeyRNG/ --list-keys KeyRNG | grep pub | tr -d "pub" | cut -b 10- | cut -b -18)
hp=$(ls btc-KeyRNG/ | grep -c "priv")
if [ "$hp" = "0" ]; then
echo ""; echo_c "YOUR PRIVATE KEYS WILL BE ENCRYPTED WITH THE MASTER GPG KEY."
echo_c "THE ONE THAT WAS CREATED WHEN YOU FIRST RAN THIS PROGRAM."; echo ""
echo_c "TO MAKE SURE YOU HAVE NOT FORGOTTON THE PASSPHRASE,"
echo_c "YOU WILL NEED TO COMPLETE A CHALLENGE ONE TIME."; echo ""
read -p "Press enter to decrypt the challenge."
x=$(gpg --armor --gen-random 2 38); echo -n "$x" > temp/test; gpg --homedir gpg-KeyRNG/ -ae -r "$kr" temp/test
echo ""; y=$(gpg --homedir gpg-KeyRNG/ --quiet -d temp/test.asc)
while [[ "$x" != "$y" ]]; do echo ""; echo "YOU FAILED THE CHALLENGE!"; echo ""
read -p "Do you want to create a new master key? (Y/no)" newmk
if [[ "$newmk" = "Y" ]]; then
firstrun
else
x=$(gpg --armor --gen-random 2 38); echo -n "$x" > temp/test; gpg --homedir gpg-KeyRNG/ -ae -r "$kr" temp/test
echo ""
y=$(gpg --homedir gpg-KeyRNG/ --quiet -d temp/test.asc)
fi
done
fi; clear; }
#----------------
## NEW ADDRESS ##
#----------------
getnewaddress ()
{
KEYRNG=$(gpg --homedir gpg-KeyRNG/ --list-keys KeyRNG | grep pub | tr -d "pub" | cut -b 10- | cut -b -18)
HAS_SPRIV=$(ls btc-KeyRNG/ | grep -c "s.priv")
HAS_ADDRFILE=$(ls btc-KeyRNG/ | grep -c "standard")
if [ "$HAS_ADDRFILE" = "0" ]; then
touch btc-KeyRNG/standard.addr
chown -R "$USER" btc-KeyRNG/standard.addr
chmod 0600 btc-KeyRNG/standard.addr
echo_c "---------------------------------------" > btc-KeyRNG/standard.addr
echo_c "| S T A N D A R D A D D R E S S E S |" >> btc-KeyRNG/standard.addr
echo_c "---------------------------------------" >> btc-KeyRNG/standard.addr
fi
if [ "$HAS_SPRIV" = "0" ]; then
touch btc-KeyRNG/s.priv
chown "$USER" btc-KeyRNG/s.priv
chmod 0600 btc-KeyRNG/s.priv
echo_c "-----------------------------------------------------------------" > btc-KeyRNG/s.priv
echo_c "| S T A N D A R D A D D R E S S E S P R I V A T E K E Y S |" >> btc-KeyRNG/s.priv
echo_c "-----------------------------------------------------------------" >> btc-KeyRNG/s.priv
gpg --homedir gpg-KeyRNG/ --yes --quiet --output btc-KeyRNG/s.priv.gpg -ae -r "$KEYRNG" btc-KeyRNG/s.priv && rm -rf btc-KeyRNG/s.priv
fi
PRIV_LOCKED=$(ls btc-KeyRNG/ | grep -c "s.priv.gpg")
if [ "$PRIV_LOCKED" = "1" ]; then
echo "Unlock the private key file."
gpg --homedir gpg-KeyRNG --yes --output btc-KeyRNG/s.priv -d btc-KeyRNG/s.priv.gpg && rm -rf btc-KeyRNG/s.priv.gpg
fi
PRIVKEY=$(pybtctools/pybtctool random_key)
WIF_COMP=$(pybtctools/pybtctool encode_privkey $(echo -n "$PRIVKEY") wif_compressed)
PUBKEY=$(pybtctools/pybtctool privtopub $(echo -n "$WIF_COMP"))
ADDRESS=$(pybtctools/pybtctool pubkey_to_address $(echo -n "$PUBKEY"))
NUM_PRIV=$(grep -c "Pubkey" btc-KeyRNG/standard.addr)
if [[ "$NUM_PRIV" = "0" ]]; then
echo -e "\n\nStandard Address 1: "$ADDRESS"\nStandard Privkey 1: "$WIF_COMP"" >> btc-KeyRNG/s.priv
gpg --quiet --homedir gpg-KeyRNG/ --output btc-KeyRNG/s.priv.gpg -ae -r "$KEYRNG" btc-KeyRNG/s.priv && srm -dr btc-KeyRNG/s.priv
unset PW; unset CHKPW
echo -e "\n\nStandard Address 1: "$ADDRESS"\nStandard Pubkey 1: "$PUBKEY"\n---"
echo "Add a note to address? (y/no)"
read IS_NOTE
if [[ "$IS_NOTE" = "y" ]]; then
echo "Type the note and press enter:"
read NOTE
echo -e "\n\nStandard Address 1: "$ADDRESS" Note: "$NOTE"\nStandard Pubkey 1: "$PUBKEY"\n---" >> btc-KeyRNG/standard.addr
echo "DONE!"
sleep 1
clear
else
echo -e "\n\nStandard Address 1: "$ADDRESS"\nStandard Pubkey 1: "$PUBKEY"\n---" >> btc-KeyRNG/standard.addr
echo "DONE!"
sleep 1
clear
fi
else
NUM_PRIV=$(expr "$NUM_PRIV" + 1)
echo -e "\nStanadard Address "$NUM_PRIV": "$ADDRESS"\nStanadard Pubkey "$NUM_PRIV": "$PUBKEY"\n---"
echo -e "\nStanadard Address "$NUM_PRIV": "$ADDRESS"\nStanadard Privkey "$NUM_PRIV": "$WIF_COMP"\n" >> btc-KeyRNG/s.priv
gpg --quiet --homedir gpg-KeyRNG/ --output btc-KeyRNG/s.priv.gpg -ae -r "$KEYRNG" btc-KeyRNG/s.priv && DEL=btc-KeyRNG/s.priv; secdelete
echo "Add a note to address? (y/no)"
read IS_NOTE
if [[ "$IS_NOTE" = "y" ]]; then
echo "Type the note and press enter:"
read NOTE
echo -e "\nStandard Address "$NUM_PRIV": "$ADDRESS" Note: "$NOTE"\nStandard Pubkey "$NUM_PRIV": "$PUBKEY"\n---" >> btc-KeyRNG/standard.addr
echo "DONE!"
clear
else
echo -e "\nStandard Address "$NUM_PRIV": "$ADDRESS"\nStandard Pubkey "$NUM_PRIV": "$PUBKEY"\n---" >> btc-KeyRNG/standard.addr
echo "DONE!"
clear
fi
fi
}
#---------------------------------------
## CREATE MULTIPLE STANDARD ADDRESSES ##
#---------------------------------------
multiplestandaddr (){
KEYRNG=$(gpg --homedir gpg-KeyRNG/ --list-keys KeyRNG | grep pub | tr -d "pub" | cut -b 10- | cut -b -18)
HAS_SPRIV=$(ls btc-KeyRNG/ | grep -c "s.priv")
HAS_ADDRFILE=$(ls btc-KeyRNG/ | grep -c "standard.addr")
if [ "$HAS_ADDRFILE" = "0" ]; then
touch btc-KeyRNG/standard.addr
chown -R "$USER" btc-KeyRNG/standard.addr
chmod 0600 btc-KeyRNG/standard.addr
echo_c "---------------------------------------" > btc-KeyRNG/standard.addr
echo_c "| S T A N D A R D A D D R E S S E S |" >> btc-KeyRNG/standard.addr
echo_c "---------------------------------------" >> btc-KeyRNG/standard.addr
fi
if [ "$HAS_SPRIV" = "0" ]; then
touch btc-KeyRNG/s.priv
chown "$USER" btc-KeyRNG/s.priv
chmod 0600 btc-KeyRNG/s.priv
echo_c "-----------------------------------------------------------------" > btc-KeyRNG/s.priv
echo_c "| S T A N D A R D A D D R E S S E S P R I V A T E K E Y S |" >> btc-KeyRNG/s.priv
echo_c "-----------------------------------------------------------------" >> btc-KeyRNG/s.priv
echo -e "\nYOUR PRIVATE KEYS WILL BE ENCRYPTED WITH THE MASTER GPG KEY\nTHAT WAS CREATED WHEN YOU FIRST RAN THIS PROGRAM."
echo -e "TO MAKE SURE YOU HAVE NOT FORGOT THE PASSPHRASE YOU WILL\nNEED TO COMPLETE A CHALLENGE."
echo ""
read -p "Press enter to decrypt the challenge."
TEST=$(gpg --armor --gen-random 2 38); echo -n "$TEST" > temp/test; gpg --homedir gpg-KeyRNG/ -ae -r "$KEYRNG" temp/test
echo ""
TRY=$(gpg --homedir gpg-KeyRNG/ --quiet -d temp/test.asc)
while [[ "$TEST" != "$TRY" ]]; do echo ""; echo "YOU FAILED THE CHALLENGE!"; echo ""
read -p "Do you want to create a new master key? (Y/no)" newmk
if [[ "$newmk" = "Y" ]]; then
firstrun
else
TEST=$(gpg --armor --gen-random 2 38); echo -n "$TEST" > temp/test; gpg --homedir gpg-KeyRNG/ -ae -r "$KEYRNG" temp/test
echo ""
TRY=$(gpg --homedir gpg-KeyRNG/ --quiet -d temp/test.asc)
fi
done
gpg --homedir gpg-KeyRNG/ --quiet --output btc-KeyRNG/s.priv.gpg -ae -r "$KEYRNG" btc-KeyRNG/s.priv && rm -rf btc-KeyRNG/s.priv
fi
echo "Unlocking your private keys..."
gpg --homedir gpg-KeyRNG/ --quiet --output btc-KeyRNG/s.priv -d btc-KeyRNG/s.priv.gpg && rm -rf btc-KeyRNG/s.priv.gpg
echo -e "\nHow may standard addresses to create?"
read NUM
echo "Creating "$NUM" standard addresses..."
for i in $(seq 1 "$NUM")
do
PRIVKEY=$(pybtctools/pybtctool random_key)
WIF_COMP=$(pybtctools/pybtctool encode_privkey $(echo -n "$PRIVKEY") wif_compressed)
PUBKEY=$(pybtctools/pybtctool privtopub $(echo -n "$WIF_COMP"))
ADDRESS=$(pybtctools/pybtctool pubkey_to_address $(echo -n "$PUBKEY"))
NUM_PRIV=$(grep -c "Pubkey" btc-KeyRNG/standard.addr)
if [[ "$NUM_PRIV" = "0" ]]; then
echo -e "\n\nStandard Address 1: "$ADDRESS"\nStandard Privkey 1: "$WIF_COMP"\n" >> btc-KeyRNG/s.priv
echo -e "\n\nStandard Address 1: "$ADDRESS"\nStandard Pubkey 1: "$PUBKEY"\n---"
echo -e "\n\nStandard Address 1: "$ADDRESS"\nStandard Pubkey 1: "$PUBKEY"\n---" >> btc-KeyRNG/standard.addr
else
NUM_PRIV=$(expr "$NUM_PRIV" + 1)
echo -e "\nStandard Address "$NUM_PRIV": "$ADDRESS"\nStandard Privkey "$NUM_PRIV": "$WIF_COMP"\n" >> btc-KeyRNG/s.priv
echo -e "\nStandard Address "$NUM_PRIV": "$ADDRESS"\nStandard Pubkey "$NUM_PRIV": "$PUBKEY"\n---"
echo -e "\nStandard Address "$NUM_PRIV": "$ADDRESS"\nStandard Pubkey "$NUM_PRIV": "$PUBKEY"\n---" >> btc-KeyRNG/standard.addr
fi
done
gpg --homedir gpg-KeyRNG/ --quiet --output btc-KeyRNG/s.priv.gpg -ae -r "$KEYRNG" btc-KeyRNG/s.priv && srm -dr btc-KeyRNG/s.priv
unset PW; unset CHKPW
echo ""; echo_c "DONE CREATING "$NUM" STANDARD ADDRESSES."
echo_c "ADDRESSES ARE STORED IN KeyRNG/btc-KeyRNG/standard.addr"; echo ""