fix #14: use ParsePKCS1PrivateKey

addon-dailer
lqqyt2423 3 years ago
parent 2682e7cc01
commit 8ed9ad168a

@ -15,6 +15,7 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
"time" "time"
@ -148,15 +149,26 @@ func (ca *CA) load() error {
return fmt.Errorf("%v 中不存在 CERTIFICATE", caFile) return fmt.Errorf("%v 中不存在 CERTIFICATE", caFile)
} }
var privateKey *rsa.PrivateKey
key, err := x509.ParsePKCS8PrivateKey(keyDERBlock.Bytes) key, err := x509.ParsePKCS8PrivateKey(keyDERBlock.Bytes)
if err != nil { if err != nil {
// fix #14
if strings.Contains(err.Error(), "use ParsePKCS1PrivateKey instead") {
privateKey, err = x509.ParsePKCS1PrivateKey(keyDERBlock.Bytes)
if err != nil {
return err
}
} else {
return err return err
} }
} else {
if v, ok := key.(*rsa.PrivateKey); ok { if v, ok := key.(*rsa.PrivateKey); ok {
ca.PrivateKey = *v privateKey = v
} else { } else {
return errors.New("found unknown rsa private key type in PKCS#8 wrapping") return errors.New("found unknown rsa private key type in PKCS#8 wrapping")
} }
}
ca.PrivateKey = *privateKey
x509Cert, err := x509.ParseCertificate(certDERBlock.Bytes) x509Cert, err := x509.ParseCertificate(certDERBlock.Bytes)
if err != nil { if err != nil {

Loading…
Cancel
Save