-
Notifications
You must be signed in to change notification settings - Fork 29
/
jose_test.go
2800 lines (2077 loc) · 117 KB
/
jose_test.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
package jose
import (
"crypto/ecdsa"
"crypto/rsa"
"errors"
"fmt"
"strings"
"testing"
"github.com/dvsekhvalnov/jose2go/base64url"
"github.com/dvsekhvalnov/jose2go/keys/ecc"
Rsa "github.com/dvsekhvalnov/jose2go/keys/rsa"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type TestSuite struct{}
var _ = Suite(&TestSuite{})
var shaKey = []byte{97, 48, 97, 50, 97, 98, 100, 56, 45, 54, 49, 54, 50, 45, 52, 49, 99, 51, 45, 56, 51, 100, 54, 45, 49, 99, 102, 53, 53, 57, 98, 52, 54, 97, 102, 99}
var aes128Key = []byte{194, 164, 235, 6, 138, 248, 171, 239, 24, 216, 11, 22, 137, 199, 215, 133}
var aes192Key = []byte{139, 156, 136, 148, 17, 147, 27, 233, 145, 80, 115, 197, 223, 11, 100, 221, 5, 50, 155, 226, 136, 222, 216, 14}
var aes256Key = []byte{164, 60, 194, 0, 161, 189, 41, 38, 130, 89, 141, 164, 45, 170, 159, 209, 69, 137, 243, 216, 191, 131, 47, 250, 32, 107, 231, 117, 37, 158, 225, 234}
var aes384Key = []byte{185, 30, 233, 199, 32, 98, 209, 3, 114, 250, 30, 124, 207, 173, 227, 152, 243, 202, 238, 165, 227, 199, 202, 230, 218, 185, 216, 113, 13, 53, 40, 100, 100, 20, 59, 67, 88, 97, 191, 3, 161, 37, 147, 223, 149, 237, 190, 156}
var aes512Key = []byte{238, 71, 183, 66, 57, 207, 194, 93, 82, 80, 80, 152, 92, 242, 84, 206, 194, 46, 67, 43, 231, 118, 208, 168, 156, 212, 33, 105, 27, 45, 60, 160, 232, 63, 61, 235, 68, 171, 206, 35, 152, 11, 142, 121, 174, 165, 140, 11, 172, 212, 13, 101, 13, 190, 82, 244, 109, 113, 70, 150, 251, 82, 215, 226}
var pubKey = `-----BEGIN CERTIFICATE-----
MIICnTCCAYUCBEReYeAwDQYJKoZIhvcNAQEFBQAwEzERMA8GA1UEAxMIand0LTIw
NDgwHhcNMTQwMTI0MTMwOTE2WhcNMzQwMjIzMjAwMDAwWjATMREwDwYDVQQDEwhq
d3QtMjA0ODCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKhWb9KXmv45
+TKOKhFJkrboZbpbKPJ9Yp12xKLXf8060KfStEStIX+7dCuAYylYWoqiGpuLVVUL
5JmHgXmK9TJpzv9Dfe3TAc/+35r8r9IYB2gXUOZkebty05R6PLY0RO/hs2ZhrOoz
HMo+x216Gwz0CWaajcuiY5Yg1V8VvJ1iQ3rcRgZapk49RNX69kQrGS63gzj0gyHn
Rtbqc/Ua2kobCA83nnznCom3AGinnlSN65AFPP5jmri0l79+4ZZNIerErSW96mUF
8jlJFZI1yJIbzbv73tL+y4i0+BvzsWBs6TkHAp4pinaI8zT+hrVQ2jD4fkJEiRN9
lAqLPUd8CNkCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAnqBw3UHOSSHtU7yMi1+H
E+9119tMh7X/fCpcpOnjYmhW8uy9SiPBZBl1z6vQYkMPcURnDMGHdA31kPKICZ6G
LWGkBLY3BfIQi064e8vWHW7zX6+2Wi1zFWdJlmgQzBhbr8pYh9xjZe6FjPwbSEuS
0uE8dWSWHJLdWsA4xNX9k3pr601R2vPVFCDKs3K1a8P/Xi59kYmKMjaX6vYT879y
gWt43yhtGTF48y85+eqLdFRFANTbBFSzdRlPQUYa5d9PZGxeBTcg7UBkK/G+d6D5
sd78T2ymwlLYrNi+cSDYD6S4hwZaLeEK6h7p/OoG02RBNuT4VqFRu5DJ6Po+C6Jh
qQ==
-----END CERTIFICATE-----`
var privKey = `-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAqFZv0pea/jn5Mo4qEUmStuhlulso8n1inXbEotd/zTrQp9K0
RK0hf7t0K4BjKVhaiqIam4tVVQvkmYeBeYr1MmnO/0N97dMBz/7fmvyv0hgHaBdQ
5mR5u3LTlHo8tjRE7+GzZmGs6jMcyj7HbXobDPQJZpqNy6JjliDVXxW8nWJDetxG
BlqmTj1E1fr2RCsZLreDOPSDIedG1upz9RraShsIDzeefOcKibcAaKeeVI3rkAU8
/mOauLSXv37hlk0h6sStJb3qZQXyOUkVkjXIkhvNu/ve0v7LiLT4G/OxYGzpOQcC
nimKdojzNP6GtVDaMPh+QkSJE32UCos9R3wI2QIDAQABAoIBAQCUmHBvSkqUHaK/
IMU7q2FqOi0KWswDefEiJKQhRu9Wv5NOgW2FrfqDIXrDp7pg1dBezgeExHLX9v6d
FAOTwbj9/m6t3+r6k6fm7gp+ao3dfD6VgPd12L2oXQ0t5NVQ1UUBJ4/QUWps9h90
3AP4vK/COG1P+CAw4DDeZi9TlwF/Pr7e492GXcLBAUJODA6538ED2nYw8xQcbzbA
wr+w07UjRNimObtOfA0HCIpsx/6LkIqe6iGChisQNgt4yDd/fZ4GWOUIU1hqgK1P
6avVl7Q5Mk0PTi9t8ui1X4EEq6Uils45J5WkobuAnFkea/uKfs8Tn9bNrEoVWgdb
fBHq/8bNAoGBANKmjpE9e+L0RtxP+u4FN5YDoKE+i96VR7ru8H6yBKMcnD2uf5mV
RueEoL0FKHxlGBBo0dJWr1AIwpcPbTs3Dgx1/EQMZLg57QBZ7QcYETPiMwMvEM3k
Zf3G4YFYwUwIQXMYPt1ckr+RncRcq0GiKPDsvzzyNS+BBSmR5onAXd7bAoGBAMyT
6ggyqmiR/UwBn87em+GjbfX6YqxHHaQBdWwnnRX0JlGTNCxt6zLTgCIYxF4AA7eR
gfGTStwUJfAScjJirOe6Cpm1XDgxEQrT6oxAl17MR/ms/Z88WrT73G+4phVvDpVr
JcK+CCESnRI8xGLOLMkCc+5NpLajqWCOf1H2J8NbAoGAKTWmTGmf092AA1euOmRQ
5IsfIIxQ5qGDn+FgsRh4acSOGE8L7WrTrTU4EOJyciuA0qz+50xIDbs4/j5pWx1B
JVTrnhBin9vNLrVo9mtR6jmFS0ko226kOUpwEVLgtdQjobWLjtiuaMW+/Iw4gKWN
ptxZ6T1lBD8UWHaPiEFW2+MCgYAmfSWoyS96YQ0QwbV5TDRzrTXA84yg8PhIpOWc
pY9OVBLpghJs0XlQpK4UvCglr0cDwGJ8OsP4x+mjUzUc+aeiKURZSt/Ayqp0KQ6V
uIlCEpjwBnXpAYfnSQNeGZVVrwFFZ1VBYFNTNZdLmRcxp6yRXN7G1ODKY9w4CFc3
6mHsxQKBgQCxEA+KAmmXxL++x/XOElOscz3vFHC4HbpHpOb4nywpE9vunnHE2WY4
EEW9aZbF22jx0ESU2XJ1JlqffvfIEvHNb5tmBWn4HZEpPUHdaFNhb9WjkMuFaLzh
cydwnEftq+3G0X3KSxp4p7R7afcnpNNqfneYODgoXxTQ4Q7ZyKo72A==
-----END RSA PRIVATE KEY-----`
func (s *TestSuite) TestDecodePlaintext(c *C) {
//given
token := "eyJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9."
//when
test, _, err := Decode(token, nil)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodePlaintextWithSignature(c *C) {
//given
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.KmLWPfxC3JGopWImDgYg9IUpgAi8gwimviUfr6eJyFI"
//when
test, _, err := Decode(token, nil)
//then
c.Assert(err, NotNil)
c.Assert(test, Equals, "")
}
func (s *TestSuite) TestDecodePlaintextWithKey(c *C) {
//given
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9."
//when
test, _, err := Decode(token, shaKey)
//then
c.Assert(err, NotNil)
c.Assert(test, Equals, "")
}
func (s *TestSuite) TestDecodeHS256(c *C) {
//given
token := "eyJhbGciOiJIUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.chIoYWrQMA8XL5nFz6oLDJyvgHk2KA4BrFGrKymjC8E"
//when
test, _, err := Decode(token, shaKey)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodeHS384(c *C) {
//given
token := "eyJhbGciOiJIUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.McDgk0h4mRdhPM0yDUtFG_omRUwwqVS2_679Yeivj-a7l6bHs_ahWiKl1KoX_hU_"
//when
test, _, err := Decode(token, shaKey)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodeHS512(c *C) {
//given
token := "eyJhbGciOiJIUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.9KirTNe8IRwFCBLjO8BZuXf3U2ZVagdsg7F9ZsvMwG3FuqY9W0vqwjzPOjLqPN-GkjPm6C3qWPnINhpr5bEDJQ"
//when
test, _, err := Decode(token, shaKey)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestEncodePlaintext(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, NONE, nil)
fmt.Printf("\nnone = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, nil)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeHS256(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, HS256, shaKey)
fmt.Printf("\nHS256 = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.UAuHfK1tObqUzQj2tdMoKjKq1SWoI17hAg17VJ2l8j0")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, shaKey)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeHS384(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, HS384, shaKey)
fmt.Printf("\nHS384 = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJIUzM4NCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.c92ouMmuQ1EmFN6IQmCEKAv5JZoVIeo_ehQl79OskFw3_y5GE_OLiUEfcRikturb")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, shaKey)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeHS512(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, HS512, shaKey)
fmt.Printf("\nHS512 = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJIUzUxMiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.tfZJJbT-Nht5_JkM0vylscOSwiuf9-X7mcBdxTIB_fdHBC-LylKQGPWLqjzDWFnx29f7U_s9c4EjA3WUahib7w")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, shaKey)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecodeRS256(c *C) {
//given
token := "eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.NL_dfVpZkhNn4bZpCyMq5TmnXbT4yiyecuB6Kax_lV8Yq2dG8wLfea-T4UKnrjLOwxlbwLwuKzffWcnWv3LVAWfeBxhGTa0c4_0TX_wzLnsgLuU6s9M2GBkAIuSMHY6UTFumJlEeRBeiqZNrlqvmAzQ9ppJHfWWkW4stcgLCLMAZbTqvRSppC1SMxnvPXnZSWn_Fk_q3oGKWw6Nf0-j-aOhK0S0Lcr0PV69ZE4xBYM9PUS1MpMe2zF5J3Tqlc1VBcJ94fjDj1F7y8twmMT3H1PI9RozO-21R0SiXZ_a93fxhE_l_dj5drgOek7jUN9uBDjkXUwJPAyp9YPehrjyLdw"
//when
test, _, err := Decode(token, PubKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodeRS384(c *C) {
//given
token := "eyJhbGciOiJSUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.cOPca7YEOxnXVdIi7cJqfgRMmDFPCrZG1M7WCJ23U57rAWvCTaQgEFdLjs7aeRAPY5Su_MVWV7YixcawKKYOGVG9eMmjdGiKHVoRcfjwVywGIb-nuD1IBzGesrQe7mFQrcWKtYD9FurjCY1WuI2FzGPp5YhW5Zf4TwmBvOKz6j2D1vOFfGsogzAyH4lqaMpkHpUAXddQxzu8rmFhZ54Rg4T-jMGVlsdrlAAlGA-fdRZ-V3F2PJjHQYUcyS6n1ULcy6ljEOgT5fY-_8DDLLpI8jAIdIhcHUAynuwvvnDr9bJ4xIy4olFRqcUQIHbcb5-WDeWul_cSGzTJdxDZsnDuvg"
//when
test, _, err := Decode(token, PubKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodeRS512(c *C) {
//given
token := "eyJhbGciOiJSUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.KP_mwCVRIxcF6ErdrzNcXZQDFGcL-Hlyocc4tIl3tJfzSfc7rz7qOLPjHpZ6UFH1ncd5TlpRc1B_pgvY-l0BNtx_s7n_QA55X4c1oeD8csrIoXQ6A6mtvdVGoSlGu2JnP6N2aqlDmlcefKqjl_Z-8nwDMGTMkDNhHKfHlIb2_Dliwxeq8LmNMREEdvNH2XVp_ffxBjiaKv2Eqbwc6I17241GCEmjDCvnagSgjX_5uu-da2H7TK2gtPJYUo8r9nzC7uzZJ5SB8suZH0COSofsP-9wvH0FESO40evCyEBylqg3bh9M9dIzeq8_bdTiC5kG93Fal44OEY8_Zm88wB_VjQ"
//when
test, _, err := Decode(token, PubKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestEncodeRS256(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, RS256, PrivKey())
fmt.Printf("\nRS256 = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJSUzI1NiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.fLVmWBDvVKZZPKNAaGrSitQpRGLoku1JPDafaTJhQUjfvrgvu8_RgTO4WmwQVngbAdT0i57EXt28WZHpAdBEJK4wi6sVzRADxO3aSiAxZn_aY_QwH7B4CGeeCvdvjUBX-wNj-4S3F9xCygq2VGtl8PknzAJLtcPmG9V-2hEfyLeL8lcOgK6SGaWWoGC5PjvVW46ilYSbySCr2c3B86TPITcx29_g4juuAM_AtHUdGimOVX1eKyHKSB8_U2IXWc2ujMMgphc0eZNY0W2nl_MwEwq-SvcdyLGfWVuEhgmfqlRHXu5eztHZsw1ejki0J-9r9reG1FbV6GzTMsU9HARW_Q")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PubKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeRS384(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, RS384, PrivKey())
fmt.Printf("\nRS384 = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJSUzM4NCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.BqDcZoC0pWa1k_gFRRSOJnDrU_0c78SdRphUikML36JrZs6fVwcP2NtdVUpDl40CwRdeHFjJF9skXI0KmMbj2bRTFyxL-At8WOVAMVRY0N9jFOjK67nwdafSDCKBqPAjw-Vv1f9yKwNvDoObI2isvhKqTF_EK_wEj-AwQIsmJNqUNF3yD3IgB6PCLS8mW5zXEp6xwf8hMguco6aHV7WBU-ZhdMFjJRydyrwBinUFig68QCdcAUI7KFVbsjani4W87jHgJhinv2GyVyKw5QpIDdvcMQKeoTZWLKQg9BBW4Ar9-YhQIuuO-7chTn2KCMpFCq3hrdrZTqVtX1nEDvBYpA")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PubKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeRS512(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, RS512, PrivKey())
fmt.Printf("\nRS512 = %v\n", test)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "eyJhbGciOiJSUzUxMiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.AqwiRtgwP0th1K8mvmL1oW8bbf8EuqDiUGLIfSQLY7Z9eXzct3Zcd3diri_-v6WczQWKtQ-NipCSEl8CWJQSZY8cRqDhFjiDnLEImY5SzC-xqYxDVb5zu_iQZNd18nlmSw504W3IvxIwk1_avZ6Q12OvRNbG3gLGZtcWi3VLdTa-SGEemEicnlRfLpTAaCk3kkJq6St5NLbiVdQMpfhDBeGCOTFMptLZ6Tw1rWaHy6y5b7_PRwWG1Cb8QEl8du-dxmhDgbenreq5EiybOL05qZRFxJ-1861j5xduG-AY6xum6HtWKPGTSsIZNxepK3DTYfovN5HidcubV747w_6PXw")
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PubKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecodePS256(c *C) {
//given
token := "eyJhbGciOiJQUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.S9xuR-IGfXEj5qsHcMtK-jcj1lezvVstw1AISp8dEQVRNgwOMZhUQnSCx9i1CA-pMucxR-lv4e7zd6h3cYCfMnyv7iuxraxNiNAgREhOT-bkBCZMNgb5t15xEtDSJ3MuBlK3YBtXyVcDDIdKH_Bwj-u363y6LuvZ8FEOGmIK5WSFi18Xjg-ihhvH1C6UzH1G82wrRbX6DyJKqrUnHAg8yzUJVP1AdgjWRt5BKpuYbXSib-MKZZkaE4q_hCb-j25xCzn8Ez8a7PO7p0fDGvZuOk_yzSfvXSavg7iE0GLuUTNv3nQ_xW-rfbrpYeyXNtstoK3JPFpdtORTyH1iIh7VVA"
//when
test, _, err := Decode(token, PubKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodePS384(c *C) {
//given
token := "eyJhbGciOiJQUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EKqVLw6nLGNt1h7KNFZbzkKhf788VBYCfnigYc0dBZBa64MrfbIFHtJuFgIGkCVSDYH-qs-i4w9ke6mD8mxTZFniMgzFXXaCFIrv6QZeMbKh6VYtSEPp7l0B1zMZiQw6egZbZ6a8VBkCRipuZggSlUTg5tHMMTj_jNVxxlY4uUwXlz7vakpbqgXe19pCDJrzEoXE0cNKV13eRCNA1tXOHx0dFL7Jm9NUq7blvhJ8iTw1jMFzK8bV6g6L7GclHBMoJ3MIvRp71m6idir-QeW1KCUfVtBs3HRn3a822LW02vGqopSkaGdRzQZOI28136AMeW4679UXE852srA2v3mWHQ"
//when
test, _, err := Decode(token, PubKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodePS512(c *C) {
//given
token := "eyJhbGciOiJQUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.IvbnmxhKvM70C0n0grkF807wOQLyPOBwJOee-p7JHCQcSstNeml3Owdyw9C3HGHzOdK9db51yAkjJ2TCojxqHW4OR5Apna8tvafYgD2femn1V3GdkGj6ZvYdV3q4ldnmahVeO36vHYy5P0zFcEGU1_j3S3DwGmhw2ktZ4p5fLZ2up2qwhzlOjbtsQpWywHj7cLdeA32MLId9MTAPVGUHIZHw_W0xwjJRS6TgxD9vPQQnP70MY-q_2pVAhfRCM_pauPYO1XH5ldizrTvVr27q_-Uqtw-wV-UDUnyWYQUDDiMTpLBoX1EEXmsbvUGx0OH3yWEaNINoCsepgZvTKbiEQQ"
//when
test, _, err := Decode(token, PubKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestEncodePS256(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, PS256, PrivKey())
fmt.Printf("\nPS256 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 3)
c.Assert(parts[0], Equals, "eyJhbGciOiJQUzI1NiJ9")
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9")
c.Assert(len(parts[1]), Equals, 24)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PubKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodePS384(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, PS384, PrivKey())
fmt.Printf("\nPS384 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 3)
c.Assert(parts[0], Equals, "eyJhbGciOiJQUzM4NCJ9")
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9")
c.Assert(len(parts[1]), Equals, 24)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PubKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodePS512(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, PS512, PrivKey())
fmt.Printf("\nPS512 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 3)
c.Assert(parts[0], Equals, "eyJhbGciOiJQUzUxMiJ9")
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9")
c.Assert(len(parts[1]), Equals, 24)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PubKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecodeES256(c *C) {
//given
token := "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EVnmDMlz-oi05AQzts-R3aqWvaBlwVZddWkmaaHyMx5Phb2NSLgyI0kccpgjjAyo1S5KCB3LIMPfmxCX_obMKA"
//when
test, _, err := Decode(token, Ecc256Public())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodeES384(c *C) {
//given
token := "eyJhbGciOiJFUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.jVTHd9T0fIQDJLNvAq3LPpgj_npXtWb64FfEK8Sm65Nr9q2goUWASrM9jv3h-71UrP4cBpM3on3yN--o6B-Tl6bscVUfpm1swPp94f7XD9VYLEjGMjQOaozr13iBZJCY"
//when
test, _, err := Decode(token, Ecc384Public())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestDecodeES512(c *C) {
//given
token := "eyJhbGciOiJFUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.AHxJYFeTVpZmrfZsltpQKkkplmbkycQKFOFucD7hE4Sm3rCswUDi8hlSCfeYByugySYLFzogTQGk79PHP6vdl39sAUc9k2bhnv-NxRmJsN8ZxEx09qYKbc14qiNWZztLweQg0U-pU0DQ66rwJ0HikzSqgmyD1bJ6RxitJwceYLAovv0v"
//when
test, _, err := Decode(token, Ecc512Public())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"hello": "world"}`)
}
func (s *TestSuite) TestEncodeES256(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, ES256, Ecc256Private())
fmt.Printf("\nES256 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 3)
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzI1NiJ9")
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9")
c.Assert(len(parts[2]), Equals, 86)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, Ecc256Public())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeES384(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, ES384, Ecc384Private())
fmt.Printf("\nES384 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 3)
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzM4NCJ9")
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9")
c.Assert(len(parts[2]), Equals, 128)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, Ecc384Public())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncodeES512(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Sign(payload, ES512, Ecc512Private())
fmt.Printf("\nES512 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 3)
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzUxMiJ9")
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9")
c.Assert(len(parts[2]), Equals, 176)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, Ecc512Public())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecrypt_DIR_A128CBC_HS256(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..3lClLoerWhxIc811QXDLbg.iFd5MNk2eWDlW3hbq7vTFLPJlC0Od_MSyWGakEn5kfYbbPk7BM_SxUMptwcvDnZ5uBKwwPAYOsHIm5IjZ79LKZul9ZnOtJONRvxWLeS9WZiX4CghOLZL7dLypKn-mB22xsmSUbtizMuNSdgJwUCxEmms7vYOpL0Che-0_YrOu3NmBCLBiZzdWVtSSvYw6Ltzbch4OAaX2ye_IIemJoU1VnrdW0y-AjPgnAUA-GY7CAKJ70leS1LyjTW8H_ecB4sDCkLpxNOUsWZs3DN0vxxSQw.bxrZkcOeBgFAo3t0585ZdQ"
//when
test, _, err := Decode(token, aes256Key)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"exp":1392553211,"sub":"alice","nbf":1392552611,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"586dd129-a29f-49c8-9de7-454af1155e27","iat":1392552611}`)
}
func (s *TestSuite) TestDecrypt_DIR_A192CBC_HS384(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0..fX42Nn8ABHClA0UfbpkX_g.ClZzxQIzg40GpTETaLejGNhCN0mqSM1BNCIU5NldeF-hGS7_u_5uFsJoWK8BLCoWRtQ3cWIeaHgOa5njCftEK1AoHvechgNCQgme-fuF3f2v5DOphU-tveYzN-uvrUthS0LIrAYrwQW0c0DKcJZ-9vQmC__EzesZgUHiDB8SnoEROPTvJcsBKI4zhFT7wOgqnFS7P7_BQZj_UnbJkzTAiE5MURBBpCYR-OS3zn--QftbdGVJ2CWmwH3HuDO9-IE2IQ5cKYHnzSwu1vyME_SpZA.qd8ZGKzmOzzPhFV-Po8KgJ5jZb5xUQtU"
//when
test, _, err := Decode(token, aes384Key)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"exp":1392553372,"sub":"alice","nbf":1392552772,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"f81648e9-e9b3-4e37-a655-fcfacace0ef0","iat":1392552772}`)
}
func (s *TestSuite) TestDecrypt_DIR_A256CBC_HS512(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0..ZD93XtD7TOa2WMbqSuaY9g.1J5BAuxNRMWaw43s7hR82gqLiaZOHBmfD3_B9k4I2VIDKzS9oEF_NS2o7UIBa6t_fWHU7vDm9lNAN4rqq7OvtCBHJpFk31dcruQHxwYKn5xNefG7YP-o6QtpyNioNWJpaSD5VRcRO5ufRrw2bu4_nOth00yJU5jjN3O3n9f-0ewrN2UXDJIbZM-NiSuEDEgOVHImQXoOtOQd0BuaDx6xTJydw_rW5-_wtiOH2k-3YGlibfOWNu51kApGarRsAhhqKIPetYf5Mgmpv1bkUo6HJw.nVpOmg3Sxri0rh6nQXaIx5X0fBtCt7Kscg6c66NugHY"
//when
test, _, err := Decode(token, aes512Key)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"exp":1392553617,"sub":"alice","nbf":1392553017,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"029ea059-b8aa-44eb-a5ad-59458de678f8","iat":1392553017}`)
}
func (s *TestSuite) TestEncrypt_DIR_A128CBC_HS256(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, DIR, A128CBC_HS256, aes256Key)
fmt.Printf("\nDIR A128CBC-HS256 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0")
c.Assert(len(parts[1]), Equals, 0)
c.Assert(len(parts[2]), Equals, 22)
c.Assert(len(parts[3]), Equals, 43)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, aes256Key)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_DIR_A192CBC_HS384(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, DIR, A192CBC_HS384, aes384Key)
fmt.Printf("\nDIR A192CBC-HS384 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0")
c.Assert(len(parts[1]), Equals, 0)
c.Assert(len(parts[2]), Equals, 22)
c.Assert(len(parts[3]), Equals, 43)
c.Assert(len(parts[4]), Equals, 32)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, aes384Key)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_DIR_A256CBC_HS512(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, DIR, A256CBC_HS512, aes512Key)
fmt.Printf("\nDIR A256CBC-HS512 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0")
c.Assert(len(parts[1]), Equals, 0)
c.Assert(len(parts[2]), Equals, 22)
c.Assert(len(parts[3]), Equals, 43)
c.Assert(len(parts[4]), Equals, 43)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, aes512Key)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecrypt_DIR_A128GCM(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..yVi-LdQQngN0C5WS.1McwSmhZzAtmmLp9y-OdnJwaJFo1nj_4ashmzl2LhubGf0Jl1OTEVJzsHZb7bkup7cGTkuxh6Vfv10ljHsjWf_URXoxP3stQqQeViVcuPV0y2Q_WHYzTNGZpmHGe-hM6gjDhyZyvu3yeXGFSvfPQmp9pWVOgDjI4RC0MQ83rzzn-rRdnZkznWjbmOPxwPrR72Qng0BISsEwbkPn4oO8-vlHkVmPpuDTaYzCT2ZR5K9JnIU8d8QdxEAGb7-s8GEJ1yqtd_w._umbK59DAKA3O89h15VoKQ"
//when
test, _, err := Decode(token, aes128Key)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"exp":1392548520,"sub":"alice","nbf":1392547920,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"0e659a67-1cd3-438b-8888-217e72951ec9","iat":1392547920}`)
}
func (s *TestSuite) TestDecrypt_DIR_A128GCM_WRONG_NONCE_SIZE(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..yVi-LQQngN0C5WS.1McwSmhZzAtmmLp9y-OdnJwaJFo1nj_4ashmzl2LhubGf0Jl1OTEVJzsHZb7bkup7cGTkuxh6Vfv10ljHsjWf_URXoxP3stQqQeViVcuPV0y2Q_WHYzTNGZpmHGe-hM6gjDhyZyvu3yeXGFSvfPQmp9pWVOgDjI4RC0MQ83rzzn-rRdnZkznWjbmOPxwPrR72Qng0BISsEwbkPn4oO8-vlHkVmPpuDTaYzCT2ZR5K9JnIU8d8QdxEAGb7-s8GEJ1yqtd_w._umbK59DAKA3O89h15VoKQ"
//when
_, _, err := Decode(token, aes128Key)
//then
c.Assert(err, NotNil)
}
func (s *TestSuite) TestDecrypt_DIR_A192GCM(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyR0NNIn0..YW2WB0afVronbgSz.tfk1VADGjBnViYD7He5mbhxpbogoT1cmhKiDKzzoBV2AxfsgJ2Eq-vtEqPi9eY9H52FLLtht26rc5fPz9ZKOUH2hYeFdaRyKYXlpEnUR2cCT9_3TYcaFhpYBH4HCa59NruKlJHMBqM2ssWZLSEblFX9srUHFtu2OQz2ydMy1fr8ABDTdVYgaqyBoYRGykTkEsgayEyfAMz9u095N2J0JTCB5Q0IiXNdBzBSxZXG-i9f5HFEb6IliaTwFTNFnhDL66O4rsg._dh02z25W7HA6b1XiFVpUw"
//when
test, _, err := Decode(token, aes192Key)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"exp":1392552631,"sub":"alice","nbf":1392552031,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"a3fea096-2e96-4d8b-b7cd-070e08b533fb","iat":1392552031}`)
}
func (s *TestSuite) TestDecrypt_DIR_A256GCM(c *C) {
//given
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..Fmz3PLVfv-ySl4IJ.LMZpXMDoBIll5yuEs81Bws2-iUUaBSpucJPL-GtDKXkPhFpJmES2T136Vd8xzvp-3JW-fvpRZtlhluqGHjywPctol71Zuz9uFQjuejIU4axA_XiAy-BadbRUm1-25FRT30WtrrxKltSkulmIS5N-Nsi_zmCz5xicB1ZnzneRXGaXY4B444_IHxGBIS_wdurPAN0OEGw4xIi2DAD1Ikc99a90L7rUZfbHNg_iTBr-OshZqDbR6C5KhmMgk5KqDJEN8Ik-Yw.Jbk8ZmO901fqECYVPKOAzg"
//when
test, _, err := Decode(token, aes256Key)
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, `{"exp":1392552841,"sub":"alice","nbf":1392552241,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"efdfc02f-945e-4e1f-85a6-9f240f6cf153","iat":1392552241}`)
}
func (s *TestSuite) TestEncrypt_DIR_A128GCM(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, DIR, A128GCM, aes128Key)
fmt.Printf("\nDIR A128GCM = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0")
c.Assert(len(parts[1]), Equals, 0)
c.Assert(len(parts[2]), Equals, 16)
c.Assert(len(parts[3]), Equals, 24)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, aes128Key)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_DIR_A192GCM(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, DIR, A192GCM, aes192Key)
fmt.Printf("\nDIR A192GCM = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyR0NNIn0")
c.Assert(len(parts[1]), Equals, 0)
c.Assert(len(parts[2]), Equals, 16)
c.Assert(len(parts[3]), Equals, 24)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, aes192Key)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_DIR_A256GCM(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, DIR, A256GCM, aes256Key)
fmt.Printf("\nDIR A256GCM = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0")
c.Assert(len(parts[1]), Equals, 0)
c.Assert(len(parts[2]), Equals, 16)
c.Assert(len(parts[3]), Equals, 24)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, aes256Key)
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecrypt_RSA1_5_A128CBC_HS256(c *C) {
//given
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.Pi1BtHrCnYfqXB0jr9lDuUoZf5yVZQKm940dNrhyEtcTg5R5Nw8NIPepVYM0Lt_BKdUs-g9iwZ4FwO0NHnaLOysqmLiOkey1gO2dBnDySISG4-SDEhkbBxVmAK-schPxXcC9hR0SpoI202h5o4jMrEvoxfiT-D5wq8iTJAiipVMA2QFO46ODuDLQOxuDTf57_z0W_5Qg-LYce7C8_nyhpGnhqkONEAwFBVwX0gPX08bui7fxs2LctvB3YZLJ5o4QDb0dRJ9HjDJ6YMiuPt9lgH4a4TScD3wZFmeksZYnNiMHPsfL-xDexbabQb2WB0CEleRXCBAcoGYQdXy-cCr4Vg.S8T50xGdXg_PzORit9s3Hg.vtHSEqDBKRiLpmO3CVzANMNu0dKcm0r1VJ-3YkZD8LEEGx4K29Scq7hMKC1XgBUYkcY0F1e7itItEvpWvwXkNAzP8YPEj8-p_wHgrqSn0Z4x_8626vKxLjlOK30uleq_pJTc4lwjG5VTRW9ax1Jy8rVu6x464e9vwfjzdFdEcDMtfM2MYrhM9XFHqaJNRmUAqd0GKepvoPVQSOw3tVxeqblCEgpZt8CEHpKpNPQkzOiaF3Ec7a8Garm7FE0zI69qVh94-ViBp7_1uxxHw-AnSg.JVC_j28xJiA0iQOhL86v7w"
//when
test, _, err := Decode(token, PrivKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "{\"exp\":1408349987,\"sub\":\"alice\",\"nbf\":1408349387,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"e82d6f67-e3ed-4a1b-9f29-114575c37e6d\",\"iat\":1408349387}")
}
func (s *TestSuite) TestDecrypt_RSA1_5_A192CBC_HS384(c *C) {
//given
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0.ApUpt1SGilnXuqvFSHdTV0K9QKSf0P6wEEOTrAqWMwyEOLlyb6VR8o6fdd4wXMTkkL5Bp9BH1x0oibTrVwVa50rxbPDlRJQe0yvBm0w02nkzl3Tt4fE3sGjEXGgI8w8ZxSVAN0EkaXLqzsG1rQ631ptzqyNzg9BWfy53cHhuzh9w00ZOXZtNc7GFBQ1LRvhK1EyLS2_my8KD091KwsjvXC-_J0eOp2W8NkycP_jCIrUzAOSwz--NZyRXt9V2o609HGItKajHplbE1PJVShaXO84MdJl3X6ef8ZXz7mCP3dRlsYfK-tlnFVeEKwC1Oy_zdFsdiY4j41Mj3usvG2j7xQ.GY4Em2zkSGMZsDLNr9pnDw.GZYJSpeQHmOtx34dk4WxEPCnt7l8R5oLKd3IyoMYbjZrWRtomyTufOKfiOVT-nY9ad0Vs5w5Imr2ysy6DnkAFoOnINV_Bzq1hQU4oFfUd_9bFfHZvGuW9H-NTUVBLDhok6NHosSBaY8xLdwHL_GiztRsX_rU4I88bmWBIFiu8T_IRskrX_kSKQ_iGpIJiDy5psIxY4il9dPihLJhcI_JqysW0pIMHB9ij_JSrCnVPs4ngXBHrQoxeDv3HiHFTGXziZ8k79LZ9LywanzC0-ZC5Q.1cmUwl7MnFl__CS9Y__a8t5aVyI9IKOY"
//when
test, _, err := Decode(token, PrivKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "{\"exp\":1391196668,\"sub\":\"alice\",\"nbf\":1391196068,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"c9d44ff8-ff1e-4490-8454-941e45766152\",\"iat\":1391196068}")
}
func (s *TestSuite) TestDecrypt_RSA1_5_A256CBC_HS512(c *C) {
//given
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.NPxfy2Oscg5bA_7pPpc8NCa_CpAu0DWCo8JHrr5acLQ4Fcn1veO0MucNLdHHXlTcolSudxLpjulfmTxafUIw0O1_rz9omsB577f3B0DA_ovnABLwIf1YUJTE-pPCn1qVU2noaWhq0OEnmzB3aJaDp1pp1Lb3UHt-X9dbXDD2zluiSyt4wAjLp7JJLPfNdypps0UwOjGPRG009C7Kbb3Gnx1YOSd_xVuRDf_CqwwF5-VoAQxbLxDU-38aCZL7VjMgiDDXs56SX2bqnpvW1Q_58wTA-7LIpiP4vk8th2jpg59W9k0vixAqszWeiw1nqVOJ5qZgusss-MXYlPHZGmWFpg.uo4pnWhJEa8Cd496i1aS8Q.buM4urwbq330U7HUM2uNExvhBHxneqy4MnU1_g3ar5aTiH0dOsKD2J8jJJPt3k2BTPOOm8YZh36M7sm5TUTdp2Suc9UyMeV-HgL5-DPGGPFaG-Kk1ZjZPBpGwf-RmpSq9yUhINx5TO3XoX1rXyJcNi8_3l1B3R5Fv3Kjl-cihbTejHz_q2IPQwDZJTaTIlmtkrflTN07aZ9Y_KFLc2qjG6KdP2CM-I1-Oq-gc-H0EdoBLj1zGvAwoPpPdviO8C8n4VBb80RV8ED-wt8J2JVc3A.6bGm8EKBxcyMvFcWXr5G1ziCD0e1Pv1TP0YOze11vZc"
//when
test, _, err := Decode(token, PrivKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "{\"exp\":1408349987,\"sub\":\"alice\",\"nbf\":1408349387,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"f6d4b905-3382-4207-be7a-611461e06c3d\",\"iat\":1408349387}")
}
func (s *TestSuite) TestDecrypt_RSA1_5_A128GCM(c *C) {
//given
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4R0NNIn0.SLM4JN2t0JHYBXQr2uJ-K3QHW4SRCWPTPL-Czo-9IJQWgBbIlBXjrXOpQ-HtLg3OeKlXGz4AIihdHpFRSpPAq-e4ht8O5DSK-O6qyl8_-PSJfinZCMeLLE9Q1L6qHY86Rv9NMFeVUZZVmBPIXUTer-jU4tAgi3Upwek0M_gMwzeH94FEhHQqCzdYsBfsqwHpuRcrjatdjxBoSBXIEvNg8fi31UYG5L6jEUt2evOVFYq1C0-R17wydC71-2ubb35xXKbsNt5pShiil0sDalLTkuVKMtDuuMWZeMWHPp81wGJSHj9Ctl_ISHHjPC99MbGq9ZXSOBX2DNbfVmUMVRfHcQ.bbsRwjtVRyEeovfu.jGoxrc-CRwigy9IXs6NwKUR2zMZL2gcj_qhEmZAL1uqhkusA4zcCvVNrt2hFL3ZprN7pjpJ0Nm56MngNgTWQZkxwt_oz-Dk7IHmemEkC3m2Xboyy9ZvfesHvJlZEs6xMmxM-7TEQrb7_FP0lR_wZVoIuMQUHl6rwxofjtPNdABzxDQyaW-PU7aOSGNO-Eg8lBGFJZFWTcpwOwsYZhSdHhtc4PnUmzfkwDMWdOAXwey4bRXih6D0LuQZZbVlsYOSZq3dpTg.Igb39yvfNHPGPVryD5a3WA"
//when
test, _, err := Decode(token, PrivKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "{\"exp\":1408349988,\"sub\":\"alice\",\"nbf\":1408349388,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"e7c97c7a-418c-440d-b3de-6f9ddc5d8f71\",\"iat\":1408349388}")
}
func (s *TestSuite) TestDecrypt_RSA1_5_A192GCM(c *C) {
//given
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyR0NNIn0.pqD1m66UeNppuOnP_H0WBQB3PCgYN0Zzf1DZraXM8XUJapw4LrwhvUXlYwcgrFdZ4v-asmzvABPc2sbGxzIJsPebGoEIlFDV3OvRRN1vUBOdst99v4q9En21FLa1MwNvCoDeg-TLK54t-NPShmsb4cLWFGS8KAKj2HEqXStw18Di4PTEfFfiJpeBUF8UHgqXfs5vqSJKmtvHPBNGUpCOPEhuNDOOKXvxMQotjoktKCyffJSgtr1fy0rOO4iR4EJjozclIAPVDCfQMVfVZBJEbUfszZ6cOCVsPLZKY3msWo3CFOQOcvXJOjkp0IXCaQxrvofetgmHP_ILsf4ty7_UIA.oIicSl5B8tBykEB-.Xlb-OZBpOdDfTEIjtYDFIm40CJeolfC7C4t2qgqi3Gd4kk-5oEbQzNuFMp8M4eUyDsSvNXdN5mlrOwAj9KsSLWB5FZf51Nvk5YJFN9scaQmdSzU7AlLhM2yMEpOmzZMo1GsiZxD8Rle0LyWmgFtMpGJk3PTEXwYnmNyyDAxhFAaWU2WOc1KofQsPbOjTA_0ijpVHG2FO-8jMPWNvl5GbZPAeId1yYt_mhTXbg6M7VRgazWQsq0n0IK8C3r0hu0UZ0DL0fg.xG8T-AWjAokmvAmBw-tiDA"
//when
test, _, err := Decode(token, PrivKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "{\"exp\":1408349988,\"sub\":\"alice\",\"nbf\":1408349388,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"0c8db172-5795-4033-badf-2e95fb8a24ac\",\"iat\":1408349388}")
}
func (s *TestSuite) TestDecrypt_RSA1_5_A256GCM(c *C) {
//given
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2R0NNIn0.atdPJ2O-zpVFKyT1_EY0OT8WfF78A6fgYabEtGUUg1KrlR-dDat8tAtj58__lu4TFrZ_J0kcWNVkPpRy0IiyCxKtuo2Gfeufiq0MCiOza0XjT87RJinvAQMJU5rjfOC9bnCgEmDdaePRYr2zbnq7cBU6xh4q9sUT6jDhOSQ49aXDZdzIsMz4lwHpEtUwpF8vFuK7CP1AyibVrrCp1PoVyx4kpT7sRP0V3cRrZutO1MGlI3BWHdFCO2Ak0PDtlqx5uh1atB4XlTD0nswLMoKRSSOuP4GviZFoX4v7REFVcNbuIVQz0bbszYSmJXNi0VBGSodrsM2Ok0ufXRxYWaBepg.hSe2EnGM-0CFZzy-.jplzmtN7z5cARKj9kpgFFUD2_4qpFyvfn4F2kUXEkgRSgRN7ej8S0GepH2qOksS0yrwD97NdVA-hqhD7EiixVHaBhyxT9hYMdJLmPygfiXG7WKvLuDR24zVUvD8q98b1lSP55JPKEIBj_y1YVmrybv_dl30wqt4cbDLhmqWScwJRSp53KX26F8-R903Zitr5dke_6G8wMcJTrszus0EDxsurSPkxkDlBmDl6h-J0XNgY7dzB4tXud8q7l6XPvbvSbNBpqg.4ppwz1DXn7ba80wmEKAwaQ"
//when
test, _, err := Decode(token, PrivKey())
//then
c.Assert(err, IsNil)
c.Assert(test, Equals, "{\"exp\":1408349988,\"sub\":\"alice\",\"nbf\":1408349388,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"0b2f4ddf-8ed0-45d5-9e25-973212099e97\",\"iat\":1408349388}")
}
func (s *TestSuite) TestEncrypt_RSA1_5_A128CBC_HS256(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, RSA1_5, A128CBC_HS256, PubKey())
fmt.Printf("\nRSA1_5 A128CBC-HS256 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0")
c.Assert(len(parts[1]), Equals, 342)
c.Assert(len(parts[2]), Equals, 22)
c.Assert(len(parts[3]), Equals, 43)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PrivKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_RSA1_5_A192CBC_HS384(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, RSA1_5, A192CBC_HS384, PubKey())
fmt.Printf("\nRSA1_5 A192CBC-HS384 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0")
c.Assert(len(parts[1]), Equals, 342)
c.Assert(len(parts[2]), Equals, 22)
c.Assert(len(parts[3]), Equals, 43)
c.Assert(len(parts[4]), Equals, 32)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PrivKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_RSA1_5_A256CBC_HS512(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, RSA1_5, A256CBC_HS512, PubKey())
fmt.Printf("\nRSA1_5 A256CBC-HS512 = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0")
c.Assert(len(parts[1]), Equals, 342)
c.Assert(len(parts[2]), Equals, 22)
c.Assert(len(parts[3]), Equals, 43)
c.Assert(len(parts[4]), Equals, 43)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PrivKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_RSA1_5_A128GCM(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, RSA1_5, A128GCM, PubKey())
fmt.Printf("\nRSA1_5 A128GCM = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4R0NNIn0")
c.Assert(len(parts[1]), Equals, 342)
c.Assert(len(parts[2]), Equals, 16)
c.Assert(len(parts[3]), Equals, 24)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PrivKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_RSA1_5_A192GCM(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, RSA1_5, A192GCM, PubKey())
fmt.Printf("\nRSA1_5 A192GCM = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyR0NNIn0")
c.Assert(len(parts[1]), Equals, 342)
c.Assert(len(parts[2]), Equals, 16)
c.Assert(len(parts[3]), Equals, 24)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PrivKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestEncrypt_RSA1_5_A256GCM(c *C) {
//given
payload := `{"hello": "world"}`
//when
test, err := Encrypt(payload, RSA1_5, A256GCM, PubKey())
fmt.Printf("\nRSA1_5 A256GCM = %v\n", test)
//then
c.Assert(err, IsNil)
parts := strings.Split(test, ".")
c.Assert(len(parts), Equals, 5)
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2R0NNIn0")
c.Assert(len(parts[1]), Equals, 342)
c.Assert(len(parts[2]), Equals, 16)
c.Assert(len(parts[3]), Equals, 24)
c.Assert(len(parts[4]), Equals, 22)
//make sure we consistent with ourselfs
t, _, _ := Decode(test, PrivKey())
c.Assert(t, Equals, payload)
}
func (s *TestSuite) TestDecrypt_RSA_OAEP_A128CBC_HS256(c *C) {
//given
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ.mlcD4YXAzTKgKsnkiPD8iBPkUkVijLCf9ODLs-ziHotR10iVPg2G2j1m-_BCgLB0SNWOcvkCTG1jzYJPr7ARs9GIBg63vtlqgk5TJhTko3J6TFwkrqMB_yeweuWvVvJ7R5CvlKRh_diUcB90RX1lPWSTx4wQHOjLssQ-xRG1iVZ2eroA1uhi8gW7Jdds2wmEnDqxfwmMaaK7IY6cpG_rUMYDqG3m9r3-B0j2MAYOtjGzPtwsJfTHsdasWz_pbypViOp35_BrUHRy6qfqR0uK3zfhe8sFfQDTDctMjissAUGo8rpqnVphoojjvxZVlkB2PmcctOzkAiaMusdOsAxhRg.yH5p6nQitVc9YxQJQP6ocw.XeHzeO9nlXJEmnKtEe_uyl72Aqyzje7Eiz96Zpz79Ot8udWPTmVpa902pGSEeLqHSmbvSpleGEGeuJP5HgOQ-VCrUd3FYL9PK88ieEwO2zsXZfGq4L-tVu7sgyYE8yz25dNRoMoXnrPRzv8dciq3XYxgIYeE0gMc9htVb42rXH7lXjbYeA1aCS2sjd-hRbh-5_afChrpDKYTavpd4EikOdz_-d7EddeUOnHmUsFBz6R6PVX4aOSUkIQug4RyXZLLaq0UkfBLfwezgO3t-dWY8Q.vjaIoaOKXR76eOuUZ1fang"
//when
test, _, err := Decode(token, PrivKey())