Skip to content

Commit 8932f2a

Browse files
committed
feat: ensure public key pairs with private key in oidc service
1 parent 482ba9d commit 8932f2a

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

internal/service/oidc_service.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ func NewOIDCService(
239239
}
240240
}
241241

242+
rPublicKey, ok := publicKey.(*rsa.PublicKey)
243+
244+
if !ok {
245+
return nil, fmt.Errorf("public key is not an rsa public key")
246+
}
247+
248+
if rPublicKey.N.Cmp(privateKey.N) != 0 || rPublicKey.E != privateKey.E {
249+
return nil, fmt.Errorf("public key does not pair with private key")
250+
}
251+
242252
// We will reorganize the client into a map with the client ID as the key
243253
clients := make(map[string]model.OIDCClientConfig)
244254

@@ -271,7 +281,7 @@ func NewOIDCService(
271281

272282
clients: clients,
273283
privateKey: privateKey,
274-
publicKey: publicKey.(*rsa.PublicKey),
284+
publicKey: rPublicKey,
275285
issuer: issuer,
276286
}
277287

@@ -822,13 +832,13 @@ func (service *OIDCService) GetJWK() ([]byte, error) {
822832
hasher.Write(der)
823833

824834
jwk := jose.JSONWebKey{
825-
Key: service.privateKey,
835+
Key: service.publicKey,
826836
Algorithm: string(jose.RS256),
827837
Use: "sig",
828838
KeyID: base64.URLEncoding.EncodeToString(hasher.Sum(nil)),
829839
}
830840

831-
return jwk.Public().MarshalJSON()
841+
return jwk.MarshalJSON()
832842
}
833843

834844
func (service *OIDCService) ValidatePKCE(codeChallenge string, codeVerifier string) bool {

0 commit comments

Comments
 (0)