| 1 |
package jose |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto/ecdsa" |
| 5 |
"crypto/rsa" |
| 6 |
"errors" |
| 7 |
"fmt" |
| 8 |
"strings" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"github.com/dvsekhvalnov/jose2go/base64url" |
| 12 |
"github.com/dvsekhvalnov/jose2go/keys/ecc" |
| 13 |
Rsa "github.com/dvsekhvalnov/jose2go/keys/rsa" |
| 14 |
|
| 15 |
. "gopkg.in/check.v1" |
| 16 |
) |
| 17 |
|
| 18 |
func Test(t *testing.T) { TestingT(t) } |
| 19 |
|
| 20 |
type TestSuite struct{} |
| 21 |
|
| 22 |
var _ = Suite(&TestSuite{}) |
| 23 |
|
| 24 |
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} |
| 25 |
var aes128Key = []byte{194, 164, 235, 6, 138, 248, 171, 239, 24, 216, 11, 22, 137, 199, 215, 133} |
| 26 |
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} |
| 27 |
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} |
| 28 |
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} |
| 29 |
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} |
| 30 |
|
| 31 |
var pubKey = `-----BEGIN CERTIFICATE----- |
| 32 |
MIICnTCCAYUCBEReYeAwDQYJKoZIhvcNAQEFBQAwEzERMA8GA1UEAxMIand0LTIw |
| 33 |
NDgwHhcNMTQwMTI0MTMwOTE2WhcNMzQwMjIzMjAwMDAwWjATMREwDwYDVQQDEwhq |
| 34 |
d3QtMjA0ODCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKhWb9KXmv45 |
| 35 |
+TKOKhFJkrboZbpbKPJ9Yp12xKLXf8060KfStEStIX+7dCuAYylYWoqiGpuLVVUL |
| 36 |
5JmHgXmK9TJpzv9Dfe3TAc/+35r8r9IYB2gXUOZkebty05R6PLY0RO/hs2ZhrOoz |
| 37 |
HMo+x216Gwz0CWaajcuiY5Yg1V8VvJ1iQ3rcRgZapk49RNX69kQrGS63gzj0gyHn |
| 38 |
Rtbqc/Ua2kobCA83nnznCom3AGinnlSN65AFPP5jmri0l79+4ZZNIerErSW96mUF |
| 39 |
8jlJFZI1yJIbzbv73tL+y4i0+BvzsWBs6TkHAp4pinaI8zT+hrVQ2jD4fkJEiRN9 |
| 40 |
lAqLPUd8CNkCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAnqBw3UHOSSHtU7yMi1+H |
| 41 |
E+9119tMh7X/fCpcpOnjYmhW8uy9SiPBZBl1z6vQYkMPcURnDMGHdA31kPKICZ6G |
| 42 |
LWGkBLY3BfIQi064e8vWHW7zX6+2Wi1zFWdJlmgQzBhbr8pYh9xjZe6FjPwbSEuS |
| 43 |
0uE8dWSWHJLdWsA4xNX9k3pr601R2vPVFCDKs3K1a8P/Xi59kYmKMjaX6vYT879y |
| 44 |
gWt43yhtGTF48y85+eqLdFRFANTbBFSzdRlPQUYa5d9PZGxeBTcg7UBkK/G+d6D5 |
| 45 |
sd78T2ymwlLYrNi+cSDYD6S4hwZaLeEK6h7p/OoG02RBNuT4VqFRu5DJ6Po+C6Jh |
| 46 |
qQ== |
| 47 |
-----END CERTIFICATE-----` |
| 48 |
|
| 49 |
var privKey = `-----BEGIN RSA PRIVATE KEY----- |
| 50 |
MIIEpAIBAAKCAQEAqFZv0pea/jn5Mo4qEUmStuhlulso8n1inXbEotd/zTrQp9K0 |
| 51 |
RK0hf7t0K4BjKVhaiqIam4tVVQvkmYeBeYr1MmnO/0N97dMBz/7fmvyv0hgHaBdQ |
| 52 |
5mR5u3LTlHo8tjRE7+GzZmGs6jMcyj7HbXobDPQJZpqNy6JjliDVXxW8nWJDetxG |
| 53 |
BlqmTj1E1fr2RCsZLreDOPSDIedG1upz9RraShsIDzeefOcKibcAaKeeVI3rkAU8 |
| 54 |
/mOauLSXv37hlk0h6sStJb3qZQXyOUkVkjXIkhvNu/ve0v7LiLT4G/OxYGzpOQcC |
| 55 |
nimKdojzNP6GtVDaMPh+QkSJE32UCos9R3wI2QIDAQABAoIBAQCUmHBvSkqUHaK/ |
| 56 |
IMU7q2FqOi0KWswDefEiJKQhRu9Wv5NOgW2FrfqDIXrDp7pg1dBezgeExHLX9v6d |
| 57 |
FAOTwbj9/m6t3+r6k6fm7gp+ao3dfD6VgPd12L2oXQ0t5NVQ1UUBJ4/QUWps9h90 |
| 58 |
3AP4vK/COG1P+CAw4DDeZi9TlwF/Pr7e492GXcLBAUJODA6538ED2nYw8xQcbzbA |
| 59 |
wr+w07UjRNimObtOfA0HCIpsx/6LkIqe6iGChisQNgt4yDd/fZ4GWOUIU1hqgK1P |
| 60 |
6avVl7Q5Mk0PTi9t8ui1X4EEq6Uils45J5WkobuAnFkea/uKfs8Tn9bNrEoVWgdb |
| 61 |
fBHq/8bNAoGBANKmjpE9e+L0RtxP+u4FN5YDoKE+i96VR7ru8H6yBKMcnD2uf5mV |
| 62 |
RueEoL0FKHxlGBBo0dJWr1AIwpcPbTs3Dgx1/EQMZLg57QBZ7QcYETPiMwMvEM3k |
| 63 |
Zf3G4YFYwUwIQXMYPt1ckr+RncRcq0GiKPDsvzzyNS+BBSmR5onAXd7bAoGBAMyT |
| 64 |
6ggyqmiR/UwBn87em+GjbfX6YqxHHaQBdWwnnRX0JlGTNCxt6zLTgCIYxF4AA7eR |
| 65 |
gfGTStwUJfAScjJirOe6Cpm1XDgxEQrT6oxAl17MR/ms/Z88WrT73G+4phVvDpVr |
| 66 |
JcK+CCESnRI8xGLOLMkCc+5NpLajqWCOf1H2J8NbAoGAKTWmTGmf092AA1euOmRQ |
| 67 |
5IsfIIxQ5qGDn+FgsRh4acSOGE8L7WrTrTU4EOJyciuA0qz+50xIDbs4/j5pWx1B |
| 68 |
JVTrnhBin9vNLrVo9mtR6jmFS0ko226kOUpwEVLgtdQjobWLjtiuaMW+/Iw4gKWN |
| 69 |
ptxZ6T1lBD8UWHaPiEFW2+MCgYAmfSWoyS96YQ0QwbV5TDRzrTXA84yg8PhIpOWc |
| 70 |
pY9OVBLpghJs0XlQpK4UvCglr0cDwGJ8OsP4x+mjUzUc+aeiKURZSt/Ayqp0KQ6V |
| 71 |
uIlCEpjwBnXpAYfnSQNeGZVVrwFFZ1VBYFNTNZdLmRcxp6yRXN7G1ODKY9w4CFc3 |
| 72 |
6mHsxQKBgQCxEA+KAmmXxL++x/XOElOscz3vFHC4HbpHpOb4nywpE9vunnHE2WY4 |
| 73 |
EEW9aZbF22jx0ESU2XJ1JlqffvfIEvHNb5tmBWn4HZEpPUHdaFNhb9WjkMuFaLzh |
| 74 |
cydwnEftq+3G0X3KSxp4p7R7afcnpNNqfneYODgoXxTQ4Q7ZyKo72A== |
| 75 |
-----END RSA PRIVATE KEY-----` |
| 76 |
|
| 77 |
func (s *TestSuite) TestDecodePlaintext(c *C) { |
| 78 |
//given |
| 79 |
token := "eyJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9." |
| 80 |
|
| 81 |
//when |
| 82 |
test, _, err := Decode(token, nil) |
| 83 |
|
| 84 |
//then |
| 85 |
c.Assert(err, IsNil) |
| 86 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 87 |
} |
| 88 |
|
| 89 |
func (s *TestSuite) TestDecodePlaintextWithSignature(c *C) { |
| 90 |
//given |
| 91 |
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.KmLWPfxC3JGopWImDgYg9IUpgAi8gwimviUfr6eJyFI" |
| 92 |
|
| 93 |
//when |
| 94 |
test, _, err := Decode(token, nil) |
| 95 |
|
| 96 |
//then |
| 97 |
c.Assert(err, NotNil) |
| 98 |
c.Assert(test, Equals, "") |
| 99 |
} |
| 100 |
|
| 101 |
func (s *TestSuite) TestDecodePlaintextWithKey(c *C) { |
| 102 |
//given |
| 103 |
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9." |
| 104 |
|
| 105 |
//when |
| 106 |
test, _, err := Decode(token, shaKey) |
| 107 |
|
| 108 |
//then |
| 109 |
c.Assert(err, NotNil) |
| 110 |
c.Assert(test, Equals, "") |
| 111 |
} |
| 112 |
|
| 113 |
func (s *TestSuite) TestDecodeHS256(c *C) { |
| 114 |
//given |
| 115 |
token := "eyJhbGciOiJIUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.chIoYWrQMA8XL5nFz6oLDJyvgHk2KA4BrFGrKymjC8E" |
| 116 |
|
| 117 |
//when |
| 118 |
test, _, err := Decode(token, shaKey) |
| 119 |
|
| 120 |
//then |
| 121 |
c.Assert(err, IsNil) |
| 122 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 123 |
} |
| 124 |
|
| 125 |
func (s *TestSuite) TestDecodeHS384(c *C) { |
| 126 |
//given |
| 127 |
token := "eyJhbGciOiJIUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.McDgk0h4mRdhPM0yDUtFG_omRUwwqVS2_679Yeivj-a7l6bHs_ahWiKl1KoX_hU_" |
| 128 |
|
| 129 |
//when |
| 130 |
test, _, err := Decode(token, shaKey) |
| 131 |
|
| 132 |
//then |
| 133 |
c.Assert(err, IsNil) |
| 134 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 135 |
} |
| 136 |
|
| 137 |
func (s *TestSuite) TestDecodeHS512(c *C) { |
| 138 |
//given |
| 139 |
token := "eyJhbGciOiJIUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.9KirTNe8IRwFCBLjO8BZuXf3U2ZVagdsg7F9ZsvMwG3FuqY9W0vqwjzPOjLqPN-GkjPm6C3qWPnINhpr5bEDJQ" |
| 140 |
|
| 141 |
//when |
| 142 |
test, _, err := Decode(token, shaKey) |
| 143 |
|
| 144 |
//then |
| 145 |
c.Assert(err, IsNil) |
| 146 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 147 |
} |
| 148 |
|
| 149 |
func (s *TestSuite) TestEncodePlaintext(c *C) { |
| 150 |
//given |
| 151 |
payload := `{"hello": "world"}` |
| 152 |
|
| 153 |
//when |
| 154 |
test, err := Sign(payload, NONE, nil) |
| 155 |
|
| 156 |
fmt.Printf("\nnone = %v\n", test) |
| 157 |
|
| 158 |
//then |
| 159 |
c.Assert(err, IsNil) |
| 160 |
c.Assert(test, Equals, "eyJhbGciOiJub25lIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.") |
| 161 |
|
| 162 |
//make sure we consistent with ourselfs |
| 163 |
t, _, _ := Decode(test, nil) |
| 164 |
c.Assert(t, Equals, payload) |
| 165 |
} |
| 166 |
|
| 167 |
func (s *TestSuite) TestEncodeHS256(c *C) { |
| 168 |
//given |
| 169 |
payload := `{"hello": "world"}` |
| 170 |
|
| 171 |
//when |
| 172 |
test, err := Sign(payload, HS256, shaKey) |
| 173 |
|
| 174 |
fmt.Printf("\nHS256 = %v\n", test) |
| 175 |
|
| 176 |
//then |
| 177 |
c.Assert(err, IsNil) |
| 178 |
c.Assert(test, Equals, "eyJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.UAuHfK1tObqUzQj2tdMoKjKq1SWoI17hAg17VJ2l8j0") |
| 179 |
|
| 180 |
//make sure we consistent with ourselfs |
| 181 |
t, _, _ := Decode(test, shaKey) |
| 182 |
c.Assert(t, Equals, payload) |
| 183 |
} |
| 184 |
|
| 185 |
func (s *TestSuite) TestEncodeHS384(c *C) { |
| 186 |
//given |
| 187 |
payload := `{"hello": "world"}` |
| 188 |
|
| 189 |
//when |
| 190 |
test, err := Sign(payload, HS384, shaKey) |
| 191 |
|
| 192 |
fmt.Printf("\nHS384 = %v\n", test) |
| 193 |
|
| 194 |
//then |
| 195 |
c.Assert(err, IsNil) |
| 196 |
c.Assert(test, Equals, "eyJhbGciOiJIUzM4NCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.c92ouMmuQ1EmFN6IQmCEKAv5JZoVIeo_ehQl79OskFw3_y5GE_OLiUEfcRikturb") |
| 197 |
|
| 198 |
//make sure we consistent with ourselfs |
| 199 |
t, _, _ := Decode(test, shaKey) |
| 200 |
c.Assert(t, Equals, payload) |
| 201 |
} |
| 202 |
|
| 203 |
func (s *TestSuite) TestEncodeHS512(c *C) { |
| 204 |
//given |
| 205 |
payload := `{"hello": "world"}` |
| 206 |
|
| 207 |
//when |
| 208 |
test, err := Sign(payload, HS512, shaKey) |
| 209 |
|
| 210 |
fmt.Printf("\nHS512 = %v\n", test) |
| 211 |
|
| 212 |
//then |
| 213 |
c.Assert(err, IsNil) |
| 214 |
c.Assert(test, Equals, "eyJhbGciOiJIUzUxMiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.tfZJJbT-Nht5_JkM0vylscOSwiuf9-X7mcBdxTIB_fdHBC-LylKQGPWLqjzDWFnx29f7U_s9c4EjA3WUahib7w") |
| 215 |
|
| 216 |
//make sure we consistent with ourselfs |
| 217 |
t, _, _ := Decode(test, shaKey) |
| 218 |
c.Assert(t, Equals, payload) |
| 219 |
} |
| 220 |
|
| 221 |
func (s *TestSuite) TestDecodeRS256(c *C) { |
| 222 |
//given |
| 223 |
token := "eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.NL_dfVpZkhNn4bZpCyMq5TmnXbT4yiyecuB6Kax_lV8Yq2dG8wLfea-T4UKnrjLOwxlbwLwuKzffWcnWv3LVAWfeBxhGTa0c4_0TX_wzLnsgLuU6s9M2GBkAIuSMHY6UTFumJlEeRBeiqZNrlqvmAzQ9ppJHfWWkW4stcgLCLMAZbTqvRSppC1SMxnvPXnZSWn_Fk_q3oGKWw6Nf0-j-aOhK0S0Lcr0PV69ZE4xBYM9PUS1MpMe2zF5J3Tqlc1VBcJ94fjDj1F7y8twmMT3H1PI9RozO-21R0SiXZ_a93fxhE_l_dj5drgOek7jUN9uBDjkXUwJPAyp9YPehrjyLdw" |
| 224 |
|
| 225 |
//when |
| 226 |
test, _, err := Decode(token, PubKey()) |
| 227 |
|
| 228 |
//then |
| 229 |
c.Assert(err, IsNil) |
| 230 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 231 |
} |
| 232 |
|
| 233 |
func (s *TestSuite) TestDecodeRS384(c *C) { |
| 234 |
//given |
| 235 |
token := "eyJhbGciOiJSUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.cOPca7YEOxnXVdIi7cJqfgRMmDFPCrZG1M7WCJ23U57rAWvCTaQgEFdLjs7aeRAPY5Su_MVWV7YixcawKKYOGVG9eMmjdGiKHVoRcfjwVywGIb-nuD1IBzGesrQe7mFQrcWKtYD9FurjCY1WuI2FzGPp5YhW5Zf4TwmBvOKz6j2D1vOFfGsogzAyH4lqaMpkHpUAXddQxzu8rmFhZ54Rg4T-jMGVlsdrlAAlGA-fdRZ-V3F2PJjHQYUcyS6n1ULcy6ljEOgT5fY-_8DDLLpI8jAIdIhcHUAynuwvvnDr9bJ4xIy4olFRqcUQIHbcb5-WDeWul_cSGzTJdxDZsnDuvg" |
| 236 |
|
| 237 |
//when |
| 238 |
test, _, err := Decode(token, PubKey()) |
| 239 |
|
| 240 |
//then |
| 241 |
c.Assert(err, IsNil) |
| 242 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 243 |
} |
| 244 |
|
| 245 |
func (s *TestSuite) TestDecodeRS512(c *C) { |
| 246 |
//given |
| 247 |
token := "eyJhbGciOiJSUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.KP_mwCVRIxcF6ErdrzNcXZQDFGcL-Hlyocc4tIl3tJfzSfc7rz7qOLPjHpZ6UFH1ncd5TlpRc1B_pgvY-l0BNtx_s7n_QA55X4c1oeD8csrIoXQ6A6mtvdVGoSlGu2JnP6N2aqlDmlcefKqjl_Z-8nwDMGTMkDNhHKfHlIb2_Dliwxeq8LmNMREEdvNH2XVp_ffxBjiaKv2Eqbwc6I17241GCEmjDCvnagSgjX_5uu-da2H7TK2gtPJYUo8r9nzC7uzZJ5SB8suZH0COSofsP-9wvH0FESO40evCyEBylqg3bh9M9dIzeq8_bdTiC5kG93Fal44OEY8_Zm88wB_VjQ" |
| 248 |
|
| 249 |
//when |
| 250 |
test, _, err := Decode(token, PubKey()) |
| 251 |
|
| 252 |
//then |
| 253 |
c.Assert(err, IsNil) |
| 254 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 255 |
} |
| 256 |
|
| 257 |
func (s *TestSuite) TestEncodeRS256(c *C) { |
| 258 |
//given |
| 259 |
payload := `{"hello": "world"}` |
| 260 |
|
| 261 |
//when |
| 262 |
test, err := Sign(payload, RS256, PrivKey()) |
| 263 |
|
| 264 |
fmt.Printf("\nRS256 = %v\n", test) |
| 265 |
|
| 266 |
//then |
| 267 |
c.Assert(err, IsNil) |
| 268 |
c.Assert(test, Equals, "eyJhbGciOiJSUzI1NiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.fLVmWBDvVKZZPKNAaGrSitQpRGLoku1JPDafaTJhQUjfvrgvu8_RgTO4WmwQVngbAdT0i57EXt28WZHpAdBEJK4wi6sVzRADxO3aSiAxZn_aY_QwH7B4CGeeCvdvjUBX-wNj-4S3F9xCygq2VGtl8PknzAJLtcPmG9V-2hEfyLeL8lcOgK6SGaWWoGC5PjvVW46ilYSbySCr2c3B86TPITcx29_g4juuAM_AtHUdGimOVX1eKyHKSB8_U2IXWc2ujMMgphc0eZNY0W2nl_MwEwq-SvcdyLGfWVuEhgmfqlRHXu5eztHZsw1ejki0J-9r9reG1FbV6GzTMsU9HARW_Q") |
| 269 |
|
| 270 |
//make sure we consistent with ourselfs |
| 271 |
t, _, _ := Decode(test, PubKey()) |
| 272 |
c.Assert(t, Equals, payload) |
| 273 |
} |
| 274 |
|
| 275 |
func (s *TestSuite) TestEncodeRS384(c *C) { |
| 276 |
//given |
| 277 |
payload := `{"hello": "world"}` |
| 278 |
|
| 279 |
//when |
| 280 |
test, err := Sign(payload, RS384, PrivKey()) |
| 281 |
|
| 282 |
fmt.Printf("\nRS384 = %v\n", test) |
| 283 |
|
| 284 |
//then |
| 285 |
c.Assert(err, IsNil) |
| 286 |
c.Assert(test, Equals, "eyJhbGciOiJSUzM4NCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.BqDcZoC0pWa1k_gFRRSOJnDrU_0c78SdRphUikML36JrZs6fVwcP2NtdVUpDl40CwRdeHFjJF9skXI0KmMbj2bRTFyxL-At8WOVAMVRY0N9jFOjK67nwdafSDCKBqPAjw-Vv1f9yKwNvDoObI2isvhKqTF_EK_wEj-AwQIsmJNqUNF3yD3IgB6PCLS8mW5zXEp6xwf8hMguco6aHV7WBU-ZhdMFjJRydyrwBinUFig68QCdcAUI7KFVbsjani4W87jHgJhinv2GyVyKw5QpIDdvcMQKeoTZWLKQg9BBW4Ar9-YhQIuuO-7chTn2KCMpFCq3hrdrZTqVtX1nEDvBYpA") |
| 287 |
|
| 288 |
//make sure we consistent with ourselfs |
| 289 |
t, _, _ := Decode(test, PubKey()) |
| 290 |
c.Assert(t, Equals, payload) |
| 291 |
} |
| 292 |
|
| 293 |
func (s *TestSuite) TestEncodeRS512(c *C) { |
| 294 |
//given |
| 295 |
payload := `{"hello": "world"}` |
| 296 |
|
| 297 |
//when |
| 298 |
test, err := Sign(payload, RS512, PrivKey()) |
| 299 |
|
| 300 |
fmt.Printf("\nRS512 = %v\n", test) |
| 301 |
|
| 302 |
//then |
| 303 |
c.Assert(err, IsNil) |
| 304 |
c.Assert(test, Equals, "eyJhbGciOiJSUzUxMiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.AqwiRtgwP0th1K8mvmL1oW8bbf8EuqDiUGLIfSQLY7Z9eXzct3Zcd3diri_-v6WczQWKtQ-NipCSEl8CWJQSZY8cRqDhFjiDnLEImY5SzC-xqYxDVb5zu_iQZNd18nlmSw504W3IvxIwk1_avZ6Q12OvRNbG3gLGZtcWi3VLdTa-SGEemEicnlRfLpTAaCk3kkJq6St5NLbiVdQMpfhDBeGCOTFMptLZ6Tw1rWaHy6y5b7_PRwWG1Cb8QEl8du-dxmhDgbenreq5EiybOL05qZRFxJ-1861j5xduG-AY6xum6HtWKPGTSsIZNxepK3DTYfovN5HidcubV747w_6PXw") |
| 305 |
|
| 306 |
//make sure we consistent with ourselfs |
| 307 |
t, _, _ := Decode(test, PubKey()) |
| 308 |
c.Assert(t, Equals, payload) |
| 309 |
} |
| 310 |
|
| 311 |
func (s *TestSuite) TestDecodePS256(c *C) { |
| 312 |
//given |
| 313 |
token := "eyJhbGciOiJQUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.S9xuR-IGfXEj5qsHcMtK-jcj1lezvVstw1AISp8dEQVRNgwOMZhUQnSCx9i1CA-pMucxR-lv4e7zd6h3cYCfMnyv7iuxraxNiNAgREhOT-bkBCZMNgb5t15xEtDSJ3MuBlK3YBtXyVcDDIdKH_Bwj-u363y6LuvZ8FEOGmIK5WSFi18Xjg-ihhvH1C6UzH1G82wrRbX6DyJKqrUnHAg8yzUJVP1AdgjWRt5BKpuYbXSib-MKZZkaE4q_hCb-j25xCzn8Ez8a7PO7p0fDGvZuOk_yzSfvXSavg7iE0GLuUTNv3nQ_xW-rfbrpYeyXNtstoK3JPFpdtORTyH1iIh7VVA" |
| 314 |
|
| 315 |
//when |
| 316 |
test, _, err := Decode(token, PubKey()) |
| 317 |
|
| 318 |
//then |
| 319 |
c.Assert(err, IsNil) |
| 320 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 321 |
} |
| 322 |
|
| 323 |
func (s *TestSuite) TestDecodePS384(c *C) { |
| 324 |
//given |
| 325 |
token := "eyJhbGciOiJQUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EKqVLw6nLGNt1h7KNFZbzkKhf788VBYCfnigYc0dBZBa64MrfbIFHtJuFgIGkCVSDYH-qs-i4w9ke6mD8mxTZFniMgzFXXaCFIrv6QZeMbKh6VYtSEPp7l0B1zMZiQw6egZbZ6a8VBkCRipuZggSlUTg5tHMMTj_jNVxxlY4uUwXlz7vakpbqgXe19pCDJrzEoXE0cNKV13eRCNA1tXOHx0dFL7Jm9NUq7blvhJ8iTw1jMFzK8bV6g6L7GclHBMoJ3MIvRp71m6idir-QeW1KCUfVtBs3HRn3a822LW02vGqopSkaGdRzQZOI28136AMeW4679UXE852srA2v3mWHQ" |
| 326 |
|
| 327 |
//when |
| 328 |
test, _, err := Decode(token, PubKey()) |
| 329 |
|
| 330 |
//then |
| 331 |
c.Assert(err, IsNil) |
| 332 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 333 |
} |
| 334 |
|
| 335 |
func (s *TestSuite) TestDecodePS512(c *C) { |
| 336 |
//given |
| 337 |
token := "eyJhbGciOiJQUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.IvbnmxhKvM70C0n0grkF807wOQLyPOBwJOee-p7JHCQcSstNeml3Owdyw9C3HGHzOdK9db51yAkjJ2TCojxqHW4OR5Apna8tvafYgD2femn1V3GdkGj6ZvYdV3q4ldnmahVeO36vHYy5P0zFcEGU1_j3S3DwGmhw2ktZ4p5fLZ2up2qwhzlOjbtsQpWywHj7cLdeA32MLId9MTAPVGUHIZHw_W0xwjJRS6TgxD9vPQQnP70MY-q_2pVAhfRCM_pauPYO1XH5ldizrTvVr27q_-Uqtw-wV-UDUnyWYQUDDiMTpLBoX1EEXmsbvUGx0OH3yWEaNINoCsepgZvTKbiEQQ" |
| 338 |
|
| 339 |
//when |
| 340 |
test, _, err := Decode(token, PubKey()) |
| 341 |
|
| 342 |
//then |
| 343 |
c.Assert(err, IsNil) |
| 344 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 345 |
} |
| 346 |
|
| 347 |
func (s *TestSuite) TestEncodePS256(c *C) { |
| 348 |
//given |
| 349 |
payload := `{"hello": "world"}` |
| 350 |
|
| 351 |
//when |
| 352 |
test, err := Sign(payload, PS256, PrivKey()) |
| 353 |
|
| 354 |
fmt.Printf("\nPS256 = %v\n", test) |
| 355 |
|
| 356 |
//then |
| 357 |
c.Assert(err, IsNil) |
| 358 |
|
| 359 |
parts := strings.Split(test, ".") |
| 360 |
|
| 361 |
c.Assert(len(parts), Equals, 3) |
| 362 |
c.Assert(parts[0], Equals, "eyJhbGciOiJQUzI1NiJ9") |
| 363 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 364 |
c.Assert(len(parts[1]), Equals, 24) |
| 365 |
|
| 366 |
//make sure we consistent with ourselfs |
| 367 |
t, _, _ := Decode(test, PubKey()) |
| 368 |
c.Assert(t, Equals, payload) |
| 369 |
} |
| 370 |
|
| 371 |
func (s *TestSuite) TestEncodePS384(c *C) { |
| 372 |
//given |
| 373 |
payload := `{"hello": "world"}` |
| 374 |
|
| 375 |
//when |
| 376 |
test, err := Sign(payload, PS384, PrivKey()) |
| 377 |
|
| 378 |
fmt.Printf("\nPS384 = %v\n", test) |
| 379 |
|
| 380 |
//then |
| 381 |
c.Assert(err, IsNil) |
| 382 |
|
| 383 |
parts := strings.Split(test, ".") |
| 384 |
|
| 385 |
c.Assert(len(parts), Equals, 3) |
| 386 |
c.Assert(parts[0], Equals, "eyJhbGciOiJQUzM4NCJ9") |
| 387 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 388 |
c.Assert(len(parts[1]), Equals, 24) |
| 389 |
|
| 390 |
//make sure we consistent with ourselfs |
| 391 |
t, _, _ := Decode(test, PubKey()) |
| 392 |
c.Assert(t, Equals, payload) |
| 393 |
} |
| 394 |
|
| 395 |
func (s *TestSuite) TestEncodePS512(c *C) { |
| 396 |
//given |
| 397 |
payload := `{"hello": "world"}` |
| 398 |
|
| 399 |
//when |
| 400 |
test, err := Sign(payload, PS512, PrivKey()) |
| 401 |
|
| 402 |
fmt.Printf("\nPS512 = %v\n", test) |
| 403 |
|
| 404 |
//then |
| 405 |
c.Assert(err, IsNil) |
| 406 |
|
| 407 |
parts := strings.Split(test, ".") |
| 408 |
|
| 409 |
c.Assert(len(parts), Equals, 3) |
| 410 |
c.Assert(parts[0], Equals, "eyJhbGciOiJQUzUxMiJ9") |
| 411 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 412 |
c.Assert(len(parts[1]), Equals, 24) |
| 413 |
|
| 414 |
//make sure we consistent with ourselfs |
| 415 |
t, _, _ := Decode(test, PubKey()) |
| 416 |
c.Assert(t, Equals, payload) |
| 417 |
} |
| 418 |
|
| 419 |
func (s *TestSuite) TestDecodeES256(c *C) { |
| 420 |
//given |
| 421 |
token := "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EVnmDMlz-oi05AQzts-R3aqWvaBlwVZddWkmaaHyMx5Phb2NSLgyI0kccpgjjAyo1S5KCB3LIMPfmxCX_obMKA" |
| 422 |
|
| 423 |
//when |
| 424 |
test, _, err := Decode(token, Ecc256Public()) |
| 425 |
|
| 426 |
//then |
| 427 |
c.Assert(err, IsNil) |
| 428 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 429 |
} |
| 430 |
|
| 431 |
func (s *TestSuite) TestDecodeES384(c *C) { |
| 432 |
//given |
| 433 |
token := "eyJhbGciOiJFUzM4NCIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.jVTHd9T0fIQDJLNvAq3LPpgj_npXtWb64FfEK8Sm65Nr9q2goUWASrM9jv3h-71UrP4cBpM3on3yN--o6B-Tl6bscVUfpm1swPp94f7XD9VYLEjGMjQOaozr13iBZJCY" |
| 434 |
|
| 435 |
//when |
| 436 |
test, _, err := Decode(token, Ecc384Public()) |
| 437 |
|
| 438 |
//then |
| 439 |
c.Assert(err, IsNil) |
| 440 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 441 |
} |
| 442 |
|
| 443 |
func (s *TestSuite) TestDecodeES512(c *C) { |
| 444 |
//given |
| 445 |
token := "eyJhbGciOiJFUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.AHxJYFeTVpZmrfZsltpQKkkplmbkycQKFOFucD7hE4Sm3rCswUDi8hlSCfeYByugySYLFzogTQGk79PHP6vdl39sAUc9k2bhnv-NxRmJsN8ZxEx09qYKbc14qiNWZztLweQg0U-pU0DQ66rwJ0HikzSqgmyD1bJ6RxitJwceYLAovv0v" |
| 446 |
|
| 447 |
//when |
| 448 |
test, _, err := Decode(token, Ecc512Public()) |
| 449 |
|
| 450 |
//then |
| 451 |
c.Assert(err, IsNil) |
| 452 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 453 |
} |
| 454 |
|
| 455 |
func (s *TestSuite) TestEncodeES256(c *C) { |
| 456 |
//given |
| 457 |
payload := `{"hello": "world"}` |
| 458 |
|
| 459 |
//when |
| 460 |
test, err := Sign(payload, ES256, Ecc256Private()) |
| 461 |
|
| 462 |
fmt.Printf("\nES256 = %v\n", test) |
| 463 |
|
| 464 |
//then |
| 465 |
c.Assert(err, IsNil) |
| 466 |
|
| 467 |
parts := strings.Split(test, ".") |
| 468 |
|
| 469 |
c.Assert(len(parts), Equals, 3) |
| 470 |
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzI1NiJ9") |
| 471 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 472 |
c.Assert(len(parts[2]), Equals, 86) |
| 473 |
|
| 474 |
//make sure we consistent with ourselfs |
| 475 |
t, _, _ := Decode(test, Ecc256Public()) |
| 476 |
c.Assert(t, Equals, payload) |
| 477 |
} |
| 478 |
|
| 479 |
func (s *TestSuite) TestEncodeES384(c *C) { |
| 480 |
//given |
| 481 |
payload := `{"hello": "world"}` |
| 482 |
|
| 483 |
//when |
| 484 |
test, err := Sign(payload, ES384, Ecc384Private()) |
| 485 |
|
| 486 |
fmt.Printf("\nES384 = %v\n", test) |
| 487 |
|
| 488 |
//then |
| 489 |
c.Assert(err, IsNil) |
| 490 |
|
| 491 |
parts := strings.Split(test, ".") |
| 492 |
|
| 493 |
c.Assert(len(parts), Equals, 3) |
| 494 |
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzM4NCJ9") |
| 495 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 496 |
c.Assert(len(parts[2]), Equals, 128) |
| 497 |
|
| 498 |
//make sure we consistent with ourselfs |
| 499 |
t, _, _ := Decode(test, Ecc384Public()) |
| 500 |
c.Assert(t, Equals, payload) |
| 501 |
} |
| 502 |
|
| 503 |
func (s *TestSuite) TestEncodeES512(c *C) { |
| 504 |
//given |
| 505 |
payload := `{"hello": "world"}` |
| 506 |
|
| 507 |
//when |
| 508 |
test, err := Sign(payload, ES512, Ecc512Private()) |
| 509 |
|
| 510 |
fmt.Printf("\nES512 = %v\n", test) |
| 511 |
|
| 512 |
//then |
| 513 |
c.Assert(err, IsNil) |
| 514 |
|
| 515 |
parts := strings.Split(test, ".") |
| 516 |
|
| 517 |
c.Assert(len(parts), Equals, 3) |
| 518 |
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzUxMiJ9") |
| 519 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 520 |
c.Assert(len(parts[2]), Equals, 176) |
| 521 |
|
| 522 |
//make sure we consistent with ourselfs |
| 523 |
t, _, _ := Decode(test, Ecc512Public()) |
| 524 |
c.Assert(t, Equals, payload) |
| 525 |
} |
| 526 |
|
| 527 |
func (s *TestSuite) TestDecrypt_DIR_A128CBC_HS256(c *C) { |
| 528 |
//given |
| 529 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..3lClLoerWhxIc811QXDLbg.iFd5MNk2eWDlW3hbq7vTFLPJlC0Od_MSyWGakEn5kfYbbPk7BM_SxUMptwcvDnZ5uBKwwPAYOsHIm5IjZ79LKZul9ZnOtJONRvxWLeS9WZiX4CghOLZL7dLypKn-mB22xsmSUbtizMuNSdgJwUCxEmms7vYOpL0Che-0_YrOu3NmBCLBiZzdWVtSSvYw6Ltzbch4OAaX2ye_IIemJoU1VnrdW0y-AjPgnAUA-GY7CAKJ70leS1LyjTW8H_ecB4sDCkLpxNOUsWZs3DN0vxxSQw.bxrZkcOeBgFAo3t0585ZdQ" |
| 530 |
|
| 531 |
//when |
| 532 |
test, _, err := Decode(token, aes256Key) |
| 533 |
|
| 534 |
//then |
| 535 |
c.Assert(err, IsNil) |
| 536 |
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}`) |
| 537 |
} |
| 538 |
|
| 539 |
func (s *TestSuite) TestDecrypt_DIR_A192CBC_HS384(c *C) { |
| 540 |
//given |
| 541 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0..fX42Nn8ABHClA0UfbpkX_g.ClZzxQIzg40GpTETaLejGNhCN0mqSM1BNCIU5NldeF-hGS7_u_5uFsJoWK8BLCoWRtQ3cWIeaHgOa5njCftEK1AoHvechgNCQgme-fuF3f2v5DOphU-tveYzN-uvrUthS0LIrAYrwQW0c0DKcJZ-9vQmC__EzesZgUHiDB8SnoEROPTvJcsBKI4zhFT7wOgqnFS7P7_BQZj_UnbJkzTAiE5MURBBpCYR-OS3zn--QftbdGVJ2CWmwH3HuDO9-IE2IQ5cKYHnzSwu1vyME_SpZA.qd8ZGKzmOzzPhFV-Po8KgJ5jZb5xUQtU" |
| 542 |
|
| 543 |
//when |
| 544 |
test, _, err := Decode(token, aes384Key) |
| 545 |
|
| 546 |
//then |
| 547 |
c.Assert(err, IsNil) |
| 548 |
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}`) |
| 549 |
} |
| 550 |
|
| 551 |
func (s *TestSuite) TestDecrypt_DIR_A256CBC_HS512(c *C) { |
| 552 |
//given |
| 553 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0..ZD93XtD7TOa2WMbqSuaY9g.1J5BAuxNRMWaw43s7hR82gqLiaZOHBmfD3_B9k4I2VIDKzS9oEF_NS2o7UIBa6t_fWHU7vDm9lNAN4rqq7OvtCBHJpFk31dcruQHxwYKn5xNefG7YP-o6QtpyNioNWJpaSD5VRcRO5ufRrw2bu4_nOth00yJU5jjN3O3n9f-0ewrN2UXDJIbZM-NiSuEDEgOVHImQXoOtOQd0BuaDx6xTJydw_rW5-_wtiOH2k-3YGlibfOWNu51kApGarRsAhhqKIPetYf5Mgmpv1bkUo6HJw.nVpOmg3Sxri0rh6nQXaIx5X0fBtCt7Kscg6c66NugHY" |
| 554 |
|
| 555 |
//when |
| 556 |
test, _, err := Decode(token, aes512Key) |
| 557 |
|
| 558 |
//then |
| 559 |
c.Assert(err, IsNil) |
| 560 |
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}`) |
| 561 |
} |
| 562 |
|
| 563 |
func (s *TestSuite) TestEncrypt_DIR_A128CBC_HS256(c *C) { |
| 564 |
//given |
| 565 |
payload := `{"hello": "world"}` |
| 566 |
|
| 567 |
//when |
| 568 |
test, err := Encrypt(payload, DIR, A128CBC_HS256, aes256Key) |
| 569 |
|
| 570 |
fmt.Printf("\nDIR A128CBC-HS256 = %v\n", test) |
| 571 |
|
| 572 |
//then |
| 573 |
c.Assert(err, IsNil) |
| 574 |
|
| 575 |
parts := strings.Split(test, ".") |
| 576 |
|
| 577 |
c.Assert(len(parts), Equals, 5) |
| 578 |
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0") |
| 579 |
c.Assert(len(parts[1]), Equals, 0) |
| 580 |
c.Assert(len(parts[2]), Equals, 22) |
| 581 |
c.Assert(len(parts[3]), Equals, 43) |
| 582 |
c.Assert(len(parts[4]), Equals, 22) |
| 583 |
|
| 584 |
//make sure we consistent with ourselfs |
| 585 |
t, _, _ := Decode(test, aes256Key) |
| 586 |
c.Assert(t, Equals, payload) |
| 587 |
} |
| 588 |
|
| 589 |
func (s *TestSuite) TestEncrypt_DIR_A192CBC_HS384(c *C) { |
| 590 |
//given |
| 591 |
payload := `{"hello": "world"}` |
| 592 |
|
| 593 |
//when |
| 594 |
test, err := Encrypt(payload, DIR, A192CBC_HS384, aes384Key) |
| 595 |
|
| 596 |
fmt.Printf("\nDIR A192CBC-HS384 = %v\n", test) |
| 597 |
|
| 598 |
//then |
| 599 |
c.Assert(err, IsNil) |
| 600 |
|
| 601 |
parts := strings.Split(test, ".") |
| 602 |
|
| 603 |
c.Assert(len(parts), Equals, 5) |
| 604 |
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0") |
| 605 |
c.Assert(len(parts[1]), Equals, 0) |
| 606 |
c.Assert(len(parts[2]), Equals, 22) |
| 607 |
c.Assert(len(parts[3]), Equals, 43) |
| 608 |
c.Assert(len(parts[4]), Equals, 32) |
| 609 |
|
| 610 |
//make sure we consistent with ourselfs |
| 611 |
t, _, _ := Decode(test, aes384Key) |
| 612 |
c.Assert(t, Equals, payload) |
| 613 |
} |
| 614 |
|
| 615 |
func (s *TestSuite) TestEncrypt_DIR_A256CBC_HS512(c *C) { |
| 616 |
//given |
| 617 |
payload := `{"hello": "world"}` |
| 618 |
|
| 619 |
//when |
| 620 |
test, err := Encrypt(payload, DIR, A256CBC_HS512, aes512Key) |
| 621 |
|
| 622 |
fmt.Printf("\nDIR A256CBC-HS512 = %v\n", test) |
| 623 |
|
| 624 |
//then |
| 625 |
c.Assert(err, IsNil) |
| 626 |
|
| 627 |
parts := strings.Split(test, ".") |
| 628 |
|
| 629 |
c.Assert(len(parts), Equals, 5) |
| 630 |
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0") |
| 631 |
c.Assert(len(parts[1]), Equals, 0) |
| 632 |
c.Assert(len(parts[2]), Equals, 22) |
| 633 |
c.Assert(len(parts[3]), Equals, 43) |
| 634 |
c.Assert(len(parts[4]), Equals, 43) |
| 635 |
|
| 636 |
//make sure we consistent with ourselfs |
| 637 |
t, _, _ := Decode(test, aes512Key) |
| 638 |
c.Assert(t, Equals, payload) |
| 639 |
} |
| 640 |
|
| 641 |
func (s *TestSuite) TestDecrypt_DIR_A128GCM(c *C) { |
| 642 |
//given |
| 643 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..yVi-LdQQngN0C5WS.1McwSmhZzAtmmLp9y-OdnJwaJFo1nj_4ashmzl2LhubGf0Jl1OTEVJzsHZb7bkup7cGTkuxh6Vfv10ljHsjWf_URXoxP3stQqQeViVcuPV0y2Q_WHYzTNGZpmHGe-hM6gjDhyZyvu3yeXGFSvfPQmp9pWVOgDjI4RC0MQ83rzzn-rRdnZkznWjbmOPxwPrR72Qng0BISsEwbkPn4oO8-vlHkVmPpuDTaYzCT2ZR5K9JnIU8d8QdxEAGb7-s8GEJ1yqtd_w._umbK59DAKA3O89h15VoKQ" |
| 644 |
|
| 645 |
//when |
| 646 |
test, _, err := Decode(token, aes128Key) |
| 647 |
|
| 648 |
//then |
| 649 |
c.Assert(err, IsNil) |
| 650 |
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}`) |
| 651 |
} |
| 652 |
|
| 653 |
func (s *TestSuite) TestDecrypt_DIR_A128GCM_WRONG_NONCE_SIZE(c *C) { |
| 654 |
//given |
| 655 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0..yVi-LQQngN0C5WS.1McwSmhZzAtmmLp9y-OdnJwaJFo1nj_4ashmzl2LhubGf0Jl1OTEVJzsHZb7bkup7cGTkuxh6Vfv10ljHsjWf_URXoxP3stQqQeViVcuPV0y2Q_WHYzTNGZpmHGe-hM6gjDhyZyvu3yeXGFSvfPQmp9pWVOgDjI4RC0MQ83rzzn-rRdnZkznWjbmOPxwPrR72Qng0BISsEwbkPn4oO8-vlHkVmPpuDTaYzCT2ZR5K9JnIU8d8QdxEAGb7-s8GEJ1yqtd_w._umbK59DAKA3O89h15VoKQ" |
| 656 |
|
| 657 |
//when |
| 658 |
_, _, err := Decode(token, aes128Key) |
| 659 |
|
| 660 |
//then |
| 661 |
c.Assert(err, NotNil) |
| 662 |
} |
| 663 |
|
| 664 |
func (s *TestSuite) TestDecrypt_DIR_A192GCM(c *C) { |
| 665 |
//given |
| 666 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyR0NNIn0..YW2WB0afVronbgSz.tfk1VADGjBnViYD7He5mbhxpbogoT1cmhKiDKzzoBV2AxfsgJ2Eq-vtEqPi9eY9H52FLLtht26rc5fPz9ZKOUH2hYeFdaRyKYXlpEnUR2cCT9_3TYcaFhpYBH4HCa59NruKlJHMBqM2ssWZLSEblFX9srUHFtu2OQz2ydMy1fr8ABDTdVYgaqyBoYRGykTkEsgayEyfAMz9u095N2J0JTCB5Q0IiXNdBzBSxZXG-i9f5HFEb6IliaTwFTNFnhDL66O4rsg._dh02z25W7HA6b1XiFVpUw" |
| 667 |
|
| 668 |
//when |
| 669 |
test, _, err := Decode(token, aes192Key) |
| 670 |
|
| 671 |
//then |
| 672 |
c.Assert(err, IsNil) |
| 673 |
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}`) |
| 674 |
} |
| 675 |
|
| 676 |
func (s *TestSuite) TestDecrypt_DIR_A256GCM(c *C) { |
| 677 |
//given |
| 678 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..Fmz3PLVfv-ySl4IJ.LMZpXMDoBIll5yuEs81Bws2-iUUaBSpucJPL-GtDKXkPhFpJmES2T136Vd8xzvp-3JW-fvpRZtlhluqGHjywPctol71Zuz9uFQjuejIU4axA_XiAy-BadbRUm1-25FRT30WtrrxKltSkulmIS5N-Nsi_zmCz5xicB1ZnzneRXGaXY4B444_IHxGBIS_wdurPAN0OEGw4xIi2DAD1Ikc99a90L7rUZfbHNg_iTBr-OshZqDbR6C5KhmMgk5KqDJEN8Ik-Yw.Jbk8ZmO901fqECYVPKOAzg" |
| 679 |
|
| 680 |
//when |
| 681 |
test, _, err := Decode(token, aes256Key) |
| 682 |
|
| 683 |
//then |
| 684 |
c.Assert(err, IsNil) |
| 685 |
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}`) |
| 686 |
} |
| 687 |
|
| 688 |
func (s *TestSuite) TestEncrypt_DIR_A128GCM(c *C) { |
| 689 |
//given |
| 690 |
payload := `{"hello": "world"}` |
| 691 |
|
| 692 |
//when |
| 693 |
test, err := Encrypt(payload, DIR, A128GCM, aes128Key) |
| 694 |
|
| 695 |
fmt.Printf("\nDIR A128GCM = %v\n", test) |
| 696 |
|
| 697 |
//then |
| 698 |
c.Assert(err, IsNil) |
| 699 |
|
| 700 |
parts := strings.Split(test, ".") |
| 701 |
|
| 702 |
c.Assert(len(parts), Equals, 5) |
| 703 |
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIn0") |
| 704 |
c.Assert(len(parts[1]), Equals, 0) |
| 705 |
c.Assert(len(parts[2]), Equals, 16) |
| 706 |
c.Assert(len(parts[3]), Equals, 24) |
| 707 |
c.Assert(len(parts[4]), Equals, 22) |
| 708 |
|
| 709 |
//make sure we consistent with ourselfs |
| 710 |
t, _, _ := Decode(test, aes128Key) |
| 711 |
c.Assert(t, Equals, payload) |
| 712 |
} |
| 713 |
|
| 714 |
func (s *TestSuite) TestEncrypt_DIR_A192GCM(c *C) { |
| 715 |
//given |
| 716 |
payload := `{"hello": "world"}` |
| 717 |
|
| 718 |
//when |
| 719 |
test, err := Encrypt(payload, DIR, A192GCM, aes192Key) |
| 720 |
|
| 721 |
fmt.Printf("\nDIR A192GCM = %v\n", test) |
| 722 |
|
| 723 |
//then |
| 724 |
c.Assert(err, IsNil) |
| 725 |
|
| 726 |
parts := strings.Split(test, ".") |
| 727 |
|
| 728 |
c.Assert(len(parts), Equals, 5) |
| 729 |
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTkyR0NNIn0") |
| 730 |
c.Assert(len(parts[1]), Equals, 0) |
| 731 |
c.Assert(len(parts[2]), Equals, 16) |
| 732 |
c.Assert(len(parts[3]), Equals, 24) |
| 733 |
c.Assert(len(parts[4]), Equals, 22) |
| 734 |
|
| 735 |
//make sure we consistent with ourselfs |
| 736 |
t, _, _ := Decode(test, aes192Key) |
| 737 |
c.Assert(t, Equals, payload) |
| 738 |
} |
| 739 |
|
| 740 |
func (s *TestSuite) TestEncrypt_DIR_A256GCM(c *C) { |
| 741 |
//given |
| 742 |
payload := `{"hello": "world"}` |
| 743 |
|
| 744 |
//when |
| 745 |
test, err := Encrypt(payload, DIR, A256GCM, aes256Key) |
| 746 |
|
| 747 |
fmt.Printf("\nDIR A256GCM = %v\n", test) |
| 748 |
|
| 749 |
//then |
| 750 |
c.Assert(err, IsNil) |
| 751 |
|
| 752 |
parts := strings.Split(test, ".") |
| 753 |
|
| 754 |
c.Assert(len(parts), Equals, 5) |
| 755 |
c.Assert(parts[0], Equals, "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0") |
| 756 |
c.Assert(len(parts[1]), Equals, 0) |
| 757 |
c.Assert(len(parts[2]), Equals, 16) |
| 758 |
c.Assert(len(parts[3]), Equals, 24) |
| 759 |
c.Assert(len(parts[4]), Equals, 22) |
| 760 |
|
| 761 |
//make sure we consistent with ourselfs |
| 762 |
t, _, _ := Decode(test, aes256Key) |
| 763 |
c.Assert(t, Equals, payload) |
| 764 |
} |
| 765 |
|
| 766 |
func (s *TestSuite) TestDecrypt_RSA1_5_A128CBC_HS256(c *C) { |
| 767 |
//given |
| 768 |
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" |
| 769 |
|
| 770 |
//when |
| 771 |
test, _, err := Decode(token, PrivKey()) |
| 772 |
|
| 773 |
//then |
| 774 |
c.Assert(err, IsNil) |
| 775 |
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}") |
| 776 |
} |
| 777 |
|
| 778 |
func (s *TestSuite) TestDecrypt_RSA1_5_A192CBC_HS384(c *C) { |
| 779 |
//given |
| 780 |
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" |
| 781 |
|
| 782 |
//when |
| 783 |
test, _, err := Decode(token, PrivKey()) |
| 784 |
|
| 785 |
//then |
| 786 |
c.Assert(err, IsNil) |
| 787 |
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}") |
| 788 |
} |
| 789 |
|
| 790 |
func (s *TestSuite) TestDecrypt_RSA1_5_A256CBC_HS512(c *C) { |
| 791 |
//given |
| 792 |
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" |
| 793 |
|
| 794 |
//when |
| 795 |
test, _, err := Decode(token, PrivKey()) |
| 796 |
|
| 797 |
//then |
| 798 |
c.Assert(err, IsNil) |
| 799 |
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}") |
| 800 |
} |
| 801 |
|
| 802 |
func (s *TestSuite) TestDecrypt_RSA1_5_A128GCM(c *C) { |
| 803 |
//given |
| 804 |
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" |
| 805 |
|
| 806 |
//when |
| 807 |
test, _, err := Decode(token, PrivKey()) |
| 808 |
|
| 809 |
//then |
| 810 |
c.Assert(err, IsNil) |
| 811 |
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}") |
| 812 |
} |
| 813 |
|
| 814 |
func (s *TestSuite) TestDecrypt_RSA1_5_A192GCM(c *C) { |
| 815 |
//given |
| 816 |
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyR0NNIn0.pqD1m66UeNppuOnP_H0WBQB3PCgYN0Zzf1DZraXM8XUJapw4LrwhvUXlYwcgrFdZ4v-asmzvABPc2sbGxzIJsPebGoEIlFDV3OvRRN1vUBOdst99v4q9En21FLa1MwNvCoDeg-TLK54t-NPShmsb4cLWFGS8KAKj2HEqXStw18Di4PTEfFfiJpeBUF8UHgqXfs5vqSJKmtvHPBNGUpCOPEhuNDOOKXvxMQotjoktKCyffJSgtr1fy0rOO4iR4EJjozclIAPVDCfQMVfVZBJEbUfszZ6cOCVsPLZKY3msWo3CFOQOcvXJOjkp0IXCaQxrvofetgmHP_ILsf4ty7_UIA.oIicSl5B8tBykEB-.Xlb-OZBpOdDfTEIjtYDFIm40CJeolfC7C4t2qgqi3Gd4kk-5oEbQzNuFMp8M4eUyDsSvNXdN5mlrOwAj9KsSLWB5FZf51Nvk5YJFN9scaQmdSzU7AlLhM2yMEpOmzZMo1GsiZxD8Rle0LyWmgFtMpGJk3PTEXwYnmNyyDAxhFAaWU2WOc1KofQsPbOjTA_0ijpVHG2FO-8jMPWNvl5GbZPAeId1yYt_mhTXbg6M7VRgazWQsq0n0IK8C3r0hu0UZ0DL0fg.xG8T-AWjAokmvAmBw-tiDA" |
| 817 |
|
| 818 |
//when |
| 819 |
test, _, err := Decode(token, PrivKey()) |
| 820 |
|
| 821 |
//then |
| 822 |
c.Assert(err, IsNil) |
| 823 |
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}") |
| 824 |
} |
| 825 |
|
| 826 |
func (s *TestSuite) TestDecrypt_RSA1_5_A256GCM(c *C) { |
| 827 |
//given |
| 828 |
token := "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2R0NNIn0.atdPJ2O-zpVFKyT1_EY0OT8WfF78A6fgYabEtGUUg1KrlR-dDat8tAtj58__lu4TFrZ_J0kcWNVkPpRy0IiyCxKtuo2Gfeufiq0MCiOza0XjT87RJinvAQMJU5rjfOC9bnCgEmDdaePRYr2zbnq7cBU6xh4q9sUT6jDhOSQ49aXDZdzIsMz4lwHpEtUwpF8vFuK7CP1AyibVrrCp1PoVyx4kpT7sRP0V3cRrZutO1MGlI3BWHdFCO2Ak0PDtlqx5uh1atB4XlTD0nswLMoKRSSOuP4GviZFoX4v7REFVcNbuIVQz0bbszYSmJXNi0VBGSodrsM2Ok0ufXRxYWaBepg.hSe2EnGM-0CFZzy-.jplzmtN7z5cARKj9kpgFFUD2_4qpFyvfn4F2kUXEkgRSgRN7ej8S0GepH2qOksS0yrwD97NdVA-hqhD7EiixVHaBhyxT9hYMdJLmPygfiXG7WKvLuDR24zVUvD8q98b1lSP55JPKEIBj_y1YVmrybv_dl30wqt4cbDLhmqWScwJRSp53KX26F8-R903Zitr5dke_6G8wMcJTrszus0EDxsurSPkxkDlBmDl6h-J0XNgY7dzB4tXud8q7l6XPvbvSbNBpqg.4ppwz1DXn7ba80wmEKAwaQ" |
| 829 |
|
| 830 |
//when |
| 831 |
test, _, err := Decode(token, PrivKey()) |
| 832 |
|
| 833 |
//then |
| 834 |
c.Assert(err, IsNil) |
| 835 |
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}") |
| 836 |
} |
| 837 |
|
| 838 |
func (s *TestSuite) TestEncrypt_RSA1_5_A128CBC_HS256(c *C) { |
| 839 |
//given |
| 840 |
payload := `{"hello": "world"}` |
| 841 |
|
| 842 |
//when |
| 843 |
test, err := Encrypt(payload, RSA1_5, A128CBC_HS256, PubKey()) |
| 844 |
|
| 845 |
fmt.Printf("\nRSA1_5 A128CBC-HS256 = %v\n", test) |
| 846 |
|
| 847 |
//then |
| 848 |
c.Assert(err, IsNil) |
| 849 |
|
| 850 |
parts := strings.Split(test, ".") |
| 851 |
|
| 852 |
c.Assert(len(parts), Equals, 5) |
| 853 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0") |
| 854 |
c.Assert(len(parts[1]), Equals, 342) |
| 855 |
c.Assert(len(parts[2]), Equals, 22) |
| 856 |
c.Assert(len(parts[3]), Equals, 43) |
| 857 |
c.Assert(len(parts[4]), Equals, 22) |
| 858 |
|
| 859 |
//make sure we consistent with ourselfs |
| 860 |
t, _, _ := Decode(test, PrivKey()) |
| 861 |
c.Assert(t, Equals, payload) |
| 862 |
} |
| 863 |
|
| 864 |
func (s *TestSuite) TestEncrypt_RSA1_5_A192CBC_HS384(c *C) { |
| 865 |
//given |
| 866 |
payload := `{"hello": "world"}` |
| 867 |
|
| 868 |
//when |
| 869 |
test, err := Encrypt(payload, RSA1_5, A192CBC_HS384, PubKey()) |
| 870 |
|
| 871 |
fmt.Printf("\nRSA1_5 A192CBC-HS384 = %v\n", test) |
| 872 |
|
| 873 |
//then |
| 874 |
c.Assert(err, IsNil) |
| 875 |
|
| 876 |
parts := strings.Split(test, ".") |
| 877 |
|
| 878 |
c.Assert(len(parts), Equals, 5) |
| 879 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0") |
| 880 |
c.Assert(len(parts[1]), Equals, 342) |
| 881 |
c.Assert(len(parts[2]), Equals, 22) |
| 882 |
c.Assert(len(parts[3]), Equals, 43) |
| 883 |
c.Assert(len(parts[4]), Equals, 32) |
| 884 |
|
| 885 |
//make sure we consistent with ourselfs |
| 886 |
t, _, _ := Decode(test, PrivKey()) |
| 887 |
c.Assert(t, Equals, payload) |
| 888 |
} |
| 889 |
|
| 890 |
func (s *TestSuite) TestEncrypt_RSA1_5_A256CBC_HS512(c *C) { |
| 891 |
//given |
| 892 |
payload := `{"hello": "world"}` |
| 893 |
|
| 894 |
//when |
| 895 |
test, err := Encrypt(payload, RSA1_5, A256CBC_HS512, PubKey()) |
| 896 |
|
| 897 |
fmt.Printf("\nRSA1_5 A256CBC-HS512 = %v\n", test) |
| 898 |
|
| 899 |
//then |
| 900 |
c.Assert(err, IsNil) |
| 901 |
|
| 902 |
parts := strings.Split(test, ".") |
| 903 |
|
| 904 |
c.Assert(len(parts), Equals, 5) |
| 905 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0") |
| 906 |
c.Assert(len(parts[1]), Equals, 342) |
| 907 |
c.Assert(len(parts[2]), Equals, 22) |
| 908 |
c.Assert(len(parts[3]), Equals, 43) |
| 909 |
c.Assert(len(parts[4]), Equals, 43) |
| 910 |
|
| 911 |
//make sure we consistent with ourselfs |
| 912 |
t, _, _ := Decode(test, PrivKey()) |
| 913 |
c.Assert(t, Equals, payload) |
| 914 |
} |
| 915 |
|
| 916 |
func (s *TestSuite) TestEncrypt_RSA1_5_A128GCM(c *C) { |
| 917 |
//given |
| 918 |
payload := `{"hello": "world"}` |
| 919 |
|
| 920 |
//when |
| 921 |
test, err := Encrypt(payload, RSA1_5, A128GCM, PubKey()) |
| 922 |
|
| 923 |
fmt.Printf("\nRSA1_5 A128GCM = %v\n", test) |
| 924 |
|
| 925 |
//then |
| 926 |
c.Assert(err, IsNil) |
| 927 |
|
| 928 |
parts := strings.Split(test, ".") |
| 929 |
|
| 930 |
c.Assert(len(parts), Equals, 5) |
| 931 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4R0NNIn0") |
| 932 |
c.Assert(len(parts[1]), Equals, 342) |
| 933 |
c.Assert(len(parts[2]), Equals, 16) |
| 934 |
c.Assert(len(parts[3]), Equals, 24) |
| 935 |
c.Assert(len(parts[4]), Equals, 22) |
| 936 |
|
| 937 |
//make sure we consistent with ourselfs |
| 938 |
t, _, _ := Decode(test, PrivKey()) |
| 939 |
c.Assert(t, Equals, payload) |
| 940 |
} |
| 941 |
|
| 942 |
func (s *TestSuite) TestEncrypt_RSA1_5_A192GCM(c *C) { |
| 943 |
//given |
| 944 |
payload := `{"hello": "world"}` |
| 945 |
|
| 946 |
//when |
| 947 |
test, err := Encrypt(payload, RSA1_5, A192GCM, PubKey()) |
| 948 |
|
| 949 |
fmt.Printf("\nRSA1_5 A192GCM = %v\n", test) |
| 950 |
|
| 951 |
//then |
| 952 |
c.Assert(err, IsNil) |
| 953 |
|
| 954 |
parts := strings.Split(test, ".") |
| 955 |
|
| 956 |
c.Assert(len(parts), Equals, 5) |
| 957 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTkyR0NNIn0") |
| 958 |
c.Assert(len(parts[1]), Equals, 342) |
| 959 |
c.Assert(len(parts[2]), Equals, 16) |
| 960 |
c.Assert(len(parts[3]), Equals, 24) |
| 961 |
c.Assert(len(parts[4]), Equals, 22) |
| 962 |
|
| 963 |
//make sure we consistent with ourselfs |
| 964 |
t, _, _ := Decode(test, PrivKey()) |
| 965 |
c.Assert(t, Equals, payload) |
| 966 |
} |
| 967 |
|
| 968 |
func (s *TestSuite) TestEncrypt_RSA1_5_A256GCM(c *C) { |
| 969 |
//given |
| 970 |
payload := `{"hello": "world"}` |
| 971 |
|
| 972 |
//when |
| 973 |
test, err := Encrypt(payload, RSA1_5, A256GCM, PubKey()) |
| 974 |
|
| 975 |
fmt.Printf("\nRSA1_5 A256GCM = %v\n", test) |
| 976 |
|
| 977 |
//then |
| 978 |
c.Assert(err, IsNil) |
| 979 |
|
| 980 |
parts := strings.Split(test, ".") |
| 981 |
|
| 982 |
c.Assert(len(parts), Equals, 5) |
| 983 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMjU2R0NNIn0") |
| 984 |
c.Assert(len(parts[1]), Equals, 342) |
| 985 |
c.Assert(len(parts[2]), Equals, 16) |
| 986 |
c.Assert(len(parts[3]), Equals, 24) |
| 987 |
c.Assert(len(parts[4]), Equals, 22) |
| 988 |
|
| 989 |
//make sure we consistent with ourselfs |
| 990 |
t, _, _ := Decode(test, PrivKey()) |
| 991 |
c.Assert(t, Equals, payload) |
| 992 |
} |
| 993 |
|
| 994 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_A128CBC_HS256(c *C) { |
| 995 |
//given |
| 996 |
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ.mlcD4YXAzTKgKsnkiPD8iBPkUkVijLCf9ODLs-ziHotR10iVPg2G2j1m-_BCgLB0SNWOcvkCTG1jzYJPr7ARs9GIBg63vtlqgk5TJhTko3J6TFwkrqMB_yeweuWvVvJ7R5CvlKRh_diUcB90RX1lPWSTx4wQHOjLssQ-xRG1iVZ2eroA1uhi8gW7Jdds2wmEnDqxfwmMaaK7IY6cpG_rUMYDqG3m9r3-B0j2MAYOtjGzPtwsJfTHsdasWz_pbypViOp35_BrUHRy6qfqR0uK3zfhe8sFfQDTDctMjissAUGo8rpqnVphoojjvxZVlkB2PmcctOzkAiaMusdOsAxhRg.yH5p6nQitVc9YxQJQP6ocw.XeHzeO9nlXJEmnKtEe_uyl72Aqyzje7Eiz96Zpz79Ot8udWPTmVpa902pGSEeLqHSmbvSpleGEGeuJP5HgOQ-VCrUd3FYL9PK88ieEwO2zsXZfGq4L-tVu7sgyYE8yz25dNRoMoXnrPRzv8dciq3XYxgIYeE0gMc9htVb42rXH7lXjbYeA1aCS2sjd-hRbh-5_afChrpDKYTavpd4EikOdz_-d7EddeUOnHmUsFBz6R6PVX4aOSUkIQug4RyXZLLaq0UkfBLfwezgO3t-dWY8Q.vjaIoaOKXR76eOuUZ1fang" |
| 997 |
|
| 998 |
//when |
| 999 |
test, _, err := Decode(token, PrivKey()) |
| 1000 |
|
| 1001 |
//then |
| 1002 |
c.Assert(err, IsNil) |
| 1003 |
c.Assert(test, Equals, "{\"exp\":1408354731,\"sub\":\"alice\",\"nbf\":1408354131,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"bda732e5-8cbd-4f9d-8205-9e05a77a1f90\",\"iat\":1408354131}") |
| 1004 |
} |
| 1005 |
|
| 1006 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_A192CBC_HS384(c *C) { |
| 1007 |
//given |
| 1008 |
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExOTJDQkMtSFMzODQifQ.cT1VUi7KyfLuDL2JUVL5nVw7OcVUJTCwU2jPbIJVpPh2oR_89BYb4c5ff21A2F-69CqOgV-FD4zlmOkvjywiVq4BRlo8AO90qbe4dSDkIedXHTb0CM0o5HJCWPRNqlBfoPl8tTk7FFtCQyQIJmmTp88h8P4fEtHPe7v50oBjV6sVVdd0-vJa2Lp8id9ezKmlQ5IcgI6E3-81xIGfGvYERbtI7Tr-VQ8LjtylbgKPljfTtVQ_gn0UmbyLBIOUfQfLdpzF7Gdh9kfkEBy1nEnDuQ8V4BqkWfcb6yOWho_zSS4b9lj5qYisjo5KiOmsNNZcyl-EWbjq98k6gAKvAjWxlw.2yxe4VSlm_No0Ii5NTU3kQ.hN_a2DF0B02g7oBTs-Ft2_8nLPI1i6yzyys6a0TIjmfQZrzZTepORlQfHymBKwJOMDbThehvj4F3Yjjk_fziSN80eeuuvRdsi4wheH_jymcgoHJE1FCgpWpLKUfGlY9lMWeqaeL047W-qPdAmUDLUIiIsA4qguX55aPHFPQyjATg0-XaM1IfLySTxCNwV9Ha6FRtxBT01L9T2hbpucu708HgHCvdXn2jzOIC_Zs7SMdb3BbVeUaAyIobU6jDNd3WrgZxwUW0S0LZhovYip-sYg.xneenkPzCRAUQGO8G4YJMGNGYZzqjKoo" |
| 1009 |
|
| 1010 |
//when |
| 1011 |
test, _, err := Decode(token, PrivKey()) |
| 1012 |
|
| 1013 |
//then |
| 1014 |
c.Assert(err, IsNil) |
| 1015 |
c.Assert(test, Equals, "{\"exp\":1408439204,\"sub\":\"alice\",\"nbf\":1408438604,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"1d22fd82-84b5-4b24-96db-c13e41097a9f\",\"iat\":1408438604}") |
| 1016 |
} |
| 1017 |
|
| 1018 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_A256CBC_HS512(c *C) { |
| 1019 |
//given |
| 1020 |
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZDQkMtSFM1MTIifQ.JY7V0pIV5tFYju-WcdfO-KxYdV-d2tjKyuXnq3HwVjQLqttlwnbcxAtUApRuc1UuB6dqp8ggc9d3kgTTZVIveT5MaP57Jm6kU33puHxdujiz0CEFBpf0IWHetq175iFfZWFgAp4BWIK-FaG7_mbinSlNmSxZ4KOM8vgkfvfXQcPwBfsrehsxWRS6BIpJ2PKjOr61z0ry5s19pcMKWzrO-ygtDsusj9ioqH8H0ZahG323um-OtxIw1eVdBsa7rBg8n3zE-Lowgog6wZBOuIzN8bMdRVk5Y08xZRLxmcazJB5aMBB-sVZ5X695ACYTdG55oDpAet5uwyOJybkHF9MSRg.kiHWbMnhKCrSkjOXoIKpAw.xx44_UzBGn_kGOSPZI6QXQTGKq8OFHKyGM1ALZhk51UoiQQe6YzrtwHZcufT3yO0oFcw6TshkdyjKvwXecmSf-LOlUkgaR9o9zQ3PtcFLtgfHdTKBRDBEiubLHMOUTuHCi8laveJ0-RYuYcpwOnSCS_6hPoO86p3aAYzZOmJ3mFLgKQxdt7tgqV7DeRt3j9FyRXmS7vusA7g2oDJz-f7aRs0hWjtPiDN3TGwByacn6T_nlPCvTs6ZR-y9BVNYTaGCJEgujbXebtae_Y94_XZ3g.H2v7BssosabkZEEIk72pFhyYR5VUjQ9EEyQVtFyVvg8" |
| 1021 |
|
| 1022 |
//when |
| 1023 |
test, _, err := Decode(token, PrivKey()) |
| 1024 |
|
| 1025 |
//then |
| 1026 |
c.Assert(err, IsNil) |
| 1027 |
c.Assert(test, Equals, "{\"exp\":1408439204,\"sub\":\"alice\",\"nbf\":1408438604,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"ccb36bb8-7fe2-43b7-93ba-63c9331d0f47\",\"iat\":1408438604}") |
| 1028 |
} |
| 1029 |
|
| 1030 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_A128GCM(c *C) { |
| 1031 |
//given |
| 1032 |
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.Prr8uxpkVLvASjHK4n_TKrMNQWx9cMN4_t1FIMhXXW9aRD4uLXLTmTasspvbprwPbR47qkCu_KcHC6p5eBpZZIW0Ja96OyQLycnhZkueyelqxeGKYMuHEPQ-cAxoe1Vf47bNYBK-9J9G9cHBjngsISlgoxv2K8AjDnAvwlKRqz1Rjg_zdM6nVpFwrWMNEBg5M8HdLR_P0S_z8S9spOsOCWl_2hybwkmuViXdprwXBVdm7TItuhw0NZVP88FzIO7F3C23788bf4JU_6I7KECuWG9uNoPfORZjNGYCIvFWJvq3Adyk3r3DuQwiWc6tE2vHcMj9f7yFxWqWUsxWOtmfuA.sMJK64MRl7g4A_Qr.D3OvvJkI_D569j6G7o8l54iJUOZ36iqge7wvNkBGP0SksZEwhBB7HOJVH8avWY-CpA6Lhh_FZvvA3phgVIQRTMSzc3pXMnirXh0qGBSvdi4OKJsUKWC0dugGY1j5sgV8mEowepg3iUM_j9WS3FW1mSh65IBlyEsLL6eUiYQepeN4vr4cN3jn-vORYVu-KaRyAnab4IJgzhhyRD48_B9w9_dffcuN4_xXPc-O0IvBsFkJTtPRvWGJFkv0r-JMXJR-BZqBrg.pd51_IhdN5YRuzCB6XIHvw" |
| 1033 |
|
| 1034 |
//when |
| 1035 |
test, _, err := Decode(token, PrivKey()) |
| 1036 |
|
| 1037 |
//then |
| 1038 |
c.Assert(err, IsNil) |
| 1039 |
c.Assert(test, Equals, "{\"exp\":1408439204,\"sub\":\"alice\",\"nbf\":1408438604,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"3c039563-1d18-48df-8008-d113ac43cf2f\",\"iat\":1408438604}") |
| 1040 |
} |
| 1041 |
|
| 1042 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_A192GCM(c *C) { |
| 1043 |
//given |
| 1044 |
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExOTJHQ00ifQ.IuvEhYtqW3TXDfc44FyXtMgWL0urYpZktuo989Y0MhusaZjTsaIRnsl2wyaRUim6vfuRE5Svtfm98UYC5zKx_FOq9CTElI7t9Q3QdvimiIbswaWCA2LKx6aiJxA2eCEhVRMUlDDe49V1HY2_zOiPN87qE-P-htRdxSBuQCDplJ7t8agp9VPM73pRAxt9gGvmlXzdGbCpR1HXhIDK14urfcuEF31w5jk0LOR2TIyt8VBWEYMdFnHpYKAQN3KQrF6yNow7AC0jIgcBM4ep41F5d9gkVp2jZWUsRT1Epgv0UcHC0t6BDArLT6Gy2xemTbs81qmARO5v4iyBRBaIuSehuw.F7NhQ3VzsCGfpRI2.jQZz-Kc6n5jUZzPTdjlbnVk-ujFpTNTsEa3J3L222eLg6cPQ6WQH9kmnoSW9WJXbun1ZFBSESv6ti3fKxEUPqs4vwy8d5JIrjrhXcw8lf2AWfFytX92U-ZqSGaoiqGjp0AHnuCqpNnBvCk2-vIHTAabWnpdGvIszVnodEF299CHDgHS9XIerZTGkQCZrRaH89koVfsO__pXnXcjy5loOV9D3ACfj3bIVRUdmg8P1mvyZfNdDErCMuu1G1TK6yaqpcDbrOg.WwWMv-v1Czh67ltSsbI0-A" |
| 1045 |
|
| 1046 |
//when |
| 1047 |
test, _, err := Decode(token, PrivKey()) |
| 1048 |
|
| 1049 |
//then |
| 1050 |
c.Assert(err, IsNil) |
| 1051 |
c.Assert(test, Equals, "{\"exp\":1408439204,\"sub\":\"alice\",\"nbf\":1408438604,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"49ea8e2e-5de8-4fdf-a3d8-f8cd348c1289\",\"iat\":1408438604}") |
| 1052 |
} |
| 1053 |
|
| 1054 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_A256GCM(c *C) { |
| 1055 |
//given |
| 1056 |
token := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ.ClRqSlrZ-3uqe5g4iiAtg3KKqFY_28sFgAh_u-_jUDwU7JBtvDazKRMK0guPqXq0pImb-bCDA6QZhzWgrrz9RGOMEJOVmq_JFl2SF-ipTz6Xj8nDAfqDnYbxj2XRdqMdgdu0BM7xXIpc5GbXuutPFcu9aVxyafv5G4JQo5qCx9Yvo-zVuLUvdOom_cIHwkWK3bx4EPBifIPdPfTQXt8yCXdF36CpT_mmbc13Fe-Uw8JgWtoLQ2nfbXjIEsSgr8BZdxfhiCFYAIyHQ2CdSzEh6J34NtF50u0DVOnkSjAMGiukB0k1fW469EutkfrZJIvo_19Qk8n5Eif7gW1WUw9u9w.rmBi9peixHbDA8cX.o5Xt4SHLSKCYX28u4_rArpfC3KgWwiIcWQMZM1YJPrqX2hRvGqg8Tcl80vXEV-mfNntao0QCPA7hsz4gaoHKLTh1nU1ucY9UGICkwgv9D2q3soOwYRlKP1PuDrh6LQPcPcn2yoSMXTjFhcgPlNGEE-mFipQEnMB5Cn47fcXxpJrWyXSo_FHuOWB1_mfSs1n-HMIDE7Wrxtegp0VNU8AFMEIeQj3pDupZhPrvHzwwRKcfyXhccyYDdfAPrL4xkqFs5en_fw.z8Oazv9h_rLZyI0wQx-QiQ" |
| 1057 |
|
| 1058 |
//when |
| 1059 |
test, _, err := Decode(token, PrivKey()) |
| 1060 |
|
| 1061 |
//then |
| 1062 |
c.Assert(err, IsNil) |
| 1063 |
c.Assert(test, Equals, "{\"exp\":1408439204,\"sub\":\"alice\",\"nbf\":1408438604,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"7b032524-9b59-4469-b92a-fdf25f2c5a7c\",\"iat\":1408438604}") |
| 1064 |
} |
| 1065 |
|
| 1066 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_A128CBC_HS256(c *C) { |
| 1067 |
//given |
| 1068 |
payload := `{"hello": "world"}` |
| 1069 |
|
| 1070 |
//when |
| 1071 |
test, err := Encrypt(payload, RSA_OAEP, A128CBC_HS256, PubKey()) |
| 1072 |
|
| 1073 |
fmt.Printf("\nRSA-OAEP A128CBC-HS256 = %v\n", test) |
| 1074 |
|
| 1075 |
//then |
| 1076 |
c.Assert(err, IsNil) |
| 1077 |
|
| 1078 |
parts := strings.Split(test, ".") |
| 1079 |
|
| 1080 |
c.Assert(len(parts), Equals, 5) |
| 1081 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ") |
| 1082 |
c.Assert(len(parts[1]), Equals, 342) |
| 1083 |
c.Assert(len(parts[2]), Equals, 22) |
| 1084 |
c.Assert(len(parts[3]), Equals, 43) |
| 1085 |
c.Assert(len(parts[4]), Equals, 22) |
| 1086 |
|
| 1087 |
//make sure we consistent with ourselfs |
| 1088 |
t, _, _ := Decode(test, PrivKey()) |
| 1089 |
c.Assert(t, Equals, payload) |
| 1090 |
} |
| 1091 |
|
| 1092 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_A192CBC_HS384(c *C) { |
| 1093 |
//given |
| 1094 |
payload := `{"hello": "world"}` |
| 1095 |
|
| 1096 |
//when |
| 1097 |
test, err := Encrypt(payload, RSA_OAEP, A192CBC_HS384, PubKey()) |
| 1098 |
|
| 1099 |
fmt.Printf("\nRSA-OAEP A192CBC-HS384 = %v\n", test) |
| 1100 |
|
| 1101 |
//then |
| 1102 |
c.Assert(err, IsNil) |
| 1103 |
|
| 1104 |
parts := strings.Split(test, ".") |
| 1105 |
|
| 1106 |
c.Assert(len(parts), Equals, 5) |
| 1107 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExOTJDQkMtSFMzODQifQ") |
| 1108 |
c.Assert(len(parts[1]), Equals, 342) |
| 1109 |
c.Assert(len(parts[2]), Equals, 22) |
| 1110 |
c.Assert(len(parts[3]), Equals, 43) |
| 1111 |
c.Assert(len(parts[4]), Equals, 32) |
| 1112 |
|
| 1113 |
//make sure we consistent with ourselfs |
| 1114 |
t, _, _ := Decode(test, PrivKey()) |
| 1115 |
c.Assert(t, Equals, payload) |
| 1116 |
} |
| 1117 |
|
| 1118 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_A256CBC_HS512(c *C) { |
| 1119 |
//given |
| 1120 |
payload := `{"hello": "world"}` |
| 1121 |
|
| 1122 |
//when |
| 1123 |
test, err := Encrypt(payload, RSA_OAEP, A256CBC_HS512, PubKey()) |
| 1124 |
|
| 1125 |
fmt.Printf("\nRSA-OAEP A256CBC-HS512 = %v\n", test) |
| 1126 |
|
| 1127 |
//then |
| 1128 |
c.Assert(err, IsNil) |
| 1129 |
|
| 1130 |
parts := strings.Split(test, ".") |
| 1131 |
|
| 1132 |
c.Assert(len(parts), Equals, 5) |
| 1133 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZDQkMtSFM1MTIifQ") |
| 1134 |
c.Assert(len(parts[1]), Equals, 342) |
| 1135 |
c.Assert(len(parts[2]), Equals, 22) |
| 1136 |
c.Assert(len(parts[3]), Equals, 43) |
| 1137 |
c.Assert(len(parts[4]), Equals, 43) |
| 1138 |
|
| 1139 |
//make sure we consistent with ourselfs |
| 1140 |
t, _, _ := Decode(test, PrivKey()) |
| 1141 |
c.Assert(t, Equals, payload) |
| 1142 |
} |
| 1143 |
|
| 1144 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_A128GCM(c *C) { |
| 1145 |
//given |
| 1146 |
payload := `{"hello": "world"}` |
| 1147 |
|
| 1148 |
//when |
| 1149 |
test, err := Encrypt(payload, RSA_OAEP, A128GCM, PubKey()) |
| 1150 |
|
| 1151 |
fmt.Printf("\nRSA-OAEP A128GCM = %v\n", test) |
| 1152 |
|
| 1153 |
//then |
| 1154 |
c.Assert(err, IsNil) |
| 1155 |
|
| 1156 |
parts := strings.Split(test, ".") |
| 1157 |
|
| 1158 |
c.Assert(len(parts), Equals, 5) |
| 1159 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ") |
| 1160 |
c.Assert(len(parts[1]), Equals, 342) |
| 1161 |
c.Assert(len(parts[2]), Equals, 16) |
| 1162 |
c.Assert(len(parts[3]), Equals, 24) |
| 1163 |
c.Assert(len(parts[4]), Equals, 22) |
| 1164 |
|
| 1165 |
//make sure we consistent with ourselfs |
| 1166 |
t, _, _ := Decode(test, PrivKey()) |
| 1167 |
c.Assert(t, Equals, payload) |
| 1168 |
} |
| 1169 |
|
| 1170 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_A192GCM(c *C) { |
| 1171 |
//given |
| 1172 |
payload := `{"hello": "world"}` |
| 1173 |
|
| 1174 |
//when |
| 1175 |
test, err := Encrypt(payload, RSA_OAEP, A192GCM, PubKey()) |
| 1176 |
|
| 1177 |
fmt.Printf("\nRSA-OAEP A192GCM = %v\n", test) |
| 1178 |
|
| 1179 |
//then |
| 1180 |
c.Assert(err, IsNil) |
| 1181 |
|
| 1182 |
parts := strings.Split(test, ".") |
| 1183 |
|
| 1184 |
c.Assert(len(parts), Equals, 5) |
| 1185 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExOTJHQ00ifQ") |
| 1186 |
c.Assert(len(parts[1]), Equals, 342) |
| 1187 |
c.Assert(len(parts[2]), Equals, 16) |
| 1188 |
c.Assert(len(parts[3]), Equals, 24) |
| 1189 |
c.Assert(len(parts[4]), Equals, 22) |
| 1190 |
|
| 1191 |
//make sure we consistent with ourselfs |
| 1192 |
t, _, _ := Decode(test, PrivKey()) |
| 1193 |
c.Assert(t, Equals, payload) |
| 1194 |
} |
| 1195 |
|
| 1196 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_A256GCM(c *C) { |
| 1197 |
//given |
| 1198 |
payload := `{"hello": "world"}` |
| 1199 |
|
| 1200 |
//when |
| 1201 |
test, err := Encrypt(payload, RSA_OAEP, A256GCM, PubKey()) |
| 1202 |
|
| 1203 |
fmt.Printf("\nRSA-OAEP A256GCM = %v\n", test) |
| 1204 |
|
| 1205 |
//then |
| 1206 |
c.Assert(err, IsNil) |
| 1207 |
|
| 1208 |
parts := strings.Split(test, ".") |
| 1209 |
|
| 1210 |
c.Assert(len(parts), Equals, 5) |
| 1211 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ") |
| 1212 |
c.Assert(len(parts[1]), Equals, 342) |
| 1213 |
c.Assert(len(parts[2]), Equals, 16) |
| 1214 |
c.Assert(len(parts[3]), Equals, 24) |
| 1215 |
c.Assert(len(parts[4]), Equals, 22) |
| 1216 |
|
| 1217 |
//make sure we consistent with ourselfs |
| 1218 |
t, _, _ := Decode(test, PrivKey()) |
| 1219 |
c.Assert(t, Equals, payload) |
| 1220 |
} |
| 1221 |
|
| 1222 |
func (s *TestSuite) TestDecrypt_A128KW_A128CBC_HS256(c *C) { |
| 1223 |
//given |
| 1224 |
token := "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.DPRoUHQ3Ac8duyD32nUNH3eNUKzUIMYgEdf5GwJ8rW4MYQdl2PCIHA.B1dR6t93aUPcFC1c1aUjeA.lHPKTK0ehgzq70_Ihdh-svI2icUa9usgqP8sF5j50fsQAGizITZpTTXKOKd9-GSEVmJo07551hq9xscZj4vXsDEx-z-akxg0nlL5fFE24km7l4T3LfAeG17gmrMcJuLP55mFUg-F98j9duV2UCyKJPXP6RwOQ5X17VNw29c4k-_AxYM0EjTv3Fww1o3AGuVa07PfpLWE-GdJeJF9RLgaP_6Pua_mdVJud77bYXOsVxsweVtKIaBeLswMUUSU6PoC5oYURP_ybW76GOCjmgXpjA.avU8f5LK_tbJOyKW6-fRnw" |
| 1225 |
|
| 1226 |
//when |
| 1227 |
test, _, err := Decode(token, aes128Key) |
| 1228 |
|
| 1229 |
//then |
| 1230 |
c.Assert(err, IsNil) |
| 1231 |
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}") |
| 1232 |
} |
| 1233 |
|
| 1234 |
func (s *TestSuite) TestDecrypt_A192KW_A192CBC_HS384(c *C) { |
| 1235 |
//given |
| 1236 |
token := "eyJhbGciOiJBMTkyS1ciLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0.OLwgc7EaQdvsf54GfU69qH143C79H_eETvM_yGBgJzEB5367k9tbw6qW4TlQ56GMj__5QDJBvAg.BvYY_v4_dxxsK4M8A0T_TA.V0jBe7o-OahMkqGDgWW0Lxq1eTKPJYix7hjKmmqaKlhdVcnT0cdOU0ahdg82Ls-Vg_NaWKas8MhahHspz18Gx2abDSwLIKbU0jcaf0LxWZkEuMmFJs5dodq0ZqQeaEldDsHe9De_V_TQwPFkcMOPYqWhx2XEb13bmFTPtxNST18Cwm_j263Y_Ouz2YNyC4uZENZDWeOXfJLy7c8jt_ToOvXEVpXj7oZN7Ik1S9bGAenTcvUDORP-gdFdJ3stLe9FmKulOlb94Y-KvP_meyIZ7Q.XPPqS5YVJu2utJcAIRTUxlBHlECGRaM5" |
| 1237 |
|
| 1238 |
//when |
| 1239 |
test, _, err := Decode(token, aes192Key) |
| 1240 |
|
| 1241 |
//then |
| 1242 |
c.Assert(err, IsNil) |
| 1243 |
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}") |
| 1244 |
} |
| 1245 |
|
| 1246 |
func (s *TestSuite) TestDecrypt_A256KW_A256CBC_HS512(c *C) { |
| 1247 |
//given |
| 1248 |
token := "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.91z9VM1VLIA_qyTbqeInFoit7c4PWVuQ5mHcDyNsfofDGXS1qUDdPCWRdLC8ybvJflqHej7SCjEUMxuzOtPOUOgo-8rcdeHi.rsx7FYNTunzditC8XTMJXg.k88BLb0qs8g0UnKjSq9rs2PcrhpafEaUEX2kT-wMdmviZ9UEJrECoQY7MmJgCyQYO30hnnay2psJcr_yaDhV-NpctBZ793Xf9tztLZZndIjz5omV9HjcFgheQZj4g1tbNcRLwxod5uYz-OLrKORzeROEM-wkLgHVEqs90wN98NAiyhGyVMw7CXVX5NdU2KFUacbflkJc5AcaiAZYAts1t9bo2877XLYSO1qBoI5k5QKv6ijjM8I03Uyr3H0p0tdF6EB-cdYNcxq68GvA5CTkOw.DBtOuSJTFu5AAIdcgymUR-JflpwfcXJ2AnZU8LNB3UA" |
| 1249 |
|
| 1250 |
//when |
| 1251 |
test, _, err := Decode(token, aes256Key) |
| 1252 |
|
| 1253 |
//then |
| 1254 |
c.Assert(err, IsNil) |
| 1255 |
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}") |
| 1256 |
} |
| 1257 |
|
| 1258 |
func (s *TestSuite) TestDecrypt_A128KW_A128GCM(c *C) { |
| 1259 |
//given |
| 1260 |
token := "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4R0NNIn0.T3p7Vi-P6jVWrvJIF3MYx6lyNtJOeFmL.IVVKIDU6Nlty559s.xFMzgqiPec95flp57O_TUrF8vDcZIz4zVMrnCQZSnGlLyS464A-whc7ORehjL-U8JLIHmnrD89GzXzC0h-0QG5x1QKv6_MzyeuGMvv4WQLapWtjhfU4s0xSyRswKPAKrjPWzBCi39OjIP0DDTjSmfTiQ6OsDf772Xy3RaZ5FmHHiwzhAs4X3J5foCKEZQXrMrE_H4y0f5eey_B5y_XrYjn2jlOHcBydSCW-cUi9q7f3WTQzlHgEzZMcGSg7imIuoSz6IQQ.xIRG_a_6eMNN4aBneKviEw" |
| 1261 |
|
| 1262 |
//when |
| 1263 |
test, _, err := Decode(token, aes128Key) |
| 1264 |
|
| 1265 |
//then |
| 1266 |
c.Assert(err, IsNil) |
| 1267 |
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}") |
| 1268 |
} |
| 1269 |
|
| 1270 |
func (s *TestSuite) TestDecrypt_A192KW_A192GCM(c *C) { |
| 1271 |
//given |
| 1272 |
token := "eyJhbGciOiJBMTkyS1ciLCJlbmMiOiJBMTkyR0NNIn0.Rd2X_AyKle5d8IO4MQCxJ7WFiVTjzlQ-sDTpOU7dllk.i6-U-bPS1XU87QLu.vJ7Dgh1OhBjniKDOCzLNHsSvZBb6lyDZsIr2v3br6Zp7xhxhq8Cjwmyd2FGqMKpMtSzdg1Y7QSLH3qIfijjp7lH8AxSvCsE2PZTFUJKjCbYtWWmsa6WCA4LIJU8IHBGr0DVQIRh-77ru1cy5xFWGiU7yJMpZpQ62MvluqBSFNYYmzfy5BwXqYMf8n0P2BhxRl4SxvsOoyi7JZvzfCCMixPJm50u65aak83NEIInqN-76AkekWOP4KY57HyKSYs3Fk7lUgw.rN3AZ46DWMtVZa42lnnIHg" |
| 1273 |
|
| 1274 |
//when |
| 1275 |
test, _, err := Decode(token, aes192Key) |
| 1276 |
|
| 1277 |
//then |
| 1278 |
c.Assert(err, IsNil) |
| 1279 |
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}") |
| 1280 |
} |
| 1281 |
|
| 1282 |
func (s *TestSuite) TestDecrypt_A256KW_A256GCM(c *C) { |
| 1283 |
//given |
| 1284 |
token := "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.LY3h_i8x7z_Duc68B-DBrKrKqQpgBbiudtRzVkEPgEsASK1QO2ycVw.KOn1Sn5NOZNVFWje.-26uGTnqc72gaUg4GYEysV9P0lApakuMihLAp7MuWXM5Q267oOVjSd-YeFBvN94A8ZvhFPrNXRcALt3FDOVoEswYy9ryloJu-YbsPt_Gcpnvk8_6OJKDU6xKPWRMCCRDyP88hZ9sMGdV12bWqAQA7LZMGKa-KU0_DUeLeWVew_uoKmR1TqbWBw9_Cmqy5qFztP0zOTACzNQQb8xXij1EZfhPTBQXXDQc4tawGNysEif7SWtlDDQ0row38SsApFtU1saB5g.lPTSTfaMmpNbYp9Yg9YgpQ" |
| 1285 |
|
| 1286 |
//when |
| 1287 |
test, _, err := Decode(token, aes256Key) |
| 1288 |
|
| 1289 |
//then |
| 1290 |
c.Assert(err, IsNil) |
| 1291 |
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}") |
| 1292 |
} |
| 1293 |
|
| 1294 |
func (s *TestSuite) TestEncrypt_A128KW_A128CBC_HS256(c *C) { |
| 1295 |
//given |
| 1296 |
payload := `{"hello": "world"}` |
| 1297 |
|
| 1298 |
//when |
| 1299 |
test, err := Encrypt(payload, A128KW, A128CBC_HS256, aes128Key) |
| 1300 |
|
| 1301 |
fmt.Printf("\nA128KW A128CBC_HS256 = %v\n", test) |
| 1302 |
|
| 1303 |
//then |
| 1304 |
c.Assert(err, IsNil) |
| 1305 |
|
| 1306 |
parts := strings.Split(test, ".") |
| 1307 |
|
| 1308 |
c.Assert(len(parts), Equals, 5) |
| 1309 |
c.Assert(parts[0], Equals, "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0") |
| 1310 |
c.Assert(len(parts[1]), Equals, 54) |
| 1311 |
c.Assert(len(parts[2]), Equals, 22) |
| 1312 |
c.Assert(len(parts[3]), Equals, 43) |
| 1313 |
c.Assert(len(parts[4]), Equals, 22) |
| 1314 |
|
| 1315 |
//make sure we consistent with ourselfs |
| 1316 |
t, _, _ := Decode(test, aes128Key) |
| 1317 |
c.Assert(t, Equals, payload) |
| 1318 |
} |
| 1319 |
|
| 1320 |
func (s *TestSuite) TestEncrypt_A192KW_A192CBC_HS384(c *C) { |
| 1321 |
//given |
| 1322 |
payload := `{"hello": "world"}` |
| 1323 |
|
| 1324 |
//when |
| 1325 |
test, err := Encrypt(payload, A192KW, A192CBC_HS384, aes192Key) |
| 1326 |
|
| 1327 |
fmt.Printf("\nA192KW A192CBC_HS384 = %v\n", test) |
| 1328 |
|
| 1329 |
//then |
| 1330 |
c.Assert(err, IsNil) |
| 1331 |
|
| 1332 |
parts := strings.Split(test, ".") |
| 1333 |
|
| 1334 |
c.Assert(len(parts), Equals, 5) |
| 1335 |
c.Assert(parts[0], Equals, "eyJhbGciOiJBMTkyS1ciLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0") |
| 1336 |
c.Assert(len(parts[1]), Equals, 75) |
| 1337 |
c.Assert(len(parts[2]), Equals, 22) |
| 1338 |
c.Assert(len(parts[3]), Equals, 43) |
| 1339 |
c.Assert(len(parts[4]), Equals, 32) |
| 1340 |
|
| 1341 |
//make sure we consistent with ourselfs |
| 1342 |
t, _, _ := Decode(test, aes192Key) |
| 1343 |
c.Assert(t, Equals, payload) |
| 1344 |
} |
| 1345 |
|
| 1346 |
func (s *TestSuite) TestEncrypt_A256KW_A256CBC_HS512(c *C) { |
| 1347 |
//given |
| 1348 |
payload := `{"hello": "world"}` |
| 1349 |
|
| 1350 |
//when |
| 1351 |
test, err := Encrypt(payload, A256KW, A256CBC_HS512, aes256Key) |
| 1352 |
|
| 1353 |
fmt.Printf("\nA256KW A256CBC_HS512 = %v\n", test) |
| 1354 |
|
| 1355 |
//then |
| 1356 |
c.Assert(err, IsNil) |
| 1357 |
|
| 1358 |
parts := strings.Split(test, ".") |
| 1359 |
|
| 1360 |
c.Assert(len(parts), Equals, 5) |
| 1361 |
c.Assert(parts[0], Equals, "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0") |
| 1362 |
c.Assert(len(parts[1]), Equals, 96) |
| 1363 |
c.Assert(len(parts[2]), Equals, 22) |
| 1364 |
c.Assert(len(parts[3]), Equals, 43) |
| 1365 |
c.Assert(len(parts[4]), Equals, 43) |
| 1366 |
|
| 1367 |
//make sure we consistent with ourselfs |
| 1368 |
t, _, _ := Decode(test, aes256Key) |
| 1369 |
c.Assert(t, Equals, payload) |
| 1370 |
} |
| 1371 |
|
| 1372 |
func (s *TestSuite) TestEncrypt_A128KW_A128GCM(c *C) { |
| 1373 |
//given |
| 1374 |
payload := `{"hello": "world"}` |
| 1375 |
|
| 1376 |
//when |
| 1377 |
test, err := Encrypt(payload, A128KW, A128GCM, aes128Key) |
| 1378 |
|
| 1379 |
fmt.Printf("\nA128KW A128GCM = %v\n", test) |
| 1380 |
|
| 1381 |
//then |
| 1382 |
c.Assert(err, IsNil) |
| 1383 |
|
| 1384 |
parts := strings.Split(test, ".") |
| 1385 |
|
| 1386 |
c.Assert(len(parts), Equals, 5) |
| 1387 |
c.Assert(parts[0], Equals, "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4R0NNIn0") |
| 1388 |
c.Assert(len(parts[1]), Equals, 32) |
| 1389 |
c.Assert(len(parts[2]), Equals, 16) |
| 1390 |
c.Assert(len(parts[3]), Equals, 24) |
| 1391 |
c.Assert(len(parts[4]), Equals, 22) |
| 1392 |
|
| 1393 |
//make sure we consistent with ourselfs |
| 1394 |
t, _, _ := Decode(test, aes128Key) |
| 1395 |
c.Assert(t, Equals, payload) |
| 1396 |
} |
| 1397 |
|
| 1398 |
func (s *TestSuite) TestEncrypt_A192KW_A192GCM(c *C) { |
| 1399 |
//given |
| 1400 |
payload := `{"hello": "world"}` |
| 1401 |
|
| 1402 |
//when |
| 1403 |
test, err := Encrypt(payload, A192KW, A192GCM, aes192Key) |
| 1404 |
|
| 1405 |
fmt.Printf("\nA192KW A192GCM = %v\n", test) |
| 1406 |
|
| 1407 |
//then |
| 1408 |
c.Assert(err, IsNil) |
| 1409 |
|
| 1410 |
parts := strings.Split(test, ".") |
| 1411 |
|
| 1412 |
c.Assert(len(parts), Equals, 5) |
| 1413 |
c.Assert(parts[0], Equals, "eyJhbGciOiJBMTkyS1ciLCJlbmMiOiJBMTkyR0NNIn0") |
| 1414 |
c.Assert(len(parts[1]), Equals, 43) |
| 1415 |
c.Assert(len(parts[2]), Equals, 16) |
| 1416 |
c.Assert(len(parts[3]), Equals, 24) |
| 1417 |
c.Assert(len(parts[4]), Equals, 22) |
| 1418 |
|
| 1419 |
//make sure we consistent with ourselfs |
| 1420 |
t, _, _ := Decode(test, aes192Key) |
| 1421 |
c.Assert(t, Equals, payload) |
| 1422 |
} |
| 1423 |
|
| 1424 |
func (s *TestSuite) TestEncrypt_A256KW_A256GCM(c *C) { |
| 1425 |
//given |
| 1426 |
payload := `{"hello": "world"}` |
| 1427 |
|
| 1428 |
//when |
| 1429 |
test, err := Encrypt(payload, A256KW, A256GCM, aes256Key) |
| 1430 |
|
| 1431 |
fmt.Printf("\nA256KW A256GCM = %v\n", test) |
| 1432 |
|
| 1433 |
//then |
| 1434 |
c.Assert(err, IsNil) |
| 1435 |
|
| 1436 |
parts := strings.Split(test, ".") |
| 1437 |
|
| 1438 |
c.Assert(len(parts), Equals, 5) |
| 1439 |
c.Assert(parts[0], Equals, "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0") |
| 1440 |
c.Assert(len(parts[1]), Equals, 54) |
| 1441 |
c.Assert(len(parts[2]), Equals, 16) |
| 1442 |
c.Assert(len(parts[3]), Equals, 24) |
| 1443 |
c.Assert(len(parts[4]), Equals, 22) |
| 1444 |
|
| 1445 |
//make sure we consistent with ourselfs |
| 1446 |
t, _, _ := Decode(test, aes256Key) |
| 1447 |
c.Assert(t, Equals, payload) |
| 1448 |
} |
| 1449 |
|
| 1450 |
func (s *TestSuite) TestDecrypt_A128GCMKW_A128CBC_HS256(c *C) { |
| 1451 |
//given |
| 1452 |
token := "eyJhbGciOiJBMTI4R0NNS1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiaXYiOiJ1SDVxVThlN2JVZXhGYWh3IiwidGFnIjoiamdxc2czdHoyUGo0QmhEWU1xTnBrdyJ9.peAzKiVO3_w2tAlSzRZdqqQpnUSpgPDHi_xgTd6VzP4.o8bhvYO_UTkrsxQmm__nIg.MSmgetpjXHWMs0TyuGgmWd-msfbQ7oVWC4WuCJcfAsbhLU9kLDLrd0naL5f_UkWBaM04bfcc31K4FRN20IiUxcHzLnMR-lY-HkvRFWYdur-kLWw1UXjIlPOb0nqCuyd2FRpxMdSfFnYr5Us9T45cF7DdK8p4iA7KqPToMHWBsvAcET_ycMIoERqJrBuiJzh-j7UtDzH6KtUfgD4tzZAm3iM6HWT2lq25Pqsu4qf19LYXxZaMIiFwFKboeexkJ5E0hc7P-wIeknzFJaZhkb5P4g.dTQAed1znLHX4cO-VDgxeA" |
| 1453 |
|
| 1454 |
//when |
| 1455 |
test, _, err := Decode(token, aes128Key) |
| 1456 |
|
| 1457 |
//then |
| 1458 |
c.Assert(err, IsNil) |
| 1459 |
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}`) |
| 1460 |
} |
| 1461 |
|
| 1462 |
func (s *TestSuite) TestDecrypt_A128GCMKW_A256CBC_HS512(c *C) { |
| 1463 |
//given |
| 1464 |
token := "eyJhbGciOiJBMTI4R0NNS1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiaXYiOiI5bUwxR1YzUUZIWGtVbEdUIiwidGFnIjoiU0xrTDVpdmhncy1HNjRBTS01bTBxdyJ9.S3_MudWEzKWCp8RRxIG5p6H2YOtMDCkOXXKM9J8J4lMX5N2CcUqsKkDQ4TE1rG7gD5qYgHsb8AiQFLbhjgDeAA.WiOHBPlws9hImQr6bZ8h5Q.jN9UbuvhTiS6uJi1jc0TsvpheXqHs8vdJzKOUVgFmVHZ_OG4vSNRLx408vSoAgSeqsRmj8C8i9Yi2R6kpgtRXZ-Rw7EQEjZ65kg2uwZuve1ObqK-uBm3UzDmcT_Jh6myp9Df1m28ng8ojfrY_JUz6oE5yEcJdlm7H8ahipJyznWOjFigOqhaiXosjW0kbGGpYE-njD5OX22vR5k0RxHlMCDAH2ONR69kaWbLQvDg7y4yMFSxi3ILUFSVz4uXo6qlb8RVCqMUWzlGho-5Cy9OPA.XQ0UmHH5btv14_km6CIlIUwzOFj-rQUYyEzF9VY0r70" |
| 1465 |
|
| 1466 |
//when |
| 1467 |
test, _, err := Decode(token, aes128Key) |
| 1468 |
|
| 1469 |
//then |
| 1470 |
c.Assert(err, IsNil) |
| 1471 |
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}`) |
| 1472 |
} |
| 1473 |
|
| 1474 |
func (s *TestSuite) TestDecrypt_A192GCMKW_A192CBC_HS384(c *C) { |
| 1475 |
//given |
| 1476 |
token := "eyJhbGciOiJBMTkyR0NNS1ciLCJlbmMiOiJBMTkyQ0JDLUhTMzg0IiwiaXYiOiJzRHRLdnRzZVk2UkFuU2twIiwidGFnIjoiZDFDS3dKWnlXSnlvcW5HTUFwbmR6dyJ9.2L9u7vV0P8bZddbkCKKe6_C5JTLf8wRZC8xzEe4gvmcGoF2K5AledhcqT6mIlaPx.1JY51r77jimrvKxts9EroQ.922BMD0HOscwZxn4pmYTRgV7oshegQ1dooU9njhonPcp46XbegdfsgeZAACVFpCc_CoY_XzOsM5trH1Z30QUDc7IGJmC0NKuPdK2KkrYQPXJAe6nuZMembGsyRkOHahtj7sew-ULZn9y0ztbntPqm5I9O716mv1Cu6_5_mBYu36c_VVd6jlzueUWun09yLDJLFuf5jRXDrqRrY4t6XIcqti8LF-QLowU_pa5DvRV_KzCtD_S8HvzJ217_TI9Y1qaApgvWr_BxDrfTXxO2xaZ2Q.0fnvCkg_ChWuf8F3KY8KUgbdIzifb_JT" |
| 1477 |
|
| 1478 |
//when |
| 1479 |
test, _, err := Decode(token, aes192Key) |
| 1480 |
|
| 1481 |
//then |
| 1482 |
c.Assert(err, IsNil) |
| 1483 |
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}`) |
| 1484 |
} |
| 1485 |
|
| 1486 |
func (s *TestSuite) TestDecrypt_A256GCMKW_A256CBC_HS512(c *C) { |
| 1487 |
//given |
| 1488 |
token := "eyJhbGciOiJBMjU2R0NNS1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiaXYiOiJvUV9xbDNJUHNibEVPaDBXIiwidGFnIjoieTllMEFfY1hZMnNDZ24tamxsNl9TdyJ9.K5BxtxcV0simNM-69RvjZuNBjxaavDVnBzP7EFXSjbWZi3NjZFoTcFljcu2TuzR_F9zdjjBbohEgaf4kUMVZfg.881rEerOD33OLCHKdTWDjQ.LvrzsNicH2slBjwERYFu-Fr4Bus2lcLTdFazEpsHc_0QH4NJ2tGrJJjByli6OaFOwtdWONEu_3Ax8xvEXWHc0WMhYKxaVLZI1HQwE0NnWyqfF9mtOkUCCXn9ljvSGSDQY5VUcupVUT6WQxAkaNe6mJ6qkJOxE4pBpiMskO0luW5PkPexk2N3bJVz-GwzMp3xVT6wtFimThucZm2V71594NPCKIkA0HvtBkW0gW0M66pSTfQTHkU0Uvm7WfRvr6TXpiuKntJUe7RX5pXFXbfN2g.aW8OWGfHFI5zTGfFyKuqeLFT5o0tleSYbpCb7kAv1Bs" |
| 1489 |
|
| 1490 |
//when |
| 1491 |
test, _, err := Decode(token, aes256Key) |
| 1492 |
|
| 1493 |
//then |
| 1494 |
c.Assert(err, IsNil) |
| 1495 |
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}`) |
| 1496 |
} |
| 1497 |
|
| 1498 |
func (s *TestSuite) TestEncrypt_A128GCMKW_A128CBC_HS256(c *C) { |
| 1499 |
//given |
| 1500 |
payload := `{"hello": "world"}` |
| 1501 |
|
| 1502 |
//when |
| 1503 |
test, err := Encrypt(payload, A128GCMKW, A128CBC_HS256, aes128Key) |
| 1504 |
|
| 1505 |
fmt.Printf("\nA128GCMKW A128CBC_HS256 = %v\n", test) |
| 1506 |
|
| 1507 |
//then |
| 1508 |
c.Assert(err, IsNil) |
| 1509 |
|
| 1510 |
parts := strings.Split(test, ".") |
| 1511 |
|
| 1512 |
c.Assert(len(parts), Equals, 5) |
| 1513 |
c.Assert(len(parts[0]), Equals, 128) |
| 1514 |
c.Assert(len(parts[1]), Equals, 43) |
| 1515 |
c.Assert(len(parts[2]), Equals, 22) |
| 1516 |
c.Assert(len(parts[3]), Equals, 43) |
| 1517 |
c.Assert(len(parts[4]), Equals, 22) |
| 1518 |
|
| 1519 |
//make sure we consistent with ourselfs |
| 1520 |
t, _, _ := Decode(test, aes128Key) |
| 1521 |
c.Assert(t, Equals, payload) |
| 1522 |
} |
| 1523 |
|
| 1524 |
func (s *TestSuite) TestEncrypt_A128GCMKW_A256CBC_HS512(c *C) { |
| 1525 |
//given |
| 1526 |
payload := `{"hello": "world"}` |
| 1527 |
|
| 1528 |
//when |
| 1529 |
test, err := Encrypt(payload, A128GCMKW, A256CBC_HS512, aes128Key) |
| 1530 |
|
| 1531 |
fmt.Printf("\nA128GCMKW A256CBC_HS512= %v\n", test) |
| 1532 |
|
| 1533 |
//then |
| 1534 |
c.Assert(err, IsNil) |
| 1535 |
|
| 1536 |
parts := strings.Split(test, ".") |
| 1537 |
|
| 1538 |
c.Assert(len(parts), Equals, 5) |
| 1539 |
c.Assert(len(parts[0]), Equals, 128) |
| 1540 |
c.Assert(len(parts[1]), Equals, 86) |
| 1541 |
c.Assert(len(parts[2]), Equals, 22) |
| 1542 |
c.Assert(len(parts[3]), Equals, 43) |
| 1543 |
c.Assert(len(parts[4]), Equals, 43) |
| 1544 |
|
| 1545 |
//make sure we consistent with ourselfs |
| 1546 |
t, _, _ := Decode(test, aes128Key) |
| 1547 |
c.Assert(t, Equals, payload) |
| 1548 |
} |
| 1549 |
|
| 1550 |
func (s *TestSuite) TestEncrypt_A192GCMKW_A192CBC_HS384(c *C) { |
| 1551 |
//given |
| 1552 |
payload := `{"hello": "world"}` |
| 1553 |
|
| 1554 |
//when |
| 1555 |
test, err := Encrypt(payload, A192GCMKW, A192CBC_HS384, aes192Key) |
| 1556 |
|
| 1557 |
fmt.Printf("\nA192GCMKW A192CBC_HS384= %v\n", test) |
| 1558 |
|
| 1559 |
//then |
| 1560 |
c.Assert(err, IsNil) |
| 1561 |
|
| 1562 |
parts := strings.Split(test, ".") |
| 1563 |
|
| 1564 |
c.Assert(len(parts), Equals, 5) |
| 1565 |
c.Assert(len(parts[0]), Equals, 128) |
| 1566 |
c.Assert(len(parts[1]), Equals, 64) |
| 1567 |
c.Assert(len(parts[2]), Equals, 22) |
| 1568 |
c.Assert(len(parts[3]), Equals, 43) |
| 1569 |
c.Assert(len(parts[4]), Equals, 32) |
| 1570 |
|
| 1571 |
//make sure we consistent with ourselfs |
| 1572 |
t, _, _ := Decode(test, aes192Key) |
| 1573 |
c.Assert(t, Equals, payload) |
| 1574 |
} |
| 1575 |
|
| 1576 |
func (s *TestSuite) TestEncrypt_A256GCMKW_A256CBC_HS512(c *C) { |
| 1577 |
//given |
| 1578 |
payload := `{"hello": "world"}` |
| 1579 |
|
| 1580 |
//when |
| 1581 |
test, err := Encrypt(payload, A256GCMKW, A256CBC_HS512, aes256Key) |
| 1582 |
|
| 1583 |
fmt.Printf("\nA256GCMKW A256CBC_HS512= %v\n", test) |
| 1584 |
|
| 1585 |
//then |
| 1586 |
c.Assert(err, IsNil) |
| 1587 |
|
| 1588 |
parts := strings.Split(test, ".") |
| 1589 |
|
| 1590 |
c.Assert(len(parts), Equals, 5) |
| 1591 |
c.Assert(len(parts[0]), Equals, 128) |
| 1592 |
c.Assert(len(parts[1]), Equals, 86) |
| 1593 |
c.Assert(len(parts[2]), Equals, 22) |
| 1594 |
c.Assert(len(parts[3]), Equals, 43) |
| 1595 |
c.Assert(len(parts[4]), Equals, 43) |
| 1596 |
|
| 1597 |
//make sure we consistent with ourselfs |
| 1598 |
t, _, _ := Decode(test, aes256Key) |
| 1599 |
c.Assert(t, Equals, payload) |
| 1600 |
} |
| 1601 |
|
| 1602 |
func (s *TestSuite) TestDecrypt_PBSE2_HS256_A128KW_A128CBC_HS256(c *C) { |
| 1603 |
//given |
| 1604 |
token := "eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwicDJjIjo4MTkyLCJwMnMiOiJiMFlFVmxMemtaNW9UUjBMIn0.dhPAhJ9kmaEbP-02VtEoPOF2QSEYM5085V6zYt1U1qIlVNRcHTGDgQ.4QAAq0dVQT41dQKDG7dhRA.H9MgJmesbU1ow6GCa0lEMwv8A_sHvgaWKkaMcdoj_z6O8LaMSgquxA-G85R_5hEILnHUnFllNJ48oJY7VmAJw0BQW73dMnn58u161S6Ftq7Mjxxq7bcksWvFTVtG5RsqqYSol5BZz5xm8Fcj-y5BMYMvrsCyQhYdeGEHkAvwzRdvZ8pGMsU2XPzl6GqxGjjuRh2vApAeNrj6MwKuD-k6AR0MH46EiNkVCmMkd2w8CNAXjJe9z97zky93xbxlOLozaC3NBRO2Q4bmdGdRg5y4Ew.xNqRi0ouQd7uo5UrPraedg" |
| 1605 |
|
| 1606 |
//when |
| 1607 |
test, _, err := Decode(token, "top secret") |
| 1608 |
|
| 1609 |
//then |
| 1610 |
c.Assert(err, IsNil) |
| 1611 |
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}`) |
| 1612 |
} |
| 1613 |
|
| 1614 |
func (s *TestSuite) TestDecrypt_PBSE2_HS384_A192KW_A192CBC_HS384(c *C) { |
| 1615 |
//given |
| 1616 |
token := "eyJhbGciOiJQQkVTMi1IUzM4NCtBMTkyS1ciLCJlbmMiOiJBMTkyQ0JDLUhTMzg0IiwicDJjIjo4MTkyLCJwMnMiOiIxZEdaODBpQTBqb3lGTzFqIn0.iElgf12HbQWt3enumKP_j3WDxGLfbwSePHYAbYEb_w3himk0swcdiTPo1Jm8MU7le7L_Z8rU2Uk.7LoW9-g7U8c3GNAYO3Z5Jw.guSjXuYN9deq6XIsbkbxAptU9Lp1jf9k11QdhsvjfUvaZRXKrWiE9vg3jEJRJnmF7lZq07cp2Ou8PztMg6R_ygT7gadmP_IYdgQwXD6HGQs__uzvFnqtjWALiwLWuL0V0INrKxBn3CivJ5Hg26nJwLACdVuO_k-fNTaphbox-nKefndS4UXaoe3hEuCzHFPgFivMlND4aZJb8pU8sQbGA29gx5U9qNBmWYOXwV2diYQ2q2SfUEbXoMV7uZyvfQ2juTcyqZBVnEfIYGf_8esALQ.QrgRr0TIlJDFkq2YWNXcoFoMpg4yMC6r" |
| 1617 |
|
| 1618 |
//when |
| 1619 |
test, _, err := Decode(token, "top secret") |
| 1620 |
|
| 1621 |
//then |
| 1622 |
c.Assert(err, IsNil) |
| 1623 |
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}`) |
| 1624 |
} |
| 1625 |
|
| 1626 |
func (s *TestSuite) TestDecrypt_PBSE2_HS512_A256KW_A256CBC_HS512(c *C) { |
| 1627 |
//given |
| 1628 |
token := "eyJhbGciOiJQQkVTMi1IUzUxMitBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwicDJjIjo4MTkyLCJwMnMiOiJCUlkxQ1M3VXNpaTZJNzhkIn0.ovjAL7yRnB_XdJbK8lAaUDRZ-CyVeio8f4pnqOt1FPj1PoQAdEX3S5x6DlzR8aqN_WR5LUwdqDSyUDYhSurnmq8VLfzd3AEe.YAjH6g_zekXJIlPN4Ooo5Q.tutaltxpeVyayXZ9pQovGXTWTf_GWWvtu25Jeg9jgoH0sUX9KCnL00A69e4GJR6EMxalmWsa45AItffbwjUBmwdyklC4ZbTgaovVRs-UwqsZFBO2fpEb7qLajjwra7o4OegzgXDD0jhrKrUusvRWGBvenvumb5euibUxmIfBUcVF1JbdfYxx7ztFeS-QKJpDkE00zyEkViq-QxfrMVl5p7LGmTz8hMrFL3LXLokypZSDgFBfsUzChJf3mlYzxiGaGUqhs7NksQJDoUYf6prPow.XwRVfVTTPogO74RnxZD_9Mse26fTSehna1pbWy4VHfY" |
| 1629 |
|
| 1630 |
//when |
| 1631 |
test, _, err := Decode(token, "top secret") |
| 1632 |
|
| 1633 |
//then |
| 1634 |
c.Assert(err, IsNil) |
| 1635 |
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}`) |
| 1636 |
} |
| 1637 |
|
| 1638 |
func (s *TestSuite) TestDecrypt_PBSE2_HS512_A256KW_A256CBC_HS512_MinIterationViolation(c *C) { |
| 1639 |
//given |
| 1640 |
pbes2Hs512 := DeregisterJwa(PBES2_HS512_A256KW) |
| 1641 |
RegisterJwa(NewPbse2HmacAesKWAlg(256, 300000, 10000)) |
| 1642 |
token := "eyJhbGciOiJQQkVTMi1IUzUxMitBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwicDJjIjo4MTkyLCJwMnMiOiJCUlkxQ1M3VXNpaTZJNzhkIn0.ovjAL7yRnB_XdJbK8lAaUDRZ-CyVeio8f4pnqOt1FPj1PoQAdEX3S5x6DlzR8aqN_WR5LUwdqDSyUDYhSurnmq8VLfzd3AEe.YAjH6g_zekXJIlPN4Ooo5Q.tutaltxpeVyayXZ9pQovGXTWTf_GWWvtu25Jeg9jgoH0sUX9KCnL00A69e4GJR6EMxalmWsa45AItffbwjUBmwdyklC4ZbTgaovVRs-UwqsZFBO2fpEb7qLajjwra7o4OegzgXDD0jhrKrUusvRWGBvenvumb5euibUxmIfBUcVF1JbdfYxx7ztFeS-QKJpDkE00zyEkViq-QxfrMVl5p7LGmTz8hMrFL3LXLokypZSDgFBfsUzChJf3mlYzxiGaGUqhs7NksQJDoUYf6prPow.XwRVfVTTPogO74RnxZD_9Mse26fTSehna1pbWy4VHfY" |
| 1643 |
|
| 1644 |
//when |
| 1645 |
test, headers, err := Decode(token, "top secret") |
| 1646 |
fmt.Printf("\np2c min iteration err= %v\n", err) |
| 1647 |
|
| 1648 |
//then |
| 1649 |
RegisterJwa(pbes2Hs512) |
| 1650 |
c.Assert(err, NotNil) |
| 1651 |
c.Assert(test, Equals, "") |
| 1652 |
c.Assert(headers, IsNil) |
| 1653 |
} |
| 1654 |
|
| 1655 |
func (s *TestSuite) TestDecrypt_PBSE2_HS512_A256KW_A256CBC_HS512_MaxIterationViolation(c *C) { |
| 1656 |
//given |
| 1657 |
pbes2Hs512 := DeregisterJwa(PBES2_HS512_A256KW) |
| 1658 |
RegisterJwa(NewPbse2HmacAesKWAlg(256, 8000, 0)) |
| 1659 |
token := "eyJhbGciOiJQQkVTMi1IUzUxMitBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwicDJjIjo4MTkyLCJwMnMiOiJCUlkxQ1M3VXNpaTZJNzhkIn0.ovjAL7yRnB_XdJbK8lAaUDRZ-CyVeio8f4pnqOt1FPj1PoQAdEX3S5x6DlzR8aqN_WR5LUwdqDSyUDYhSurnmq8VLfzd3AEe.YAjH6g_zekXJIlPN4Ooo5Q.tutaltxpeVyayXZ9pQovGXTWTf_GWWvtu25Jeg9jgoH0sUX9KCnL00A69e4GJR6EMxalmWsa45AItffbwjUBmwdyklC4ZbTgaovVRs-UwqsZFBO2fpEb7qLajjwra7o4OegzgXDD0jhrKrUusvRWGBvenvumb5euibUxmIfBUcVF1JbdfYxx7ztFeS-QKJpDkE00zyEkViq-QxfrMVl5p7LGmTz8hMrFL3LXLokypZSDgFBfsUzChJf3mlYzxiGaGUqhs7NksQJDoUYf6prPow.XwRVfVTTPogO74RnxZD_9Mse26fTSehna1pbWy4VHfY" |
| 1660 |
|
| 1661 |
//when |
| 1662 |
test, headers, err := Decode(token, "top secret") |
| 1663 |
fmt.Printf("\np2c max iteration err= %v\n", err) |
| 1664 |
|
| 1665 |
//then |
| 1666 |
RegisterJwa(pbes2Hs512) |
| 1667 |
c.Assert(err, NotNil) |
| 1668 |
c.Assert(test, Equals, "") |
| 1669 |
c.Assert(headers, IsNil) |
| 1670 |
} |
| 1671 |
|
| 1672 |
func (s *TestSuite) TestEncrypt_PBSE2_HS256_A128KW_A128GCM(c *C) { |
| 1673 |
//given |
| 1674 |
payload := `{"hello": "world"}` |
| 1675 |
|
| 1676 |
//when |
| 1677 |
test, err := Encrypt(payload, PBES2_HS256_A128KW, A128GCM, "top secret") |
| 1678 |
|
| 1679 |
fmt.Printf("\nPBES2-HS256+A128KW A128GCM= %v\n", test) |
| 1680 |
|
| 1681 |
//then |
| 1682 |
c.Assert(err, IsNil) |
| 1683 |
|
| 1684 |
parts := strings.Split(test, ".") |
| 1685 |
|
| 1686 |
c.Assert(len(parts), Equals, 5) |
| 1687 |
c.Assert(len(parts[0]), Equals, 107) |
| 1688 |
c.Assert(len(parts[1]), Equals, 32) |
| 1689 |
c.Assert(len(parts[2]), Equals, 16) |
| 1690 |
c.Assert(len(parts[3]), Equals, 24) |
| 1691 |
c.Assert(len(parts[4]), Equals, 22) |
| 1692 |
|
| 1693 |
//make sure we consistent with ourselfs |
| 1694 |
t, _, _ := Decode(test, "top secret") |
| 1695 |
c.Assert(t, Equals, payload) |
| 1696 |
} |
| 1697 |
|
| 1698 |
func (s *TestSuite) TestEncrypt_PBSE2_HS384_A192KW_A192GCM(c *C) { |
| 1699 |
//given |
| 1700 |
payload := `{"hello": "world"}` |
| 1701 |
|
| 1702 |
//when |
| 1703 |
test, err := Encrypt(payload, PBES2_HS384_A192KW, A192GCM, "top secret") |
| 1704 |
|
| 1705 |
fmt.Printf("\nPBES2-HS384+A192KW A192GCM= %v\n", test) |
| 1706 |
|
| 1707 |
//then |
| 1708 |
c.Assert(err, IsNil) |
| 1709 |
|
| 1710 |
parts := strings.Split(test, ".") |
| 1711 |
|
| 1712 |
c.Assert(len(parts), Equals, 5) |
| 1713 |
c.Assert(len(parts[0]), Equals, 107) |
| 1714 |
c.Assert(len(parts[1]), Equals, 43) |
| 1715 |
c.Assert(len(parts[2]), Equals, 16) |
| 1716 |
c.Assert(len(parts[3]), Equals, 24) |
| 1717 |
c.Assert(len(parts[4]), Equals, 22) |
| 1718 |
|
| 1719 |
//make sure we consistent with ourselfs |
| 1720 |
t, _, _ := Decode(test, "top secret") |
| 1721 |
c.Assert(t, Equals, payload) |
| 1722 |
} |
| 1723 |
|
| 1724 |
func (s *TestSuite) TestEncrypt_PBSE2_HS512_A256KW_A256GCM(c *C) { |
| 1725 |
//given |
| 1726 |
payload := `{"hello": "world"}` |
| 1727 |
|
| 1728 |
//when |
| 1729 |
test, err := Encrypt(payload, PBES2_HS512_A256KW, A256GCM, "top secret") |
| 1730 |
|
| 1731 |
fmt.Printf("\nPBES2-HS512+A256KW A256GCM= %v\n", test) |
| 1732 |
|
| 1733 |
//then |
| 1734 |
c.Assert(err, IsNil) |
| 1735 |
|
| 1736 |
parts := strings.Split(test, ".") |
| 1737 |
|
| 1738 |
c.Assert(len(parts), Equals, 5) |
| 1739 |
c.Assert(len(parts[0]), Equals, 107) |
| 1740 |
c.Assert(len(parts[1]), Equals, 54) |
| 1741 |
c.Assert(len(parts[2]), Equals, 16) |
| 1742 |
c.Assert(len(parts[3]), Equals, 24) |
| 1743 |
c.Assert(len(parts[4]), Equals, 22) |
| 1744 |
|
| 1745 |
//make sure we consistent with ourselfs |
| 1746 |
t, _, _ := Decode(test, "top secret") |
| 1747 |
c.Assert(t, Equals, payload) |
| 1748 |
} |
| 1749 |
|
| 1750 |
func (s *TestSuite) TestEncrypt_PBSE2_HS256_A128KW_A256CBC_HS512(c *C) { |
| 1751 |
//given |
| 1752 |
payload := `{"hello": "world"}` |
| 1753 |
|
| 1754 |
//when |
| 1755 |
test, err := Encrypt(payload, PBES2_HS256_A128KW, A256CBC_HS512, "top secret") |
| 1756 |
|
| 1757 |
fmt.Printf("\nPBES2-HS256+A128KW A256CBC_HS512= %v\n", test) |
| 1758 |
|
| 1759 |
//then |
| 1760 |
c.Assert(err, IsNil) |
| 1761 |
|
| 1762 |
parts := strings.Split(test, ".") |
| 1763 |
|
| 1764 |
c.Assert(len(parts), Equals, 5) |
| 1765 |
c.Assert(len(parts[0]), Equals, 115) |
| 1766 |
c.Assert(len(parts[1]), Equals, 96) |
| 1767 |
c.Assert(len(parts[2]), Equals, 22) |
| 1768 |
c.Assert(len(parts[3]), Equals, 43) |
| 1769 |
c.Assert(len(parts[4]), Equals, 43) |
| 1770 |
|
| 1771 |
//make sure we consistent with ourselfs |
| 1772 |
t, _, _ := Decode(test, "top secret") |
| 1773 |
c.Assert(t, Equals, payload) |
| 1774 |
} |
| 1775 |
|
| 1776 |
func (s *TestSuite) TestEncrypt_PBES2_HS512_A256KW_A256CBC_HS512_Custom_p2c(c *C) { |
| 1777 |
// given |
| 1778 |
payload := `{"exp":1389189552,"sub":"alice","nbf":1389188952,"aud":["https:\/\/app-one.com","https:\/\/app-two.com"],"iss":"https:\/\/openid.net","jti":"e543edf6-edf0-4348-8940-c4e28614d463","iat":1389188952}"` |
| 1779 |
|
| 1780 |
// when |
| 1781 |
test, err := Encrypt(payload, PBES2_HS256_A128KW, A256CBC_HS512, "top secret", Header("p2c", 10000)) |
| 1782 |
|
| 1783 |
fmt.Printf("\nPBES2-HS256+A128KW A256CBC_HS512 (custom p2c=10000)= %v\n", test) |
| 1784 |
|
| 1785 |
//then |
| 1786 |
c.Assert(err, IsNil) |
| 1787 |
|
| 1788 |
parts := strings.Split(test, ".") |
| 1789 |
|
| 1790 |
c.Assert(len(parts), Equals, 5) |
| 1791 |
c.Assert(len(parts[0]), Equals, 116) |
| 1792 |
c.Assert(len(parts[1]), Equals, 96) |
| 1793 |
c.Assert(len(parts[2]), Equals, 22) |
| 1794 |
c.Assert(len(parts[3]), Equals, 278) |
| 1795 |
c.Assert(len(parts[4]), Equals, 43) |
| 1796 |
|
| 1797 |
// ensure custom 'p2c' header have been included |
| 1798 |
v, _ := base64url.Decode(parts[0]) |
| 1799 |
c.Assert(string(v), Matches, `.*"p2c":10000.*`) |
| 1800 |
|
| 1801 |
//make sure we consistent with ourselfs |
| 1802 |
t, _, _ := Decode(test, "top secret") |
| 1803 |
c.Assert(t, Equals, payload) |
| 1804 |
} |
| 1805 |
|
| 1806 |
func (s *TestSuite) TestEncrypt_PBES2_HS512_A256KW_A256CBC_HS512_MaxIterationViolation(c *C) { |
| 1807 |
// given |
| 1808 |
pbes2Hs512 := DeregisterJwa(PBES2_HS512_A256KW) |
| 1809 |
RegisterJwa(NewPbse2HmacAesKWAlg(256, 8000, 0)) |
| 1810 |
|
| 1811 |
payload := `{"hello": "world"}` |
| 1812 |
|
| 1813 |
// when |
| 1814 |
test, err := Encrypt(payload, PBES2_HS512_A256KW, A256CBC_HS512, "top secret", Header("p2c", 10000)) |
| 1815 |
|
| 1816 |
fmt.Printf("\nTestEncrypt_PBES2_HS512_A256KW_A256CBC_HS512_MaxIterationViolation, err = %v\n", err) |
| 1817 |
|
| 1818 |
//then |
| 1819 |
RegisterJwa(pbes2Hs512) |
| 1820 |
c.Assert(err, NotNil) |
| 1821 |
c.Assert(test, Equals, "") |
| 1822 |
} |
| 1823 |
|
| 1824 |
func (s *TestSuite) TestEncrypt_PBES2_HS512_A256KW_A256CBC_HS512_MinIterationViolation(c *C) { |
| 1825 |
// given |
| 1826 |
pbes2Hs512 := DeregisterJwa(PBES2_HS512_A256KW) |
| 1827 |
RegisterJwa(NewPbse2HmacAesKWAlg(256, 800000, 300000)) |
| 1828 |
|
| 1829 |
payload := `{"hello": "world"}` |
| 1830 |
|
| 1831 |
// when |
| 1832 |
test, err := Encrypt(payload, PBES2_HS512_A256KW, A256CBC_HS512, "top secret", Header("p2c", 10000)) |
| 1833 |
|
| 1834 |
fmt.Printf("\nTestEncrypt_PBES2_HS512_A256KW_A256CBC_HS512_MinIterationViolation, err = %v\n", err) |
| 1835 |
|
| 1836 |
//then |
| 1837 |
RegisterJwa(pbes2Hs512) |
| 1838 |
c.Assert(err, NotNil) |
| 1839 |
c.Assert(test, Equals, "") |
| 1840 |
} |
| 1841 |
|
| 1842 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A128CBC_HS256(c *C) { |
| 1843 |
//given |
| 1844 |
token := "eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTEyOENCQy1IUzI1NiIsImVwayI6eyJrdHkiOiJFQyIsIngiOiItVk1LTG5NeW9IVHRGUlpGNnFXNndkRm5BN21KQkdiNzk4V3FVMFV3QVhZIiwieSI6ImhQQWNReTgzVS01Qjl1U21xbnNXcFZzbHVoZGJSZE1nbnZ0cGdmNVhXTjgiLCJjcnYiOiJQLTI1NiJ9fQ..UA3N2j-TbYKKD361AxlXUA.XxFur_nY1GauVp5W_KO2DEHfof5s7kUwvOgghiNNNmnB4Vxj5j8VRS8vMOb51nYy2wqmBb2gBf1IHDcKZdACkCOMqMIcpBvhyqbuKiZPLHiilwSgVV6ubIV88X0vK0C8ZPe5lEyRudbgFjdlTnf8TmsvuAsdtPn9dXwDjUR23bD2ocp8UGAV0lKqKzpAw528vTfD0gwMG8gt_op8yZAxqqLLljMuZdTnjofAfsW2Rq3Z6GyLUlxR51DAUlQKi6UpsKMJoXTrm1Jw8sXBHpsRqA.UHCYOtnqk4SfhAknCnymaQ" |
| 1845 |
|
| 1846 |
//when |
| 1847 |
test, _, err := Decode(token, Ecc256Private()) |
| 1848 |
|
| 1849 |
//then |
| 1850 |
c.Assert(err, IsNil) |
| 1851 |
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}`) |
| 1852 |
} |
| 1853 |
|
| 1854 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A192CBC_HS384(c *C) { |
| 1855 |
//given |
| 1856 |
token := "eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTE5MkNCQy1IUzM4NCIsImVwayI6eyJrdHkiOiJFQyIsIngiOiJPaFdQMHdYQy10YnotZEZPbzJUZGljZ2dBWnNPUm1CMTFwTHd0T1lGamhTS0diSEo2U05lRVU3akNzeXNRVzJZIiwieSI6IlNRdlFrbnJoRjk5RzJ2aHhkNE82Y1NQb2lOLVhTbm5LMS11UmM4LXZpS2lHTXJIQzkyXzZyeWRPeEtlN0JPdDgiLCJjcnYiOiJQLTM4NCJ9fQ..11aQFJ3lbGxS8hKGG0-qBw.8885t-_OenCjccLenOIsX2OiTe-xGejXJuKl4AyBRugk4VsBC16GQ24kGUtDPNASXcswgJhiCJde6BNte2aq9xyeuT6RSknua7lnl7njtnU19ssz9hhXJ_wuZr_XNGYmuyM0Pb_fmNK0mA0k2vo9rcfLktTFfprdKg7iLeCHt8576g_GGF577BOc5s4Pl0dVBGdiutSdczTf67hGBoTWIr6Q-9cipLinxr9DwbOpCtceX1gFlAxsWjqswICk6Vwah56GZ7_1XqwyBsO5flNyrQ.xzEn_kq5JvwoYpuPT1ePE4QRzje1qBCT" |
| 1857 |
|
| 1858 |
//when |
| 1859 |
test, _, err := Decode(token, Ecc384Private()) |
| 1860 |
|
| 1861 |
//then |
| 1862 |
c.Assert(err, IsNil) |
| 1863 |
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}`) |
| 1864 |
} |
| 1865 |
|
| 1866 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A256CBC_HS512(c *C) { |
| 1867 |
//given |
| 1868 |
token := "eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTI1NkNCQy1IUzUxMiIsImVwayI6eyJrdHkiOiJFQyIsIngiOiJBV3JGb092UkRnWWpaUmF4dXVWMk54c1U1NVNlT1QxUTJ4V3I1ektvbUtHS2hZVmxoVFRQWEtka2MtMzM1bDBWRHlXRTlQZl9SLUpCSThtdWpEaHlSYmVfIiwieSI6IkFhbjBIMEcwRVhWaHNpaDBicU1XeGZHb2JsM2FlUTM1eVZCaG5pSmhfMERNRHFUX3hxVHRWaEtGQWlOWEIwTGJKTjJnd0NSY182OE1vS1p5R3FrV3RIVDciLCJjcnYiOiJQLTUyMSJ9fQ..uA7eYAKVhOr6nnO1bQnhpQ.G5qlUuzVAWgN_szXjFa4eAdXVPEcjpStnw4YYFm2p_lsQs6VG5huSGseV3Wgr22gdc0xHk5XgwRyihB5tr4MiXf41mVKwmxT-u9z5N236fDZ6LYYBY1YrUAp_1pOlyO7RpxpHGrZTKTeuIxhTHhs0jkVC_RZlVNlsjEhU3ssWDCJsCxetLwbq8huL1zlzwyAYqV7uPYIrp2JdT7GkZYcxrsaP8dCkPIdfORRn_qhYIwDnum2rLiYMLc8H0KmpzZKYUVxI7PVPK4oRQpv6n801A.QL0cDhvNKWmMMF1fLUXhI80zE5w5Ghm1Z3_7hGOEesQ" |
| 1869 |
|
| 1870 |
//when |
| 1871 |
test, _, err := Decode(token, Ecc512Private()) |
| 1872 |
|
| 1873 |
//then |
| 1874 |
c.Assert(err, IsNil) |
| 1875 |
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}`) |
| 1876 |
} |
| 1877 |
|
| 1878 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A128GCM(c *C) { |
| 1879 |
//given |
| 1880 |
token := "eyJhbGciOiJFQ0RILUVTIiwiZW5jIjoiQTEyOEdDTSIsImVwayI6eyJrdHkiOiJFQyIsIngiOiJPbDdqSWk4SDFpRTFrcnZRTmFQeGp5LXEtY3pQME40RVdPM1I3NTg0aEdVIiwieSI6Ik1kU2V1OVNudWtwOWxLZGU5clVuYmp4a3ozbV9kTWpqQXc5NFd3Q0xaa3MiLCJjcnYiOiJQLTI1NiJ9fQ..E4XwpWZ2kO-Vg0xb.lP5LWPlabtmzS-m2EPGhlPGgllLNhI5OF2nAbbV9tVvtCckKpt358IQNRk-W8-JNL9SsLdWmVUMplrw-GO-KA2qwxEeh_8-muYCw3qfdhVVhLnOF-kL4mW9a00Xls_6nIZponGrqpHCwRQM5aSr365kqTNpfOnXgJTKG2459nqv8n4oSfmwV2iRUBlXEgTO-1Tvrq9doDwZCCHj__JKvbuPfyRBp5T7d-QJio0XRF1TO4QY36GtKMXWR264lS7g-T1xxtA.vFevA9zsyOnNA5RZanKqHA" |
| 1881 |
|
| 1882 |
//when |
| 1883 |
test, _, err := Decode(token, Ecc256Private()) |
| 1884 |
|
| 1885 |
//then |
| 1886 |
c.Assert(err, IsNil) |
| 1887 |
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}`) |
| 1888 |
} |
| 1889 |
|
| 1890 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A128CBC_HS256(c *C) { |
| 1891 |
//given |
| 1892 |
payload := `{"hello": "world"}` |
| 1893 |
|
| 1894 |
//when |
| 1895 |
test, err := Encrypt(payload, ECDH_ES, A128CBC_HS256, Ecc256Public()) |
| 1896 |
|
| 1897 |
fmt.Printf("\nECDH-ES A128CBC_HS256= %v\n", test) |
| 1898 |
|
| 1899 |
//then |
| 1900 |
c.Assert(err, IsNil) |
| 1901 |
|
| 1902 |
parts := strings.Split(test, ".") |
| 1903 |
|
| 1904 |
c.Assert(len(parts), Equals, 5) |
| 1905 |
c.Assert(len(parts[0]), Equals, 230) |
| 1906 |
c.Assert(len(parts[1]), Equals, 0) |
| 1907 |
c.Assert(len(parts[2]), Equals, 22) |
| 1908 |
c.Assert(len(parts[3]), Equals, 43) |
| 1909 |
c.Assert(len(parts[4]), Equals, 22) |
| 1910 |
|
| 1911 |
//make sure we consistent with ourselfs |
| 1912 |
t, _, _ := Decode(test, Ecc256Private()) |
| 1913 |
c.Assert(t, Equals, payload) |
| 1914 |
} |
| 1915 |
|
| 1916 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A192CBC_HS384(c *C) { |
| 1917 |
//given |
| 1918 |
payload := `{"hello": "world"}` |
| 1919 |
|
| 1920 |
//when |
| 1921 |
test, err := Encrypt(payload, ECDH_ES, A192CBC_HS384, Ecc384Public()) |
| 1922 |
|
| 1923 |
fmt.Printf("\nECDH-ES A192CBC_H384= %v\n", test) |
| 1924 |
|
| 1925 |
//then |
| 1926 |
c.Assert(err, IsNil) |
| 1927 |
|
| 1928 |
parts := strings.Split(test, ".") |
| 1929 |
|
| 1930 |
c.Assert(len(parts), Equals, 5) |
| 1931 |
c.Assert(len(parts[0]), Equals, 286) |
| 1932 |
c.Assert(len(parts[1]), Equals, 0) |
| 1933 |
c.Assert(len(parts[2]), Equals, 22) |
| 1934 |
c.Assert(len(parts[3]), Equals, 43) |
| 1935 |
c.Assert(len(parts[4]), Equals, 32) |
| 1936 |
|
| 1937 |
//make sure we consistent with ourselfs |
| 1938 |
t, _, _ := Decode(test, Ecc384Private()) |
| 1939 |
c.Assert(t, Equals, payload) |
| 1940 |
} |
| 1941 |
|
| 1942 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A256CBC_HS512(c *C) { |
| 1943 |
//given |
| 1944 |
payload := `{"hello": "world"}` |
| 1945 |
|
| 1946 |
//when |
| 1947 |
test, err := Encrypt(payload, ECDH_ES, A256CBC_HS512, Ecc512Public()) |
| 1948 |
|
| 1949 |
fmt.Printf("\nECDH-ES A256CBC_HS512 = %v\n", test) |
| 1950 |
|
| 1951 |
//then |
| 1952 |
c.Assert(err, IsNil) |
| 1953 |
|
| 1954 |
parts := strings.Split(test, ".") |
| 1955 |
|
| 1956 |
c.Assert(len(parts), Equals, 5) |
| 1957 |
c.Assert(len(parts[0]), Equals, 350) |
| 1958 |
c.Assert(len(parts[1]), Equals, 0) |
| 1959 |
c.Assert(len(parts[2]), Equals, 22) |
| 1960 |
c.Assert(len(parts[3]), Equals, 43) |
| 1961 |
c.Assert(len(parts[4]), Equals, 43) |
| 1962 |
|
| 1963 |
//make sure we consistent with ourselfs |
| 1964 |
t, _, _ := Decode(test, Ecc512Private()) |
| 1965 |
c.Assert(t, Equals, payload) |
| 1966 |
} |
| 1967 |
|
| 1968 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A128GCM(c *C) { |
| 1969 |
//given |
| 1970 |
payload := `{"hello": "world"}` |
| 1971 |
|
| 1972 |
//when |
| 1973 |
test, err := Encrypt(payload, ECDH_ES, A128GCM, Ecc256Public()) |
| 1974 |
|
| 1975 |
fmt.Printf("\nECDH-ES A128GCM = %v\n", test) |
| 1976 |
|
| 1977 |
//then |
| 1978 |
c.Assert(err, IsNil) |
| 1979 |
|
| 1980 |
parts := strings.Split(test, ".") |
| 1981 |
|
| 1982 |
c.Assert(len(parts), Equals, 5) |
| 1983 |
c.Assert(len(parts[0]), Equals, 222) |
| 1984 |
c.Assert(len(parts[1]), Equals, 0) |
| 1985 |
c.Assert(len(parts[2]), Equals, 16) |
| 1986 |
c.Assert(len(parts[3]), Equals, 24) |
| 1987 |
c.Assert(len(parts[4]), Equals, 22) |
| 1988 |
|
| 1989 |
//make sure we consistent with ourselfs |
| 1990 |
t, _, _ := Decode(test, Ecc256Private()) |
| 1991 |
c.Assert(t, Equals, payload) |
| 1992 |
} |
| 1993 |
|
| 1994 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A128KW_A128GCM(c *C) { |
| 1995 |
//given |
| 1996 |
token := "eyJhbGciOiJFQ0RILUVTK0ExMjhLVyIsImVuYyI6IkExMjhHQ00iLCJlcGsiOnsia3R5IjoiRUMiLCJ4IjoiNnlzVWZVd09vVWxENUpGZG9qUHFXeFd3ZkJ3b2ttWmpOVmxJRFFrcG1PMCIsInkiOiJKZVpia19QazIybWowVFUwcG5uQjNVaUwySzJJcVl6Tk0xVVRPZS1KY3dZIiwiY3J2IjoiUC0yNTYifX0.e1n3YTorJJ-H7eWby-pfGWzVx0aDScCT.VQLnlbAD3N1O-k-S.mJzcAMoxUMQxXIHFGcVjuEVKw70lC6rNbcGqverZBkycPQ2EDgZCiqMgJenHuecvG_YqShi50uZYVyYS4TTrGh1Bj4jP6iFZ8Ksww3hW_jYzKQbp9CdbmOL1f0f25RKwUq61AraXGoJ1Lrs8IM96tvTjKTGpDkNMJ8xN4kVcRcrM5fjTIx973XKo2_nbuCpn-BlAhB6wzYuw_EFsqis8-8cssPENLuGA-n-xX66akqdhycfh5RiqrTPYUnk5ss1Fo_LWWA.l0-CNccSNLTgVdGW1CZr9w" |
| 1997 |
|
| 1998 |
//when |
| 1999 |
test, _, err := Decode(token, Ecc256Private()) |
| 2000 |
|
| 2001 |
//then |
| 2002 |
c.Assert(err, IsNil) |
| 2003 |
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}`) |
| 2004 |
} |
| 2005 |
|
| 2006 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A192KW_A192GCM(c *C) { |
| 2007 |
//given |
| 2008 |
token := "eyJhbGciOiJFQ0RILUVTK0ExOTJLVyIsImVuYyI6IkExOTJHQ00iLCJlcGsiOnsia3R5IjoiRUMiLCJ4IjoiX1huZ0s2a1Q0XzR4dWpBZzFFZWpNZHQ3WW9sTkMySENZMDVyNUNTWUNmQVdUQ0phRi1ic1ZJUnpOY3hDeG5GUSIsInkiOiJPekl2T1NIeERjMTh5eXNqeVpQblZvaVhMZWU4OUhFUklvaVhrLW9nclVlTkFfRFFZTUFmbVFEZWtRbFk2SWZ4IiwiY3J2IjoiUC0zODQifX0.edrJoQt5wA7K11UvLxz3ExKyazayJ2O5fZVUETQh1RA.F886lZeI68UEU666.2woVI6lnFEeLNIxmlUbrTUHvV2dz3h47BVUs4ylSoYZ7OcdamP8cvdnxJY6N_kq2cxhyOzgsJAlbk4uG6UpyK0snl8fNExyNiDwyCCKCbUE8jAoGV7zBRDPioTbMIzprWt9qmBOW-pmzh8l_eiI_fPbvUulcIfqGdUK6fDifQAAjCB5RnxMFbkpVVkkcvHXVzaPnNvkZ_GLLRElInLx2H3mpFaby0a-zEK27qLzAe-t6WupS9rIKUhK0skPgeSkdRmHDxw.Qic27YS5eIoc0M4nMP365w" |
| 2009 |
|
| 2010 |
//when |
| 2011 |
test, _, err := Decode(token, Ecc384Private()) |
| 2012 |
|
| 2013 |
//then |
| 2014 |
c.Assert(err, IsNil) |
| 2015 |
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}`) |
| 2016 |
} |
| 2017 |
|
| 2018 |
func (s *TestSuite) TestDecrypt_ECDH_ES_A256KW_A256GCM(c *C) { |
| 2019 |
//given |
| 2020 |
token := "eyJhbGciOiJFQ0RILUVTK0EyNTZLVyIsImVuYyI6IkEyNTZHQ00iLCJlcGsiOnsia3R5IjoiRUMiLCJ4IjoiQUlMTkMzX2lEN0hhSWFhZEU5bGZPcHI5YzBCYzV6cEtraUtkcUNpeGVubHdydlhFVDF4Y0RqbFMtSWZxSUR6VWNoekhiVFgxN0Z4ZGM2X1dOZ2std3VlUyIsInkiOiJBQlFwLWRsalVrZHlOcHFOTkxlSlEyUEZGVmplUlV4SjRGOFZYNGpOMGw4U1Q3Y0NMY0tmVVpKQmJ5b2FNbzhuX3Q1dDc3a1hSOE1aRllOcFhadFBHQTRWIiwiY3J2IjoiUC01MjEifX0.HbaOJoNm7rKdFPeNNxk5NZGWqyleUBrpme7kBfkPSNgStHua5SGqgA.qvi8Wxs7EFXTvDAI.HnPWLNveG0ypTWGWb-V4ORyshMmoR7IhaWUDKkoV9HoD-V6z9WZqAx3uX45Se2fxO9aqSVWqQbrLkw9C9A4DGGiMv27tr29m_c4jUOF_TEGWuhAUAo3Lv-srLFGxQoA3yNWsCpI5VsUVxqc7Sx1dJcEHe8DQcsYTaroNTh0cUMQuqJX9waQm2H-qFjrkLk3d9bo8rhB3x8JTi_X5uNcB1mNH51pPDtRGO41t7EFII1KmAUgjL8c6bCw__Cc6hoteely2Pg.QRsOLaELO2d2MCjpFZKsCg" |
| 2021 |
|
| 2022 |
//when |
| 2023 |
test, _, err := Decode(token, Ecc512Private()) |
| 2024 |
|
| 2025 |
//then |
| 2026 |
c.Assert(err, IsNil) |
| 2027 |
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}`) |
| 2028 |
} |
| 2029 |
|
| 2030 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A128KW_A128CBC_HS256(c *C) { |
| 2031 |
//given |
| 2032 |
payload := `{"hello": "world"}` |
| 2033 |
|
| 2034 |
//when |
| 2035 |
test, err := Encrypt(payload, ECDH_ES_A128KW, A128CBC_HS256, Ecc256Public()) |
| 2036 |
|
| 2037 |
fmt.Printf("\nECDH-ES+A128KW A128CBC-HS256 = %v\n", test) |
| 2038 |
|
| 2039 |
//then |
| 2040 |
c.Assert(err, IsNil) |
| 2041 |
|
| 2042 |
parts := strings.Split(test, ".") |
| 2043 |
|
| 2044 |
c.Assert(len(parts), Equals, 5) |
| 2045 |
c.Assert(len(parts[0]), Equals, 239) |
| 2046 |
c.Assert(len(parts[1]), Equals, 54) |
| 2047 |
c.Assert(len(parts[2]), Equals, 22) |
| 2048 |
c.Assert(len(parts[3]), Equals, 43) |
| 2049 |
c.Assert(len(parts[4]), Equals, 22) |
| 2050 |
|
| 2051 |
//make sure we consistent with ourselfs |
| 2052 |
t, _, _ := Decode(test, Ecc256Private()) |
| 2053 |
c.Assert(t, Equals, payload) |
| 2054 |
} |
| 2055 |
|
| 2056 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A192KW_A192CBC_HS384(c *C) { |
| 2057 |
//given |
| 2058 |
payload := `{"hello": "world"}` |
| 2059 |
|
| 2060 |
//when |
| 2061 |
test, err := Encrypt(payload, ECDH_ES_A192KW, A192CBC_HS384, Ecc384Public()) |
| 2062 |
|
| 2063 |
fmt.Printf("\nECDH-ES+A192KW A192CBC-HS384 = %v\n", test) |
| 2064 |
|
| 2065 |
//then |
| 2066 |
c.Assert(err, IsNil) |
| 2067 |
|
| 2068 |
parts := strings.Split(test, ".") |
| 2069 |
|
| 2070 |
c.Assert(len(parts), Equals, 5) |
| 2071 |
c.Assert(len(parts[0]), Equals, 295) |
| 2072 |
c.Assert(len(parts[1]), Equals, 75) |
| 2073 |
c.Assert(len(parts[2]), Equals, 22) |
| 2074 |
c.Assert(len(parts[3]), Equals, 43) |
| 2075 |
c.Assert(len(parts[4]), Equals, 32) |
| 2076 |
|
| 2077 |
//make sure we consistent with ourselfs |
| 2078 |
t, _, _ := Decode(test, Ecc384Private()) |
| 2079 |
c.Assert(t, Equals, payload) |
| 2080 |
} |
| 2081 |
|
| 2082 |
func (s *TestSuite) TestEncrypt_ECDH_ES_A256KW_A256GCM(c *C) { |
| 2083 |
//given |
| 2084 |
payload := `{"hello": "world"}` |
| 2085 |
|
| 2086 |
//when |
| 2087 |
test, err := Encrypt(payload, ECDH_ES_A256KW, A256GCM, Ecc512Public()) |
| 2088 |
|
| 2089 |
fmt.Printf("\nECDH-ES+A256KW A265GCM = %v\n", test) |
| 2090 |
|
| 2091 |
//then |
| 2092 |
c.Assert(err, IsNil) |
| 2093 |
|
| 2094 |
parts := strings.Split(test, ".") |
| 2095 |
|
| 2096 |
c.Assert(len(parts), Equals, 5) |
| 2097 |
c.Assert(len(parts[0]), Equals, 351) |
| 2098 |
c.Assert(len(parts[1]), Equals, 54) |
| 2099 |
c.Assert(len(parts[2]), Equals, 16) |
| 2100 |
c.Assert(len(parts[3]), Equals, 24) |
| 2101 |
c.Assert(len(parts[4]), Equals, 22) |
| 2102 |
|
| 2103 |
//make sure we consistent with ourselfs |
| 2104 |
t, _, _ := Decode(test, Ecc512Private()) |
| 2105 |
c.Assert(t, Equals, payload) |
| 2106 |
} |
| 2107 |
|
| 2108 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_256_A128CBC_HS256(c *C) { |
| 2109 |
//given |
| 2110 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.bje66yTjMUpyGzbt3QvPNOmCmUPowgEmoBHXw-pByhST2VBSs0_67JKDymKW0VpmQC5Qb7ZLC6nNG8YW5pxTZDOeTQLodhAvzoNAsrx4M2R_N58ZVqBPLKTq7FKi1NNd8oJ80dwWbOJ13dkLH68SlhOK5bhqKFgtbzalnglL2kq8Fki1GkN4YyFnS8-chC-mlrS5bJrPSHUF7oAsG_flL_e9-KzYqYTQgGCB3GYSo_pgalsp2rUO3Oz2Pfe9IEJNlX7R9wOT1nTT0UUg-lSzQ2oOaXNvNyaPgEa76mJ1nk7ZQq7ZNix1m8snjk0Vizd8EOFCSRyOGcp4mHMn7-s00Q.tMFMCdFNQXbhEnwE6mP_XQ.E_O_ZBtJ8P0FvhKOV_W98oxIySDgdd0up0c8FAjo-3OVZ_6XMEQYFDKVG_Zc3zkbaz1Z2hmc7D7M28RbhRdya3yJN6Hcv1KuXeZ9ociI7o739Ni_bPvv8xCmGxlASS5AF7N4JR7XjrWL-SYKGNL1p0XNTlPo3B3qYqgAY6jFNvlcjWupim-pQbWKNqPbO2KmSCtUzyKE5oHjsomH0hnQs0_DXv3cgQ_ZFLFZBc1tC4AjQ8QZex5kWg5BmlJDM5F_jD7QRhb7B1u4Mi563-AKVA.0lraw3IXMM6wPqUZVYA8pg" |
| 2111 |
|
| 2112 |
//when |
| 2113 |
test, _, err := Decode(token, PrivKey()) |
| 2114 |
|
| 2115 |
//then |
| 2116 |
c.Assert(err, IsNil) |
| 2117 |
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}`) |
| 2118 |
} |
| 2119 |
|
| 2120 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_256_A192CBC_HS384(c *C) { |
| 2121 |
//given |
| 2122 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0.COuKvozBVi2vkEPpFdx0HTMpU9tmpP1lLngbmGn8RVphY-vjhVaduv8D_Ay_1j8LuMz4tgP98xWtbJkTyhxY1kBwXe0CgqFUOSJ1mTEPRkKSXpdFR7rT1Pv68qug2yKaXT_qcviyBerIcUVFbXBmtiYAosYO4kaPSOE1IvLadFOrMkxdZv6QiiCROzWgJNCCMgNQZGRoPhqLe3wrcxi86DhNO7Bpqq_yeNVyHdU_qObMuMVZIWWEQIDhiU4nE8WGJLG_NtKElc_nQwbmclL_YYgTiHsIAKWZCdj0nwfLe5mwJQN4r7pjakiUVzCbNNgI1-iBH1vJD5VCPxgWldzfYA.7cDs4wzbNDt1Kq40Q5ae4w.u1bR6ChVd90QkFIp3H6IkOCIMwf5aIKsQOvqgFangRLrDjctl5qO5jTHr1o1GwBQvAkRmaGSE7fRIwWB_l-Ayx2c2WDFOkVXFSR_D23GrWaLMLbugPItQd2Mny6H4QOzO3O0EK_Qm7frqwKQI3og72SB8DUqzEaKsrz7HR2z_qMa2CEEApxai_R6NIlAdMUbYvOfZx262MWFGrITBDmma-Mnqiz9WJUv2wexfwjROaaS4wXfkGy5B6ltESifpZZk5NerExR3GA6yX7cFqJc4pQ.FKcbLyB9eP1UXmxyliTu1_GQrnS-JtAB" |
| 2123 |
|
| 2124 |
//when |
| 2125 |
test, _, err := Decode(token, PrivKey()) |
| 2126 |
|
| 2127 |
//then |
| 2128 |
c.Assert(err, IsNil) |
| 2129 |
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}`) |
| 2130 |
} |
| 2131 |
|
| 2132 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_256_A256CBC_HS512(c *C) { |
| 2133 |
//given |
| 2134 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.Pt1q6MNdaiVWhMnY7r6DVpkYQmzyIjhb0cj10LowP_FgMu1dOQVuNwhK14MO1ki1y1Pvxouct9wwmb5gE7jNJBy6vU-FrrY62WNr_hKL3Cq2030LlJwauv1XQrEE-GCw1srxOAsw6LNT14v4f0qjeW46mIHNX4CZMEO9ntwojWsHTNsh4Qk6SU1QlS3WbbVl7gjjfqTP54j2ZwZM38s7Cs4pSAChP04UbW6Uhrm65JSi0lyg25OBXIxMEt1z9WY8lnjuh3iL_WttnFn9lf5fUuuR2N70HwANz2mxH3CxjO0ygXJtV-FhFzz3HqI2-ELrve4Igj_2f2_S6OrRTWRucA.er5K9Gk0wp3wF_sq7ib7BQ.L80B9FGSjUbEblpJ6tuiaq6NAsW89YQGD0awxtE-irKN65PT8nndBd0hlel8RRThXRF0kiYYor2GpgvVVaoOzSQcwL-aDgNO7BeRsaOL5ku2NlyT1erbg_8jEVG5BFMM0-jCb4kD0jBKWYCGoB7qs_QQxZ394H5GPwG68vlizKEa8PoaNIM0at5oFT7EHPdmGmwQyQCHR43e6uN4k28PWNxjN9Ndo5lvlYnxnAyDGVDu8lCjozaA_ZTrEPS-UBb6lOEW39CXdwVk1MgvyQfswQ.yuDMf_77Wr9Er3FG1_0FwHXJTOVQPjzBwGoKEg81mQo" |
| 2135 |
|
| 2136 |
//when |
| 2137 |
test, _, err := Decode(token, PrivKey()) |
| 2138 |
|
| 2139 |
//then |
| 2140 |
c.Assert(err, IsNil) |
| 2141 |
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}`) |
| 2142 |
} |
| 2143 |
|
| 2144 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_256_A128GCM(c *C) { |
| 2145 |
//given |
| 2146 |
token := "eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.TkU8bSCiRjegZmVvgs2ShFawIB-tjEm4Ep_FfiZX_cIT065MDCanVkR76EY-SScbElDlKYeFB8eAfLRe0_eKm6b3uK7M89odlwZ57t0SfBCr4xSU2X6MS8v9_0h9MwS8cSsRDIroO77c8RiFpRh1IkvxO8OzMHSCC_UYp05-KsaoFwLLKHWeLmyjrR_0uI2aUibBrGeTNVyspbQG7kRmv5QZGEKpL4aa8KggCJHexZmDDvkV4IVn4HSlTAboVc6TljtWSzHmSVJckI8GlHWGC_97o7DIxWaQwjcjCjhxPSwXct43ZvYCpcl5KSV_DJMJPXnoAB6m5BBK2tN1-EbLkA.460VEh_C0JsW80gx.cYeTgJXacKbTbXWGWNKIm9DitmeiBvCzneyyG2UOZECBMdCEa5FdABrpyk-sWTZO9MRRdMkcS3cVj01qFfKQmaw0SVjqDnKdCa5JtyTSdWSVaeVFUFEDTk8lKZJm-dPwVCxJ_oD21JG_bfMN69sbSEQFUPdUKYUSpGnm9_psJlsLUNlNMLW2bIJMbtQz74Dt2N51N0kSqm9MCB0c5k-7Z5lDVFgIw-JSJqV8TF3kYdWo6dTBpv0f8xuGKYs2cA.1qCoVWt2PrFu1VFD6kZ7jA" |
| 2147 |
|
| 2148 |
//when |
| 2149 |
test, _, err := Decode(token, PrivKey()) |
| 2150 |
|
| 2151 |
//then |
| 2152 |
c.Assert(err, IsNil) |
| 2153 |
c.Assert(test, Equals, `{"sub":"alice","aud":["https://app-one.com","https://app-two.com"],"nbf":1731426506,"iss":"https://openid.net","exp":1731427106,"iat":1731426506,"jti":"ab98ac57-5742-466c-ae59-8a48c6a947f3"}`) |
| 2154 |
} |
| 2155 |
|
| 2156 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_384_A192GCM(c *C) { |
| 2157 |
//given |
| 2158 |
token := "eyJlbmMiOiJBMTkyR0NNIiwiYWxnIjoiUlNBLU9BRVAtMzg0In0.pT2_03Aa03PWky6L5LoW9UR2KYbdgQqpiU2lRsZxfKk2OUC-MPs6rAECylRtSPOWMYhW1NKaGrmt07jAi7gCs2ijwgpyD1VyM3GmmOrnsWwP_MW8WTWIpnLgaL1ajHjrlM3ZZuSFNLSw-O_-JfY6JHKUeCbq7Gta95l6AESDDGLxVW_wJnZLkNVqY-pq5_eBR1Gk1jOWpxb68MTr8k8gLivvuRRBWRiX4i52kcRFFaKcNp65ZmXTr3HOgf0BiGSzEZQFDwwpzGE5aaD8DcWEyn8R3LsxZU9puOILdkKo7MvHNkjZkTHWQFpe9L4Ppd8wX-fh4mLweyCCcJylzJHN1g.Vz8ymkRo6KT-ADV4.BmVs6Y4PE6zR2ALEDYjC8bCUQjALvsWwhbt9MU-Vo0mZpCIXZdwW8sAIF9n62GH7FPoNQbaXTXfpziyGPGFCxiB6StkppiGFo5Af4mGXx55YFNXghMkZfS9Oy3Ib0SbagF0GNR_cWXyfzanHCeskqcYOICEHwiAdONzwLhgCXt57R3TdoK6EL_wJKy6vhEL2pOsg5woj2P7NLuGezNUoB1vrpqTbySeoS8eZJ3Rz54_ShzdcVl8kBJ7WRRN_Iw.yErR3LUS8PbBClIwF7kI_Q" |
| 2159 |
|
| 2160 |
//when |
| 2161 |
test, _, err := Decode(token, PrivKey()) |
| 2162 |
|
| 2163 |
//then |
| 2164 |
c.Assert(err, IsNil) |
| 2165 |
c.Assert(test, Equals, `{"sub":"alice","aud":["https://app-one.com","https://app-two.com"],"nbf":1731426506,"iss":"https://openid.net","exp":1731427106,"iat":1731426506,"jti":"49c091f4-f176-4227-ab82-b236beac2b94"}`) |
| 2166 |
} |
| 2167 |
|
| 2168 |
func (s *TestSuite) TestDecrypt_RSA_OAEP_512_A256GCM(c *C) { |
| 2169 |
//given |
| 2170 |
token := "eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAtNTEyIn0.dDvBnxku8qBk0Ry8MRoIkWVszEsI0NKiBQtYnDQ6sq8mQyFp9dEbF-4_0a6_e6qZs5lyEjE-4y9Y-dV3rKymTXHqOVtsyUvrF_bGQ5rOThBkd08wcpEe7OiFIuWWcujJQ5p77IAkBlpedt3hb7tE2kbhMkocTSUXzWmWjLIka3teYUfbv2Rifacpj_XPXejDgYifVMnOcN7LFjbhEl7aajpy9nseWx9ihnAFbPdf7fT8cm9lEM8damUoFPIH4KUrHmAk72F49yT8OODjY-Sl93Q1vo1PbVMX-J6kTY3h0CcsAabnLs3Cn8OamHXxeWtQsWKmfazmOIp_uRCisTgwcg.hrJ7S_BfciovKcRB.YSqRYn0c-NQ3C86O7kpFev0Wt5RpOi_hHknLVgn04zwZGZGqS3zr7t5v-j4bHgouFhv1GdN5xvu0gFW1xXjo0_ZxcLNmHFmOAa3I7LtsPy4cW3Hkuy3wEblLg8cRoPTaLSvRPt9w2j_wy1beH9zrEqcf_KC3cKCzmoY0FatVwof5V9ICqtfFunv4h6ows-Fwhi_zzuL7zO5ydR-MH7D5Yhq1ni6SvRogp3Utfj2R_4jTGy8jGRRowfjsXR-GuQ.w15ByyQnK2G1_qnmkQU8QA" |
| 2171 |
|
| 2172 |
//when |
| 2173 |
test, _, err := Decode(token, PrivKey()) |
| 2174 |
|
| 2175 |
//then |
| 2176 |
c.Assert(err, IsNil) |
| 2177 |
c.Assert(test, Equals, `{"sub":"alice","aud":["https://app-one.com","https://app-two.com"],"nbf":1731426506,"iss":"https://openid.net","exp":1731427106,"iat":1731426506,"jti":"6278505b-6dcd-483c-8dd1-7c35b7d1a1e5"}`) |
| 2178 |
} |
| 2179 |
|
| 2180 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_256_A128GCM(c *C) { |
| 2181 |
//given |
| 2182 |
payload := `{"hello": "world"}` |
| 2183 |
|
| 2184 |
//when |
| 2185 |
test, err := Encrypt(payload, RSA_OAEP_256, A128GCM, PubKey()) |
| 2186 |
|
| 2187 |
fmt.Printf("\nRSA-OAEP-256 A128GCM = %v\n", test) |
| 2188 |
|
| 2189 |
//then |
| 2190 |
c.Assert(err, IsNil) |
| 2191 |
|
| 2192 |
parts := strings.Split(test, ".") |
| 2193 |
|
| 2194 |
c.Assert(len(parts), Equals, 5) |
| 2195 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTI4R0NNIn0") |
| 2196 |
c.Assert(len(parts[1]), Equals, 342) |
| 2197 |
c.Assert(len(parts[2]), Equals, 16) |
| 2198 |
c.Assert(len(parts[3]), Equals, 24) |
| 2199 |
c.Assert(len(parts[4]), Equals, 22) |
| 2200 |
|
| 2201 |
//make sure we consistent with ourselfs |
| 2202 |
t, _, _ := Decode(test, PrivKey()) |
| 2203 |
c.Assert(t, Equals, payload) |
| 2204 |
} |
| 2205 |
|
| 2206 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_256_A192GCM(c *C) { |
| 2207 |
//given |
| 2208 |
payload := `{"hello": "world"}` |
| 2209 |
|
| 2210 |
//when |
| 2211 |
test, err := Encrypt(payload, RSA_OAEP_256, A192GCM, PubKey()) |
| 2212 |
|
| 2213 |
fmt.Printf("\nRSA-OAEP-256 A192GCM = %v\n", test) |
| 2214 |
|
| 2215 |
//then |
| 2216 |
c.Assert(err, IsNil) |
| 2217 |
|
| 2218 |
parts := strings.Split(test, ".") |
| 2219 |
|
| 2220 |
c.Assert(len(parts), Equals, 5) |
| 2221 |
c.Assert(len(parts[0]), Equals, 51) |
| 2222 |
c.Assert(len(parts[1]), Equals, 342) |
| 2223 |
c.Assert(len(parts[2]), Equals, 16) |
| 2224 |
c.Assert(len(parts[3]), Equals, 24) |
| 2225 |
c.Assert(len(parts[4]), Equals, 22) |
| 2226 |
|
| 2227 |
//make sure we consistent with ourselfs |
| 2228 |
t, _, _ := Decode(test, PrivKey()) |
| 2229 |
c.Assert(t, Equals, payload) |
| 2230 |
} |
| 2231 |
|
| 2232 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_256_A256GCM(c *C) { |
| 2233 |
//given |
| 2234 |
payload := `{"hello": "world"}` |
| 2235 |
|
| 2236 |
//when |
| 2237 |
test, err := Encrypt(payload, RSA_OAEP_256, A256GCM, PubKey()) |
| 2238 |
|
| 2239 |
fmt.Printf("\nRSA-OAEP-256 A256GCM = %v\n", test) |
| 2240 |
|
| 2241 |
//then |
| 2242 |
c.Assert(err, IsNil) |
| 2243 |
|
| 2244 |
parts := strings.Split(test, ".") |
| 2245 |
|
| 2246 |
c.Assert(len(parts), Equals, 5) |
| 2247 |
c.Assert(len(parts[0]), Equals, 51) |
| 2248 |
c.Assert(len(parts[1]), Equals, 342) |
| 2249 |
c.Assert(len(parts[2]), Equals, 16) |
| 2250 |
c.Assert(len(parts[3]), Equals, 24) |
| 2251 |
c.Assert(len(parts[4]), Equals, 22) |
| 2252 |
|
| 2253 |
//make sure we consistent with ourselfs |
| 2254 |
t, _, _ := Decode(test, PrivKey()) |
| 2255 |
c.Assert(t, Equals, payload) |
| 2256 |
} |
| 2257 |
|
| 2258 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_384_A192GCM(c *C) { |
| 2259 |
//given |
| 2260 |
payload := `{"hello": "world"}` |
| 2261 |
|
| 2262 |
//when |
| 2263 |
test, err := Encrypt(payload, RSA_OAEP_384, A192GCM, PubKey()) |
| 2264 |
|
| 2265 |
fmt.Printf("\nRSA-OAEP-384 A192GCM = %v\n", test) |
| 2266 |
|
| 2267 |
//then |
| 2268 |
c.Assert(err, IsNil) |
| 2269 |
|
| 2270 |
parts := strings.Split(test, ".") |
| 2271 |
|
| 2272 |
c.Assert(len(parts), Equals, 5) |
| 2273 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUC0zODQiLCJlbmMiOiJBMTkyR0NNIn0") |
| 2274 |
c.Assert(len(parts[1]), Equals, 342) |
| 2275 |
c.Assert(len(parts[2]), Equals, 16) |
| 2276 |
c.Assert(len(parts[3]), Equals, 24) |
| 2277 |
c.Assert(len(parts[4]), Equals, 22) |
| 2278 |
|
| 2279 |
//make sure we consistent with ourselfs |
| 2280 |
t, _, _ := Decode(test, PrivKey()) |
| 2281 |
c.Assert(t, Equals, payload) |
| 2282 |
} |
| 2283 |
|
| 2284 |
func (s *TestSuite) TestEncrypt_RSA_OAEP_512_A256GCM(c *C) { |
| 2285 |
//given |
| 2286 |
payload := `{"hello": "world"}` |
| 2287 |
|
| 2288 |
//when |
| 2289 |
test, err := Encrypt(payload, RSA_OAEP_512, A256GCM, PubKey()) |
| 2290 |
|
| 2291 |
fmt.Printf("\nRSA-OAEP-512 A256GCM = %v\n", test) |
| 2292 |
|
| 2293 |
//then |
| 2294 |
c.Assert(err, IsNil) |
| 2295 |
|
| 2296 |
parts := strings.Split(test, ".") |
| 2297 |
|
| 2298 |
c.Assert(len(parts), Equals, 5) |
| 2299 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUC01MTIiLCJlbmMiOiJBMjU2R0NNIn0") |
| 2300 |
c.Assert(len(parts[1]), Equals, 342) |
| 2301 |
c.Assert(len(parts[2]), Equals, 16) |
| 2302 |
c.Assert(len(parts[3]), Equals, 24) |
| 2303 |
c.Assert(len(parts[4]), Equals, 22) |
| 2304 |
|
| 2305 |
//make sure we consistent with ourselfs |
| 2306 |
t, _, _ := Decode(test, PrivKey()) |
| 2307 |
c.Assert(t, Equals, payload) |
| 2308 |
} |
| 2309 |
|
| 2310 |
func (s *TestSuite) TestDecrypt_Deflated(c *C) { |
| 2311 |
//given |
| 2312 |
token := "eyJhbGciOiJSU0EtT0FFUCIsInppcCI6IkRFRiIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ.nXSS9jDwE0dXkcGI7UquZBhn2nsB2P8u-YSWEuTAgEeuV54qNU4SlE76bToI1z4LUuABHmZOv9S24xkF45b7Mrap_Fu4JXH8euXrQgKQb9o_HL5FvE8m4zk5Ow13MKGPvHvWKOaNEBFriwYIfPi6QBYrpuqn0BaANc_aMyInV0Fn7e8EAgVmvoagmy7Hxic2sPUeLEIlRCDSGa82mpiGusjo7VMJxymkhnMdKufpGPh4wod7pvgb-jDWasUHpsUkHqSKZxlrDQxcy1-Pu1G37TAnImlWPa9NU7500IXc-W07IJccXhR3qhA5QaIyBbmHY0j1Dn3808oSFOYSF85A9w.uwbZhK-8iNzcjvKRb1a2Ig.jxj1GfH9Ndu1y0b7NRz_yfmjrvX2rXQczyK9ZJGWTWfeNPGR_PZdJmddiam15Qtz7R-pzIeyR4_qQoMzOISkq6fDEvEWVZdHnnTUHQzCoGX1dZoG9jXEwfAk2G1vXYT2vynEQZ72xk0V_OBtKhpIAUEFsXwCUeLAAgjFNY4OGWZl_Kmv9RTGhnePZfVbrbwg.WuV64jlV03OZm99qHMP9wQ" |
| 2313 |
|
| 2314 |
//when |
| 2315 |
test, _, err := Decode(token, PrivKey()) |
| 2316 |
|
| 2317 |
//then |
| 2318 |
c.Assert(err, IsNil) |
| 2319 |
c.Assert(test, Equals, "{\"exp\":1392963710,\"sub\":\"alice\",\"nbf\":1392963110,\"aud\":[\"https:\\/\\/app-one.com\",\"https:\\/\\/app-two.com\"],\"iss\":\"https:\\/\\/openid.net\",\"jti\":\"9fa7a38a-28fd-421c-825c-8fab3bbf3fb4\",\"iat\":1392963110}") |
| 2320 |
} |
| 2321 |
|
| 2322 |
func (s *TestSuite) TestEncrypt_Deflated(c *C) { |
| 2323 |
//given |
| 2324 |
payload := `{"hello": "world"}` |
| 2325 |
|
| 2326 |
//when |
| 2327 |
test, err := Encrypt(payload, RSA_OAEP, A256GCM, PubKey(), Zip(DEF)) |
| 2328 |
|
| 2329 |
fmt.Printf("\nRSA-OAEP A256GCM DEF = %v\n", test) |
| 2330 |
|
| 2331 |
//then |
| 2332 |
c.Assert(err, IsNil) |
| 2333 |
|
| 2334 |
parts := strings.Split(test, ".") |
| 2335 |
|
| 2336 |
c.Assert(len(parts), Equals, 5) |
| 2337 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00iLCJ6aXAiOiJERUYifQ") |
| 2338 |
c.Assert(len(parts[2]), Equals, 16) |
| 2339 |
c.Assert(len(parts[3]), Equals, 32) |
| 2340 |
c.Assert(len(parts[4]), Equals, 22) |
| 2341 |
|
| 2342 |
//make sure we consistent with ourselfs |
| 2343 |
t, _, _ := Decode(test, PrivKey()) |
| 2344 |
c.Assert(t, Equals, payload) |
| 2345 |
} |
| 2346 |
|
| 2347 |
func (s *TestSuite) TestDecodeSignedHeader(c *C) { |
| 2348 |
//given |
| 2349 |
token := "eyJhbGciOiJSUzUxMiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.KP_mwCVRIxcF6ErdrzNcXZQDFGcL-Hlyocc4tIl3tJfzSfc7rz7qOLPjHpZ6UFH1ncd5TlpRc1B_pgvY-l0BNtx_s7n_QA55X4c1oeD8csrIoXQ6A6mtvdVGoSlGu2JnP6N2aqlDmlcefKqjl_Z-8nwDMGTMkDNhHKfHlIb2_Dliwxeq8LmNMREEdvNH2XVp_ffxBjiaKv2Eqbwc6I17241GCEmjDCvnagSgjX_5uu-da2H7TK2gtPJYUo8r9nzC7uzZJ5SB8suZH0COSofsP-9wvH0FESO40evCyEBylqg3bh9M9dIzeq8_bdTiC5kG93Fal44OEY8_Zm88wB_VjQ" |
| 2350 |
|
| 2351 |
//when |
| 2352 |
_, test, err := Decode(token, PubKey()) |
| 2353 |
|
| 2354 |
//then |
| 2355 |
c.Assert(err, IsNil) |
| 2356 |
c.Assert(test, DeepEquals, map[string]interface{}{"alg": "RS512", "cty": "text/plain"}) |
| 2357 |
} |
| 2358 |
|
| 2359 |
func (s *TestSuite) TestDecodeEncryptedHeader(c *C) { |
| 2360 |
//given |
| 2361 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.Pt1q6MNdaiVWhMnY7r6DVpkYQmzyIjhb0cj10LowP_FgMu1dOQVuNwhK14MO1ki1y1Pvxouct9wwmb5gE7jNJBy6vU-FrrY62WNr_hKL3Cq2030LlJwauv1XQrEE-GCw1srxOAsw6LNT14v4f0qjeW46mIHNX4CZMEO9ntwojWsHTNsh4Qk6SU1QlS3WbbVl7gjjfqTP54j2ZwZM38s7Cs4pSAChP04UbW6Uhrm65JSi0lyg25OBXIxMEt1z9WY8lnjuh3iL_WttnFn9lf5fUuuR2N70HwANz2mxH3CxjO0ygXJtV-FhFzz3HqI2-ELrve4Igj_2f2_S6OrRTWRucA.er5K9Gk0wp3wF_sq7ib7BQ.L80B9FGSjUbEblpJ6tuiaq6NAsW89YQGD0awxtE-irKN65PT8nndBd0hlel8RRThXRF0kiYYor2GpgvVVaoOzSQcwL-aDgNO7BeRsaOL5ku2NlyT1erbg_8jEVG5BFMM0-jCb4kD0jBKWYCGoB7qs_QQxZ394H5GPwG68vlizKEa8PoaNIM0at5oFT7EHPdmGmwQyQCHR43e6uN4k28PWNxjN9Ndo5lvlYnxnAyDGVDu8lCjozaA_ZTrEPS-UBb6lOEW39CXdwVk1MgvyQfswQ.yuDMf_77Wr9Er3FG1_0FwHXJTOVQPjzBwGoKEg81mQo" |
| 2362 |
|
| 2363 |
//when |
| 2364 |
_, test, err := Decode(token, PrivKey()) |
| 2365 |
|
| 2366 |
//then |
| 2367 |
c.Assert(err, IsNil) |
| 2368 |
c.Assert(test, DeepEquals, map[string]interface{}{"enc": "A256CBC-HS512", "alg": "RSA-OAEP-256"}) |
| 2369 |
} |
| 2370 |
|
| 2371 |
func (s *TestSuite) TestDecrypt_TwoPhased(c *C) { |
| 2372 |
//given |
| 2373 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0.Pt1q6MNdaiVWhMnY7r6DVpkYQmzyIjhb0cj10LowP_FgMu1dOQVuNwhK14MO1ki1y1Pvxouct9wwmb5gE7jNJBy6vU-FrrY62WNr_hKL3Cq2030LlJwauv1XQrEE-GCw1srxOAsw6LNT14v4f0qjeW46mIHNX4CZMEO9ntwojWsHTNsh4Qk6SU1QlS3WbbVl7gjjfqTP54j2ZwZM38s7Cs4pSAChP04UbW6Uhrm65JSi0lyg25OBXIxMEt1z9WY8lnjuh3iL_WttnFn9lf5fUuuR2N70HwANz2mxH3CxjO0ygXJtV-FhFzz3HqI2-ELrve4Igj_2f2_S6OrRTWRucA.er5K9Gk0wp3wF_sq7ib7BQ.L80B9FGSjUbEblpJ6tuiaq6NAsW89YQGD0awxtE-irKN65PT8nndBd0hlel8RRThXRF0kiYYor2GpgvVVaoOzSQcwL-aDgNO7BeRsaOL5ku2NlyT1erbg_8jEVG5BFMM0-jCb4kD0jBKWYCGoB7qs_QQxZ394H5GPwG68vlizKEa8PoaNIM0at5oFT7EHPdmGmwQyQCHR43e6uN4k28PWNxjN9Ndo5lvlYnxnAyDGVDu8lCjozaA_ZTrEPS-UBb6lOEW39CXdwVk1MgvyQfswQ.yuDMf_77Wr9Er3FG1_0FwHXJTOVQPjzBwGoKEg81mQo" |
| 2374 |
|
| 2375 |
//when |
| 2376 |
test, _, err := Decode(token, func(headers map[string]interface{}, payload string) interface{} { |
| 2377 |
//ensure that callback executed with correct arguments |
| 2378 |
c.Assert(headers, DeepEquals, map[string]interface{}{"alg": "RSA-OAEP-256", "enc": "A256CBC-HS512"}) |
| 2379 |
|
| 2380 |
return PrivKey() |
| 2381 |
}) |
| 2382 |
|
| 2383 |
//then |
| 2384 |
c.Assert(err, IsNil) |
| 2385 |
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}`) |
| 2386 |
} |
| 2387 |
|
| 2388 |
func (s *TestSuite) TestDecode_TwoPhased(c *C) { |
| 2389 |
//given |
| 2390 |
token := "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EVnmDMlz-oi05AQzts-R3aqWvaBlwVZddWkmaaHyMx5Phb2NSLgyI0kccpgjjAyo1S5KCB3LIMPfmxCX_obMKA" |
| 2391 |
|
| 2392 |
//when |
| 2393 |
test, _, err := Decode(token, func(headers map[string]interface{}, payload string) interface{} { |
| 2394 |
//ensure that callback executed with correct arguments |
| 2395 |
c.Assert(headers, DeepEquals, map[string]interface{}{"alg": "ES256", "cty": "text/plain"}) |
| 2396 |
c.Assert(payload, Equals, `{"hello": "world"}`) |
| 2397 |
|
| 2398 |
return Ecc256Public() |
| 2399 |
}) |
| 2400 |
|
| 2401 |
//then |
| 2402 |
c.Assert(err, IsNil) |
| 2403 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 2404 |
} |
| 2405 |
|
| 2406 |
func (s *TestSuite) TestDecode_TwoPhased_Error(c *C) { |
| 2407 |
//given |
| 2408 |
token := "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EVnmDMlz-oi05AQzts-R3aqWvaBlwVZddWkmaaHyMx5Phb2NSLgyI0kccpgjjAyo1S5KCB3LIMPfmxCX_obMKA" |
| 2409 |
|
| 2410 |
//when |
| 2411 |
test, _, err := Decode(token, func(headers map[string]interface{}, payload string) interface{} { |
| 2412 |
return errors.New("Test error") |
| 2413 |
}) |
| 2414 |
|
| 2415 |
//then |
| 2416 |
fmt.Printf("\ntwo phased err= %v\n", err) |
| 2417 |
c.Assert(err, NotNil) |
| 2418 |
c.Assert(test, Equals, "") |
| 2419 |
} |
| 2420 |
|
| 2421 |
func (s *TestSuite) TestSignWithExtraHeaders(c *C) { |
| 2422 |
//given |
| 2423 |
payload := `{"hello": "world"}` |
| 2424 |
|
| 2425 |
//when |
| 2426 |
test, err := Sign(payload, ES256, Ecc256Private(), Header("keyid", "111-222-333"), Header("trans-id", "aaa-bbb"), |
| 2427 |
Headers(map[string]interface{}{"alg": "RS256", "cty": "text/plain"})) |
| 2428 |
|
| 2429 |
fmt.Printf("\nES256 + extra headers = %v\n", test) |
| 2430 |
|
| 2431 |
//then |
| 2432 |
c.Assert(err, IsNil) |
| 2433 |
|
| 2434 |
parts := strings.Split(test, ".") |
| 2435 |
|
| 2436 |
c.Assert(len(parts), Equals, 3) |
| 2437 |
c.Assert(parts[0], Equals, "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHQvcGxhaW4iLCJrZXlpZCI6IjExMS0yMjItMzMzIiwidHJhbnMtaWQiOiJhYWEtYmJiIn0") |
| 2438 |
c.Assert(parts[1], Equals, "eyJoZWxsbyI6ICJ3b3JsZCJ9") |
| 2439 |
c.Assert(len(parts[2]), Equals, 86) |
| 2440 |
|
| 2441 |
//make sure we consistent with ourselfs |
| 2442 |
t, _, _ := Decode(test, Ecc256Public()) |
| 2443 |
c.Assert(t, Equals, payload) |
| 2444 |
} |
| 2445 |
|
| 2446 |
func (s *TestSuite) TestEncryptWithExtraHeaders(c *C) { |
| 2447 |
//given |
| 2448 |
payload := `{"hello": "world"}` |
| 2449 |
|
| 2450 |
//when |
| 2451 |
test, err := Encrypt(payload, ECDH_ES, A128CBC_HS256, Ecc256Public(), |
| 2452 |
Header("keyid", "111-222-333"), |
| 2453 |
Header("trans-id", "aaa-bbb"), |
| 2454 |
Headers(map[string]interface{}{"alg": "RS256", "cty": "text/plain", "zip": "DEFLATE"})) |
| 2455 |
|
| 2456 |
fmt.Printf("\nECDH-ES A128CBC_HS256 + extra headers = %v\n", test) |
| 2457 |
|
| 2458 |
//then |
| 2459 |
c.Assert(err, IsNil) |
| 2460 |
|
| 2461 |
parts := strings.Split(test, ".") |
| 2462 |
|
| 2463 |
c.Assert(len(parts), Equals, 5) |
| 2464 |
c.Assert(len(parts[0]), Equals, 312) |
| 2465 |
c.Assert(len(parts[1]), Equals, 0) |
| 2466 |
c.Assert(len(parts[2]), Equals, 22) |
| 2467 |
c.Assert(len(parts[3]), Equals, 43) |
| 2468 |
c.Assert(len(parts[4]), Equals, 22) |
| 2469 |
|
| 2470 |
//make sure we consistent with ourselfs |
| 2471 |
t, _, _ := Decode(test, Ecc256Private()) |
| 2472 |
c.Assert(t, Equals, payload) |
| 2473 |
} |
| 2474 |
|
| 2475 |
func (s *TestSuite) TestDecodeMissingAlgHeader(c *C) { |
| 2476 |
//given |
| 2477 |
token := "eyJjdHkiOiJ0ZXh0XC9wbGFpbiJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.chIoYWrQMA8XL5nFz6oLDJyvgHk2KA4BrFGrKymjC8E" |
| 2478 |
|
| 2479 |
//when |
| 2480 |
test, _, err := Decode(token, shaKey) |
| 2481 |
|
| 2482 |
fmt.Printf("\nmissing sign 'alg' header err= %v\n", err) |
| 2483 |
|
| 2484 |
//then |
| 2485 |
c.Assert(err, NotNil) |
| 2486 |
c.Assert(test, Equals, "") |
| 2487 |
} |
| 2488 |
|
| 2489 |
func (s *TestSuite) TestDecodeInvalidAlgHeader(c *C) { |
| 2490 |
//given |
| 2491 |
token := "eyJhbGciOjEyMywiY3R5IjoidGV4dFwvcGxhaW4ifQ.eyJoZWxsbyI6ICJ3b3JsZCJ9.chIoYWrQMA8XL5nFz6oLDJyvgHk2KA4BrFGrKymjC8E" |
| 2492 |
|
| 2493 |
//when |
| 2494 |
test, _, err := Decode(token, shaKey) |
| 2495 |
|
| 2496 |
fmt.Printf("\ninvalid sign 'alg' header err= %v\n", err) |
| 2497 |
|
| 2498 |
//then |
| 2499 |
c.Assert(err, NotNil) |
| 2500 |
c.Assert(test, Equals, "") |
| 2501 |
} |
| 2502 |
|
| 2503 |
func (s *TestSuite) TestDecryptMissingAlgHeader(c *C) { |
| 2504 |
//given |
| 2505 |
token := "eyJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.bje66yTjMUpyGzbt3QvPNOmCmUPowgEmoBHXw-pByhST2VBSs0_67JKDymKW0VpmQC5Qb7ZLC6nNG8YW5pxTZDOeTQLodhAvzoNAsrx4M2R_N58ZVqBPLKTq7FKi1NNd8oJ80dwWbOJ13dkLH68SlhOK5bhqKFgtbzalnglL2kq8Fki1GkN4YyFnS8-chC-mlrS5bJrPSHUF7oAsG_flL_e9-KzYqYTQgGCB3GYSo_pgalsp2rUO3Oz2Pfe9IEJNlX7R9wOT1nTT0UUg-lSzQ2oOaXNvNyaPgEa76mJ1nk7ZQq7ZNix1m8snjk0Vizd8EOFCSRyOGcp4mHMn7-s00Q.tMFMCdFNQXbhEnwE6mP_XQ.E_O_ZBtJ8P0FvhKOV_W98oxIySDgdd0up0c8FAjo-3OVZ_6XMEQYFDKVG_Zc3zkbaz1Z2hmc7D7M28RbhRdya3yJN6Hcv1KuXeZ9ociI7o739Ni_bPvv8xCmGxlASS5AF7N4JR7XjrWL-SYKGNL1p0XNTlPo3B3qYqgAY6jFNvlcjWupim-pQbWKNqPbO2KmSCtUzyKE5oHjsomH0hnQs0_DXv3cgQ_ZFLFZBc1tC4AjQ8QZex5kWg5BmlJDM5F_jD7QRhb7B1u4Mi563-AKVA.0lraw3IXMM6wPqUZVYA8pg" |
| 2506 |
|
| 2507 |
//when |
| 2508 |
test, _, err := Decode(token, shaKey) |
| 2509 |
|
| 2510 |
fmt.Printf("\nmissing encrypt 'alg' header err= %v\n", err) |
| 2511 |
|
| 2512 |
//then |
| 2513 |
c.Assert(err, NotNil) |
| 2514 |
c.Assert(test, Equals, "") |
| 2515 |
} |
| 2516 |
|
| 2517 |
func (s *TestSuite) TestDecryptInvalidAlgHeader(c *C) { |
| 2518 |
//given |
| 2519 |
token := "eyJhbGciOiAxMTEsICJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.bje66yTjMUpyGzbt3QvPNOmCmUPowgEmoBHXw-pByhST2VBSs0_67JKDymKW0VpmQC5Qb7ZLC6nNG8YW5pxTZDOeTQLodhAvzoNAsrx4M2R_N58ZVqBPLKTq7FKi1NNd8oJ80dwWbOJ13dkLH68SlhOK5bhqKFgtbzalnglL2kq8Fki1GkN4YyFnS8-chC-mlrS5bJrPSHUF7oAsG_flL_e9-KzYqYTQgGCB3GYSo_pgalsp2rUO3Oz2Pfe9IEJNlX7R9wOT1nTT0UUg-lSzQ2oOaXNvNyaPgEa76mJ1nk7ZQq7ZNix1m8snjk0Vizd8EOFCSRyOGcp4mHMn7-s00Q.tMFMCdFNQXbhEnwE6mP_XQ.E_O_ZBtJ8P0FvhKOV_W98oxIySDgdd0up0c8FAjo-3OVZ_6XMEQYFDKVG_Zc3zkbaz1Z2hmc7D7M28RbhRdya3yJN6Hcv1KuXeZ9ociI7o739Ni_bPvv8xCmGxlASS5AF7N4JR7XjrWL-SYKGNL1p0XNTlPo3B3qYqgAY6jFNvlcjWupim-pQbWKNqPbO2KmSCtUzyKE5oHjsomH0hnQs0_DXv3cgQ_ZFLFZBc1tC4AjQ8QZex5kWg5BmlJDM5F_jD7QRhb7B1u4Mi563-AKVA.0lraw3IXMM6wPqUZVYA8pg" |
| 2520 |
|
| 2521 |
//when |
| 2522 |
test, _, err := Decode(token, shaKey) |
| 2523 |
|
| 2524 |
fmt.Printf("\ninvalid encrypt 'alg' header err= %v\n", err) |
| 2525 |
|
| 2526 |
//then |
| 2527 |
c.Assert(err, NotNil) |
| 2528 |
c.Assert(test, Equals, "") |
| 2529 |
} |
| 2530 |
|
| 2531 |
func (s *TestSuite) TestDecryptMissingEncHeader(c *C) { |
| 2532 |
//given |
| 2533 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYifQ.bje66yTjMUpyGzbt3QvPNOmCmUPowgEmoBHXw-pByhST2VBSs0_67JKDymKW0VpmQC5Qb7ZLC6nNG8YW5pxTZDOeTQLodhAvzoNAsrx4M2R_N58ZVqBPLKTq7FKi1NNd8oJ80dwWbOJ13dkLH68SlhOK5bhqKFgtbzalnglL2kq8Fki1GkN4YyFnS8-chC-mlrS5bJrPSHUF7oAsG_flL_e9-KzYqYTQgGCB3GYSo_pgalsp2rUO3Oz2Pfe9IEJNlX7R9wOT1nTT0UUg-lSzQ2oOaXNvNyaPgEa76mJ1nk7ZQq7ZNix1m8snjk0Vizd8EOFCSRyOGcp4mHMn7-s00Q.tMFMCdFNQXbhEnwE6mP_XQ.E_O_ZBtJ8P0FvhKOV_W98oxIySDgdd0up0c8FAjo-3OVZ_6XMEQYFDKVG_Zc3zkbaz1Z2hmc7D7M28RbhRdya3yJN6Hcv1KuXeZ9ociI7o739Ni_bPvv8xCmGxlASS5AF7N4JR7XjrWL-SYKGNL1p0XNTlPo3B3qYqgAY6jFNvlcjWupim-pQbWKNqPbO2KmSCtUzyKE5oHjsomH0hnQs0_DXv3cgQ_ZFLFZBc1tC4AjQ8QZex5kWg5BmlJDM5F_jD7QRhb7B1u4Mi563-AKVA.0lraw3IXMM6wPqUZVYA8pg" |
| 2534 |
|
| 2535 |
//when |
| 2536 |
test, _, err := Decode(token, shaKey) |
| 2537 |
|
| 2538 |
fmt.Printf("\nmissing encrypt 'enc' header err= %v\n", err) |
| 2539 |
|
| 2540 |
//then |
| 2541 |
c.Assert(err, NotNil) |
| 2542 |
c.Assert(test, Equals, "") |
| 2543 |
} |
| 2544 |
|
| 2545 |
func (s *TestSuite) TestDecryptInvalidEncHeader(c *C) { |
| 2546 |
//given |
| 2547 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOjExMX0.bje66yTjMUpyGzbt3QvPNOmCmUPowgEmoBHXw-pByhST2VBSs0_67JKDymKW0VpmQC5Qb7ZLC6nNG8YW5pxTZDOeTQLodhAvzoNAsrx4M2R_N58ZVqBPLKTq7FKi1NNd8oJ80dwWbOJ13dkLH68SlhOK5bhqKFgtbzalnglL2kq8Fki1GkN4YyFnS8-chC-mlrS5bJrPSHUF7oAsG_flL_e9-KzYqYTQgGCB3GYSo_pgalsp2rUO3Oz2Pfe9IEJNlX7R9wOT1nTT0UUg-lSzQ2oOaXNvNyaPgEa76mJ1nk7ZQq7ZNix1m8snjk0Vizd8EOFCSRyOGcp4mHMn7-s00Q.tMFMCdFNQXbhEnwE6mP_XQ.E_O_ZBtJ8P0FvhKOV_W98oxIySDgdd0up0c8FAjo-3OVZ_6XMEQYFDKVG_Zc3zkbaz1Z2hmc7D7M28RbhRdya3yJN6Hcv1KuXeZ9ociI7o739Ni_bPvv8xCmGxlASS5AF7N4JR7XjrWL-SYKGNL1p0XNTlPo3B3qYqgAY6jFNvlcjWupim-pQbWKNqPbO2KmSCtUzyKE5oHjsomH0hnQs0_DXv3cgQ_ZFLFZBc1tC4AjQ8QZex5kWg5BmlJDM5F_jD7QRhb7B1u4Mi563-AKVA.0lraw3IXMM6wPqUZVYA8pg" |
| 2548 |
|
| 2549 |
//when |
| 2550 |
test, _, err := Decode(token, shaKey) |
| 2551 |
|
| 2552 |
fmt.Printf("\ninvalid encrypt 'enc' header err= %v\n", err) |
| 2553 |
|
| 2554 |
//then |
| 2555 |
c.Assert(err, NotNil) |
| 2556 |
c.Assert(test, Equals, "") |
| 2557 |
} |
| 2558 |
|
| 2559 |
func (s *TestSuite) TestDecodeBytes_HS512(c *C) { |
| 2560 |
//given |
| 2561 |
token := "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.AAECAwQFBgcICQ.iTZ3VKv6n2JdDxMyM4qRZMuiYZOOaZ-58yCvs48vRaCRYQZmbAK6q-DWuBNEutL1LorEVGo8LZC0LyE7b8L1UA" |
| 2562 |
|
| 2563 |
//when |
| 2564 |
test, _, err := DecodeBytes(token, shaKey) |
| 2565 |
|
| 2566 |
//then |
| 2567 |
c.Assert(err, IsNil) |
| 2568 |
c.Assert(test, DeepEquals, []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}) |
| 2569 |
} |
| 2570 |
|
| 2571 |
func (s *TestSuite) TestDecodeBytes_RSA_OAEP_A256GCM(c *C) { |
| 2572 |
//given |
| 2573 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0.G23wC6QtVVaxoCp9ijgvbK5veMJ6YvoQW_Zdcaxb_2-cNHBbRP8E44kDRVkHXXIj_gPlm1knqK9-y-7lyxhyVbG0w71gZnfSuOKegKwXO9KpCX60dc8NbkrlTSDDey5EbSjmoqLlnllajdCdkssrF1KFPzIcnct8ecfJkhxTeKnmjis8xSfGB2sk6HP8C8eYDAEjeO5qPuYmfGwpm4BaYycbylqv4r0zZpFMOADZx2oJw3u7aFe8DL-JYAo5WbfFukg30MBHAfNNiLMu1tLRrjXvcr9i7MeHaUGgo281d9B8d7KUonbwJSwi4Ov3Lm00zrGYFE5WTgtan3vb33ndpg.tLpzdIKoJeytyZv_.RKIL2pXKTmIa3g.5SjeG9R0jmNtgdNY-sMZKw" |
| 2574 |
|
| 2575 |
//when |
| 2576 |
test, _, err := DecodeBytes(token, PrivKey()) |
| 2577 |
|
| 2578 |
//then |
| 2579 |
c.Assert(err, IsNil) |
| 2580 |
c.Assert(test, DeepEquals, []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}) |
| 2581 |
} |
| 2582 |
|
| 2583 |
func (s *TestSuite) TestEncodeBytes_HS256(c *C) { |
| 2584 |
//given |
| 2585 |
payload := []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9} |
| 2586 |
|
| 2587 |
//when |
| 2588 |
test, err := SignBytes(payload, HS256, shaKey) |
| 2589 |
|
| 2590 |
fmt.Printf("\nHS256 (bytes) = %v\n", test) |
| 2591 |
|
| 2592 |
//then |
| 2593 |
c.Assert(err, IsNil) |
| 2594 |
c.Assert(test, Equals, "eyJhbGciOiJIUzI1NiJ9.AAECAwQFBgcICQ.HmKT9jcQJZVtDWPipYjkbyy7cdCMUjyUhiTw25B49Gc") |
| 2595 |
|
| 2596 |
//make sure we consistent with ourselfs |
| 2597 |
t, _, _ := DecodeBytes(test, shaKey) |
| 2598 |
c.Assert(t, DeepEquals, payload) |
| 2599 |
} |
| 2600 |
|
| 2601 |
func (s *TestSuite) TestEncryptBytes_RSA_OAEP_256_A128GCM(c *C) { |
| 2602 |
//given |
| 2603 |
payload := []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9} |
| 2604 |
|
| 2605 |
//when |
| 2606 |
test, err := EncryptBytes(payload, RSA_OAEP_256, A128GCM, PubKey()) |
| 2607 |
|
| 2608 |
fmt.Printf("\nRSA-OAEP-256 A128GCM (bytes) = %v\n", test) |
| 2609 |
|
| 2610 |
//then |
| 2611 |
c.Assert(err, IsNil) |
| 2612 |
|
| 2613 |
parts := strings.Split(test, ".") |
| 2614 |
|
| 2615 |
c.Assert(len(parts), Equals, 5) |
| 2616 |
c.Assert(parts[0], Equals, "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTI4R0NNIn0") |
| 2617 |
c.Assert(len(parts[1]), Equals, 342) |
| 2618 |
c.Assert(len(parts[2]), Equals, 16) |
| 2619 |
c.Assert(len(parts[3]), Equals, 14) |
| 2620 |
c.Assert(len(parts[4]), Equals, 22) |
| 2621 |
|
| 2622 |
//make sure we consistent with ourselfs |
| 2623 |
t, _, _ := DecodeBytes(test, PrivKey()) |
| 2624 |
c.Assert(t, DeepEquals, payload) |
| 2625 |
} |
| 2626 |
|
| 2627 |
func (s *TestSuite) TestDeregisterJwa(c *C) { |
| 2628 |
//given |
| 2629 |
alg := DeregisterJwa(PBES2_HS256_A128KW) |
| 2630 |
token := "eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwicDJjIjo4MTkyLCJwMnMiOiJiMFlFVmxMemtaNW9UUjBMIn0.dhPAhJ9kmaEbP-02VtEoPOF2QSEYM5085V6zYt1U1qIlVNRcHTGDgQ.4QAAq0dVQT41dQKDG7dhRA.H9MgJmesbU1ow6GCa0lEMwv8A_sHvgaWKkaMcdoj_z6O8LaMSgquxA-G85R_5hEILnHUnFllNJ48oJY7VmAJw0BQW73dMnn58u161S6Ftq7Mjxxq7bcksWvFTVtG5RsqqYSol5BZz5xm8Fcj-y5BMYMvrsCyQhYdeGEHkAvwzRdvZ8pGMsU2XPzl6GqxGjjuRh2vApAeNrj6MwKuD-k6AR0MH46EiNkVCmMkd2w8CNAXjJe9z97zky93xbxlOLozaC3NBRO2Q4bmdGdRg5y4Ew.xNqRi0ouQd7uo5UrPraedg" |
| 2631 |
|
| 2632 |
//when |
| 2633 |
test, _, err := Decode(token, shaKey) |
| 2634 |
|
| 2635 |
fmt.Printf("\nunknown 'alg' header err= %v\n", err) |
| 2636 |
|
| 2637 |
//then |
| 2638 |
RegisterJwa(alg) |
| 2639 |
c.Assert(err, NotNil) |
| 2640 |
c.Assert(test, Equals, "") |
| 2641 |
} |
| 2642 |
|
| 2643 |
func (s *TestSuite) TestDeregisterJwe(c *C) { |
| 2644 |
//given |
| 2645 |
alg := DeregisterJwe(A128CBC_HS256) |
| 2646 |
token := "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..3lClLoerWhxIc811QXDLbg.iFd5MNk2eWDlW3hbq7vTFLPJlC0Od_MSyWGakEn5kfYbbPk7BM_SxUMptwcvDnZ5uBKwwPAYOsHIm5IjZ79LKZul9ZnOtJONRvxWLeS9WZiX4CghOLZL7dLypKn-mB22xsmSUbtizMuNSdgJwUCxEmms7vYOpL0Che-0_YrOu3NmBCLBiZzdWVtSSvYw6Ltzbch4OAaX2ye_IIemJoU1VnrdW0y-AjPgnAUA-GY7CAKJ70leS1LyjTW8H_ecB4sDCkLpxNOUsWZs3DN0vxxSQw.bxrZkcOeBgFAo3t0585ZdQ" |
| 2647 |
|
| 2648 |
//when |
| 2649 |
test, _, err := Decode(token, shaKey) |
| 2650 |
|
| 2651 |
fmt.Printf("\nunknown 'enc' header err= %v\n", err) |
| 2652 |
|
| 2653 |
//then |
| 2654 |
RegisterJwe(alg) |
| 2655 |
c.Assert(err, NotNil) |
| 2656 |
c.Assert(test, Equals, "") |
| 2657 |
} |
| 2658 |
|
| 2659 |
func (s *TestSuite) TestDeregisterJws(c *C) { |
| 2660 |
//given |
| 2661 |
alg := DeregisterJws(HS256) |
| 2662 |
token := "eyJhbGciOiJIUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.chIoYWrQMA8XL5nFz6oLDJyvgHk2KA4BrFGrKymjC8E" |
| 2663 |
|
| 2664 |
//when |
| 2665 |
test, _, err := Decode(token, shaKey) |
| 2666 |
|
| 2667 |
fmt.Printf("\nunknown 'alg' header err= %v\n", err) |
| 2668 |
|
| 2669 |
//then |
| 2670 |
RegisterJws(alg) |
| 2671 |
c.Assert(err, NotNil) |
| 2672 |
c.Assert(test, Equals, "") |
| 2673 |
} |
| 2674 |
|
| 2675 |
func (s *TestSuite) TestDeregisterJwc(c *C) { |
| 2676 |
//given |
| 2677 |
alg := DeregisterJwc(DEF) |
| 2678 |
token := "eyJhbGciOiJSU0EtT0FFUCIsInppcCI6IkRFRiIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ.nXSS9jDwE0dXkcGI7UquZBhn2nsB2P8u-YSWEuTAgEeuV54qNU4SlE76bToI1z4LUuABHmZOv9S24xkF45b7Mrap_Fu4JXH8euXrQgKQb9o_HL5FvE8m4zk5Ow13MKGPvHvWKOaNEBFriwYIfPi6QBYrpuqn0BaANc_aMyInV0Fn7e8EAgVmvoagmy7Hxic2sPUeLEIlRCDSGa82mpiGusjo7VMJxymkhnMdKufpGPh4wod7pvgb-jDWasUHpsUkHqSKZxlrDQxcy1-Pu1G37TAnImlWPa9NU7500IXc-W07IJccXhR3qhA5QaIyBbmHY0j1Dn3808oSFOYSF85A9w.uwbZhK-8iNzcjvKRb1a2Ig.jxj1GfH9Ndu1y0b7NRz_yfmjrvX2rXQczyK9ZJGWTWfeNPGR_PZdJmddiam15Qtz7R-pzIeyR4_qQoMzOISkq6fDEvEWVZdHnnTUHQzCoGX1dZoG9jXEwfAk2G1vXYT2vynEQZ72xk0V_OBtKhpIAUEFsXwCUeLAAgjFNY4OGWZl_Kmv9RTGhnePZfVbrbwg.WuV64jlV03OZm99qHMP9wQ" |
| 2679 |
|
| 2680 |
//when |
| 2681 |
test, _, err := Decode(token, PrivKey()) |
| 2682 |
|
| 2683 |
fmt.Printf("\nunknown 'zip' header err= %v\n", err) |
| 2684 |
|
| 2685 |
//then |
| 2686 |
RegisterJwc(alg) |
| 2687 |
c.Assert(err, NotNil) |
| 2688 |
c.Assert(test, Equals, "") |
| 2689 |
} |
| 2690 |
|
| 2691 |
func (s *TestSuite) TestDecode_TwoPhased_MatchAlg(c *C) { |
| 2692 |
//given |
| 2693 |
token := "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EVnmDMlz-oi05AQzts-R3aqWvaBlwVZddWkmaaHyMx5Phb2NSLgyI0kccpgjjAyo1S5KCB3LIMPfmxCX_obMKA" |
| 2694 |
|
| 2695 |
//when |
| 2696 |
test, _, err := Decode(token, Alg(Ecc256Public(), "ES256")) |
| 2697 |
|
| 2698 |
//then |
| 2699 |
c.Assert(err, IsNil) |
| 2700 |
c.Assert(test, Equals, `{"hello": "world"}`) |
| 2701 |
} |
| 2702 |
|
| 2703 |
func (s *TestSuite) TestDecode_TwoPhased_MatchAlg_Invalid(c *C) { |
| 2704 |
//given |
| 2705 |
token := "eyJhbGciOiJFUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.EVnmDMlz-oi05AQzts-R3aqWvaBlwVZddWkmaaHyMx5Phb2NSLgyI0kccpgjjAyo1S5KCB3LIMPfmxCX_obMKA" |
| 2706 |
|
| 2707 |
//when |
| 2708 |
test, headers, err := Decode(token, Alg(Ecc256Public(), "RS256")) |
| 2709 |
|
| 2710 |
fmt.Printf("\nalg doesn't match err=%v\n", err) |
| 2711 |
|
| 2712 |
//then |
| 2713 |
c.Assert(headers, IsNil) |
| 2714 |
c.Assert(err, NotNil) |
| 2715 |
c.Assert(test, Equals, "") |
| 2716 |
} |
| 2717 |
|
| 2718 |
func (s *TestSuite) TestDecode_TwoPhased_MatchEnc(c *C) { |
| 2719 |
//given |
| 2720 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0.COuKvozBVi2vkEPpFdx0HTMpU9tmpP1lLngbmGn8RVphY-vjhVaduv8D_Ay_1j8LuMz4tgP98xWtbJkTyhxY1kBwXe0CgqFUOSJ1mTEPRkKSXpdFR7rT1Pv68qug2yKaXT_qcviyBerIcUVFbXBmtiYAosYO4kaPSOE1IvLadFOrMkxdZv6QiiCROzWgJNCCMgNQZGRoPhqLe3wrcxi86DhNO7Bpqq_yeNVyHdU_qObMuMVZIWWEQIDhiU4nE8WGJLG_NtKElc_nQwbmclL_YYgTiHsIAKWZCdj0nwfLe5mwJQN4r7pjakiUVzCbNNgI1-iBH1vJD5VCPxgWldzfYA.7cDs4wzbNDt1Kq40Q5ae4w.u1bR6ChVd90QkFIp3H6IkOCIMwf5aIKsQOvqgFangRLrDjctl5qO5jTHr1o1GwBQvAkRmaGSE7fRIwWB_l-Ayx2c2WDFOkVXFSR_D23GrWaLMLbugPItQd2Mny6H4QOzO3O0EK_Qm7frqwKQI3og72SB8DUqzEaKsrz7HR2z_qMa2CEEApxai_R6NIlAdMUbYvOfZx262MWFGrITBDmma-Mnqiz9WJUv2wexfwjROaaS4wXfkGy5B6ltESifpZZk5NerExR3GA6yX7cFqJc4pQ.FKcbLyB9eP1UXmxyliTu1_GQrnS-JtAB" |
| 2721 |
|
| 2722 |
//when |
| 2723 |
test, _, err := Decode(token, Enc(PrivKey(), "RSA-OAEP-256", "A192CBC-HS384")) |
| 2724 |
|
| 2725 |
//then |
| 2726 |
c.Assert(err, IsNil) |
| 2727 |
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}`) |
| 2728 |
} |
| 2729 |
|
| 2730 |
func (s *TestSuite) TestDecode_TwoPhased_MatchEnc_InvalidAlg(c *C) { |
| 2731 |
//given |
| 2732 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0.COuKvozBVi2vkEPpFdx0HTMpU9tmpP1lLngbmGn8RVphY-vjhVaduv8D_Ay_1j8LuMz4tgP98xWtbJkTyhxY1kBwXe0CgqFUOSJ1mTEPRkKSXpdFR7rT1Pv68qug2yKaXT_qcviyBerIcUVFbXBmtiYAosYO4kaPSOE1IvLadFOrMkxdZv6QiiCROzWgJNCCMgNQZGRoPhqLe3wrcxi86DhNO7Bpqq_yeNVyHdU_qObMuMVZIWWEQIDhiU4nE8WGJLG_NtKElc_nQwbmclL_YYgTiHsIAKWZCdj0nwfLe5mwJQN4r7pjakiUVzCbNNgI1-iBH1vJD5VCPxgWldzfYA.7cDs4wzbNDt1Kq40Q5ae4w.u1bR6ChVd90QkFIp3H6IkOCIMwf5aIKsQOvqgFangRLrDjctl5qO5jTHr1o1GwBQvAkRmaGSE7fRIwWB_l-Ayx2c2WDFOkVXFSR_D23GrWaLMLbugPItQd2Mny6H4QOzO3O0EK_Qm7frqwKQI3og72SB8DUqzEaKsrz7HR2z_qMa2CEEApxai_R6NIlAdMUbYvOfZx262MWFGrITBDmma-Mnqiz9WJUv2wexfwjROaaS4wXfkGy5B6ltESifpZZk5NerExR3GA6yX7cFqJc4pQ.FKcbLyB9eP1UXmxyliTu1_GQrnS-JtAB" |
| 2733 |
|
| 2734 |
//when |
| 2735 |
test, _, err := Decode(token, Enc(PrivKey(), "RSA-OAEP-256", "A256CBC-HS512")) |
| 2736 |
|
| 2737 |
fmt.Printf("\nalg/enc doesn't match err=%v\n", err) |
| 2738 |
|
| 2739 |
//then |
| 2740 |
c.Assert(err, NotNil) |
| 2741 |
c.Assert(test, Equals, "") |
| 2742 |
} |
| 2743 |
|
| 2744 |
func (s *TestSuite) TestDecode_TwoPhased_MatchEnc_InvalidEnc(c *C) { |
| 2745 |
//given |
| 2746 |
token := "eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMTkyQ0JDLUhTMzg0In0.COuKvozBVi2vkEPpFdx0HTMpU9tmpP1lLngbmGn8RVphY-vjhVaduv8D_Ay_1j8LuMz4tgP98xWtbJkTyhxY1kBwXe0CgqFUOSJ1mTEPRkKSXpdFR7rT1Pv68qug2yKaXT_qcviyBerIcUVFbXBmtiYAosYO4kaPSOE1IvLadFOrMkxdZv6QiiCROzWgJNCCMgNQZGRoPhqLe3wrcxi86DhNO7Bpqq_yeNVyHdU_qObMuMVZIWWEQIDhiU4nE8WGJLG_NtKElc_nQwbmclL_YYgTiHsIAKWZCdj0nwfLe5mwJQN4r7pjakiUVzCbNNgI1-iBH1vJD5VCPxgWldzfYA.7cDs4wzbNDt1Kq40Q5ae4w.u1bR6ChVd90QkFIp3H6IkOCIMwf5aIKsQOvqgFangRLrDjctl5qO5jTHr1o1GwBQvAkRmaGSE7fRIwWB_l-Ayx2c2WDFOkVXFSR_D23GrWaLMLbugPItQd2Mny6H4QOzO3O0EK_Qm7frqwKQI3og72SB8DUqzEaKsrz7HR2z_qMa2CEEApxai_R6NIlAdMUbYvOfZx262MWFGrITBDmma-Mnqiz9WJUv2wexfwjROaaS4wXfkGy5B6ltESifpZZk5NerExR3GA6yX7cFqJc4pQ.FKcbLyB9eP1UXmxyliTu1_GQrnS-JtAB" |
| 2747 |
|
| 2748 |
//when |
| 2749 |
test, _, err := Decode(token, Enc(PrivKey(), "RSA-OAEP", "A192CBC-HS384")) |
| 2750 |
|
| 2751 |
fmt.Printf("\nalg/enc doesn't match err=%v\n", err) |
| 2752 |
|
| 2753 |
//then |
| 2754 |
c.Assert(err, NotNil) |
| 2755 |
c.Assert(test, Equals, "") |
| 2756 |
} |
| 2757 |
|
| 2758 |
// test utils |
| 2759 |
func PubKey() *rsa.PublicKey { |
| 2760 |
key, _ := Rsa.ReadPublic([]byte(pubKey)) |
| 2761 |
return key |
| 2762 |
} |
| 2763 |
|
| 2764 |
func PrivKey() *rsa.PrivateKey { |
| 2765 |
key, _ := Rsa.ReadPrivate([]byte(privKey)) |
| 2766 |
return key |
| 2767 |
} |
| 2768 |
|
| 2769 |
func Ecc256Public() *ecdsa.PublicKey { |
| 2770 |
return ecc.NewPublic([]byte{4, 114, 29, 223, 58, 3, 191, 170, 67, 128, 229, 33, 242, 178, 157, 150, 133, 25, 209, 139, 166, 69, 55, 26, 84, 48, 169, 165, 67, 232, 98, 9}, |
| 2771 |
[]byte{131, 116, 8, 14, 22, 150, 18, 75, 24, 181, 159, 78, 90, 51, 71, 159, 214, 186, 250, 47, 207, 246, 142, 127, 54, 183, 72, 72, 253, 21, 88, 53}) |
| 2772 |
} |
| 2773 |
|
| 2774 |
func Ecc256Private() *ecdsa.PrivateKey { |
| 2775 |
return ecc.NewPrivate([]byte{4, 114, 29, 223, 58, 3, 191, 170, 67, 128, 229, 33, 242, 178, 157, 150, 133, 25, 209, 139, 166, 69, 55, 26, 84, 48, 169, 165, 67, 232, 98, 9}, |
| 2776 |
[]byte{131, 116, 8, 14, 22, 150, 18, 75, 24, 181, 159, 78, 90, 51, 71, 159, 214, 186, 250, 47, 207, 246, 142, 127, 54, 183, 72, 72, 253, 21, 88, 53}, |
| 2777 |
[]byte{42, 148, 231, 48, 225, 196, 166, 201, 23, 190, 229, 199, 20, 39, 226, 70, 209, 148, 29, 70, 125, 14, 174, 66, 9, 198, 80, 251, 95, 107, 98, 206}) |
| 2778 |
} |
| 2779 |
|
| 2780 |
func Ecc384Public() *ecdsa.PublicKey { |
| 2781 |
return ecc.NewPublic([]byte{70, 151, 220, 179, 62, 0, 79, 232, 114, 64, 58, 75, 91, 209, 232, 128, 7, 137, 151, 42, 13, 148, 15, 133, 93, 215, 7, 3, 136, 124, 14, 101, 242, 207, 192, 69, 212, 145, 88, 59, 222, 33, 127, 46, 30, 218, 175, 79}, |
| 2782 |
[]byte{189, 202, 196, 30, 153, 53, 22, 122, 171, 4, 188, 42, 71, 2, 9, 193, 191, 17, 111, 180, 78, 6, 110, 153, 240, 147, 203, 45, 152, 236, 181, 156, 232, 223, 227, 148, 68, 148, 221, 176, 57, 149, 44, 203, 83, 85, 75, 55}) |
| 2783 |
} |
| 2784 |
|
| 2785 |
func Ecc384Private() *ecdsa.PrivateKey { |
| 2786 |
return ecc.NewPrivate([]byte{70, 151, 220, 179, 62, 0, 79, 232, 114, 64, 58, 75, 91, 209, 232, 128, 7, 137, 151, 42, 13, 148, 15, 133, 93, 215, 7, 3, 136, 124, 14, 101, 242, 207, 192, 69, 212, 145, 88, 59, 222, 33, 127, 46, 30, 218, 175, 79}, |
| 2787 |
[]byte{189, 202, 196, 30, 153, 53, 22, 122, 171, 4, 188, 42, 71, 2, 9, 193, 191, 17, 111, 180, 78, 6, 110, 153, 240, 147, 203, 45, 152, 236, 181, 156, 232, 223, 227, 148, 68, 148, 221, 176, 57, 149, 44, 203, 83, 85, 75, 55}, |
| 2788 |
[]byte{137, 199, 183, 105, 188, 90, 128, 82, 116, 47, 161, 100, 221, 97, 208, 64, 173, 247, 9, 42, 186, 189, 181, 110, 24, 225, 254, 136, 75, 156, 242, 209, 94, 218, 58, 14, 33, 190, 15, 82, 141, 238, 207, 214, 159, 140, 247, 139}) |
| 2789 |
} |
| 2790 |
|
| 2791 |
func Ecc512Public() *ecdsa.PublicKey { |
| 2792 |
return ecc.NewPublic([]byte{0, 248, 73, 203, 53, 184, 34, 69, 111, 217, 230, 255, 108, 212, 241, 229, 95, 239, 93, 131, 100, 37, 86, 152, 87, 98, 170, 43, 25, 35, 80, 137, 62, 112, 197, 113, 138, 116, 114, 55, 165, 128, 8, 139, 148, 237, 109, 121, 40, 205, 3, 61, 127, 28, 195, 58, 43, 228, 224, 228, 82, 224, 219, 148, 204, 96}, |
| 2793 |
[]byte{0, 60, 71, 97, 112, 106, 35, 121, 80, 182, 20, 167, 143, 8, 246, 108, 234, 160, 193, 10, 3, 148, 45, 11, 58, 177, 190, 172, 26, 178, 188, 240, 91, 25, 67, 79, 64, 241, 203, 65, 223, 218, 12, 227, 82, 178, 66, 160, 19, 194, 217, 172, 61, 250, 23, 78, 218, 130, 160, 105, 216, 208, 235, 124, 46, 32}) |
| 2794 |
} |
| 2795 |
|
| 2796 |
func Ecc512Private() *ecdsa.PrivateKey { |
| 2797 |
return ecc.NewPrivate([]byte{0, 248, 73, 203, 53, 184, 34, 69, 111, 217, 230, 255, 108, 212, 241, 229, 95, 239, 93, 131, 100, 37, 86, 152, 87, 98, 170, 43, 25, 35, 80, 137, 62, 112, 197, 113, 138, 116, 114, 55, 165, 128, 8, 139, 148, 237, 109, 121, 40, 205, 3, 61, 127, 28, 195, 58, 43, 228, 224, 228, 82, 224, 219, 148, 204, 96}, |
| 2798 |
[]byte{0, 60, 71, 97, 112, 106, 35, 121, 80, 182, 20, 167, 143, 8, 246, 108, 234, 160, 193, 10, 3, 148, 45, 11, 58, 177, 190, 172, 26, 178, 188, 240, 91, 25, 67, 79, 64, 241, 203, 65, 223, 218, 12, 227, 82, 178, 66, 160, 19, 194, 217, 172, 61, 250, 23, 78, 218, 130, 160, 105, 216, 208, 235, 124, 46, 32}, |
| 2799 |
[]byte{0, 222, 129, 9, 133, 207, 123, 116, 176, 83, 95, 169, 29, 121, 160, 137, 22, 21, 176, 59, 203, 129, 62, 111, 19, 78, 14, 174, 20, 211, 56, 160, 83, 42, 74, 219, 208, 39, 231, 33, 84, 114, 71, 106, 109, 161, 116, 243, 166, 146, 252, 231, 137, 228, 99, 149, 152, 123, 201, 157, 155, 131, 181, 106, 179, 112}) |
| 2800 |
} |