Merge pull request #490 from ericchiang/reduce-key-id-length

*: update go-oidc to shorten length of key IDs
This commit is contained in:
Eric Chiang 2016-06-28 10:48:32 -07:00 committed by GitHub
commit 5bfe0a1898
4 changed files with 25 additions and 11 deletions

6
glide.lock generated
View file

@ -1,10 +1,10 @@
hash: ed84ba1c371faf2f9a0bf64f6a7767a017e663cb99afa273ec5659432bb474d5
updated: 2016-06-28T10:15:56.223659517-07:00
hash: 2e6ef5ae85fe17d9b695b37ba6875b438a617692cc1f6fefc682c4e405a4dcf1
updated: 2016-06-28T10:36:39.146887182-07:00
imports:
- name: github.com/andybalholm/cascadia
version: 6122e68c2642b7b75c538a63b15168c6c80fb757
- name: github.com/coreos/go-oidc
version: 8ae400b75540a4f57ec549a89b3e9d994c636f2a
version: 5aa9381f6e998aa16cc96b4347d33dcc29792864
subpackages:
- http
- jose

View file

@ -5,7 +5,7 @@ import:
- package: github.com/andybalholm/cascadia
version: 6122e68c2642b7b75c538a63b15168c6c80fb757
- package: github.com/coreos/go-oidc
version: 8ae400b75540a4f57ec549a89b3e9d994c636f2a
version: 5aa9381f6e998aa16cc96b4347d33dcc29792864
subpackages:
- http
- jose

View file

@ -3,9 +3,9 @@ package key
import (
"crypto/rand"
"crypto/rsa"
"encoding/base64"
"encoding/hex"
"encoding/json"
"math/big"
"io"
"time"
"github.com/coreos/go-oidc/jose"
@ -139,15 +139,15 @@ func GeneratePrivateKey() (*PrivateKey, error) {
if err != nil {
return nil, err
}
keyID := make([]byte, 20)
if _, err := io.ReadFull(rand.Reader, keyID); err != nil {
return nil, err
}
k := PrivateKey{
KeyID: base64BigInt(pk.PublicKey.N),
KeyID: hex.EncodeToString(keyID),
PrivateKey: pk,
}
return &k, nil
}
func base64BigInt(b *big.Int) string {
return base64.URLEncoding.EncodeToString(b.Bytes())
}

View file

@ -87,3 +87,17 @@ func TestPublicKeyMarshalJSON(t *testing.T) {
t.Errorf("got != want:\n%s\n%s", got, want)
}
}
func TestGeneratePrivateKeyIDs(t *testing.T) {
key1, err := GeneratePrivateKey()
if err != nil {
t.Fatalf("GeneratePrivateKey(): %v", err)
}
key2, err := GeneratePrivateKey()
if err != nil {
t.Fatalf("GeneratePrivateKey(): %v", err)
}
if key1.KeyID == key2.KeyID {
t.Fatalf("expected different keys to have different key IDs")
}
}