-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable more govet checks and address issues
It turns out that the 'govet' linter has a few more tricks up its sleeve, you just need to enable them. This find a couple of bugs in the tests which are also being fixed in this commit: 1. The spire-server tests for BatchCreateFederatedBundle and friends were accidentally not including JWT keys in the bundle they were testing. This ended up only affecting assertions on log message fields, which are being fixed here. The fix for this engendered a bit of refactoring to enable access to the required JWT struct conversion function. 2. The spire-server tests for the CA journal were _almost_ failing in their attempt to list CA journals; it ended up working anyway because a conversion between different struct types happened to be unnecessary because gorm could work with either one due to matching struct field names. Signed-off-by: Carlo Teubner <carlo@cteubner.net>
- Loading branch information
Showing
6 changed files
with
312 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package jwtutil | ||
|
||
import ( | ||
"crypto" | ||
"crypto/x509" | ||
"fmt" | ||
|
||
"github.com/spiffe/spire-api-sdk/proto/spire/api/types" | ||
) | ||
|
||
// JWTKeysFromProto converts JWT keys from the given []*types.JWTKey to map[string]crypto.PublicKey. | ||
// The key ID of the public key is used as the key in the returned map. | ||
func JWTKeysFromProto(proto []*types.JWTKey) (map[string]crypto.PublicKey, error) { | ||
keys := make(map[string]crypto.PublicKey) | ||
for i, publicKey := range proto { | ||
jwtSigningKey, err := x509.ParsePKIXPublicKey(publicKey.PublicKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse JWT signing key %d: %w", i, err) | ||
} | ||
keys[publicKey.KeyId] = jwtSigningKey | ||
} | ||
return keys, nil | ||
} | ||
|
||
// ProtoFromJWTKeys converts JWT keys from the given map[string]crypto.PublicKey to []*types.JWTKey | ||
func ProtoFromJWTKeys(keys map[string]crypto.PublicKey) ([]*types.JWTKey, error) { | ||
var resp []*types.JWTKey | ||
|
||
for kid, key := range keys { | ||
pkixBytes, err := x509.MarshalPKIXPublicKey(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp = append(resp, &types.JWTKey{ | ||
PublicKey: pkixBytes, | ||
KeyId: kid, | ||
}) | ||
} | ||
|
||
return resp, nil | ||
} |
Oops, something went wrong.