File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,7 +55,14 @@ func PublicKeyFromX509DER(bytes []byte) (PublicKey, error) {
5555 if err != nil {
5656 return PublicKey {}, err
5757 }
58- return PublicKey {k : pub .(ed25519.PublicKey )}, nil
58+ ed25519Pub , ok := pub .(ed25519.PublicKey )
59+ if ! ok {
60+ return PublicKey {}, fmt .Errorf ("invalid ed25519 public key type" )
61+ }
62+ if len (ed25519Pub ) != PublicKeyBytesSize {
63+ return PublicKey {}, fmt .Errorf ("invalid ed25519 public key size" )
64+ }
65+ return PublicKey {k : ed25519Pub }, nil
5966}
6067
6168// PublicKeyFromX509PEM decodes an X.509 PEM (string) encoded public key.
Original file line number Diff line number Diff line change @@ -101,7 +101,18 @@ func PublicKeyFromX509DER(bytes []byte) (*PublicKey, error) {
101101 if err != nil {
102102 return nil , err
103103 }
104- return & PublicKey {k : pub .(* ecdh.PublicKey )}, nil
104+ ecdhPub , ok := pub .(* ecdh.PublicKey )
105+ if ! ok {
106+ return nil , fmt .Errorf ("invalid x25519 public key type" )
107+ }
108+ if ecdhPub .Curve () != ecdh .X25519 () {
109+ return nil , fmt .Errorf ("invalid x25519 curve" )
110+ }
111+ keyBytes := ecdhPub .Bytes ()
112+ if len (keyBytes ) != PublicKeyBytesSize {
113+ return nil , fmt .Errorf ("invalid x25519 public key size" )
114+ }
115+ return & PublicKey {k : ecdhPub }, nil
105116}
106117
107118// PublicKeyFromX509PEM decodes an X.509 PEM (string) encoded public key.
You can’t perform that action at this time.
0 commit comments