internal/cryptutil: fixed panic on nil pubkey

This commit is contained in:
Bobby DeSimone 2019-07-15 19:36:02 -07:00
parent 22fb3a0f7e
commit c5bcc9bbef
No known key found for this signature in database
GPG key ID: AEE4CF12FE86D07E
5 changed files with 81 additions and 13 deletions

View file

@ -1,5 +1,5 @@
// Package cryptutil provides encoding and decoding routines for various cryptographic structures.
package cryptutil
package cryptutil // import "github.com/pomerium/pomerium/internal/cryptutil"
import (
"crypto/ecdsa"
@ -13,11 +13,9 @@ import (
// DecodePublicKey decodes a PEM-encoded ECDSA public key.
func DecodePublicKey(encodedKey []byte) (*ecdsa.PublicKey, error) {
block, _ := pem.Decode(encodedKey)
if block == nil || block.Type != "PUBLIC KEY" {
return nil, fmt.Errorf("marshal: could not decode PEM block type %s", block.Type)
if block == nil {
return nil, fmt.Errorf("marshal: decoded nil PEM block")
}
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return nil, err