-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-suite.lisp
1767 lines (1600 loc) · 83.9 KB
/
test-suite.lisp
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
;; Copyright (c) 2020 Marin Atanasov Nikolov <dnaeon@gmail.com>
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer
;; in this position and unchanged.
;; 2. Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
;; IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(in-package :cl-user)
(defpackage :cl-ssh-keys.test
(:use :cl :rove)
(:nicknames :ssh-keys.test)
(:import-from
:cl-ssh-keys))
(in-package :cl-ssh-keys.test)
(defparameter *test-keys-path*
(asdf:system-relative-pathname :cl-ssh-keys.test "t/test-keys/")
"Path to public and private test keys")
(defun get-test-key-path (name)
"Returns the path to a test key"
(merge-pathnames *test-keys-path* name))
(deftest rsa-keys
(testing "Parse RSA 1024-bit public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_rsa_1024.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"dd:e6:24:29:55:48:40:af:28:2c:68:f3:33:40:58:20")
"RSA 1024-bit public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"6K8c+b+HKqUjfIcT6WbQhoEjQM0")
"RSA 1024-bit public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"jVI0ipXN04yjWVqOo4jjdS3ndneErRTHXKJUDbXjg18")
"RSA 1024-bit public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"RSA 1024-bit key kind")
(ok (= (ssh-keys:key-bits key) 1024)
"RSA 1024-bit key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"RSA 1024-bit key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_rsa_1024.pub"))
(get-output-stream-string string-out-stream))
"Write RSA 1024-bit public key")))
(testing "Parse RSA 1024-bit private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_rsa_1024")))
(string-out-stream (make-string-output-stream)))
;; Fingerprints of private keys are computed against the embedded public key
(ok (string= (ssh-keys:fingerprint :md5 key)
"dd:e6:24:29:55:48:40:af:28:2c:68:f3:33:40:58:20")
"RSA 1024-bit private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"6K8c+b+HKqUjfIcT6WbQhoEjQM0")
"RSA 1024-bit private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"jVI0ipXN04yjWVqOo4jjdS3ndneErRTHXKJUDbXjg18")
"RSA 1024-bit private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"RSA 1024-bit key kind")
(ok (= (ssh-keys:key-bits key) 1024)
"RSA 1024-bit key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"RSA 1024-bit private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"RSA 1024-bit private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"RSA 1024-bit private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil) ;; Un-encrypted keys do not have salt set
"RSA 1024-bit private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil) ;; Un-encrypted keys do not have rounds set
"RSA 1024-bit private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil) ;; Un-encrypted keys do not have passphrase set
"RSA 1024-bit private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_rsa_1024"))
(get-output-stream-string string-out-stream))
"Write RSA 1024-bit private key")))
(testing "Parse RSA 3072-bit public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_rsa_3072.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"04:02:4b:b2:43:39:a4:8e:89:47:49:6f:30:78:94:1e")
"RSA 3072-bit public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"RnLPLG93GrABjOqc6xOvVFpQXsc")
"RSA 3072-bit public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"VmYpd+5gvA5Cj57ZZcI8lnFMNNic6jpnnBd0WoNG1F8")
"RSA 3072-bit public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"RSA 3072-bit public key kind")
(ok (= (ssh-keys:key-bits key) 3072)
"RSA 3072-bit public key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"RSA 3072-bit public key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_rsa_3072.pub"))
(get-output-stream-string string-out-stream))
"Write RSA 3072-bit public key")))
(testing "Parse RSA 3072-bit private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_rsa_3072")))
(string-out-stream (make-string-output-stream)))
;; Fingerprints of private keys are computed against the embedded public key
(ok (string= (ssh-keys:fingerprint :md5 key)
"04:02:4b:b2:43:39:a4:8e:89:47:49:6f:30:78:94:1e")
"RSA 3072-bit private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"RnLPLG93GrABjOqc6xOvVFpQXsc")
"RSA 3072-bit private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"VmYpd+5gvA5Cj57ZZcI8lnFMNNic6jpnnBd0WoNG1F8")
"RSA 3072-bit private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"RSA 3072-bit key kind")
(ok (= (ssh-keys:key-bits key) 3072)
"RSA 3072-bit private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"RSA 3072-bit private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"RSA 3072-bit private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"RSA 3072-bit private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil)
"RSA 3072-bit private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil)
"RSA 3072-bit private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil)
"RSA 3072-bit private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_rsa_3072"))
(get-output-stream-string string-out-stream))
"Write RSA 3072-bit private key")))
(testing "Generate RSA private/public key pair"
(multiple-value-bind (priv-key pub-key) (ssh-keys:generate-key-pair :rsa :comment "rsa-key@localhost")
;; Public key
(ok (string= (ssh-keys:key-comment pub-key) "rsa-key@localhost")
"Generated RSA public key comment")
(ok (= (ssh-keys:key-bits pub-key) 3072)
"Generated RSA public key number of bits")
(ok (equal (ssh-keys:key-kind pub-key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"Generated RSA public key kind")
(ok (plusp (ssh-keys:rsa-key-exponent pub-key))
"Generated RSA pulic key exponent")
(ok (plusp (ssh-keys:rsa-key-modulus pub-key))
"Generated RSA public key modulus")
;; Private key
(ok (string= (ssh-keys:key-comment priv-key) "rsa-key@localhost")
"Generated RSA private key comment")
(ok (= (ssh-keys:key-bits priv-key) 3072)
"Generated RSA private key number of bits")
(ok (equal (ssh-keys:key-kind priv-key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"Generated RSA private key kind")
(ok (string= (ssh-keys:key-cipher-name priv-key) "none")
"Generated RSA private key cipher name")
(ok (string= (ssh-keys:key-kdf-name priv-key) "none")
"Generated RSA private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt priv-key)) 16) ;; Generated keys have salt initialized
"Generated RSA private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds priv-key) 16) ;; Generated keys have rounds initialized
"Generated RSA private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase priv-key) nil) ;; Generated keys do not have a default passphrase
"Generated RSA private key passphrase")
(ok (equal (ssh-keys:embedded-public-key priv-key)
pub-key)
"Generated RSA private key embedded public key")
(ok (plusp (ssh-keys:rsa-key-exponent priv-key))
"Generated RSA private key exponent")
(ok (plusp (ssh-keys:rsa-key-modulus priv-key))
"Generated RSA private key modulus")
(ok (plusp (ssh-keys:rsa-key-prime-p priv-key))
"Generated RSA private key first prime factor - p")
(ok (plusp (ssh-keys:rsa-key-prime-q priv-key))
"Generated RSA private key second prime factor - q")))
(testing "Generate RSA private/public key -- invalid number of bits"
(ok (signals (ssh-keys:generate-key-pair :rsa :num-bits 512))
"Generate RSA 512-bit keys -- signals on bit size less than 1024")))
(deftest dsa-keys
(testing "Parse DSA 1024-bit public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_dsa.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"ee:c9:41:84:29:e7:1f:95:98:ac:35:75:a5:5b:c7:a6")
"DSA 1024-bit public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"2KBDiLfGio8CGoSHG4v2/CP2p/w")
"DSA 1024-bit public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"kdAVH2jkXqT0WPyczN9bXsyH4WCct87C4kH55kTdqRo")
"DSA 1024-bit public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-dss" :plain-name "ssh-dss" :short-name "DSA" :id :ssh-dss :is-cert nil))
"DSA 1024-bit public key kind")
(ok (= (ssh-keys:key-bits key) 1024)
"DSA 1024-bit public key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"DSA 1024-bit public key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_dsa.pub"))
(get-output-stream-string string-out-stream))
"Write DSA 1024-bit public key")))
(testing "Parse DSA 1024-bit private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_dsa")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"ee:c9:41:84:29:e7:1f:95:98:ac:35:75:a5:5b:c7:a6")
"DSA 1024-bit private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"2KBDiLfGio8CGoSHG4v2/CP2p/w")
"DSA 1024-bit private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"kdAVH2jkXqT0WPyczN9bXsyH4WCct87C4kH55kTdqRo")
"DSA 1024-bit private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-dss" :plain-name "ssh-dss" :short-name "DSA" :id :ssh-dss :is-cert nil))
"DSA 1024-bit private key kind")
(ok (= (ssh-keys:key-bits key) 1024)
"DSA 1024-bit private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"DSA 1024-bit private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"DSA 1024-bit private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"DSA 1024-bit private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil)
"DSA 1024-bit private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil)
"DSA 1024-bit private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil)
"DSA 124-bit private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_dsa"))
(get-output-stream-string string-out-stream))
"Write DSA 1024-bit private key")))
(testing "Generate DSA private/public key pair"
(multiple-value-bind (priv-key pub-key) (ssh-keys:generate-key-pair :dsa :comment "dsa-key@localhost")
;; Public key
(ok (string= (ssh-keys:key-comment pub-key) "dsa-key@localhost")
"Generated DSA public key comment")
(ok (= (ssh-keys:key-bits pub-key) 1024)
"Generated DSA public key number of bits")
(ok (equal (ssh-keys:key-kind pub-key)
'(:name "ssh-dss" :plain-name "ssh-dss" :short-name "DSA" :id :ssh-dss :is-cert nil))
"Generated DSA public key kind")
(ok (plusp (ssh-keys:dsa-key-p pub-key))
"Generated DSA pulic key - p")
(ok (plusp (ssh-keys:dsa-key-q pub-key))
"Generated DSA public key - q")
(ok (plusp (ssh-keys:dsa-key-g pub-key))
"Generated DSA public key - g")
(ok (plusp (ssh-keys:dsa-key-y pub-key))
"Generated DSA public key - y")
;; Private key
(ok (string= (ssh-keys:key-comment priv-key) "dsa-key@localhost")
"Generated DSA private key comment")
(ok (= (ssh-keys:key-bits priv-key) 1024)
"Generated DSA private key number of bits")
(ok (equal (ssh-keys:key-kind priv-key)
'(:name "ssh-dss" :plain-name "ssh-dss" :short-name "DSA" :id :ssh-dss :is-cert nil))
"Generated DSA private key kind")
(ok (string= (ssh-keys:key-cipher-name priv-key) "none")
"Generated DSA private key cipher name")
(ok (string= (ssh-keys:key-kdf-name priv-key) "none")
"Generated DSA private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt priv-key)) 16)
"Generated DSA private key KDF salt")
(ok (equal (ssh-keys:key-passphrase priv-key) nil)
"Generated DSA private key passphrase")
(ok (= (ssh-keys:key-kdf-rounds priv-key) 16)
"Generated DSA private key KDF rounds")
(ok (equal (ssh-keys:embedded-public-key priv-key)
pub-key)
"Generated DSA private key embedded public key")
(ok (plusp (ssh-keys:dsa-key-p priv-key))
"Generated DSA private key - p")
(ok (plusp (ssh-keys:dsa-key-q priv-key))
"Generated DSA private key - q")
(ok (plusp (ssh-keys:dsa-key-g priv-key))
"Generated DSA private key - g")
(ok (plusp (ssh-keys:dsa-key-y priv-key))
"Generated DSA private key - y")
(ok (plusp (ssh-keys:dsa-key-x priv-key))
"Generated DSA private key - x"))))
(deftest ed25519-keys
(testing "Parse Ed25519 public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_ed25519.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"5a:53:0e:89:dd:92:5b:5a:0a:e4:b7:f2:0e:81:49:fe")
"Ed25519 public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"wfa33emGK+n5KO6ksuyCP5J3nPI")
"Ed25519 public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"SVZTs6OE/EiAhmiZD9vGPQlavM+tmW0Y2pWRoUE+/kY")
"Ed25519 public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 public key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 public key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 public key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ed25519.pub"))
(get-output-stream-string string-out-stream))
"Write Ed25519 public key")))
(testing "Parse Ed25519 private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ed25519")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"5a:53:0e:89:dd:92:5b:5a:0a:e4:b7:f2:0e:81:49:fe")
"Ed25519 private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"wfa33emGK+n5KO6ksuyCP5J3nPI")
"Ed25519 private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"SVZTs6OE/EiAhmiZD9vGPQlavM+tmW0Y2pWRoUE+/kY")
"Ed25519 private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"Ed25519 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"Ed25519 private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil)
"Ed25519 private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil)
"Ed25519 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil)
"Ed25519 private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ed25519"))
(get-output-stream-string string-out-stream))
"Write Ed25519 private key")))
(testing "Generate Ed25519 private/public key pair"
(multiple-value-bind (priv-key pub-key) (ssh-keys:generate-key-pair :ed25519 :comment "ed25519-key@localhost")
;; Public key
(ok (string= (ssh-keys:key-comment pub-key) "ed25519-key@localhost")
"Generated Ed25519 public key comment")
(ok (= (ssh-keys:key-bits pub-key) 256)
"Generated Ed25519 public key number of bits")
(ok (equal (ssh-keys:key-kind pub-key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Generated Ed25519 public key kind")
(ok (= (length (ssh-keys:ed25519-key-y pub-key)) 32)
"Generated Ed25519 pulic key - y")
;; Private key
(ok (string= (ssh-keys:key-comment priv-key) "ed25519-key@localhost")
"Generated Ed25519 private key comment")
(ok (= (ssh-keys:key-bits priv-key) 256)
"Generated Ed25519 private key number of bits")
(ok (equal (ssh-keys:key-kind priv-key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Generated Ed25519 private key kind")
(ok (string= (ssh-keys:key-cipher-name priv-key) "none")
"Generated Ed25519 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name priv-key) "none")
"Generated Ed25519 private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt priv-key)) 16)
"Generated Ed25519 private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds priv-key) 16)
"Generated Ed25519 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase priv-key) nil)
"Generated Ed25519 private key passphrase")
(ok (equal (ssh-keys:embedded-public-key priv-key)
pub-key)
"Generated Ed25519 private key embedded public key")
(ok (= (length (ssh-keys:ed25519-key-y priv-key)) 32)
"Generated Ed25519 private key - y")
(ok (= (length (ssh-keys:ed25519-key-x priv-key)) 32)
"Generated Ed25519 private key - x"))))
(deftest ecdsa-nistp256-keys
(testing "Parse ECDSA NIST P-256 public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_ecdsa_nistp256.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"3a:36:ba:c7:2c:26:9e:e3:14:bb:61:40:46:60:31:ae")
"ECDSA NIST P-256 public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"eTmWRwNGK7FQsfbFiIGzfNG2hxo")
"ECDSA NIST P-256 public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"q56e29ej1aTV9ptIX/ERikzqk0HWEtaBDBH33ziQVSM")
"ECDSA NIST P-256 public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ecdsa-sha2-nistp256" :plain-name "ecdsa-sha2-nistp256" :short-name "ECDSA" :id :ecdsa-sha2-nistp256 :is-cert nil))
"ECDSA NIST P-256 public key kind")
(ok (= (ssh-keys:key-bits key) 256)
"ECDSA NIST P-256 public key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"ECDSA NIST P-256 public key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ecdsa_nistp256.pub"))
(get-output-stream-string string-out-stream))
"Write ECDSA NIST P-256 public key")))
(testing "Parse ECDSA NIST P-256 private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ecdsa_nistp256")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"3a:36:ba:c7:2c:26:9e:e3:14:bb:61:40:46:60:31:ae")
"ECDSA NIST P-256 private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"eTmWRwNGK7FQsfbFiIGzfNG2hxo")
"ECDSA NIST P-256 private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"q56e29ej1aTV9ptIX/ERikzqk0HWEtaBDBH33ziQVSM")
"ECDSA NIST P-256 private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ecdsa-sha2-nistp256" :plain-name "ecdsa-sha2-nistp256" :short-name "ECDSA" :id :ecdsa-sha2-nistp256 :is-cert nil))
"ECDSA NIST P-256 private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"ECDSA NIST P-256 private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"ECDSA NIST P-256 private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"ECDSA NIST P-256 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"ECDSA NIST P-256 private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil)
"ECDSA NIST P-256 private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil)
"ECDSA NIST P-256 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil)
"ECDSA NIST P-256 private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ecdsa_nistp256"))
(get-output-stream-string string-out-stream))
"Write ECDSA NIST P-256 private key")))
(testing "Generate ECDSA NIST P-256 private/public key pair"
(multiple-value-bind (priv-key pub-key) (ssh-keys:generate-key-pair :ecdsa-nistp256 :comment "ecdsa-nistp256-key@localhost")
;; Public key
(ok (string= (ssh-keys:key-comment pub-key) "ecdsa-nistp256-key@localhost")
"Generated ECDSA NIST P-256 public key comment")
(ok (= (ssh-keys:key-bits pub-key) 256)
"Generated ECDSA NIST P-256 public key number of bits")
(ok (equal (ssh-keys:key-kind pub-key)
'(:name "ecdsa-sha2-nistp256" :plain-name "ecdsa-sha2-nistp256" :short-name "ECDSA" :id :ecdsa-sha2-nistp256 :is-cert nil))
"Generated ECDSA NIST P-256 public key kind")
(ok (plusp (length (ssh-keys:secp256r1-key-y pub-key)))
"Generated ECDSA NIST P-256 pulic key - y")
;; Private key
(ok (string= (ssh-keys:key-comment priv-key) "ecdsa-nistp256-key@localhost")
"Generated ECDSA NIST P-256 private key comment")
(ok (= (ssh-keys:key-bits priv-key) 256)
"Generated ECDSA NIST P-256 private key number of bits")
(ok (equal (ssh-keys:key-kind priv-key)
'(:name "ecdsa-sha2-nistp256" :plain-name "ecdsa-sha2-nistp256" :short-name "ECDSA" :id :ecdsa-sha2-nistp256 :is-cert nil))
"Generated ECDSA NIST P-256 private key kind")
(ok (string= (ssh-keys:key-cipher-name priv-key) "none")
"Generated ECDSA NIST P-256 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name priv-key) "none")
"Generated ECDSA NIST P-256 private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt priv-key)) 16)
"Generated ECDSA NIST P-256 private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds priv-key) 16)
"Generated ECDSA NIST P-256 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase priv-key) nil)
"Generated ECDSA NIST P-256 private key passphrase")
(ok (equal (ssh-keys:embedded-public-key priv-key)
pub-key)
"Generated ECDSA NIST P-256 private key embedded public key")
(ok (plusp (length (ssh-keys:secp256r1-key-y priv-key)))
"Generated ECDSA NIST P-256 private key - y")
(ok (plusp (length (ssh-keys:secp256r1-key-x priv-key)))
"Generated ECDSA NIST P-256 private key - x"))))
(deftest ecdsa-nistp384-keys
(testing "Parse ECDSA NIST P-384 public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_ecdsa_nistp384.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"4b:4d:9f:0b:51:2a:0b:8c:7f:db:f2:e8:cc:20:93:f2")
"ECDSA NIST P-384 public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"O4neOo5GtvUUZUErlDu8gD/MKr4")
"ECDSA NIST P-384 public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"3HR8kr5XphIWXy312brnRHbrTMq6WmKP/8EkVMLRqMU")
"ECDSA NIST P-384 public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ecdsa-sha2-nistp384" :plain-name "ecdsa-sha2-nistp384" :short-name "ECDSA" :id :ecdsa-sha2-nistp384 :is-cert nil))
"ECDSA NIST P-384 public key kind")
(ok (= (ssh-keys:key-bits key) 384)
"ECDSA NIST P-384 public key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"ECDSA NIST P-384 public key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ecdsa_nistp384.pub"))
(get-output-stream-string string-out-stream))
"Write ECDSA NIST P-384 public key")))
(testing "Parse ECDSA NIST P-384 private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ecdsa_nistp384")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"4b:4d:9f:0b:51:2a:0b:8c:7f:db:f2:e8:cc:20:93:f2")
"ECDSA NIST P-384 private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"O4neOo5GtvUUZUErlDu8gD/MKr4")
"ECDSA NIST P-384 private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"3HR8kr5XphIWXy312brnRHbrTMq6WmKP/8EkVMLRqMU")
"ECDSA NIST P-384 private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ecdsa-sha2-nistp384" :plain-name "ecdsa-sha2-nistp384" :short-name "ECDSA" :id :ecdsa-sha2-nistp384 :is-cert nil))
"ECDSA NIST P-384 private key kind")
(ok (= (ssh-keys:key-bits key) 384)
"ECDSA NIST P-384 private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"ECDSA NIST P-384 private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"ECDSA NIST P-384 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"ECDSA NIST P-384 private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil)
"ECDSA NIST P-384 private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil)
"ECDSA NIST P-384 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil)
"ECDSA NIST P-384 private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ecdsa_nistp384"))
(get-output-stream-string string-out-stream))
"Write ECDSA NIST P-384 private key")))
(testing "Generate ECDSA NIST P-384 private/public key pair"
(multiple-value-bind (priv-key pub-key) (ssh-keys:generate-key-pair :ecdsa-nistp384 :comment "ecdsa-nistp384-key@localhost")
;; Public key
(ok (string= (ssh-keys:key-comment pub-key) "ecdsa-nistp384-key@localhost")
"Generated ECDSA NIST P-384 public key comment")
(ok (= (ssh-keys:key-bits pub-key) 384)
"Generated ECDSA NIST P-384 public key number of bits")
(ok (equal (ssh-keys:key-kind pub-key)
'(:name "ecdsa-sha2-nistp384" :plain-name "ecdsa-sha2-nistp384" :short-name "ECDSA" :id :ecdsa-sha2-nistp384 :is-cert nil))
"Generated ECDSA NIST P-384 public key kind")
(ok (plusp (length (ssh-keys:secp384r1-key-y pub-key)))
"Generated ECDSA NIST P-384 pulic key - y")
;; Private key
(ok (string= (ssh-keys:key-comment priv-key) "ecdsa-nistp384-key@localhost")
"Generated ECDSA NIST P-384 private key comment")
(ok (= (ssh-keys:key-bits priv-key) 384)
"Generated ECDSA NIST P-384 private key number of bits")
(ok (equal (ssh-keys:key-kind priv-key)
'(:name "ecdsa-sha2-nistp384" :plain-name "ecdsa-sha2-nistp384" :short-name "ECDSA" :id :ecdsa-sha2-nistp384 :is-cert nil))
"Generated ECDSA NIST P-384 private key kind")
(ok (string= (ssh-keys:key-cipher-name priv-key) "none")
"Generated ECDSA NIST P-384 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name priv-key) "none")
"Generated ECDSA NIST P-384 private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt priv-key)) 16)
"Generated ECDSA NIST P-384 private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds priv-key) 16)
"Generated ECDSA NIST P-384 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase priv-key) nil)
"Generated ECDSA NIST P-384 private key passphrase")
(ok (equal (ssh-keys:embedded-public-key priv-key)
pub-key)
"Generated ECDSA NIST P-384 private key embedded public key")
(ok (plusp (length (ssh-keys:secp384r1-key-y priv-key)))
"Generated ECDSA NIST P-384 private key - y")
(ok (plusp (length (ssh-keys:secp384r1-key-x priv-key)))
"Generated ECDSA NIST P-384 private key - x"))))
(deftest ecdsa-nistp521-keys
(testing "Parse ECDSA NIST P-521 public key"
(let ((key (ssh-keys:parse-public-key-file (get-test-key-path #P"id_ecdsa_nistp521.pub")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"20:e7:81:b1:5b:25:5b:51:86:68:d9:0d:f2:4f:c2:bc")
"ECDSA NIST P-521 public key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"1itTOyxo/LDunoesxEBlQbvRnSM")
"ECDSA NIST P-521 public key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"IpPQNSCfvLbG1/RfcELgaG12r3RH4av+qWE32dp2yWE")
"ECDSA NIST P-521 public key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ecdsa-sha2-nistp521" :plain-name "ecdsa-sha2-nistp521" :short-name "ECDSA" :id :ecdsa-sha2-nistp521 :is-cert nil))
"ECDSA NIST P-521 public key kind")
(ok (= (ssh-keys:key-bits key) 521)
"ECDSA NIST P-521 public key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"ECDSA NIST P-521 public key comment")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ecdsa_nistp521.pub"))
(get-output-stream-string string-out-stream))
"Write ECDSA NIST P-521 public key")))
(testing "Parse ECDSA NIST P-521 private key"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ecdsa_nistp521")))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"20:e7:81:b1:5b:25:5b:51:86:68:d9:0d:f2:4f:c2:bc")
"ECDSA NIST P-521 private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"1itTOyxo/LDunoesxEBlQbvRnSM")
"ECDSA NIST P-521 private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"IpPQNSCfvLbG1/RfcELgaG12r3RH4av+qWE32dp2yWE")
"ECDSA NIST P-521 private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ecdsa-sha2-nistp521" :plain-name "ecdsa-sha2-nistp521" :short-name "ECDSA" :id :ecdsa-sha2-nistp521 :is-cert nil))
"ECDSA NIST P-521 private key kind")
(ok (= (ssh-keys:key-bits key) 521)
"ECDSA NIST P-521 private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"ECDSA NIST P-521 private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "none")
"ECDSA NIST P-521 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "none")
"ECDSA NIST P-521 private key KDF name")
(ok (equal (ssh-keys:key-kdf-salt key) nil)
"ECDSA NIST P-521 private key KDF salt")
(ok (equal (ssh-keys:key-kdf-rounds key) nil)
"ECDSA NIST P-521 private key KDF rounds")
(ok (equal (ssh-keys:key-passphrase key) nil)
"ECDSA NIST P-521 private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ecdsa_nistp521"))
(get-output-stream-string string-out-stream))
"Write ECDSA NIST P-521 private key")))
(testing "Generate ECDSA NIST P-521 private/public key pair"
(multiple-value-bind (priv-key pub-key) (ssh-keys:generate-key-pair :ecdsa-nistp521 :comment "ecdsa-nistp521-key@localhost")
;; Public key
(ok (string= (ssh-keys:key-comment pub-key) "ecdsa-nistp521-key@localhost")
"Generated ECDSA NIST P-521 public key comment")
(ok (= (ssh-keys:key-bits pub-key) 521)
"Generated ECDSA NIST P-521 public key number of bits")
(ok (equal (ssh-keys:key-kind pub-key)
'(:name "ecdsa-sha2-nistp521" :plain-name "ecdsa-sha2-nistp521" :short-name "ECDSA" :id :ecdsa-sha2-nistp521 :is-cert nil))
"Generated ECDSA NIST P-521 public key kind")
(ok (plusp (length (ssh-keys:secp521r1-key-y pub-key)))
"Generated ECDSA NIST P-521 pulic key - y")
;; Private key
(ok (string= (ssh-keys:key-comment priv-key) "ecdsa-nistp521-key@localhost")
"Generated ECDSA NIST P-521 private key comment")
(ok (= (ssh-keys:key-bits priv-key) 521)
"Generated ECDSA NIST P-521 private key number of bits")
(ok (equal (ssh-keys:key-kind priv-key)
'(:name "ecdsa-sha2-nistp521" :plain-name "ecdsa-sha2-nistp521" :short-name "ECDSA" :id :ecdsa-sha2-nistp521 :is-cert nil))
"Generated ECDSA NIST P-521 private key kind")
(ok (string= (ssh-keys:key-cipher-name priv-key) "none")
"Generated ECDSA NIST P-521 private key cipher name")
(ok (string= (ssh-keys:key-kdf-name priv-key) "none")
"Generated ECDSA NIST P-521 private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt priv-key)) 16)
"Generated ECDSA NIST P-521 private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds priv-key) 16)
"Generated ECDSA NIST P-521 private key rounds")
(ok (equal (ssh-keys:key-passphrase priv-key) nil)
"Generated ECDSA NIST P-521 private key passphrase")
(ok (equal (ssh-keys:embedded-public-key priv-key)
pub-key)
"Generated ECDSA NIST P-521 private key embedded public key")
(ok (plusp (length (ssh-keys:secp521r1-key-y priv-key)))
"Generated ECDSA NIST P-521 private key - y")
(ok (plusp (length (ssh-keys:secp521r1-key-x priv-key)))
"Generated ECDSA NIST P-521 private key - x"))))
(deftest with-macros
(testing "with-public-key macro"
(ok (expands '(ssh-keys:with-public-key (key "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDi...")
(ssh-keys:fingerprint :sha256 key))
'(let ((key (ssh-keys:parse-public-key "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDi...")))
(ssh-keys:fingerprint :sha256 key)))
"Test WITH-PUBLIC-KEY macro expanding"))
(testing "with-public-key-file macro"
(ok (expands '(ssh-keys:with-public-key-file (key #P"id_rsa.pub")
(ssh-keys:fingerprint :sha256 key))
'(let ((key (ssh-keys:parse-public-key-file #P"id_rsa.pub")))
(ssh-keys:fingerprint :sha256 key)))
"Test WITH-PUBLIC-KEY-FILE macro"))
(testing "with-private-key macro"
(ok (expands '(ssh-keys:with-private-key (key "-----BEGIN OPENSSH PRIVATE KEY----- ...")
(ssh-keys:fingerprint :sha256 key))
'(let ((key (ssh-keys:parse-private-key "-----BEGIN OPENSSH PRIVATE KEY----- ..." :passphrase nil)))
(ssh-keys:fingerprint :sha256 key)))
"Test WITH-PRIVATE-KEY macro expanding"))
(testing "with-private-key-file macro"
(ok (expands '(ssh-keys:with-private-key-file (key #P"id_rsa")
(ssh-keys:fingerprint :sha256 key))
'(let ((key (ssh-keys:parse-private-key-file #P"id_rsa" :passphrase nil)))
(ssh-keys:fingerprint :sha256 key)))
"Test WITH-PRIVATE-KEY-FILE macro expanding")))
(deftest invalid-keys
(ok (signals (ssh-keys:parse-public-key-file (get-test-key-path #P"id_rsa_unknown_key_type.pub")))
"Signals on unknown key type")
(ok (signals (ssh-keys:parse-public-key-file (get-test-key-path #P"id_rsa_unknown_key_type")))
"Signals on invalid public key file")
(ok (signals (ssh-keys:parse-public-key-file (get-test-key-path #P"id_ed25519_key_type_mismatch")))
"Signals on mismatched key types")
(ok (signals (ssh-keys:parse-public-key-file (get-test-key-path #P"id_rsa_missing_key_type")))
"Signals on missing key type")
(ok (signals (ssh-keys:parse-private-key-file (get-test-key-path #P"id_rsa_invalid_padding")))
"Signals on invalid padding"))
(deftest encrypted-keys
(testing "3des-cbc cipher"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ed25519_encrypted_3des-cbc")
:passphrase "123456"))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"01:ea:ad:b6:c8:b1:e8:dd:41:90:d2:b2:eb:ea:f5:2c")
"Ed25519 encrypted (3des-cbc) private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"5JUVhhFIo/Fyv7HAGb5HgHIyKlA")
"Ed25519 encrypted (3des-cbc) private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"SIOpsNueWsiP6+nrQrjytlKZajcb5RhezuAfsKqrEE4")
"Ed25519 encrypted (3des-cbc) private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 encrypted (3des-cbc) private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 encrypted (3des-cbc) private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 encrypted (3des-cbc) private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "3des-cbc")
"Ed25519 encrypted (3des-cbc) private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "bcrypt")
"Ed25519 encrypted (3des-cbc) private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt key)) 16)
"Ed25519 encrypted (3des-cbc) private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds key) 16)
"Ed25519 encrypted (3des-cbc) private key KDF rounds")
(ok (string= (ssh-keys:key-passphrase key) "123456")
"Ed25519 encrypted (3des-cbc) private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ed25519_encrypted_3des-cbc"))
(get-output-stream-string string-out-stream))
"Write Ed25519 encrypted (3des-cbc) private key")))
(testing "aes128-cbc cipher"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_rsa_3072_encrypted_aes128-cbc")
:passphrase "123456"))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"37:4c:1b:16:c6:44:d3:60:ab:01:08:89:d7:0c:c4:e7")
"RSA 3072-bit encrypted (aes128-cbc) private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"Uhv44DazaYbCxqVuusTGxRmJNc8")
"RSA 3072-bit encrypted (aes128-cbc) private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"stNdz9DhMN7fUB3TlOa9raRZCmwXbZq/ZpzUNgp3ORo")
"RSA 3072-bit encrypted (aes128-cbc) private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-rsa" :plain-name "ssh-rsa" :short-name "RSA" :id :ssh-rsa :is-cert nil))
"RSA 3072-bit encrypted (aes128-cbc) private key kind")
(ok (= (ssh-keys:key-bits key) 3072)
"RSA 3072-bit encrypted (aes128-cbc) private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"RSA 3072-bit encrypted (aes128-cbc) private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "aes128-cbc")
"RSA 3072-bit encrypted (aes128-cbc) private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "bcrypt")
"RSA 3072-bit encrypted (aes128-cbc) private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt key)) 16)
"RSA 3072-bit encrypted (aes128-cbc) private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds key) 16)
"RSA 3072-bit encrypted (aes128-cbc) private key KDF rounds")
(ok (string= (ssh-keys:key-passphrase key) "123456")
"RSA 3072-bit encrypted (aes128-cbc) private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_rsa_3072_encrypted_aes128-cbc"))
(get-output-stream-string string-out-stream))
"Write RSA 3072-bit encrypted (aes128-cbc) private key")))
(testing "aes192-cbc cipher"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ed25519_encrypted_aes192-cbc")
:passphrase "123456"))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"b3:a3:91:f2:3c:cb:0d:70:93:65:89:77:c2:8d:92:a7")
"Ed25519 encrypted (aes192-cbc) private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"oBeKn++EPaep01WEgUWjw2+kVDo")
"Ed25519 encrypted (aes192-cbc) private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"NNuRRk3z77YR5I3Ah3HMxuhLWqdq+CsMucsyNBsIX1Y")
"Ed25519 encrypted (aes192-cbc) private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 encrypted (aes192-cbc) private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 encrypted (aes192-cbc) private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 encrypted (aes192-cbc) private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "aes192-cbc")
"Ed25519 encrypted (aes192-cbc) private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "bcrypt")
"Ed25519 encrypted (aes192-cbc) private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt key)) 16)
"Ed25519 encrypted (aes192-cbc) private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds key) 16)
"Ed25519 encrypted (aes192-cbc) private key KDF rounds")
(ok (string= (ssh-keys:key-passphrase key) "123456")
"Ed25519 encrypted (aes192-cbc) private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ed25519_encrypted_aes192-cbc"))
(get-output-stream-string string-out-stream))
"Write Ed25519 encrypted (aes192-cbc) private key")))
(testing "aes256-cbc cipher"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ed25519_encrypted_aes256-cbc")
:passphrase "123456"))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"4d:06:b5:c2:71:e9:1a:bf:bc:b4:bb:d2:6e:ac:7b:b5")
"Ed25519 encrypted (aes256-cbc) private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"QFjs0FShCioe/XiDD8caoVbDCZ0")
"Ed25519 encrypted (aes256-cbc) private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"gNZRqz4XJDx565eOeBQwg6ADPEnXf49DvjZCYNYjwGA")
"Ed25519 encrypted (aes256-cbc) private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 encrypted (aes256-cbc) private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 encrypted (aes256-cbc) private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 encrypted (aes256-cbc) private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "aes256-cbc")
"Ed25519 encrypted (aes256-cbc) private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "bcrypt")
"Ed25519 encrypted (aes256-cbc) private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt key)) 16)
"Ed25519 encrypted (aes256-cbc) private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds key) 16)
"Ed25519 encrypted (aes256-cbc) private key KDF rounds")
(ok (string= (ssh-keys:key-passphrase key) "123456")
"Ed25519 encrypted (aes256-cbc) private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ed25519_encrypted_aes256-cbc"))
(get-output-stream-string string-out-stream))
"Write Ed25519 encrypted (aes256-cbc) private key")))
(testing "aes128-ctr cipher"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ed25519_encrypted_aes128-ctr")
:passphrase "123456"))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"13:67:ef:8f:75:2e:b2:de:32:53:af:4d:df:30:e9:89")
"Ed25519 encrypted (aes128-ctr) private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"QTaQLwebmEeB+CBQ/7yMXHyBZzM")
"Ed25519 encrypted (aes128-ctr) private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"bhY2M4AsyATQtB7Vdz7DKra6fxunTSLmBSszUt2pdQw")
"Ed25519 encrypted (aes128-ctr) private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 encrypted (aes128-ctr) private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 encrypted (aes128-ctr) private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 encrypted (aes128-ctr) private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "aes128-ctr")
"Ed25519 encrypted (aes128-ctr) private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "bcrypt")
"Ed25519 encrypted (aes128-ctr) private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt key)) 16)
"Ed25519 encrypted (aes128-ctr) private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds key) 16)
"Ed25519 encrypted (aes128-ctr) private key KDF rounds")
(ok (string= (ssh-keys:key-passphrase key) "123456")
"Ed25519 encrypted (aes128-ctr) private key passphrase")
;; Verify encoding back into text representation
(ssh-keys:write-key key string-out-stream)
(ok (string= (alexandria:read-file-into-string (get-test-key-path #P"id_ed25519_encrypted_aes128-ctr"))
(get-output-stream-string string-out-stream))
"Write Ed25519 encrypted (aes128-ctr) private key")))
(testing "aes192-ctr cipher"
(let ((key (ssh-keys:parse-private-key-file (get-test-key-path #P"id_ed25519_encrypted_aes192-ctr")
:passphrase "123456"))
(string-out-stream (make-string-output-stream)))
(ok (string= (ssh-keys:fingerprint :md5 key)
"52:b1:86:94:6e:29:02:2c:ef:cf:71:f5:a8:30:ba:10")
"Ed25519 encrypted (aes192-ctr) private key MD5 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha1 key)
"Jo8jDqzVpnnC4QTOy1jFLWnm7zs")
"Ed25519 encrypted (aes192-ctr) private key SHA-1 fingerprint")
(ok (string= (ssh-keys:fingerprint :sha256 key)
"8riamI/02xAvqncuVJZwjdlMH4wEy8AQnfSfJtwSw3I")
"Ed25519 encrypted (aes192-ctr) private key SHA-256 fingerprint")
(ok (equal (ssh-keys:key-kind key)
'(:name "ssh-ed25519" :plain-name "ssh-ed25519" :short-name "ED25519" :id :ssh-ed25519 :is-cert nil))
"Ed25519 encrypted (aes192-ctr) private key kind")
(ok (= (ssh-keys:key-bits key) 256)
"Ed25519 encrypted (aes192-ctr) private key number of bits")
(ok (string= (ssh-keys:key-comment key) "john.doe@localhost")
"Ed25519 encrypted (aes192-ctr) private key comment")
(ok (string= (ssh-keys:key-cipher-name key) "aes192-ctr")
"Ed25519 encrypted (aes192-ctr) private key cipher name")
(ok (string= (ssh-keys:key-kdf-name key) "bcrypt")
"Ed25519 encrypted (aes192-ctr) private key KDF name")
(ok (= (length (ssh-keys:key-kdf-salt key)) 16)
"Ed25519 encrypted (aes192-ctr) private key KDF salt")
(ok (= (ssh-keys:key-kdf-rounds key) 16)
"Ed25519 encrypted (aes192-ctr) private key KDF rounds")