Use algorithm number to determine private key type.
This commit is contained in:
parent
32c1cd51a9
commit
f074745b0b
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,8 +35,12 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (PrivateKey, error) {
|
||||||
return nil, ErrPrivKey
|
return nil, ErrPrivKey
|
||||||
}
|
}
|
||||||
// TODO(mg): check if the pubkey matches the private key
|
// TODO(mg): check if the pubkey matches the private key
|
||||||
switch m["algorithm"] {
|
algo, err := strconv.Atoi(strings.SplitN(m["algorithm"], " ", 2)[0])
|
||||||
case "3 (DSA)":
|
if err != nil {
|
||||||
|
return nil, ErrPrivKey
|
||||||
|
}
|
||||||
|
switch uint8(algo) {
|
||||||
|
case DSA:
|
||||||
priv, e := readPrivateKeyDSA(m)
|
priv, e := readPrivateKeyDSA(m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
|
@ -46,15 +51,15 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (PrivateKey, error) {
|
||||||
}
|
}
|
||||||
priv.PublicKey = *pub
|
priv.PublicKey = *pub
|
||||||
return (*DSAPrivateKey)(priv), e
|
return (*DSAPrivateKey)(priv), e
|
||||||
case "1 (RSAMD5)":
|
case RSAMD5:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "5 (RSASHA1)":
|
case RSASHA1:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "7 (RSASHA1NSEC3SHA1)":
|
case RSASHA1NSEC3SHA1:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "8 (RSASHA256)":
|
case RSASHA256:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "10 (RSASHA512)":
|
case RSASHA512:
|
||||||
priv, e := readPrivateKeyRSA(m)
|
priv, e := readPrivateKeyRSA(m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
|
@ -65,11 +70,11 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (PrivateKey, error) {
|
||||||
}
|
}
|
||||||
priv.PublicKey = *pub
|
priv.PublicKey = *pub
|
||||||
return (*RSAPrivateKey)(priv), e
|
return (*RSAPrivateKey)(priv), e
|
||||||
case "12 (ECC-GOST)":
|
case ECCGOST:
|
||||||
return nil, ErrPrivKey
|
return nil, ErrPrivKey
|
||||||
case "13 (ECDSAP256SHA256)":
|
case ECDSAP256SHA256:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "14 (ECDSAP384SHA384)":
|
case ECDSAP384SHA384:
|
||||||
priv, e := readPrivateKeyECDSA(m)
|
priv, e := readPrivateKeyECDSA(m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
|
|
Loading…
Reference in New Issue