Documentation
¶
Index ¶
- Constants
- Variables
- func CreateNewRRSIG(zone string, dnsKeyRR *dns.DNSKEY, expDate time.Time, rrSetTTL uint32) *dns.RRSIG
- func DurationToTime(now time.Time, dStr string) (d time.Time, err error)
- func GetDNSKEY(keys *SigKeys, session SignSession) (zsk, ksk *dns.DNSKEY, err error)
- func NormalizeFQDN(fqdn string) string
- func Sign(session SignSession) (ds *dns.DS, err error)
- type Context
- func (ctx *Context) AddNSEC13()
- func (ctx *Context) AddZONEMDRecord()
- func (ctx *Context) CalculateDigest(hashAlg uint8) (string, error)
- func (ctx *Context) CleanDigests()
- func (ctx *Context) Close() error
- func (ctx *Context) CreateNewDNSKEY(flags uint16, publicKey string) *dns.DNSKEY
- func (ctx *Context) Digest() error
- func (ctx *Context) NewFileSession(zsk, ksk io.ReadWriteSeeker) (SignSession, error)
- func (ctx *Context) NewPKCS11Session(key, label, p11lib string) (SignSession, error)
- func (ctx *Context) PrintDS()
- func (ctx *Context) ReadAndParseZone(updateSerial bool) error
- func (ctx *Context) UpdateDigest() (err error)
- func (ctx *Context) ValidateOrderedZoneDigest(hashAlg uint8, mddigest string) error
- func (ctx *Context) VerifyDigest() error
- func (ctx *Context) VerifyFile() (err error)
- func (ctx *Context) WriteZone() error
- type ContextConfig
- type FileSession
- func (session *FileSession) Context() *Context
- func (session *FileSession) DestroyAllKeys() error
- func (session *FileSession) End() error
- func (session *FileSession) GetKeys() (keys *SigKeys, err error)
- func (session *FileSession) GetPublicKeyBytes(keys *SigKeys) (zskBytes, kskBytes []byte, err error)
- type NSEC3List
- type PKCS11RRSigner
- type PKCS11Session
- func (session *PKCS11Session) Context() *Context
- func (session *PKCS11Session) DestroyAllKeys() error
- func (session *PKCS11Session) End() error
- func (session *PKCS11Session) GetKeys() (keys *SigKeys, err error)
- func (session *PKCS11Session) GetPublicKeyBytes(keys *SigKeys) (zskBytes, kskBytes []byte, err error)
- type RRArray
- type RRSetList
- type RRSigPair
- type SigKeys
- type SignAlgorithm
- type SignSession
Constants ¶
const ( RsaSha256 = 8 // RSA SHA256 EcdsaP256Sha256 = 13 // ECDSA P256 SHA256 )
Signing algorithms
Variables ¶
var ErrNoValidKeys = fmt.Errorf("no valid keys")
ErrNoValidKeys represents an error returned when the session does not have valid keys
var ErrNotEnoughDNSkeys = fmt.Errorf("could not find enough dnskeys")
var StringToSignAlgorithm = map[string]SignAlgorithm{ "rsa": RsaSha256, "rsa_sha256": RsaSha256, "ecdsa": EcdsaP256Sha256, "ecdsa_p256": EcdsaP256Sha256, "ecdsa_p256_sha256": EcdsaP256Sha256, }
StringToSignAlgorithm takes the name of an algorithm
Functions ¶
func CreateNewRRSIG ¶
func CreateNewRRSIG(zone string, dnsKeyRR *dns.DNSKEY, expDate time.Time, rrSetTTL uint32) *dns.RRSIG
CreateNewRRSIG creates a new RRSIG RR, using the parameters provided.
func DurationToTime ¶
DurationToTime parses a duration string and returns a time relative to now.
func GetDNSKEY ¶
func GetDNSKEY(keys *SigKeys, session SignSession) (zsk, ksk *dns.DNSKEY, err error)
GetDNSKEY returns two DNSKEY RRs based on the session SigKeys
func NormalizeFQDN ¶
NormalizeFQDN normalizes a fqdn to ASCII (punycode).
Types ¶
type Context ¶
type Context struct { Config *ContextConfig File io.Reader // zone path Output io.WriteCloser // Out path Log *log.Logger // Logger SignAlgorithm SignAlgorithm // Sign Algorithm DelegatedZones map[string]struct{} // Map with Delegated zones. WithDS map[string]struct{} // Map with zones with a DS RR DNSKEYS struct { ZSK, KSK map[uint16]*dns.DNSKEY // DNSKEYS } // contains filtered or unexported fields }
Context contains the state of a zone signing process.
func NewContext ¶
func NewContext(config *ContextConfig, log *log.Logger) (ctx *Context, err error)
NewContext creates a new context based on a configuration structure. It also receives a logger to log errors.
func (*Context) AddNSEC13 ¶
func (ctx *Context) AddNSEC13()
AddNSEC13 adds NSEC 1 and 3 rrs to the RR list.
func (*Context) AddZONEMDRecord ¶
func (ctx *Context) AddZONEMDRecord()
AddZONEMDRecord adds a zone digest following draft-ietf-dnsop-dns-zone-digest-05 we need the SOA info for that
func (*Context) CalculateDigest ¶
CalculateDigest calculates the digest for a PREVIOUSLY ORDERED zone. This method returns the digest hex value.
func (*Context) CleanDigests ¶
func (ctx *Context) CleanDigests()
CleanDigests sets all root zone digests to 0 It is used before zone signing
func (*Context) CreateNewDNSKEY ¶
CreateNewDNSKEY creates a new DNSKEY RR, using the parameters provided.
func (*Context) NewFileSession ¶
func (ctx *Context) NewFileSession(zsk, ksk io.ReadWriteSeeker) (SignSession, error)
NewFileSession creates a new File session. The arguments define the readers for the zone signing and key signing keys.
func (*Context) NewPKCS11Session ¶
func (ctx *Context) NewPKCS11Session(key, label, p11lib string) (SignSession, error)
NewPKCS11Session creates a new session. The arguments also define the HSM user key and the pkcs11 label the keys will use when created or retrieved.
func (*Context) PrintDS ¶
func (ctx *Context) PrintDS()
PrintDS prints to log device DS value of zone:
func (*Context) ReadAndParseZone ¶
ReadAndParseZone parses a DNS zone file and returns an array of rrs and the zone minTTL. It also updates the serial in the SOA record if updateSerial is true. If setCredits is true, it adds a TXT record to the zone, under the subdomain _dnstools, with signing information Returns the SOA. IT DOES NOT SORT THE RR LIST
func (*Context) UpdateDigest ¶
UpdateDigest calculates the digest for a PREVIOUSLY ORDERED zone with one ZONEMD RR This method updates the ZONEMD RR directly
func (*Context) ValidateOrderedZoneDigest ¶
ValidateOrderedZoneDigest validates the digest for a PREVIOUSLY ORDERED zone. Returns nil if the calculated digest is equals the ZONEMD one, and an error otherwise. Follows the validation from https://datatracker.ietf.org/doc/draft-ietf-dnsop-dns-zone-digest. It is hardcoded to use SIMPLE scheme.
func (*Context) VerifyDigest ¶
VerifyDigest validates a version of a zone with a valid ZONEMD RR.
func (*Context) VerifyFile ¶
VerifyFile verifies the signatures in an already signed zone file. zone represents the domain origin, while path is the zone location, and it is used to resolve $INCLUDE directives. reader has the zone input and logger allows us to log the operations.
type ContextConfig ¶
type ContextConfig struct { Zone string // Zone name CreateKeys bool // If True, the sign process creates new keys for the signature. NSEC3 bool // If true, the zone is signed using NSEC3 OptOut bool // If true and NSEC3 is true, the zone is signed using OptOut NSEC3 flag. DigestEnabled bool // If true, the zone is hashed and DigestEnabled is used SignAlgorithm string // Signature algorithm FilePath string // Output Path OutputPath string // Output Path RRSIGExpDate time.Time // RRSIG Expiration Date Info bool // If true, a credits txt will be added to _dnstools subdomain. Lazy bool // If true, the zone will not be signed if it is not needed. VerifyThreshold time.Time // Verification Threshold HashAlg uint8 // 1:sha384 (default), 2:sha512 NSEC3Iterations uint16 NSEC3SaltLength uint8 NSEC3SaltValue string }
ContextConfig contains the common args to sign and verify files
type FileSession ¶
type FileSession struct {
// contains filtered or unexported fields
}
FileSession represents a File session. It includes the context and a Label String, used in creation and retrieval of DNS keys.
func (*FileSession) Context ¶
func (session *FileSession) Context() *Context
Context returns the session context
func (*FileSession) DestroyAllKeys ¶
func (session *FileSession) DestroyAllKeys() error
DestroyAllKeys destroys all keys inside the session. In the case of FileSession it does nothing
func (*FileSession) End ¶
func (session *FileSession) End() error
End ends the session. In FileSession it does nothing
func (*FileSession) GetKeys ¶
func (session *FileSession) GetKeys() (keys *SigKeys, err error)
GetKeys returns the keys (zsk, ksk) related to the session
func (*FileSession) GetPublicKeyBytes ¶
func (session *FileSession) GetPublicKeyBytes(keys *SigKeys) (zskBytes, kskBytes []byte, err error)
GetPublicKeyBytes returns the public key bytes for ZSK and KSK keys
type PKCS11RRSigner ¶
type PKCS11RRSigner struct { Session *PKCS11Session // PKCS#11 PKCS11Session SK, PK pkcs11.ObjectHandle // Secret and Public PKCS11Key handles }
PKCS11RRSigner represents a signer using a PKCS11 device to sign and store the keys
func (*PKCS11RRSigner) Public ¶
func (rs *PKCS11RRSigner) Public() crypto.PublicKey
Public returns the public key related to the signer
func (*PKCS11RRSigner) Sign ¶
func (rs *PKCS11RRSigner) Sign(rand io.Reader, rr []byte, opts crypto.SignerOpts) ([]byte, error)
Sign signs a wire-format ww set.
type PKCS11Session ¶
type PKCS11Session struct { P11Context *pkcs11.Ctx // PKCS#11 Context Handle pkcs11.SessionHandle // PKCS11Session Handle Label string // Signature Label Key string // Signature key // contains filtered or unexported fields }
PKCS11Session represents a PKCS#11 session. It includes the context, the session handle and a Label String, used in creation and retrieval of DNS keys.
func (*PKCS11Session) Context ¶
func (session *PKCS11Session) Context() *Context
Context Returns the session context
func (*PKCS11Session) DestroyAllKeys ¶
func (session *PKCS11Session) DestroyAllKeys() error
DestroyAllKeys destroys all the keys using the rsaLabel defined in the session struct.
func (*PKCS11Session) End ¶
func (session *PKCS11Session) End() error
End finishes a session execution, logging out and clossing the session.
func (*PKCS11Session) GetKeys ¶
func (session *PKCS11Session) GetKeys() (keys *SigKeys, err error)
GetKeys get the public key string and private key habdler from HSM. returns an error, if any.
func (*PKCS11Session) GetPublicKeyBytes ¶
func (session *PKCS11Session) GetPublicKeyBytes(keys *SigKeys) (zskBytes, kskBytes []byte, err error)
GetPublicKeyBytes returns bytestrings of public zsk and ksk keys.
type RRArray ¶
RRArray represents an array of rrs It implements Swapper interface, and is sortable.
func (RRArray) Less ¶
Less returns true if the element in the position i of RRArray is less than the element in position j of RRArray.
type RRSetList ¶
type RRSetList []RRArray
RRSetList is an array of RRArrays.
type SigKeys ¶
type SigKeys struct {
// contains filtered or unexported fields
}
SigKeys contains the four keys used in zone signing.
type SignAlgorithm ¶
type SignAlgorithm uint8
SignAlgorithm represents the algorithm used to sign a zone The numbers are the same the RFC defined for the algorithms.