From 00efd4a4c9dcdc17ac57c29545e1c8ecc29d513b Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Wed, 6 Jan 2016 14:04:25 +0000 Subject: [PATCH] Update jose2go to latest to fix #239 This seems to have never been applied; fixes Arm build Signed-off-by: Justin Cormack --- Godeps/Godeps.json | 3 +- .../github.com/dvsekhvalnov/jose2go/README.md | 86 +- .../dvsekhvalnov/jose2go/aes/ecb.go | 32 +- .../dvsekhvalnov/jose2go/aes/ecb_test.go | 38 - .../dvsekhvalnov/jose2go/aes/key_wrap_test.go | 240 -- .../dvsekhvalnov/jose2go/arrays/arrays.go | 100 +- .../jose2go/arrays/arrays_test.go | 80 - .../jose2go/base64url/base64url_test.go | 40 - .../dvsekhvalnov/jose2go/compact/compact.go | 37 +- .../jose2go/compact/compact_test.go | 90 - .../github.com/dvsekhvalnov/jose2go/jose.go | 85 +- .../dvsekhvalnov/jose2go/jose_test.go | 2245 ----------------- .../jose2go/kdf/nist_sp800_56a.go | 6 +- .../jose2go/kdf/nist_sp800_56a_test.go | 57 - .../dvsekhvalnov/jose2go/kdf/pbkdf2.go | 2 +- .../dvsekhvalnov/jose2go/kdf/pbkdf2_test.go | 112 - .../dvsekhvalnov/jose2go/keys/ecc/ecc_test.go | 113 - .../dvsekhvalnov/jose2go/keys/rsa/rsa_test.go | 85 - .../jose2go/padding/align_test.go | 52 - .../jose2go/padding/pkcs7_test.go | 109 - 20 files changed, 245 insertions(+), 3367 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/key_wrap_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/arrays/arrays_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/base64url/base64url_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/compact/compact_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/jose_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/ecc/ecc_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/rsa/rsa_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/align_test.go delete mode 100644 Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/pkcs7_test.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index aeee6da1f5..a9f4d1dbdf 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -101,7 +101,8 @@ }, { "ImportPath": "github.com/dvsekhvalnov/jose2go", - "Rev": "5307afb3bb6169b0f68cdf519a5964c843344441" + "Comment": "v1.2", + "Rev": "6387d3c1f5abd8443b223577d5a7e0f4e0e5731f" }, { "ImportPath": "github.com/go-sql-driver/mysql", diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/README.md b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/README.md index 88f4299018..2a75db640b 100644 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/README.md +++ b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/README.md @@ -10,11 +10,14 @@ Extensively unit tested and cross tested (100+ tests) for compatibility with [jo ## Status -Used in production. GA ready. Current version is 1.1 +Used in production. GA ready. Current version is 1.2 ## Important v1.2 breaks `jose.Decode` interface by returning 3 values instead of 2. +v1.2 deprecates `jose.Compress` method in favor of using configuration options to `jose.Encrypt`, +the method will be removed in next release. + ###Migration to v1.2 Pre v1.2 decoding: @@ -28,6 +31,17 @@ Should be updated to v1.2: payload, headers, err := jose.Decode(token,sharedKey) ``` +Pre v1.2 compression: + +```Go +token,err := jose.Compress(payload,jose.DIR,jose.A128GCM,jose.DEF, key) +``` + +Should be update to v1.2: + +```Go +token, err := jose.Encrypt(payload, jose.DIR, jose.A128GCM, key, jose.Zip(jose.DEF)) +``` ## Supported JWA algorithms @@ -368,15 +382,15 @@ import ( func main() { - payload := `{"hello": "world"}` + payload := `{"hello": "world"}` - sharedKey :=[]byte{194,164,235,6,138,248,171,239,24,216,11,22,137,199,215,133} + sharedKey := []byte{194, 164, 235, 6, 138, 248, 171, 239, 24, 216, 11, 22, 137, 199, 215, 133} - token,err := jose.Compress(payload,jose.DIR,jose.A128GCM,jose.DEF, sharedKey) + token, err := jose.Encrypt(payload, jose.DIR, jose.A128GCM, sharedKey, jose.Zip(jose.DEF)) - if(err==nil) { + if err == nil { //go use token - fmt.Printf("\nDIR A128GCM DEFLATED= %v\n",token) + fmt.Printf("\nDIR A128GCM DEFLATED= %v\n", token) } } ``` @@ -583,6 +597,64 @@ func main() { } ``` +### Adding extra headers +It's possible to pass additional headers while encoding token. **jose2go** provides convenience configuration helpers: `Header(name string, value interface{})` and `Headers(headers map[string]interface{})` that can be passed to `Sign(..)` and `Encrypt(..)` calls. + +Note: **jose2go** do not allow to override `alg`, `enc` and `zip` headers. + +Example of signing with extra headers: +```Go + token, err := jose.Sign(payload, jose.ES256, key, + jose.Header("keyid", "111-222-333"), + jose.Header("trans-id", "aaa-bbb")) +``` + +Encryption with extra headers: +```Go +token, err := jose.Encrypt(payload, jose.DIR, jose.A128GCM, sharedKey, + jose.Headers(map[string]interface{}{"keyid": "111-22-33", "cty": "text/plain"})) +``` + +### Two phase validation +In some cases validation (decoding) key can be unknown prior to examining token content. For instance one can use different keys per token issuer or rely on headers information to determine which key to use, do logging or other things. + +**jose2go** allows to pass `func(headers map[string]interface{}, payload string) key interface{}` callback instead of key to `jose.Decode(..)`. Callback will be executed prior to decoding and integrity validation and will recieve parsed headers and payload as is (for encrypted tokens it will be cipher text). Callback should return key to be used for actual decoding process. + +Example of decoding token with callback: + +```Go +package main + +import ( + "crypto/rsa" + "fmt" + "github.com/dvsekhvalnov/jose2go" + "github.com/dvsekhvalnov/jose2go/keys/rsa" + "io/ioutil" +) + +func main() { + + token := "eyJhbGciOiJSUzI1NiIsImN0eSI6InRleHRcL3BsYWluIn0.eyJoZWxsbyI6ICJ3b3JsZCJ9.NL_dfVpZkhNn4bZpCyMq5TmnXbT4yiyecuB6Kax_lV8Yq2dG8wLfea-T4UKnrjLOwxlbwLwuKzffWcnWv3LVAWfeBxhGTa0c4_0TX_wzLnsgLuU6s9M2GBkAIuSMHY6UTFumJlEeRBeiqZNrlqvmAzQ9ppJHfWWkW4stcgLCLMAZbTqvRSppC1SMxnvPXnZSWn_Fk_q3oGKWw6Nf0-j-aOhK0S0Lcr0PV69ZE4xBYM9PUS1MpMe2zF5J3Tqlc1VBcJ94fjDj1F7y8twmMT3H1PI9RozO-21R0SiXZ_a93fxhE_l_dj5drgOek7jUN9uBDjkXUwJPAyp9YPehrjyLdw" + + payload, _, err := jose.Decode(token, + func(headers map[string]interface{}, payload string) interface{} { + //log something + fmt.Printf("\nHeaders before decoding: %v\n", headers) + fmt.Printf("\nPayload before decoding: %v\n", payload) + + //lookup key based on keyid header as en example + //or lookup based on something from payload, e.g. 'iss' claim for instance + return FindKey(headers['keyid']) + }) + + if err == nil { + //go use token + fmt.Printf("\ndecoded payload = %v\n", payload) + } +} +``` + ### Dealing with keys **jose2go** provides several helper methods to simplify loading & importing of elliptic and rsa keys. Import `jose2go/keys/rsa` or `jose2go/keys/ecc` respectively: @@ -733,6 +805,8 @@ Checkout `jose_test.go` for more examples. ##Changelog ### 1.2 - interface to access token headers after decoding +- interface to provide extra headers for token encoding +- two-phase validation support ### 1.1 - security and bug fixes diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb.go index 7f3a46b9c7..ec9af99dce 100644 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb.go +++ b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb.go @@ -14,53 +14,53 @@ type ecbDecrypter ecb // NewECBEncrypter creates BlockMode for AES encryption in ECB mode func NewECBEncrypter(b cipher.Block) cipher.BlockMode { - return &ecbEncrypter {b:b} + return &ecbEncrypter{b: b} } // NewECBDecrypter creates BlockMode for AES decryption in ECB mode func NewECBDecrypter(b cipher.Block) cipher.BlockMode { - return &ecbDecrypter {b:b} + return &ecbDecrypter{b: b} } func (x *ecbEncrypter) BlockSize() int { return x.b.BlockSize() } func (x *ecbDecrypter) BlockSize() int { return x.b.BlockSize() } -func (x *ecbDecrypter) CryptBlocks(dst, src []byte) { +func (x *ecbDecrypter) CryptBlocks(dst, src []byte) { bs := x.BlockSize() - - if len(src) % bs != 0 { + + if len(src)%bs != 0 { panic("ecbDecrypter.CryptBlocks(): input not full blocks") } - + if len(dst) < len(src) { - panic("ecbDecrypter.CryptBlocks(): output smaller than input") + panic("ecbDecrypter.CryptBlocks(): output smaller than input") } - + if len(src) == 0 { return } - + for len(src) > 0 { x.b.Decrypt(dst, src) src = src[bs:] - } + } } func (x *ecbEncrypter) CryptBlocks(dst, src []byte) { bs := x.BlockSize() - - if len(src) % bs != 0 { + + if len(src)%bs != 0 { panic("ecbEncrypter.CryptBlocks(): input not full blocks") } - + if len(dst) < len(src) { - panic("ecbEncrypter.CryptBlocks(): output smaller than input") + panic("ecbEncrypter.CryptBlocks(): output smaller than input") } - + if len(src) == 0 { return } - + for len(src) > 0 { x.b.Encrypt(dst, src) src = src[bs:] diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb_test.go deleted file mode 100644 index 67649bf8a8..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/ecb_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package aes - -import ( - // "fmt" - "crypto/aes" - // "crypto/cipher" - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestNewECBEncryptor(c *C) { - //given - plaintext := []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255} - kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} - block, _ := aes.NewCipher(kek) - - test := make([]byte,len(plaintext)) - - //when - NewECBEncrypter(block).CryptBlocks(test,plaintext) - - //then - c.Assert(test, DeepEquals, []byte{105,196,224,216,106,123,4,48,216,205,183,128,112,180,197,90}) -} - -func (s *TestSuite) TestNewECBDecryptor(c *C) { - //given - ciphertext := []byte{105,196,224,216,106,123,4,48,216,205,183,128,112,180,197,90} - kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} - block, _ := aes.NewCipher(kek) - - test := make([]byte,len(ciphertext)) - - //when - NewECBDecrypter(block).CryptBlocks(test,ciphertext) - - //then - c.Assert(test, DeepEquals, []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}) -} diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/key_wrap_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/key_wrap_test.go deleted file mode 100644 index e6a0accb77..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/aes/key_wrap_test.go +++ /dev/null @@ -1,240 +0,0 @@ -package aes - -import ( - "testing" - // "fmt" - . "gopkg.in/check.v1" - // "github.com/dvsekhvalnov/jose2go/arrays" -) - -func Test(t *testing.T) { TestingT(t) } -type TestSuite struct{} -var _ = Suite(&TestSuite{}) - -func (s *TestSuite) TestWrap_128Key_128Kek(c *C) { - //given (Section 4.1) - - //000102030405060708090A0B0C0D0E0F - kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} - - //00112233445566778899AABBCCDDEEFF - key := []byte{0,17,34,51,68,85,102,119,136,153,170,187,204,221,238,255} - - //1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5 - expected := []byte{ 31, 166, 139, 10, 129, 18, 180, 71, 174, 243, 75, 216, 251, 90, 123, 130, 157, 62, 134,35, 113, 210, 207, 229} - - //when - test,_ := KeyWrap(key, kek); - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Unwrap128Key_128Kek(c *C) { - //given (Section 4.1) - - //000102030405060708090A0B0C0D0E0F - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } - - //00112233445566778899AABBCCDDEEFF - expected := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 } - - //1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5 - key := []byte{ 31, 166, 139, 10, 129, 18, 180, 71, 174, 243, 75, 216, 251, 90, 123, 130, 157, 62, 134, 35, 113, 210, 207, 229 } - - //when - test,_ := KeyUnwrap(key, kek) - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Wrap_128Key_192Kek(c *C) { - //given (Section 4.2) - - //000102030405060708090A0B0C0D0E0F1011121314151617 - kek := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23} - - //00112233445566778899AABBCCDDEEFF - key := []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255} - - //96778B25AE6CA435F92B5B97C050AED2468AB8A17AD84E5D - expected := []byte{150, 119, 139, 37, 174, 108, 164, 53, 249, 43, 91, 151, 192, 80, 174, 210, 70, 138, 184, 161, 122, 216, 78, 93} - - //when - test,_ := KeyWrap(key, kek); - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Unwrap128Key_192Kek(c *C) { - //given (Section 4.2) - - //000102030405060708090A0B0C0D0E0F1011121314151617 - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 } - - //00112233445566778899AABBCCDDEEFF - expected := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 } - - //96778B25AE6CA435F92B5B97C050AED2468AB8A17AD84E5D - key := []byte{ 150, 119, 139, 37, 174, 108, 164, 53, 249, 43, 91, 151, 192, 80, 174, 210, 70, 138, 184, 161, 122, 216, 78, 93 } - - //when - test,_ := KeyUnwrap(key, kek) - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Wrap_128Key_256Kek(c *C) { - //given (Section 4.3) - - //000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F - kek := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31} - - //00112233445566778899AABBCCDDEEFF - key := []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255} - - //64E8C3F9CE0F5BA263E9777905818A2A93C8191E7D6E8AE7 - expected := []byte{100, 232, 195, 249, 206, 15, 91, 162, 99, 233, 119, 121, 5, 129, 138, 42, 147, 200, 25, 30, 125, 110, 138, 231} - - //when - test,_ := KeyWrap(key, kek); - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Unwrap128Key_256Kek(c *C) { - //given (Section 4.3) - - //000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } - - //00112233445566778899AABBCCDDEEFF - expected := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 } - - //64E8C3F9CE0F5BA263E9777905818A2A93C8191E7D6E8AE7 - key := []byte{ 100, 232, 195, 249, 206, 15, 91, 162, 99, 233, 119, 121, 5, 129, 138, 42, 147, 200, 25, 30, 125, 110, 138, 231 } - - //when - test,_ := KeyUnwrap(key, kek) - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Wrap_192Key_192Kek(c *C) { - //given (Section 4.4) - - //000102030405060708090A0B0C0D0E0F1011121314151617 - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 } - - //00112233445566778899AABBCCDDEEFF0001020304050607 - key := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 0, 1, 2, 3, 4, 5, 6, 7 } - - //031D33264E15D33268F24EC260743EDCE1C6C7DDEE725A936BA814915C6762D2 - expected := []byte{ 3, 29, 51, 38, 78, 21, 211, 50, 104, 242, 78, 194, 96, 116, 62, 220, 225, 198, 199, 221, 238, 114, 90, 147, 107, 168, 20, 145, 92, 103, 98, 210 } - - //when - test,_ := KeyWrap(key, kek); - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Unwrap192Key_192Kek(c *C) { - //given (Section 4.4) - - //000102030405060708090A0B0C0D0E0F1011121314151617 - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 } - - //00112233445566778899AABBCCDDEEFF0001020304050607 - expected := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 0, 1, 2, 3, 4, 5, 6, 7 } - - //031D33264E15D33268F24EC260743EDCE1C6C7DDEE725A936BA814915C6762D2 - key := []byte{ 3, 29, 51, 38, 78, 21, 211, 50, 104, 242, 78, 194, 96, 116, 62, 220, 225, 198, 199, 221, 238, 114, 90, 147, 107, 168, 20, 145, 92, 103, 98, 210 } - - //when - test,_ := KeyUnwrap(key, kek) - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Wrap_192Key_256Kek(c *C) { - //given (Section 4.5) - - //000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } - - //00112233445566778899AABBCCDDEEFF0001020304050607 - key := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 0, 1, 2, 3, 4, 5, 6, 7 } - - //A8F9BC1612C68B3FF6E6F4FBE30E71E4769C8B80A32CB8958CD5D17D6B254DA1 - expected := []byte{ 168, 249, 188, 22, 18, 198, 139, 63, 246, 230, 244, 251, 227, 14, 113, 228, 118, 156, 139, 128, 163, 44, 184, 149, 140, 213, 209, 125, 107, 37, 77, 161 } - - //when - test,_ := KeyWrap(key, kek); - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Unwrap192Key_256Kek(c *C) { - //given (Section 4.5) - - //000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } - - //00112233445566778899AABBCCDDEEFF0001020304050607 - expected := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 0, 1, 2, 3, 4, 5, 6, 7 } - - //A8F9BC1612C68B3FF6E6F4FBE30E71E4769C8B80A32CB8958CD5D17D6B254DA1 - key := []byte{ 168, 249, 188, 22, 18, 198, 139, 63, 246, 230, 244, 251, 227, 14, 113, 228, 118, 156, 139, 128, 163, 44, 184, 149, 140, 213, 209, 125, 107, 37, 77, 161 } - - //when - test,_ := KeyUnwrap(key, kek) - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Wrap_256Key_256Kek(c *C) { - //given (Section 4.6) - - //000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } - - //00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F - key := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } - - //28C9F404C4B810F4CBCCB35CFB87F8263F5786E2D80ED326CBC7F0E71A99F43BFB988B9B7A02DD21 - expected := []byte{ 40, 201, 244, 4, 196, 184, 16, 244, 203, 204, 179, 92, 251, 135, 248, 38, 63, 87, 134, 226, 216, 14, 211, 38, 203, 199, 240, 231, 26, 153, 244, 59, 251, 152, 139, 155, 122, 2, 221, 33 } - - //when - test,_ := KeyWrap(key, kek); - - //then - c.Assert(test, DeepEquals, expected) -} - -func (s *TestSuite) Test_Unwrap256Key_256Kek(c *C) { - //given (Section 4.6) - - //000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F - kek := []byte{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } - - //00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F - expected := []byte{ 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } - - //28C9F404C4B810F4CBCCB35CFB87F8263F5786E2D80ED326CBC7F0E71A99F43BFB988B9B7A02DD21 - key := []byte{ 40, 201, 244, 4, 196, 184, 16, 244, 203, 204, 179, 92, 251, 135, 248, 38, 63, 87, 134, 226, 216, 14, 211, 38, 203, 199, 240, 231, 26, 153, 244, 59, 251, 152, 139, 155, 122, 2, 221, 33 } - - //when - test,_ := KeyUnwrap(key, kek) - - //then - c.Assert(test, DeepEquals, expected) -} diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/arrays/arrays.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/arrays/arrays.go index 6b89e50809..17ff0bd86e 100644 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/arrays/arrays.go +++ b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/arrays/arrays.go @@ -2,70 +2,70 @@ package arrays import ( - "encoding/binary" "bytes" - "github.com/dvsekhvalnov/jose2go/base64url" "crypto/rand" - "fmt" + "encoding/binary" + "fmt" + "github.com/dvsekhvalnov/jose2go/base64url" ) // Xor is doing byte by byte exclusive or of 2 byte arrays -func Xor(left,right []byte) []byte { - result:=make([]byte,len(left)) - - for i:=0;i>1); +) + // DeriveConcatKDF implements NIST SP 800-56A Concatenation Key Derivation Function. Derives // key material of keydatalen bits size given Z (sharedSecret), OtherInfo (AlgorithmID | // PartyUInfo | PartyVInfo | SuppPubInfo | SuppPrivInfo) and hash function @@ -17,7 +21,7 @@ func DeriveConcatKDF(keydatalen int, sharedSecret, algId, partyUInfo, partyVInfo reps := int(math.Ceil(float64(keyLenBytes) / float64(h.Size()))) - if reps > 4294967295 { + if reps > MaxInt { panic("kdf.DeriveConcatKDF: too much iterations (more than 2^32-1).") } diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a_test.go deleted file mode 100644 index 68ada5967e..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package kdf - -import ( - . "gopkg.in/check.v1" - "crypto/sha256" - "github.com/dvsekhvalnov/jose2go/arrays" - "github.com/dvsekhvalnov/jose2go/base64url" -) - -var z=[]byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31} -var z2=[]byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47} - -var algId=prependDatalen([]byte("alg")) -var partyUInfo=datalenFormat("pui") -var partyVInfo=datalenFormat("pvi") - -func (s *TestSuite) Test256Secret_256Key(c *C) { - //when - test:=DeriveConcatKDF(256,z,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(256),nil,sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{190, 69, 15, 62, 38, 64, 30, 141, 208, 163, 55, 202, 18, 71, 176, 174, 114, 221, 249, 255, 207, 131, 190, 77, 12, 115, 220, 144, 102, 149, 78, 28}) -} - -func (s *TestSuite) Test256Secret_384Key(c *C) { - //when - test:=DeriveConcatKDF(384,z,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(384),nil,sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{187, 16, 110, 253, 151, 199, 57, 235, 219, 8, 73, 191, 208, 108, 63, 241, 235, 137, 178, 149, 3, 199, 216, 99, 105, 217, 45, 114, 109, 213, 83, 198, 52, 101, 99, 146, 193, 31, 172, 157, 19, 140, 25, 202, 153, 92, 252, 192}) -} - -func (s *TestSuite) Test256Secret_521Key(c *C) { - //when - test:=DeriveConcatKDF(521,z,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(521),nil,sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{245, 40, 159, 13, 25, 70, 170, 74, 210, 240, 242, 224, 37, 215, 23, 201, 126, 90, 108, 103, 205, 180, 48, 193, 131, 40, 86, 183, 97, 144, 1, 150, 154, 186, 196, 127, 6, 19, 17, 230, 75, 144, 229, 195, 61, 240, 20, 173, 167, 159, 50, 103, 133, 177, 241, 145, 134, 84, 50, 246, 157, 252, 51, 24, 35}) -} - -func (s *TestSuite) Test384Secret_256Key(c *C) { - //when - test:=DeriveConcatKDF(256,z2,algId,partyUInfo,partyVInfo,arrays.UInt32ToBytes(256),nil,sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{27, 55, 33, 99, 20, 191, 202, 69, 84, 176, 250, 108, 99, 7, 91, 49, 200, 47, 219, 142, 190, 216, 197, 154, 235, 17, 76, 12, 165, 75, 201, 108}) -} - -//test utils -func datalenFormat(str string) []byte { - bytes,_:=base64url.Decode(str) - return prependDatalen(bytes) -} - -func prependDatalen(bytes []byte) []byte { - return arrays.Concat(arrays.UInt32ToBytes(uint32(len(bytes))),bytes) -} diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2.go index 2814a36b5f..b09cd2c75f 100644 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2.go +++ b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2.go @@ -20,7 +20,7 @@ func DerivePBKDF2(password, salt []byte, iterationCount, keyBitLength int, h has r := dkLen - (l-1)*hLen // 1. If dkLen > (2^32 - 1) * hLen, output "derived key too long" and stop. - if dkLen > 4294967295 { + if dkLen > MaxInt { panic(fmt.Sprintf("kdf.DerivePBKDF2: expects derived key size to be not more that (2^32-1) bits, but was requested %v bits.", keyBitLength)) } diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2_test.go deleted file mode 100644 index 9e395a38ee..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/kdf/pbkdf2_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package kdf - -import ( - "testing" - . "gopkg.in/check.v1" - "crypto/sha256" - "crypto/sha512" -) - -func Test(t *testing.T) { TestingT(t) } -type TestSuite struct{} -var _ = Suite(&TestSuite{}) - -var password=[]byte("password") -var salt=[]byte("salt") - -func (s *TestSuite) TestDerivePbkdf2Sha256Count1(c *C) { - //when - test:=DerivePBKDF2(password, salt, 1, 256, sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 18, 15, 182, 207, 252, 248, 179, 44, 67, 231, 34, 82, 86, 196, 248, 55, 168, 101, 72, 201, 44, 204, 53, 72, 8, 5, 152, 124, 183, 11, 225, 123 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha256Count2(c *C) { - //when - test:=DerivePBKDF2(password, salt, 2, 256, sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 174, 77, 12, 149, 175, 107, 70, 211, 45, 10, 223, 249, 40, 240, 109, 208, 42, 48, 63, 142, 243, 194, 81, 223, 214, 226, 216, 90, 149, 71, 76, 67 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha256Count4096(c *C) { - //when - test:=DerivePBKDF2(password, salt, 4096, 256, sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 197, 228, 120, 213, 146, 136, 200, 65, 170, 83, 13, 182, 132, 92, 76, 141, 150, 40, 147, 160, 1, 206, 78, 17, 164, 150, 56, 115, 170, 152, 19, 74 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha256Count4096Len320(c *C) { - //when - test:=DerivePBKDF2([]byte("passwordPASSWORDpassword"), []byte("saltSALTsaltSALTsaltSALTsaltSALTsalt"), 4096, 320, sha256.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 52, 140, 137, 219, 203, 211, 43, 47, 50, 216, 20, 184, 17, 110, 132, 207, 43, 23, 52, 126, 188, 24, 0, 24, 28, 78, 42, 31, 184, 221, 83, 225, 198, 53, 81, 140, 125, 172, 71, 233 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha384Count1Len384(c *C) { - //when - test:=DerivePBKDF2(password,salt, 1, 384, sha512.New384()) - - //then - c.Assert(test, DeepEquals, []byte{ 192, 225, 79, 6, 228, 158, 50, 215, 63, 159, 82, 221, 241, 208, 197, 199, 25, 22, 9, 35, 54, 49, 218, 221, 118, 165, 103, 219, 66, 183, 134, 118, 179, 143, 200, 0, 204, 83, 221, 182, 66, 245, 199, 68, 66, 230, 43, 228 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha384Count2Len384(c *C) { - //when - test:=DerivePBKDF2(password,salt, 2, 384, sha512.New384()) - - //then - c.Assert(test, DeepEquals, []byte{ 84, 247, 117, 198, 215, 144, 242, 25, 48, 69, 145, 98, 252, 83, 93, 191, 4, 169, 57, 24, 81, 39, 1, 106, 4, 23, 106, 7, 48, 198, 241, 244, 251, 72, 131, 42, 209, 38, 27, 170, 221, 44, 237, 213, 8, 20, 177, 200 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha384Count4096Len384(c *C) { - //when - test:=DerivePBKDF2(password,salt, 4096, 384, sha512.New384()) - - //then - c.Assert(test, DeepEquals, []byte{ 85, 151, 38, 190, 56, 219, 18, 91, 200, 94, 215, 137, 95, 110, 60, 245, 116, 199, 160, 28, 8, 12, 52, 71, 219, 30, 138, 118, 118, 77, 235, 60, 48, 123, 148, 133, 63, 190, 66, 79, 100, 136, 197, 244, 241, 40, 150, 38 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha384Count4096Len768(c *C) { - //when - test:=DerivePBKDF2([]byte("passwordPASSWORDpassword"), []byte("saltSALTsaltSALTsaltSALTsaltSALTsalt"), 4096, 768, sha512.New384()) - - //then - c.Assert(test, DeepEquals, []byte{ 129, 145, 67, 173, 102, 223, 154, 85, 37, 89, 185, 225, 49, 197, 42, 230, 197, 193, 176, 238, 209, 143, 77, 40, 59, 140, 92, 158, 174, 185, 43, 57, 44, 20, 124, 194, 210, 134, 157, 88, 255, 226, 247, 218, 19, 209, 95, 141, 146, 87, 33, 240, 237, 26, 250, 250, 36, 72, 13, 85, 207, 96, 96, 177, 127, 17, 42, 61, 231, 76, 174, 37, 253, 243, 86, 158, 36, 127, 41, 228, 219, 184, 68, 33, 132, 120, 34, 234, 153, 189, 32, 40, 60, 58, 37, 166 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha512Count1Len512(c *C) { - //when - test:=DerivePBKDF2(password, salt, 1, 512, sha512.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 134, 127, 112, 207, 26, 222, 2, 207, 243, 117, 37, 153, 163, 165, 61, 196, 175, 52, 199, 166, 105, 129, 90, 229, 213, 19, 85, 78, 28, 140, 242, 82, 192, 45, 71, 10, 40, 90, 5, 1, 186, 217, 153, 191, 233, 67, 192, 143, 5, 2, 53, 215, 214, 139, 29, 165, 94, 99, 247, 59, 96, 165, 127, 206 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha512Count2Len512(c *C) { - //when - test:=DerivePBKDF2(password, salt, 2, 512, sha512.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 225, 217, 193, 106, 166, 129, 112, 138, 69, 245, 199, 196, 226, 21, 206, 182, 110, 1, 26, 46, 159, 0, 64, 113, 63, 24, 174, 253, 184, 102, 213, 60, 247, 108, 171, 40, 104, 163, 155, 159, 120, 64, 237, 206, 79, 239, 90, 130, 190, 103, 51, 92, 119, 166, 6, 142, 4, 17, 39, 84, 242, 124, 207, 78 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha512Count4096Len512(c *C) { - //when - test:=DerivePBKDF2(password, salt, 4096, 512, sha512.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 209, 151, 177, 179, 61, 176, 20, 62, 1, 139, 18, 243, 209, 209, 71, 158, 108, 222, 189, 204, 151, 197, 192, 248, 127, 105, 2, 224, 114, 244, 87, 181, 20, 63, 48, 96, 38, 65, 179, 213, 92, 211, 53, 152, 140, 179, 107, 132, 55, 96, 96, 236, 213, 50, 224, 57, 183, 66, 162, 57, 67, 74, 242, 213 }) -} - -func (s *TestSuite) TestDerivePbkdf2Sha256Count4096Len1024(c *C) { - //when - test:=DerivePBKDF2([]byte("passwordPASSWORDpassword"), []byte("saltSALTsaltSALTsaltSALTsaltSALTsalt"), 4096, 1024, sha512.New()) - - //then - c.Assert(test, DeepEquals, []byte{ 140, 5, 17, 244, 198, 229, 151, 198, 172, 99, 21, 216, 240, 54, 46, 34, 95, 60, 80, 20, 149, 186, 35, 184, 104, 192, 5, 23, 77, 196, 238, 113, 17, 91, 89, 249, 230, 12, 217, 83, 47, 163, 62, 15, 117, 174, 254, 48, 34, 92, 88, 58, 24, 108, 216, 43, 212, 218, 234, 151, 36, 163, 211, 184, 4, 247, 91, 221, 65, 73, 79, 163, 36, 202, 178, 75, 204, 104, 15, 179, 185, 106, 48, 207, 93, 33, 250, 195, 194, 135, 89, 19, 145, 159, 51, 153, 177, 217, 206, 126, 181, 76, 149, 186, 73, 17, 133, 150, 207, 116, 101, 113, 155, 190, 2, 196, 236, 171, 27, 21, 65, 41, 140, 50, 29, 19, 198, 246 }) -} - diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/ecc/ecc_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/ecc/ecc_test.go deleted file mode 100644 index 6693589786..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/ecc/ecc_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package ecc - -import ( - "testing" - . "gopkg.in/check.v1" - "io/ioutil" - "math/big" - "crypto/elliptic" -) - -func Test(t *testing.T) { TestingT(t) } -type TestSuite struct{} -var _ = Suite(&TestSuite{}) - -func (s *TestSuite) TestNewPublic(c *C) { - //given - x:=[]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} - y:=[]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} - - //when - test:=NewPublic(x,y) - - //then - c.Assert(test.X, DeepEquals, bigInt("2010878128539620107131539503221291822343443356718189500659356750794038206985")) - c.Assert(test.Y, DeepEquals, bigInt("59457993017710823357637488495120101390437944162821778556218889662829000218677")) - c.Assert(test.Curve, Equals, elliptic.P256()) -} - -func (s *TestSuite) TestNewPrivate(c *C) { - //given - x:=[]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} - y:=[]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} - d:=[]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 } - - //when - test:=NewPrivate(x,y,d) - - //then - c.Assert(test.X, DeepEquals, bigInt("2010878128539620107131539503221291822343443356718189500659356750794038206985")) - c.Assert(test.Y, DeepEquals, bigInt("59457993017710823357637488495120101390437944162821778556218889662829000218677")) - c.Assert(test.D, DeepEquals, bigInt("19260228627344101198652694952536756709538941185117188878548538012226554651342")) - c.Assert(test.Curve, Equals, elliptic.P256()) -} - -func (s *TestSuite) TestReadPublicPKIX(c *C) { - //given - keyBytes, _ := ioutil.ReadFile("./ec_public.key") - - //when - test,e := ReadPublic(keyBytes) - - //then - c.Assert(e, IsNil) - - c.Assert(test.X, DeepEquals, bigInt("76939435694210362824363841832595476784225842365248086547769733757874741672069")) - c.Assert(test.Y, DeepEquals, bigInt("80047042001812490693675653292813886154388201612539715595028491948003157744818")) - c.Assert(test.Curve, Equals, elliptic.P256()) -} - -func (s *TestSuite) TestReadPublicPKCS1(c *C) { - //given - keyBytes, _ := ioutil.ReadFile("./ec_cert.pem") - - //when - test,e := ReadPublic(keyBytes) - - //then - c.Assert(e, IsNil) - - c.Assert(test.X, DeepEquals, bigInt("76939435694210362824363841832595476784225842365248086547769733757874741672069")) - c.Assert(test.Y, DeepEquals, bigInt("80047042001812490693675653292813886154388201612539715595028491948003157744818")) - c.Assert(test.Curve, Equals, elliptic.P256()) -} - -func (s *TestSuite) TestReadPrivatePKCS1(c *C) { - //given - keyBytes, _ := ioutil.ReadFile("./ec_private.key") - - //when - test,e := ReadPrivate(keyBytes) - - //then - c.Assert(e, IsNil) - - c.Assert(test.X, DeepEquals, bigInt("76939435694210362824363841832595476784225842365248086547769733757874741672069")) - c.Assert(test.Y, DeepEquals, bigInt("80047042001812490693675653292813886154388201612539715595028491948003157744818")) - c.Assert(test.D, DeepEquals, bigInt("7222604869653061109880849859470152714201198955914263913554931724612175399644")) - c.Assert(test.Curve, Equals, elliptic.P256()) -} - -func (s *TestSuite) TestReadPrivatePKCS8(c *C) { - //given - keyBytes, _ := ioutil.ReadFile("./ec_private.pem") - - //when - test,e := ReadPrivate(keyBytes) - - //then - c.Assert(e, IsNil) - - c.Assert(test.X, DeepEquals, bigInt("76939435694210362824363841832595476784225842365248086547769733757874741672069")) - c.Assert(test.Y, DeepEquals, bigInt("80047042001812490693675653292813886154388201612539715595028491948003157744818")) - c.Assert(test.D, DeepEquals, bigInt("7222604869653061109880849859470152714201198955914263913554931724612175399644")) - c.Assert(test.Curve, Equals, elliptic.P256()) -} - -//utils -func bigInt(value string) *big.Int { - i:=new (big.Int) - i.SetString(value,10) - - return i -} diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/rsa/rsa_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/rsa/rsa_test.go deleted file mode 100644 index df2f923225..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/keys/rsa/rsa_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package Rsa - -import ( - "io/ioutil" - "math/big" - "testing" - . "gopkg.in/check.v1" -) - -func Test(t *testing.T) { TestingT(t) } -type TestSuite struct{} -var _ = Suite(&TestSuite{}) - - -func (s *TestSuite) TestNewPrivateRsaKeyPKCS1(c *C) { - - //given - keyBytes, _ := ioutil.ReadFile("priv.pem") - - //when - test,e := ReadPrivate(keyBytes) - - //then - c.Assert(e, IsNil) - c.Assert(test.D, DeepEquals, bigInt("124664500442337916425629948081980373708538939606058968438393904444884872144817323585651521088406960965803456218656807473171367526874204593887158860695954252405916280866383288176587587469870736553178754458686625418367566925639753001190058223163696966510495553421774149906056482201169970508069587759758018186673")) - c.Assert(test.Primes, HasLen, 2) - c.Assert(test.Primes[0], DeepEquals, bigInt("12153319500662601635346432957857245055929638609873673015885135318360261418965835817520733410832489021447922460160007366037402643276624674886502627435389593")) - c.Assert(test.Primes[1], DeepEquals, bigInt("10891140096045830766355607974974880425030121636560867106153739255802668290122259699296919947637286459736524694263050343032461619592457541146877906031793883")) - c.Assert(test.E, Equals, 65537) - c.Assert(test.N, DeepEquals, bigInt("132363505313722155184876628715249052276006747427497555521215412160460427148722445294983292629743653314149228192824806664548107146354876411009845771623017501212568714555984634301944063168503260813720165931647377932654326833738173931173570212088015547040743996672392373035728084429156775233489529905624779259619")) -} - -func (s *TestSuite) TestNewPrivateRsaKeyPKCS8(c *C) { - - //given - keyBytes, _ := ioutil.ReadFile("priv.pem") - - //when - test,e := ReadPrivate(keyBytes) - - //then - c.Assert(e, IsNil) - c.Assert(test.D, DeepEquals, bigInt("124664500442337916425629948081980373708538939606058968438393904444884872144817323585651521088406960965803456218656807473171367526874204593887158860695954252405916280866383288176587587469870736553178754458686625418367566925639753001190058223163696966510495553421774149906056482201169970508069587759758018186673")) - c.Assert(test.Primes, HasLen, 2) - c.Assert(test.Primes[0], DeepEquals, bigInt("12153319500662601635346432957857245055929638609873673015885135318360261418965835817520733410832489021447922460160007366037402643276624674886502627435389593")) - c.Assert(test.Primes[1], DeepEquals, bigInt("10891140096045830766355607974974880425030121636560867106153739255802668290122259699296919947637286459736524694263050343032461619592457541146877906031793883")) - c.Assert(test.E, Equals, 65537) - c.Assert(test.N, DeepEquals, bigInt("132363505313722155184876628715249052276006747427497555521215412160460427148722445294983292629743653314149228192824806664548107146354876411009845771623017501212568714555984634301944063168503260813720165931647377932654326833738173931173570212088015547040743996672392373035728084429156775233489529905624779259619")) -} - -func (s *TestSuite) TestNewPublicRsaKeyPKCS1(c *C) { - - //given - keyBytes, _ := ioutil.ReadFile("pub.pem") - - //when - test,e := ReadPublic(keyBytes) - - //then - c.Assert(e, IsNil) - c.Assert(test.E, Equals, 65537) - c.Assert(test.N, DeepEquals, bigInt("132363505313722155184876628715249052276006747427497555521215412160460427148722445294983292629743653314149228192824806664548107146354876411009845771623017501212568714555984634301944063168503260813720165931647377932654326833738173931173570212088015547040743996672392373035728084429156775233489529905624779259619")) -} - -func (s *TestSuite) TestNewPublicRsaKeyPKIX(c *C) { - - //given - keyBytes, _ := ioutil.ReadFile("pub.key") - - //when - test,e := ReadPublic(keyBytes) - - //then - c.Assert(e, IsNil) - c.Assert(test.E, Equals, 65537) - c.Assert(test.N, DeepEquals, bigInt("132363505313722155184876628715249052276006747427497555521215412160460427148722445294983292629743653314149228192824806664548107146354876411009845771623017501212568714555984634301944063168503260813720165931647377932654326833738173931173570212088015547040743996672392373035728084429156775233489529905624779259619")) -} - -//utils -func bigInt(value string) *big.Int { - i:=new (big.Int) - i.SetString(value,10) - - return i -} diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/align_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/align_test.go deleted file mode 100644 index 8ad9deda34..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/align_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package padding - -import ( - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestAlignOneByte(c *C) { - //given - data:=[]byte{1,2,3} - - //when - test:=Align(data,27) - - //then - c.Assert(test, DeepEquals, []byte{0,1,2,3}) - -} - -func (s *TestSuite) TestAlignMultiByte(c *C) { - //given - data:=[]byte{1,2,3} - - //when - test:=Align(data,40) - - //then - c.Assert(test, DeepEquals, []byte{0,0,1,2,3}) - -} - -func (s *TestSuite) TestAlignMultiBytePartial(c *C) { - //given - data:=[]byte{1,2,3} - - //when - test:=Align(data,43) - - //then - c.Assert(test, DeepEquals, []byte{0,0,0,1,2,3}) - -} - -func (s *TestSuite) TestAlignedArray(c *C) { - //given - data:=[]byte{1,2,3} - - //when - test:=Align(data,24) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3}) -} diff --git a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/pkcs7_test.go b/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/pkcs7_test.go deleted file mode 100644 index 61b4e0dde9..0000000000 --- a/Godeps/_workspace/src/github.com/dvsekhvalnov/jose2go/padding/pkcs7_test.go +++ /dev/null @@ -1,109 +0,0 @@ -package padding - -import ( - "testing" - . "gopkg.in/check.v1" -) - -func Test(t *testing.T) { TestingT(t) } -type TestSuite struct{} -var _ = Suite(&TestSuite{}) - -func (s *TestSuite) TestRemovePkcs7NoPadding(c *C) { - //given - padded:=[]byte{1,2,3,4,5,6,7,8} - - //when - test:=RemovePkcs7(padded,8) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5,6,7,8}) -} - -func (s *TestSuite) TestRemovePkcs7(c *C) { - //given - padded:=[]byte{1,2,3,4,5,3,3,3} - - //when - test:=RemovePkcs7(padded,8) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5}) -} - -func (s *TestSuite) TestRemovePkcs7OneBytePadding(c *C) { - //given - padded:=[]byte{1,2,3,4,5,1} - - //when - test:=RemovePkcs7(padded,6) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5}) -} - -func (s *TestSuite) TestRemovePkcs7TrailingZeroByte(c *C) { - //given - padded:=[]byte{1,2,3,4,5,0} - - //when - test:=RemovePkcs7(padded,6) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5,0}) -} - -func (s *TestSuite) TestRemovePkcs7ExtraBlockPadding(c *C) { - //given - padded:=[]byte{1,2,3,4,5,5,5,5,5,5} - - //when - test:=RemovePkcs7(padded,5) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5}) -} - -func (s *TestSuite) TestRemovePkcs7TrailingByteGreaterBlockSize(c *C) { - //given - padded:=[]byte{1,2,3,4,5,10} - - //when - test:=RemovePkcs7(padded,6) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5,10}) -} - -func (s *TestSuite) TestAddPkcs7(c *C) { - //given - in:=[]byte{1,2,3,4,5} - - //when - test := AddPkcs7(in,8) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5,3,3,3}) -} - -func (s *TestSuite) TestAddPkcs7OneBytePadding(c *C) { - //given - in:=[]byte{1,2,3,4,5} - - //when - test := AddPkcs7(in,6) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5,1}) -} - -func (s *TestSuite) TestAddPkcs7ExtraBlockPadding(c *C) { - //given - in:=[]byte{1,2,3,4,5,6,7,8} - - //when - test := AddPkcs7(in,8) - - //then - c.Assert(test, DeepEquals, []byte{1,2,3,4,5,6,7,8,8,8,8,8,8,8,8,8}) -}