Commit f5a85e97 authored by Eric Chiang's avatar Eric Chiang

*: update go-oidc to shorten length of key IDs

parent bdaded57
hash: ed84ba1c371faf2f9a0bf64f6a7767a017e663cb99afa273ec5659432bb474d5 hash: 2e6ef5ae85fe17d9b695b37ba6875b438a617692cc1f6fefc682c4e405a4dcf1
updated: 2016-06-28T10:15:56.223659517-07:00 updated: 2016-06-28T10:36:39.146887182-07:00
imports: imports:
- name: github.com/andybalholm/cascadia - name: github.com/andybalholm/cascadia
version: 6122e68c2642b7b75c538a63b15168c6c80fb757 version: 6122e68c2642b7b75c538a63b15168c6c80fb757
- name: github.com/coreos/go-oidc - name: github.com/coreos/go-oidc
version: 8ae400b75540a4f57ec549a89b3e9d994c636f2a version: 5aa9381f6e998aa16cc96b4347d33dcc29792864
subpackages: subpackages:
- http - http
- jose - jose
......
...@@ -5,7 +5,7 @@ import: ...@@ -5,7 +5,7 @@ import:
- package: github.com/andybalholm/cascadia - package: github.com/andybalholm/cascadia
version: 6122e68c2642b7b75c538a63b15168c6c80fb757 version: 6122e68c2642b7b75c538a63b15168c6c80fb757
- package: github.com/coreos/go-oidc - package: github.com/coreos/go-oidc
version: 8ae400b75540a4f57ec549a89b3e9d994c636f2a version: 5aa9381f6e998aa16cc96b4347d33dcc29792864
subpackages: subpackages:
- http - http
- jose - jose
......
...@@ -3,9 +3,9 @@ package key ...@@ -3,9 +3,9 @@ package key
import ( import (
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"encoding/base64" "encoding/hex"
"encoding/json" "encoding/json"
"math/big" "io"
"time" "time"
"github.com/coreos/go-oidc/jose" "github.com/coreos/go-oidc/jose"
...@@ -139,15 +139,15 @@ func GeneratePrivateKey() (*PrivateKey, error) { ...@@ -139,15 +139,15 @@ func GeneratePrivateKey() (*PrivateKey, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
keyID := make([]byte, 20)
if _, err := io.ReadFull(rand.Reader, keyID); err != nil {
return nil, err
}
k := PrivateKey{ k := PrivateKey{
KeyID: base64BigInt(pk.PublicKey.N), KeyID: hex.EncodeToString(keyID),
PrivateKey: pk, PrivateKey: pk,
} }
return &k, nil return &k, nil
} }
func base64BigInt(b *big.Int) string {
return base64.URLEncoding.EncodeToString(b.Bytes())
}
...@@ -87,3 +87,17 @@ func TestPublicKeyMarshalJSON(t *testing.T) { ...@@ -87,3 +87,17 @@ func TestPublicKeyMarshalJSON(t *testing.T) {
t.Errorf("got != want:\n%s\n%s", got, want) 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")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment