55import java .security .PrivateKey ;
66import java .time .Duration ;
77import java .time .Instant ;
8+ import org .xbill .DNS .DNSSEC .DNSSECException ;
89
910/**
1011 * Creates SIG(0) transaction signatures.
@@ -34,6 +35,22 @@ private SIG0() {}
3435 public static void signMessage (
3536 Message message , KEYRecord key , PrivateKey privkey , SIGRecord previous )
3637 throws DNSSEC .DNSSECException {
38+ signMessage (message , key , privkey , previous , Instant .now ());
39+ }
40+
41+ /**
42+ * Sign a message with SIG(0). The DNS key and private key must refer to the same underlying
43+ * cryptographic key.
44+ *
45+ * @param message The message to be signed
46+ * @param key The DNSKEY record to use as part of signing
47+ * @param privkey The PrivateKey to use when signing
48+ * @param previous If this message is a response, the SIG(0) from the query
49+ * @param timeSigned The time instant when the message has been signed.
50+ */
51+ public static void signMessage (
52+ Message message , KEYRecord key , PrivateKey privkey , SIGRecord previous , Instant timeSigned )
53+ throws DNSSEC .DNSSECException {
3754
3855 int validityOption = Options .intValue ("sig0validity" );
3956 Duration validity ;
@@ -43,7 +60,6 @@ public static void signMessage(
4360 validity = Duration .ofSeconds (validityOption );
4461 }
4562
46- Instant timeSigned = Instant .now ();
4763 Instant timeExpires = timeSigned .plus (validity );
4864
4965 SIGRecord sig = DNSSEC .signMessage (message , previous , key , privkey , timeSigned , timeExpires );
@@ -52,7 +68,7 @@ public static void signMessage(
5268 }
5369
5470 /**
55- * Verify a message using SIG(0).
71+ * Verify a message using SIG(0). Uses the current system clock for the date/time.
5672 *
5773 * @param message The message to be signed
5874 * @param b An array containing the message in unparsed form. This is necessary since SIG(0) signs
@@ -62,6 +78,23 @@ public static void signMessage(
6278 * @param previous If this message is a response, the SIG(0) from the query
6379 */
6480 public static void verifyMessage (Message message , byte [] b , KEYRecord key , SIGRecord previous )
81+ throws DNSSECException {
82+ verifyMessage (message , b , key , previous , Instant .now ());
83+ }
84+
85+ /**
86+ * Verify a message using SIG(0).
87+ *
88+ * @param message The message to be signed
89+ * @param b An array containing the message in unparsed form. This is necessary since SIG(0) signs
90+ * the message in wire format, and we can't recreate the exact wire format (with the same name
91+ * compression).
92+ * @param key The KEY record to verify the signature with.
93+ * @param previous If this message is a response, the SIG(0) from the query
94+ * @param now the time instant to verify the message.
95+ */
96+ public static void verifyMessage (
97+ Message message , byte [] b , KEYRecord key , SIGRecord previous , Instant now )
6598 throws DNSSEC .DNSSECException {
6699 SIGRecord sig = null ;
67100 Record [] additional = message .getSectionArray (Section .ADDITIONAL );
@@ -75,6 +108,6 @@ public static void verifyMessage(Message message, byte[] b, KEYRecord key, SIGRe
75108 sig = (SIGRecord ) record ;
76109 break ;
77110 }
78- DNSSEC .verifyMessage (message , b , sig , previous , key );
111+ DNSSEC .verifyMessage (message , b , sig , previous , key , now );
79112 }
80113}
0 commit comments