Skip to content

Commit

Permalink
rsakey: Resolve HS256 kid mismatch
Browse files Browse the repository at this point in the history
Closes #83
  • Loading branch information
arekkas authored and arekkas committed Jul 7, 2018
1 parent 3d5df8b commit 6d647d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rsakey/manager_local_hs256.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
package rsakey

import (
"github.com/pborman/uuid"
"crypto/sha256"
"fmt"
)

type LocalHS256Manager struct {
Expand All @@ -30,9 +31,12 @@ type LocalHS256Manager struct {
}

func NewLocalHS256Manager(key []byte) *LocalHS256Manager {
h := sha256.New()
h.Write(key)

return &LocalHS256Manager{
key: key,
kid: uuid.New(),
kid: fmt.Sprintf("%x", h.Sum(nil)),
}
}

Expand Down
35 changes: 35 additions & 0 deletions rsakey/manager_local_hs256_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright © 2017-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Aeneas Rekkas <aeneas+oss@aeneas.io>
* @copyright 2017-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
* @license Apache-2.0
*/

package rsakey

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLocalHS256Manager(t *testing.T) {
key := []byte("somkey")
m1 := NewLocalHS256Manager(key)
m2 := NewLocalHS256Manager(key)

assert.EqualValues(t, m1.PublicKeyID(), m2.PublicKeyID())
}

0 comments on commit 6d647d7

Please sign in to comment.