Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyLabel = errors.New("Empty Label provided (RPZ the root?)")
ErrEmptyLabel is returned when it is attempted to encode an empty label
var ErrEmptySublabel = errors.New("Empty Sub Label (eg. dom..example.com)")
ErrEmptySublabel is returned when a situation like "dom..example.com" is encountered
var ErrInvalidOriginDomain = errors.New("Invalid Origin Domain (empty/root/leading-dot)")
ErrInvalidOriginDomain is returned when the provided is empty, the root (.) or has a leading dot.
var ErrTooLong = errors.New("Domain too long to hash")
ErrTooLong indicates that the input domain was too long when hashed the result from the Hash function is that final only contains the hashed labels upto that error. The caller can decide to wildcard the domain or not.
This is used for a very simple check that just checks that we will never exceed the maximum domainlength; though, one already has to substract the $ORIGIN of the domain (e.g. ```.rpz.example.net```) that this RPZ ownername is part of. Thus typically, eg. given ```.rpz.example.net``` of length 14, it already becomes 255-16-15 = 224; hence why 200 is normally the suggested value, but one can accurately guess this value given the origin.
var ErrWildcardNotAtStart = errors.New("Wildcard (*) not at start of left hand side")
ErrWildcardNotAtStart is returned when there is a wildcard in the middle of the left hand side
Functions ¶
This section is empty.
Types ¶
type HashCallback ¶
HashCallback is called by Hash after each sublabel has been hashed allowing a caller to check at each part of the lefthandside the label that has been hashed.
var NoCallback HashCallback = nil
NoCallback can be used to clearly show in the calling function that no callback is being used (opposed to having a 'nil' and having to check what that nil is for)
type HashedRPZ ¶
HashedRPZ represents a hasher, it has a mutex to ensure only a single caller at a time
func New ¶
New creates a new HashedRPZ deriving the BLAKE3 key from the given string The string should be composed of both an inline and a out-of-band key.
func (*HashedRPZ) Hash ¶
func (h *HashedRPZ) Hash(lefthandside string, origindomain string, callback HashCallback) (final string, err error)
Hash hashes the lefthandside that should be in domain format (thus ```host.example.org```) and returns the HashedRPZ hashed variant of that.
Lefthandside is allowed to end to be fully qualified (ending in a '.') but it will be ignored.
The origindomain (e.g. ```rpz.example.com```) is supplied to limit the length of the resulting ownername to ensure it does not exceed the full length of a domain name.
The origindomain is not used for hashing, only for limiting/detecting length issues.
A mutex ensures that only one hasher at the same time runs Create multiple HashedRPZ, e.g. one per go process, for parallel operation.
The callback will be called for every hashed label, thus allowing the user to do intermediate lookups. One can use a function closure to pass parameters that the callback might need.
Will return ErrInvalidOriginDomain if the origin domain is empty or root, or start with a '.'.
Will return ErrEmptyLabel if the label to hash is empty, this to avoid blocking the root of DNS.
Will return ErrWildcardNotAtStart when there is a wildcard not at the start of the left hand side.
Might return ErrTooLong (see description for details on how to handle it), thus do check for error returns.
Will return ErrEmptySubLabel if an empty sublabel is found.
func (*HashedRPZ) HashWildcard ¶
func (h *HashedRPZ) HashWildcard(lefthandside string, origindomain string, callback HashCallback) (final string, iswildcard bool, err error)
HashWildcard calls Hash() but when the maxdomainlength is exceeded, it encodes the remaining labels as a wildcard inside the domain that fitted.
Thus for example an input of ```host.v.e.r.y.l.o.n.g.example.com``` would encode as ```*.n.g.example.com```. (if the domainname would be much longer than given in this example, see test cases for the real version).