Skip to content

Commit

Permalink
Set public key from private key in DNSKEY instead of copying it from …
Browse files Browse the repository at this point in the history
…DNSKEY to private key
  • Loading branch information
Martin Frausing committed Apr 26, 2024
1 parent e4ef594 commit 4c2c49c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions dnssec_keyscan.go
Expand Up @@ -5,6 +5,7 @@ import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rsa"
"io"
"math/big"
Expand Down Expand Up @@ -48,22 +49,21 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
if err != nil {
return nil, err
}
pub := k.publicKeyRSA()
if pub == nil {
return nil, ErrKey
}
priv.PublicKey = *pub
k.setPublicKeyRSA(priv.PublicKey.E, priv.PublicKey.N)
return priv, nil
case ECDSAP256SHA256, ECDSAP384SHA384:
priv, err := readPrivateKeyECDSA(m)
if err != nil {
return nil, err
}
pub := k.publicKeyECDSA()
if pub == nil {
return nil, ErrKey
switch uint8(algo) {
case ECDSAP256SHA256:
priv.PublicKey.Curve = elliptic.P256()
case ECDSAP384SHA384:
priv.PublicKey.Curve = elliptic.P384()
}
priv.PublicKey = *pub
priv.PublicKey.X, priv.PublicKey.Y = priv.PublicKey.Curve.ScalarBaseMult(priv.D.Bytes())
k.setPublicKeyECDSA(priv.PublicKey.X, priv.PublicKey.Y)
return priv, nil
case ED25519:
return readPrivateKeyED25519(m)
Expand Down

0 comments on commit 4c2c49c

Please sign in to comment.