-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
14867 lines (13545 loc) 路 411 KB
/
main.go
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
/*
EDGE Toolkit -- Pure Go Command-line Unique Integrated Security Suite
Copyright (C) 2020-2024 Pedro F. Albanese <pedroalbanese@hotmail.com>
This program is free software: you can redistribute it and/or modify it
under the terms of the ISC License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package main
import (
"bufio"
"bytes"
"crypto"
"crypto/aes"
"crypto/cipher"
"crypto/des"
"crypto/ecdh"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/hmac"
"crypto/md5"
"crypto/rand"
"crypto/rc4"
"crypto/rsa"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/ascii85"
"encoding/asn1"
"encoding/base32"
"encoding/base64"
"encoding/binary"
"encoding/gob"
"encoding/hex"
"encoding/pem"
"errors"
"flag"
"fmt"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/bcrypt"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/blake2s"
"golang.org/x/crypto/blowfish"
"golang.org/x/crypto/chacha20"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/hkdf"
"golang.org/x/crypto/md4"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/poly1305"
"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/salsa20"
"golang.org/x/crypto/sha3"
"golang.org/x/crypto/twofish"
"hash"
"io"
"io/ioutil"
"log"
"math/big"
"math/bits"
"net"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"unsafe"
"crypto/go.cypherpunks.ru/gogost/v5/gost3410"
"gitee.com/Trisia/gotlcp/tlcp"
"github.com/RyuaNerin/go-krypto/aria"
"github.com/RyuaNerin/go-krypto/has160"
"github.com/RyuaNerin/go-krypto/lea"
"github.com/RyuaNerin/go-krypto/lsh256"
"github.com/RyuaNerin/go-krypto/lsh512"
"github.com/deatil/go-cryptobin/cipher/ascon"
"github.com/deatil/go-cryptobin/cipher/cast256"
"github.com/deatil/go-cryptobin/cipher/clefia"
"github.com/deatil/go-cryptobin/cipher/crypton1"
"github.com/deatil/go-cryptobin/cipher/e2"
"github.com/deatil/go-cryptobin/cipher/grain"
"github.com/deatil/go-cryptobin/cipher/khazad"
"github.com/deatil/go-cryptobin/cipher/loki97"
"github.com/deatil/go-cryptobin/cipher/mars"
"github.com/deatil/go-cryptobin/cipher/mars2"
"github.com/deatil/go-cryptobin/cipher/noekeon"
"github.com/deatil/go-cryptobin/cipher/panama"
"github.com/deatil/go-cryptobin/cipher/present"
"github.com/deatil/go-cryptobin/cipher/twine"
"github.com/deatil/go-cryptobin/cipher/xoodoo/xoodyak"
"github.com/emmansun/certinfo"
"github.com/emmansun/gmsm/sm2"
"github.com/emmansun/gmsm/sm3"
"github.com/emmansun/gmsm/sm4"
"github.com/emmansun/gmsm/sm9"
"github.com/emmansun/gmsm/sm9/bn256"
"github.com/emmansun/gmsm/smx509"
"github.com/emmansun/gmsm/zuc"
"github.com/emmansun/go-pkcs12"
"github.com/kasperdi/SPHINCSPLUS-golang/parameters"
"github.com/kasperdi/SPHINCSPLUS-golang/sphincs"
"github.com/pedroalbanese/IGE-go/ige"
"github.com/pedroalbanese/anubis"
"github.com/pedroalbanese/camellia"
"github.com/pedroalbanese/cast5"
"github.com/pedroalbanese/ccm"
"github.com/pedroalbanese/cfb8"
"github.com/pedroalbanese/cmac"
"github.com/pedroalbanese/crypto/hc128"
"github.com/pedroalbanese/crypto/hc256"
"github.com/pedroalbanese/crypto/serpent"
"github.com/pedroalbanese/crystals-go/crystals-dilithium"
"github.com/pedroalbanese/crystals-go/crystals-kyber"
"github.com/pedroalbanese/cubehash"
"github.com/pedroalbanese/eax"
"github.com/pedroalbanese/ecb"
"github.com/pedroalbanese/ecka-eg/core/curves"
"github.com/pedroalbanese/ecka-eg/elgamal"
elgamalAlt "github.com/pedroalbanese/ecka-eg/elgamal-alt"
"github.com/pedroalbanese/gmac"
"github.com/pedroalbanese/go-chaskey"
"github.com/pedroalbanese/go-external-ip"
"github.com/pedroalbanese/go-idea"
"github.com/pedroalbanese/go-kcipher2"
"github.com/pedroalbanese/go-krcrypt"
"github.com/pedroalbanese/go-misty1"
"github.com/pedroalbanese/go-rc5"
"github.com/pedroalbanese/go-ripemd"
"github.com/pedroalbanese/gogost/gost28147"
"github.com/pedroalbanese/gogost/gost34112012256"
"github.com/pedroalbanese/gogost/gost34112012512"
"github.com/pedroalbanese/gogost/gost341194"
"github.com/pedroalbanese/gogost/gost341264"
"github.com/pedroalbanese/gogost/mgm"
"github.com/pedroalbanese/golang-rc6"
"github.com/pedroalbanese/gopass"
"github.com/pedroalbanese/groestl-1"
"github.com/pedroalbanese/haraka"
"github.com/pedroalbanese/jh"
"github.com/pedroalbanese/kalyna"
"github.com/pedroalbanese/kuznechik"
"github.com/pedroalbanese/lyra2re"
"github.com/pedroalbanese/makwa-go"
"github.com/pedroalbanese/ocb"
"github.com/pedroalbanese/ocb3"
"github.com/pedroalbanese/pmac"
"github.com/pedroalbanese/rabbitio"
"github.com/pedroalbanese/randomart"
"github.com/pedroalbanese/rc2"
"github.com/pedroalbanese/siphash"
"github.com/pedroalbanese/skein"
skeincipher "github.com/pedroalbanese/skein-1"
"github.com/pedroalbanese/spritz"
"github.com/pedroalbanese/threefish"
"github.com/pedroalbanese/tiger"
"github.com/pedroalbanese/trivium"
"github.com/pedroalbanese/vmac"
"github.com/pedroalbanese/whirlpool"
"github.com/zeebo/blake3"
)
var (
alg = flag.String("algorithm", "RSA", "Public key algorithm: EC, Ed25519, GOST2012, SM2.")
cacert = flag.String("cacert", "", "CA Certificate path. (for TLCP Protocol)")
cakey = flag.String("cakey", "", "CA Private key. (for TLCP Protocol)")
cert = flag.String("cert", "", "Certificate path.")
check = flag.Bool("check", false, "Check hashsum file. ('-' for STDIN)")
cph = flag.String("cipher", "aes", "Symmetric algorithm: aes, blowfish, magma or sm4.")
crl = flag.String("crl", "", "Certificate Revocation List path.")
crypt = flag.String("crypt", "", "Bulk Encryption with Stream and Block ciphers. [enc|dec|help]")
curveFlag = flag.String("curve", "ecdsa", "Subjacent curve (ECDSA, BLS12381G1 and G2.)")
digest = flag.Bool("digest", false, "Target file/wildcard to generate hashsum list. ('-' for STDIN)")
encode = flag.String("hex", "", "Encode binary string to hex format and vice-versa. [enc|dump|dec]")
b85 = flag.String("base85", "", "Encode binary string to Base85 format and vice-versa. [enc|dec]")
b64 = flag.String("base64", "", "Encode binary string to Base64 format and vice-versa. [enc|dec]")
b32 = flag.String("base32", "", "Encode binary string to Base32 format and vice-versa. [enc|dec]")
factorPStr = flag.String("factorp", "", "Makwa private Factor P. (for Makwa Password-hashing Scheme)")
factorQStr = flag.String("factorq", "", "Makwa private Factor Q. (for Makwa Password-hashing Scheme)")
hierarchy = flag.Uint("hid", 0x01, "Hierarchy Identifier. (for SM9 User Private Key)")
id = flag.String("id", "", "User Identifier. (for SM9 User Private Key operations)")
id2 = flag.String("peerid", "", "Remote's side User Identifier. (for SM9 Key Exchange)")
info = flag.String("info", "", "Additional info. (for HKDF command and AEAD bulk encryption)")
iport = flag.String("ipport", "", "Local Port/remote's side Public IP:Port.")
iter = flag.Int("iter", 1, "Iter. (for Password-based key derivation function)")
kdf = flag.String("kdf", "", "Key derivation function. [pbkdf2|hkdf|scrypt|argon2]")
key = flag.String("key", "", "Asymmetric key, symmetric key or HMAC key, depending on operation.")
length = flag.Int("bits", 0, "Key length. (for keypair generation and symmetric encryption)")
mac = flag.String("mac", "", "Compute Hash/Cipher-based message authentication code.")
master = flag.String("master", "Master.pem", "Master key path. (for sm9 setup)")
md = flag.String("md", "sha256", "Hash algorithm: sha256, sha3-256 or whirlpool.")
mode = flag.String("mode", "CTR", "Mode of operation: GCM, MGM, CBC, CFB8, OCB, OFB.")
modulusStr = flag.String("modulus", "", "Makwa modulus. (Makwa hash Public Parameter)")
paramset = flag.String("paramset", "A", "Elliptic curve ParamSet: A, B, C, D. (for GOST2012)")
params = flag.String("params", "", "ElGamal Public Parameters path.")
pkey = flag.String("pkey", "", "Subcommands: keygen|certgen, sign|verify|derive, text|modulus.")
priv = flag.String("priv", "Private.pem", "Private key path. (for keypair generation)")
pub = flag.String("pub", "Public.pem", "Public key path. (for keypair generation)")
pwd = flag.String("pass", "", "Password/Passphrase. (for Private key PEM encryption)")
pwd2 = flag.String("passout", "", "User Password. (for SM9 User Private Key PEM encryption)")
random = flag.Int("rand", 0, "Generate random cryptographic key with given bit length.")
recover = flag.Bool("recover", false, "Recover Passphrase from Makwa hash with Private Parameters.")
recursive = flag.Bool("recursive", false, "Process directories recursively. (for DIGEST command only)")
root = flag.String("root", "", "Root CA Certificate path.")
salt = flag.String("salt", "", "Salt. (for HKDF and PBKDF2 commands)")
sig = flag.String("signature", "", "Input signature. (for VERIFY command and MAC verification)")
tcpip = flag.String("tcp", "", "Encrypted TCP/IP Transfer Protocol. [server|ip|client]")
vector = flag.String("iv", "", "Initialization Vector. (for symmetric encryption)")
col = flag.Int("wrap", 64, "Wrap lines after N columns. (for Base64/32 encoding)")
pad = flag.Bool("nopad", false, "No padding. (for Base64 and Base32 encoding)")
version = flag.Bool("version", false, "Print version info.")
)
func publicKey(priv interface{}) interface{} {
switch k := priv.(type) {
case *sm2.PrivateKey:
return &k.PublicKey
case *ecdsa.PrivateKey:
return &k.PublicKey
case *ecdh.PrivateKey:
return k.Public().(*ecdh.PublicKey)
case *gost3410.PrivateKey:
return k.Public().(*gost3410.PublicKey)
case ed25519.PrivateKey:
return k.Public().(ed25519.PublicKey)
case *rsa.PrivateKey:
return &k.PublicKey
default:
return nil
}
}
var (
oidEmailAddress = []int{1, 2, 840, 113549, 1, 9, 1}
oidDomainComponent = []int{0, 9, 2342, 19200300, 100, 1, 25}
oidUserID = []int{0, 9, 2342, 19200300, 100, 1, 1}
oidExtensionAuthorityInfoAccess = []int{1, 3, 6, 1, 5, 5, 7, 1, 1}
oidNSComment = []int{2, 16, 840, 1, 113730, 1, 13}
oidStepProvisioner = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 37476, 9000, 64, 1}
oidStepCertificateAuthority = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 37476, 9000, 64, 2}
)
func handleConnectionTLS(c net.Conn) {
log.Printf("Client(TLS) %v connected via secure channel.", c.RemoteAddr())
}
func handleConnectionTLCP(c net.Conn) {
log.Printf("Client(TLCP) %v connected via secure channel.", c.RemoteAddr())
}
func main() {
flag.Parse()
if *version {
fmt.Println("EDGE Toolkit v1.4.5 22 Mar 2024")
}
if len(os.Args) < 2 {
fmt.Println(`Standard Commands:
crypt digest check kdf
mac pkey rand tcp
Public Key Subcommands:
keygen check text derive
setup pkcs12 fingerprint vko
certgen crl modulus x25519
recover req randomart wrapkey
encrypt validate sign unwrapkey
decrypt x509 verify help
Public Key Algorithms:
ecdsa elgamal sm2 gost2012
ed25519 ec-elgamal sm9encrypt sphincs
kyber/dilithium rsa (default) sm9sign x25519
Stream Ciphers:
ascon (aead) grain128a rabbit spritz
chacha20 hc128 rc4 [obsolete] trivium
chacha20poly1305 hc256 salsa20 zuc128/eea128
grain (aead) kcipher2 skein zuc256/eea256
Modes of Operation:
eax (aead) ocb3 (aead) cbc ecb [obsolete]
gcm (aead) mgm (aead) cfb/cfb8 ige
ocb (aead) ccm (aead) ctr (default) ofb
Block Ciphers:
3des des [obsolete] khazad rc5
aes (default) e2 kuznechik rc6
anubis gost89 lea seed
aria hight loki97 serpent
blowfish idea [obsolete] magma sm4
camellia kalyna128_128 mars/2 threefish
cast5 kalyna128_256 misty1 threefish512
cast256 kalyna256_256 noekeon threefish1024
clefia kalyna256_512 present twine
crypton kalyna512_512 rc2 [obsolete] twofish
Key Derivation Functions:
hkdf pbkdf2 scrypt bcrypt (phs)
argon2 (phs/kdf) lyra2 (phs/kdf) makwa (phs) help
Message Athentication Code:
chaskey hmac siphash xoodyak
cmac mgmac siphash64 zuc128/eia128
gmac pmac skein zuc256/eia256
gost poly1305 vmac help
Message Digests:
blake2b256 keccak256 rmd256 shake128
blake2b512 keccak512 rmd320 shake256
blake2s128 (MAC) lsh224 sha1 [obsolete] siphash
blake2s256 lsh256 sha224 siphash64
blake3 lsh384 sha256 (default) skein256
cubehash lsh512 sha384 skein512
gost94 lsh512-224 sha512 sm3
groestl lsh512-256 sha512-256 streebog256
haraka256 md4 [obsolete] sha3-224 streebog512
haraka512 md5 [obsolete] sha3-256 tiger/2
has160 [obsolete] rmd128 sha3-384 whirlpool
jh rmd160 sha3-512 xoodyak`)
os.Exit(3)
}
if *crypt == "help" {
fmt.Println(`Syntax:
edgetk -crypt <enc|dec> [-cipher <cipher>] [-iv <iv>] [-key <key>] FILE
PBKDF2 Subcommand Parameters:
[...] -kdf pbkdf2 [-md <hash>] [-iter N] [-salt <salt>] -key "PASS" [...]
Example:
edgetk -crypt enc -kdf pbkdf2 -key "PASSPHRASE" -iter 32768 FILE > OUTPUT
AEAD Modes Subcommand Parameters:
[...] -mode gcm [-info "ADDITIONAL AUTHENTICATED DATA"] [...]
Example:
edgetk -crypt enc -key "HEXKEY" -mode gcm -info "AAD" FILE > OUTPUT`)
os.Exit(3)
}
if *mac == "help" {
fmt.Println(`Syntax:
edgetk -mac <method> [-md <hash>] [-cipher <ciph>] [-key <secret>] FILE
Methods:
cmac, pmac, hmac, chaskey, gost, poly1305, eia128/256, siphash, xoodyak
HMAC:
edgetk -mac hmac [-md sha256] -key <secret> FILE
edgetk -mac hmac [-md sha256] -key <secret> -signature $256bitmac FILE
echo $?
CMAC:
edgetk -mac cmac [-cipher aes] -key <secret> FILE
edgetk -mac cmac [-cipher aes] -key <secret> -signature $128bitmac FILE
echo $?`)
os.Exit(3)
}
if *kdf == "help" {
fmt.Println(`Syntax:
edgetk -kdf <method> [-bits N] [-md <hash>] [-key <secret>] [-salt <salt>]
Methods:
hkdf, pbkdf2, scrypt, argon2, lyra2
HKDF:
edgetk -kdf hkdf [-bits N] [-salt "SALT"] [-info "AAD"] [-key "IKM"]
Argon2:
edgetk -kdf argon2 [-bits N] [-salt "SALT"] [-iter N] [-key "PASSPHRASE"]
Lyra2:
edgetk -kdf lyra2 [-bits N] [-salt "SALT"] [-iter N] [-key "PASSPHRASE"]
PBKDF2:
edgetk -kdf pbkdf2 [-bits N] [-salt "SALT"] [-iter N] [-key "PASSPHRASE"]
Scrypt[*]:
edgetk -kdf scrypt [-bits N] [-salt "SALT"] [-iter N] [-key "PASSPHRASE"]
[*] scrypt iter must be greater than 1 and a power of 2:
2^10 = 1.024
2^11 = 2.048
2^12 = 4.096 (Minimum Recommended)
2^13 = 8.192
2^14 = 16.384
2^15 = 32.768
2^16 = 65.536
2^17 = 131.072
2^18 = 262.144
2^19 = 524.288
2^20 = 1.048.576`)
os.Exit(3)
}
if *pkey == "help" {
fmt.Println(`Syntax:
edgetk -pkey <command> [-algorithm <alg>] [-key <private>] [-pub <public>]
[-root <cacert>] [-cert <certificate>] [-signature <sign>] [-bits N] FILE
Subcommands:
keygen, certgen, req, x509, check, pkcs12, encrypt, decrypt
derive, x25519, vko, text, modulus, randomart, sign, verify
Generate Key Pair:
edgetk -pkey keygen [-algorithm <alg>] [-priv <private>] [-pub <public>]
Generate Self-Signed Certificate:
edgetk -pkey certgen [-algorithm <alg>] [-key <priv>] [-cert <cert.crt>]
Generate Certificate Sign Request:
edgetk -pkey req [-algorithm <alg>] [-key <private>] [-cert <cert.csr>]
Sign the Certificate Sign Request:
edgetk -pkey x509 [-algorithm <alg>] [-root <cacert>] [-key <private>]
[-cert <certificate.csr>] CERTIFICATE.crt
Generate Certificate Revocation List:
edgetk -pkey crl [-algorithm <alg>] [-cert <cacert>] [-key <private>]
[-crl <old.crl>] [serials.txt] NewCRL.crl
Parse Keypair:
edgetk -pkey <text|modulus> [-pass "passphrase"] [-key <private.pem>]
edgetk -pkey <text|modulus|randomart> [-key <public.pem>]
Parse Certificate/CRL:
edgetk -pkey <text|modulus> [-cert <certificate.pem>]
edgetk -pkey <text> [-crl <crl.pem>]
echo $?
Check Certificate Signature:
edgetk -pkey check [-cert <certificate.pem>] [-key <capublic.pem>]
echo $?
Check CRL Authenticity:
edgetk -pkey check [-cert <cacert.pem>] [-crl <crl.pem>]
echo $?
Validate a Certificate against the CRL:
edgetk -pkey validate [-cert <certificate.pem>] [-crl <crl.pem>]
echo $?
Derive Shared Secret:
edgetk -pkey <derive|vko|x25519> [-key <privatekey>] [-pub <peerkey>]
Digital Signature:
edgetk -pkey <sign|verify> [-algorithm <alg>] [-key <private|public>]
[-signature <signature>] FILE.ext
Example:
edgetk -pkey sign -key private.pem [-pass "pass"] FILE.ext > sign.txt
sign=$(cat sign.txt|awk '{print $2}')
edgetk -pkey verify -key public.pem -signature $sign FILE.ext
echo $?`)
os.Exit(3)
}
if *tcpip == "help" {
fmt.Println(`Syntax:
edgetk -tcp <server|client> [-cert <cert>] [-key <private>] [-ipport "IP"]
Examples:
edgetk -tcp ip > MyExternalIP.txt
edgetk -tcp server -cert cert.pem -key priv.pem [-ipport "8081"]
edgetk -tcp client -cert cert.pem -key priv.pem [-ipport "127.0.0.1:8081"]`)
os.Exit(3)
}
if (*pkey == "keygen") && (*alg != "sm9encrypt" && *alg != "sm9sign") && *pwd == "" {
print("Passphrase: ")
pass, _ := gopass.GetPasswdMasked()
*pwd = string(pass)
} else if (*pkey == "keygen") && (*alg != "sm9encrypt" && *alg != "sm9sign") && *pwd == "nil" {
*pwd = ""
}
if (*pkey == "setup") && *pwd == "" && strings.ToUpper(*alg) != "ELGAMAL" {
print("Passphrase: ")
pass, _ := gopass.GetPasswdMasked()
*pwd = string(pass)
}
if (*pkey == "keygen") && (*alg == "sm9encrypt" || *alg == "sm9sign") && *pwd == "" {
file, err := os.Open(*master)
if err != nil {
log.Fatal(err)
}
info, err := file.Stat()
if err != nil {
log.Fatal(err)
}
buf := make([]byte, info.Size())
file.Read(buf)
var block *pem.Block
block, _ = pem.Decode(buf)
if block == nil {
errors.New("no valid private key found")
}
if IsEncryptedPEMBlock(block) {
print("MasterKey Passphrase: ")
pass, _ := gopass.GetPasswd()
*pwd = string(pass)
}
}
if (*pkey == "keygen") && (*alg == "sm9encrypt" || *alg == "sm9sign") && *pwd2 == "" {
print("UserKey Passphrase: ")
pass, _ := gopass.GetPasswdMasked()
*pwd2 = string(pass)
}
if (*pkey == "sign" || *pkey == "decrypt" || *pkey == "derive" || *pkey == "derivea" || *pkey == "unwrapkey" || *pkey == "deriveb" || *pkey == "certgen" || *pkey == "text" || *pkey == "modulus" || *tcpip == "server" || *tcpip == "client" || *pkey == "pkcs12" || *pkey == "req" || *pkey == "x509" || *pkey == "x25519" || *pkey == "vko" || *pkey == "crl") && (*key != "") && *pwd == "" {
file, err := os.Open(*key)
if err != nil {
log.Fatal(err)
}
info, err := file.Stat()
if err != nil {
log.Fatal(err)
}
buf := make([]byte, info.Size())
file.Read(buf)
var block *pem.Block
block, _ = pem.Decode(buf)
if block == nil {
errors.New("no valid private key found")
}
if IsEncryptedPEMBlock(block) {
print("Passphrase: ")
pass, _ := gopass.GetPasswd()
*pwd = string(pass)
}
}
if (*pkey == "pkcs12") && *key == "" && *pwd == "" {
pfxBytes, err := os.ReadFile(*cert)
if err != nil {
log.Fatal(err)
}
_, _, err = pkcs12.Decode(pfxBytes, *pwd)
if err != nil {
print("Passphrase: ")
pass, _ := gopass.GetPasswd()
*pwd = string(pass)
}
}
var myHash func() hash.Hash
if *md == "sha224" {
myHash = sha256.New224
} else if *md == "sha256" {
myHash = sha256.New
} else if *md == "sha384" {
myHash = sha512.New384
} else if *md == "sha512" {
myHash = sha512.New
} else if *md == "sha512-256" {
myHash = sha512.New512_256
} else if *md == "sha1" {
myHash = sha1.New
} else if *md == "rmd160" {
myHash = ripemd160.New
} else if *md == "rmd128" {
myHash = ripemd.New128
} else if *md == "rmd256" {
myHash = ripemd.New256
} else if *md == "rmd320" {
myHash = ripemd.New320
} else if *md == "sha3-224" {
myHash = sha3.New224
} else if *md == "sha3-256" {
myHash = sha3.New256
} else if *md == "sha3-384" {
myHash = sha3.New384
} else if *md == "sha3-512" {
myHash = sha3.New512
} else if *md == "keccak" || *md == "keccak256" {
myHash = sha3.NewLegacyKeccak256
} else if *md == "keccak512" {
myHash = sha3.NewLegacyKeccak512
} else if *md == "shake128" {
myHash = func() hash.Hash {
return sha3.NewShake128()
}
} else if *md == "shake256" {
myHash = func() hash.Hash {
return sha3.NewShake256()
}
} else if *md == "lsh224" || *md == "lsh256-224" {
myHash = lsh256.New224
} else if *md == "lsh" || *md == "lsh256" || *md == "lsh256-256" {
myHash = lsh256.New
} else if *md == "lsh512-256" {
myHash = lsh512.New256
} else if *md == "lsh512-224" {
myHash = lsh512.New224
} else if *md == "lsh384" || *md == "lsh512-384" {
myHash = lsh512.New384
} else if *md == "lsh512" {
myHash = lsh512.New
} else if *md == "has160" {
myHash = has160.New
} else if *md == "whirlpool" {
myHash = whirlpool.New
} else if *md == "blake2b256" {
myHash = crypto.BLAKE2b_256.New
} else if *md == "blake2b512" {
myHash = crypto.BLAKE2b_512.New
} else if *md == "blake2s256" {
myHash = crypto.BLAKE2s_256.New
} else if *md == "blake3" {
myHash = func() hash.Hash {
return blake3.New()
}
} else if *md == "md5" {
myHash = md5.New
} else if *md == "gost94" {
myHash = func() hash.Hash {
return gost341194.New(&gost28147.SboxIdGostR341194CryptoProParamSet)
}
} else if *md == "streebog" || *md == "streebog256" {
myHash = gost34112012256.New
} else if *md == "streebog512" {
myHash = gost34112012512.New
} else if *md == "sm3" {
myHash = sm3.New
} else if *md == "md4" {
myHash = md4.New
} else if *md == "cubehash" {
myHash = cubehash.New
} else if *md == "xoodyak" || *md == "xhash" {
myHash = xoodyak.NewXoodyakHash
} else if *md == "skein" || *md == "skein256" {
myHash = func() hash.Hash {
return skein.New256(nil)
}
} else if *md == "skein512" {
myHash = func() hash.Hash {
return skein.New512(nil)
}
} else if *md == "jh" {
myHash = jh.New256
} else if *md == "groestl" {
myHash = groestl.New256
} else if *md == "tiger" {
myHash = tiger.New
} else if *md == "tiger2" {
myHash = tiger.New2
}
if *random != 0 {
var key []byte
var err error
key = make([]byte, *random/8)
_, err = io.ReadFull(rand.Reader, key)
if err != nil {
log.Fatal(err)
}
fmt.Println(hex.EncodeToString(key))
os.Exit(0)
}
Files := strings.Join(flag.Args(), " ")
var inputfile io.Reader
var inputdesc string
var err error
if Files == "-" || Files == "" || strings.Contains(Files, "*") {
inputfile = os.Stdin
inputdesc = "stdin"
} else if *pkey != "x509" && *pkey != "req" && *pkey != "wrapkey" {
inputfile, err = os.Open(flag.Arg(0))
if err != nil {
log.Fatalf("failed opening file: %s", err)
}
inputdesc = flag.Arg(0)
}
if *encode == "enc" {
b, err := ioutil.ReadAll(inputfile)
if len(b) == 0 {
os.Exit(0)
}
if err != nil {
log.Fatal(err)
}
o := make([]byte, hex.EncodedLen(len(b)))
hex.Encode(o, b)
os.Stdout.Write(o)
os.Exit(0)
} else if *encode == "dec" {
var err error
buf := bytes.NewBuffer(nil)
data := inputfile
io.Copy(buf, data)
b := strings.TrimSuffix(string(buf.Bytes()), "\r\n")
b = strings.TrimSuffix(string(b), "\n")
if !isHexDump(b) {
data, err := decodeHexDump(b)
if err != nil {
log.Fatal(err)
}
os.Stdout.Write(data)
os.Exit(0)
}
if len(b) == 0 {
os.Exit(0)
}
if len(b) < 2 {
os.Exit(0)
}
if (len(b)%2 != 0) || (err != nil) {
log.Fatal(err)
}
o := make([]byte, hex.DecodedLen(len(b)))
_, err = hex.Decode(o, []byte(b))
if err != nil {
log.Fatal(err)
}
os.Stdout.Write(o)
os.Exit(0)
} else if *encode == "dump" {
buf := bytes.NewBuffer(nil)
data := inputfile
io.Copy(buf, data)
dump := hex.Dump(buf.Bytes())
os.Stdout.Write([]byte(dump))
os.Exit(0)
} else if *encode == "split" {
data, _ := ioutil.ReadAll(inputfile)
b := strings.TrimSuffix(string(data), "\r\n")
b = strings.TrimSuffix(b, "\n")
print(len(b)/2, " bytes ", len(b)*4, " bits\n")
splitx := SplitSubN(b, 4)
for _, chunk := range split(strings.Trim(fmt.Sprint(splitx), "[]"), 40) {
fmt.Println(strings.ToUpper(chunk))
}
} else if *encode == "split+" {
data, _ := ioutil.ReadAll(inputfile)
b := strings.TrimSuffix(string(data), "\r\n")
b = strings.TrimSuffix(b, "\n")
print(len(b)/2, " bytes ", len(b)*4, " bits\n")
splitx := SplitSubN(b, 4)
for _, chunk := range split(strings.Trim(fmt.Sprint(splitx), "[]"), 80) {
fmt.Println(strings.ToUpper(chunk))
}
} else if *encode == "join" {
data, _ := ioutil.ReadAll(inputfile)
join := strings.ReplaceAll(string(data), " ", "")
join = strings.ReplaceAll(join, "\r\n", "")
join = strings.ReplaceAll(join, "\n", "")
fmt.Println(strings.ToLower(join))
}
if *b85 == "enc" || *b85 == "dec" {
if *col == 0 && len(flag.Args()) > 0 {
inputFile := flag.Arg(0)
data, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("Error reading the file:", err)
os.Exit(1)
}
inputData := string(data)
if *b85 == "enc" {
fmt.Print(encodeAscii85([]byte(inputData)))
} else {
decoder := ascii85.NewDecoder(strings.NewReader(inputData))
decodedData, err := ioutil.ReadAll(decoder)
if err != nil {
fmt.Println("Error decoding data:", err)
os.Exit(1)
}
fmt.Print(string(decodedData))
}
} else {
var inputData string
if len(flag.Args()) == 0 {
data, _ := ioutil.ReadAll(os.Stdin)
inputData = string(data)
} else {
inputFile := flag.Arg(0)
data, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("Error reading the file:", err)
os.Exit(1)
}
inputData = string(data)
}
if *col != 0 {
if *b85 == "enc" {
printChunks(encodeAscii85([]byte(inputData)), *col)
} else {
decoder := ascii85.NewDecoder(strings.NewReader(inputData))
decodedData, err := ioutil.ReadAll(decoder)
if err != nil {
fmt.Println("Error decoding data:", err)
os.Exit(1)
}
fmt.Print(string(decodedData))
}
} else {
if *b85 == "enc" {
fmt.Print(encodeAscii85([]byte(inputData)))
} else {
decoder := ascii85.NewDecoder(strings.NewReader(inputData))
decodedData, err := ioutil.ReadAll(decoder)
if err != nil {
fmt.Println("Error decoding data:", err)
os.Exit(1)
}
fmt.Print(string(decodedData))
}
}
}
}
if *b64 == "enc" || *b64 == "dec" {
if *col == 0 && len(flag.Args()) > 0 {
inputFile := flag.Arg(0)
data, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("Error reading the file:", err)
os.Exit(1)
}
inputData := string(data)
if *b64 == "enc" && *pad == false {
sEnc := base64.StdEncoding.EncodeToString([]byte(inputData))
fmt.Println(sEnc)
} else if *b64 == "enc" && *pad == true {
sEnc := base64.StdEncoding.WithPadding(-1).EncodeToString([]byte(inputData))
fmt.Println(sEnc)
}
} else {
var inputData string
if len(flag.Args()) == 0 {
data, _ := ioutil.ReadAll(os.Stdin)
inputData = string(data)
} else {
inputFile := flag.Arg(0)
data, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("Error reading the file:", err)
os.Exit(1)
}
inputData = string(data)
}
if *col != 0 {
if *b64 == "enc" && *pad == false {
sEnc := base64.StdEncoding.EncodeToString([]byte(inputData))
for _, chunk := range split(sEnc, *col) {
fmt.Println(chunk)
}
} else if *b64 == "dec" && *pad == false {
sDec, _ := base64.StdEncoding.DecodeString(inputData)
os.Stdout.Write(sDec)
}
if *b64 == "enc" && *pad == true {
sEnc := base64.StdEncoding.WithPadding(-1).EncodeToString([]byte(inputData))
for _, chunk := range split(sEnc, *col) {
fmt.Println(chunk)
}
} else if *b64 == "dec" && *pad == true {
sDec, _ := base64.StdEncoding.WithPadding(-1).DecodeString(inputData)
os.Stdout.Write(sDec)
}
} else {
if *b64 == "enc" && *pad == false {
sEnc := base64.StdEncoding.EncodeToString([]byte(inputData))
fmt.Println(sEnc)
} else if *b64 == "dec" && *pad == false {
sDec, _ := base64.StdEncoding.DecodeString(inputData)
os.Stdout.Write(sDec)
}
if *b64 == "enc" && *pad == true {
sEnc := base64.StdEncoding.WithPadding(-1).EncodeToString([]byte(inputData))
fmt.Println(sEnc)
} else if *b64 == "dec" && *pad == true {
sDec, _ := base64.StdEncoding.WithPadding(-1).DecodeString(inputData)
os.Stdout.Write(sDec)
}
}
}
}
if *b32 == "enc" || *b32 == "dec" {
if *col == 0 && len(flag.Args()) > 0 {
inputFile := flag.Arg(0)
data, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("Error reading the file:", err)
os.Exit(1)
}
inputData := string(data)
if *b32 == "enc" && *pad == false {
sEnc := base32.StdEncoding.EncodeToString([]byte(inputData))
fmt.Println(sEnc)
} else if *b32 == "enc" && *pad == true {
sEnc := base32.StdEncoding.WithPadding(-1).EncodeToString([]byte(inputData))
fmt.Println(sEnc)
}
} else {
var inputData string
if len(flag.Args()) == 0 {
data, _ := ioutil.ReadAll(os.Stdin)
inputData = string(data)
} else {
inputFile := flag.Arg(0)
data, err := ioutil.ReadFile(inputFile)
if err != nil {
fmt.Println("Error reading the file:", err)
os.Exit(1)
}
inputData = string(data)
}
if *col != 0 {
if *b32 == "enc" && *pad == false {
sEnc := base32.StdEncoding.EncodeToString([]byte(inputData))
for _, chunk := range split(sEnc, *col) {
fmt.Println(chunk)
}
} else if *b32 == "dec" && *pad == false {
sDec, _ := base32.StdEncoding.DecodeString(inputData)
os.Stdout.Write(sDec)
}
if *b32 == "enc" && *pad == true {
sEnc := base32.StdEncoding.WithPadding(-1).EncodeToString([]byte(inputData))
for _, chunk := range split(sEnc, *col) {
fmt.Println(chunk)
}
} else if *b32 == "dec" && *pad == true {
sDec, _ := base32.StdEncoding.WithPadding(-1).DecodeString(inputData)
os.Stdout.Write(sDec)
}
} else {
if *b32 == "enc" && *pad == false {
sEnc := base32.StdEncoding.EncodeToString([]byte(inputData))
fmt.Println(sEnc)
} else if *b32 == "dec" && *pad == false {
sDec, _ := base32.StdEncoding.DecodeString(inputData)
os.Stdout.Write(sDec)
}
if *b32 == "enc" && *pad == true {
sEnc := base32.StdEncoding.WithPadding(-1).EncodeToString([]byte(inputData))
fmt.Println(sEnc)
} else if *b32 == "dec" && *pad == true {
sDec, _ := base32.StdEncoding.WithPadding(-1).DecodeString(inputData)
os.Stdout.Write(sDec)
}
}
}
}
if (*cph == "aes" || *cph == "aria" || *cph == "mars" || *cph == "mars2" || *cph == "cast256" || *cph == "cast6" || *cph == "clefia" || *cph == "kalyna128_256" || *cph == "kalyna256_256" || *cph == "crypton" || *cph == "e2" || *cph == "loki97" || *cph == "grasshopper" || *cph == "kuznechik" || *cph == "magma" || *cph == "gost89" || *cph == "camellia" || *cph == "chacha20poly1305" || *cph == "chacha20" || *cph == "salsa20" || *cph == "twofish" || *cph == "lea" || *cph == "hc256" || *cph == "eea256" || *cph == "zuc256" || *cph == "skein" || *cph == "serpent" || *cph == "rc6") && *pkey != "keygen" && (*length != 256 && *length != 192 && *length != 128) && *crypt != "" {
*length = 256
}
if *mac == "skein" && *length == 0 {
*length = 256
}
if *cph == "3des" && *pkey != "keygen" && *length != 192 && *crypt != "" {
*length = 192
}
if (*cph == "blowfish" || *cph == "cast5" || *cph == "idea" || *cph == "rc2" || *cph == "rc5" || *cph == "rc4" || *cph == "sm4" || *cph == "seed" || *cph == "hight" || *cph == "misty1" || *cph == "khazad" || *cph == "present" || *cph == "twine" || *cph == "noekeon" || *cph == "xoodyak" || *cph == "hc128" || *cph == "eea128" || *cph == "zuc128" || *cph == "ascon" || *cph == "grain128a" || *cph == "grain128aead" || *cph == "kcipher2" || *cph == "rabbit" || *cph == "kalyna128_128") && *pkey != "keygen" && (*length != 128) && *crypt != "" {