2 Copyright (c) 2020 Apple Inc. All rights reserved.
5 #ifndef __DNSServerDNSSEC_h
6 #define __DNSServerDNSSEC_h
8 #include <CoreUtils/CoreUtils.h>
10 CU_ASSUME_NONNULL_BEGIN
14 //---------------------------------------------------------------------------------------------------------------------------
15 /*! @brief Zone Label Argument Limits
18 #define kZoneLabelIndexArgMin 1
19 #define kZoneLabelIndexArgMax 3
21 //---------------------------------------------------------------------------------------------------------------------------
22 /*! @brief Reference to a DNSKeyInfo object.
24 typedef const union DNSKeyInfo
* DNSKeyInfoRef
;
26 //---------------------------------------------------------------------------------------------------------------------------
27 /*! @brief Gets a constant DNSKeyInfo object, which represents a DNSSEC DNS key.
29 @param inAlgorithm The desired DNSKeyInfo object's DNSSEC algorithm number.
30 @param inIndex The desired DNSKeyInfo object's index number.
31 @param inGetZSK If true, gets a zone-signing key. Otherwise a key-signing key.
33 @result If a reference to the DNSKeyInfo object if it exists, otherwise, NULL.
35 DNSKeyInfoRef _Nullable
GetDNSKeyInfoEx( uint32_t inAlgorithm
, uint32_t inIndex
, Boolean inGetZSK
);
36 #define GetDNSKeyInfoKSK( ALGORITHM, INDEX ) GetDNSKeyInfoEx( ALGORITHM, INDEX, false )
37 #define GetDNSKeyInfoZSK( ALGORITHM, INDEX ) GetDNSKeyInfoEx( ALGORITHM, INDEX, true )
39 //---------------------------------------------------------------------------------------------------------------------------
40 /*! @brief Gets a DNSKeyInfo object's DNSSEC algorithm number.
42 @param inKeyInfo The DNSKeyInfo object.
44 @result The DNSSEC algorithm number.
46 @discussion See <https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml#dns-sec-alg-numbers-1>.
48 uint8_t DNSKeyInfoGetAlgorithm( DNSKeyInfoRef inKeyInfo
);
50 //---------------------------------------------------------------------------------------------------------------------------
51 /*! @brief Gets a pointer to a DNSKeyInfo object's DNSKEY record data.
53 @param inKeyInfo The DNSKeyInfo object.
55 @result The DNSKEY record data in wire format. See <https://tools.ietf.org/html/rfc4034#section-2.1>.
57 @discussion Use DNSKeyInfoGetRDataLen() to get the record data's length.
59 const uint8_t * DNSKeyInfoGetRDataPtr( DNSKeyInfoRef inKeyInfo
);
61 //---------------------------------------------------------------------------------------------------------------------------
62 /*! @brief Gets the length of a DNSKeyInfo object's DNSKEY record data.
64 @param inKeyInfo The DNSKeyInfo object.
66 @result The length of the record data.
68 uint16_t DNSKeyInfoGetRDataLen( DNSKeyInfoRef inKeyInfo
);
70 //---------------------------------------------------------------------------------------------------------------------------
71 /*! @brief Gets a pointer to a DNSKeyInfo object's public key.
73 @param inKeyInfo The DNSKeyInfo object.
75 @result A pointer to the public key.
77 @discussion Use DNSKeyInfoGetPubKeyLen() to get the public key's length.
79 const uint8_t * _Nullable
DNSKeyInfoGetPubKeyPtr( DNSKeyInfoRef inKeyInfo
);
81 //---------------------------------------------------------------------------------------------------------------------------
82 /*! @brief Gets the length of a DNSKeyInfo object's public key.
84 @param inKeyInfo The DNSKeyInfo object.
86 @result The length of the public key.
88 size_t DNSKeyInfoGetPubKeyLen( DNSKeyInfoRef inKeyInfo
);
90 //---------------------------------------------------------------------------------------------------------------------------
91 /*! @brief Gets the DNSSEC key tag of DNSKeyInfo objects' DNSKEY record data.
93 @param inKeyInfo The DNSKeyInfo object.
95 @result The DNSSEC key tag.
97 uint16_t DNSKeyInfoGetKeyTag( DNSKeyInfoRef inKeyInfo
);
99 //---------------------------------------------------------------------------------------------------------------------------
100 /*! @defined kDNSServerSignatureLengthMax
102 @discussion The maximum length of a DNSSEC signature for DNSSEC algorithms currently implemented by the test DNS server.
104 #define kDNSServerSignatureLengthMax 256
106 //---------------------------------------------------------------------------------------------------------------------------
107 /*! @brief Signs a message using a DNSKeyInfo object's secret key.
109 @param inKeyInfo The DNSKeyInfo object.
110 @param inMsgPtr Pointer to the message to sign.
111 @param inMsgLen Length, in bytes, of the message to sign.
112 @param outSignature Buffer to which to write the signature.
113 @param outSignatureLen Pointer of variable to get set to the signature's length.
115 @result Returns true if the message was able to be signed, otherwise, returns false.
119 DNSKeyInfoRef inKeyInfo
,
120 const uint8_t * inMsgPtr
,
122 uint8_t outSignature
[ STATIC_PARAM kDNSServerSignatureLengthMax
],
123 size_t * outSignatureLen
);
125 //---------------------------------------------------------------------------------------------------------------------------
126 /*! @brief Verifies a signature using a DNSKeyInfo object's public key.
128 @param inKeyInfo The DNSKeyInfo object.
129 @param inMsgPtr Pointer to the message that was signed.
130 @param inMsgLen Length, in bytes, of the message that was signed.
131 @param inSignaturePtr Pointer to the supposed signature.
132 @param inSignatureLen Length, in bytes, of the supposed signature.
134 @result Returns true if the signature was verified, otherwise, returns false.
138 DNSKeyInfoRef inKeyInfo
,
139 const uint8_t * inMsgPtr
,
141 const uint8_t * inSignaturePtr
,
142 size_t inSignatureLen
);
144 //---------------------------------------------------------------------------------------------------------------------------
145 /*! @brief Gets a short description of a DNSKeyInfo object's DNSSEC algorithm.
147 @param inKeyInfo The DNSKeyInfo object.
149 @result The description as a UTF-8 C string.
151 const char * DNSKeyInfoGetAlgorithmDescription( DNSKeyInfoRef inKeyInfo
);
155 CU_ASSUME_NONNULL_END
157 #endif // __DNSServerDNSSEC_h