Fix occur panic when invalid PublicKey parsing.

This commit is contained in:
Naoki Kosaka
2020-01-29 17:36:56 +09:00
parent 91e147ac0d
commit f90b6a85c0
3 changed files with 10 additions and 0 deletions

View File

@ -25,6 +25,9 @@ func ReadPrivateKeyRSAfromPath(path string) (*rsa.PrivateKey, error) {
func ReadPublicKeyRSAfromString(pemString string) (*rsa.PublicKey, error) {
pemByte := []byte(pemString)
decoded, _ := pem.Decode(pemByte)
defer func() {
recover()
}()
keyInterface, err := x509.ParsePKIXPublicKey(decoded.Bytes)
if err != nil {
fmt.Fprintln(os.Stderr, err)