@@ -3,9 +3,12 @@ package provisioner
33import (
44 "context"
55 "crypto/ecdh"
6+ "crypto/ecdsa"
67 "crypto/ed25519"
8+ "crypto/elliptic"
79 "crypto/x509"
810 "encoding/base64"
11+ "math/big"
912 "net"
1013 "time"
1114
@@ -338,13 +341,20 @@ func (p *Nebula) authorizeToken(token string, audiences []string) (*nebula.Nebul
338341 return nil , nil , errs .Unauthorized ("token is not valid: failed to verify certificate against configured CA" )
339342 }
340343
341- var pub interface {}
344+ var pub any
342345 switch {
343346 case c .Details .Curve == nebula .Curve_P256 :
344347 // When Nebula is used with ECDSA P-256 keys, both CAs and clients use the same type.
345- if pub , err = ecdh .P256 ().NewPublicKey (c .Details .PublicKey ); err != nil {
348+ ecdhPub , err := ecdh .P256 ().NewPublicKey (c .Details .PublicKey )
349+ if err != nil {
346350 return nil , nil , errs .UnauthorizedErr (err , errs .WithMessage ("failed to parse nebula public key" ))
347351 }
352+ publicKeyBytes := ecdhPub .Bytes ()
353+ pub = & ecdsa.PublicKey { // convert back to *ecdsa.PublicKey, because our jose package nor go-jose supports *ecdh.PublicKey
354+ Curve : elliptic .P256 (),
355+ X : big .NewInt (0 ).SetBytes (publicKeyBytes [1 :33 ]),
356+ Y : big .NewInt (0 ).SetBytes (publicKeyBytes [33 :]),
357+ }
348358 case c .Details .IsCA :
349359 pub = ed25519 .PublicKey (c .Details .PublicKey )
350360 default :
@@ -365,6 +375,7 @@ func (p *Nebula) authorizeToken(token string, audiences []string) (*nebula.Nebul
365375 }, time .Minute ); err != nil {
366376 return nil , nil , errs .UnauthorizedErr (err , errs .WithMessage ("token is not valid: invalid claims" ))
367377 }
378+
368379 // Validate token and subject too.
369380 if ! matchesAudience (claims .Audience , audiences ) {
370381 return nil , nil , errs .Unauthorized ("token is not valid: invalid claims" )
0 commit comments