65638c
From e6ffc27f24321017a5ad9af3707f4e2e54bbac74 Mon Sep 17 00:00:00 2001
65638c
From: Thomas Markwalder <tmark@isc.org>
65638c
Date: Mon, 11 Dec 2017 07:19:43 -0500
65638c
Subject: [PATCH] [master] Adds key-algorithm statement to omshell
65638c
65638c
    Merges in rt46771.
65638c
---
65638c
 RELNOTES            |  7 +++++++
65638c
 common/conflex.c    |  2 ++
65638c
 dhcpctl/omshell.1   | 32 ++++++++++++++++++++++++--------
65638c
 dhcpctl/omshell.c   | 38 +++++++++++++++++++++++++++++++++++---
65638c
 includes/dhctoken.h |  3 ++-
65638c
 5 files changed, 70 insertions(+), 12 deletions(-)
65638c
65638c
diff --git a/common/conflex.c b/common/conflex.c
65638c
index 8ce024af..045b655d 100644
65638c
--- a/common/conflex.c
65638c
+++ b/common/conflex.c
65638c
@@ -1104,6 +1104,8 @@ intern(char *atom, enum dhcp_token dfv) {
65638c
 		}
65638c
 		if (!strcasecmp (atom + 1, "ey"))
65638c
 			return KEY;
65638c
+		if (!strcasecmp (atom + 1, "ey-algorithm"))
65638c
+			return KEY_ALGORITHM;
65638c
 		break;
65638c
 	      case 'l':
65638c
 		if (!strcasecmp (atom + 1, "case"))
65638c
diff --git a/dhcpctl/omshell.1 b/dhcpctl/omshell.1
65638c
index 4846272a..2f55e965 100644
65638c
--- a/dhcpctl/omshell.1
65638c
+++ b/dhcpctl/omshell.1
65638c
@@ -1,7 +1,6 @@
65638c
 .\"	$Id: omshell.1,v 1.6 2009/11/24 02:06:56 sar Exp $
65638c
 .\"
65638c
-.\" Copyright (c) 2012,2014 by Internet Systems Consortium, Inc. ("ISC")
65638c
-.\" Copyright (c) 2004,2009 by Internet Systems Consortium, Inc. ("ISC")
65638c
+.\" Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
65638c
 .\" Copyright (c) 2001-2003 by Internet Software Consortium
65638c
 .\"
65638c
 .\" Permission to use, copy, modify, and distribute this software for any
65638c
@@ -81,7 +80,24 @@ where number is the port that OMAPI listens on.  By default, this is 7911.
65638c
 This specifies the TSIG key to use to authenticate the OMAPI transactions.
65638c
 \fIname\fR is the name of a key defined in \fIdhcpd.conf\fR with the
65638c
 \fBomapi-key\fR statement.  The \fIsecret\fR is the secret key generated from
65638c
-\fBdnssec-keygen\fR or another key generation program.
65638c
+\fBdnssec-keygen\fR or another key generation program.  The key algorithm is
65638c
+assumed to be HMAC-MD5 key. If a different algorithm was specified in dhcpd.conf
65638c
+file for the key, then it must be specified via the \fIkey-algorithm\fR statement.
65638c
+.RE
65638c
+.PP
65638c
+.B key-algorithm \fIalgorithm\fR
65638c
+.RS 0.5i
65638c
+This specifies the cryptographic algorithm for the key used when authenticating OMAPI
65638c
+transactions. Supported values for \fIalgorithm\fR are:
65638c
+.nf
65638c
+        HMAC-MD5
65638c
+        HMAC-SHA1
65638c
+        HMAC-SHA224
65638c
+        HMAC-SHA256
65638c
+        HMAC-SHA384
65638c
+        HMAC-SHA512
65638c
+fi
65638c
+The default is HMAC-MD5. (Value is not case sensitive).
65638c
 .RE
65638c
 .PP
65638c
 .B connect
65638c
@@ -253,7 +269,7 @@ name = "some-host"
65638c
 hardware-address = 00:80:c7:84:b1:94
65638c
 hardware-type = 00:00:00:01
65638c
 ip-address = c0:a8:04:28
65638c
-> 
65638c
+>
65638c
 .fi
65638c
 .PP
65638c
 Your dhcpd.leases file would then have an entry like this in it:
65638c
@@ -267,7 +283,7 @@ host some-host {
65638c
 .fi
65638c
 .PP
65638c
 The \fIdynamic;\fR line is to denote that this host entry did not come from
65638c
-dhcpd.conf, but was created dynamically via OMAPI.  
65638c
+dhcpd.conf, but was created dynamically via OMAPI.
65638c
 .SH RESETTING ATTRIBUTES
65638c
 .PP
65638c
 If you want to remove an attribute from an object, you can do this with the
65638c
@@ -288,7 +304,7 @@ name = "some-host"
65638c
 hardware-address = 00:80:c7:84:b1:94
65638c
 hardware-type = 00:00:00:01
65638c
 ip-address = <null>
65638c
-> 
65638c
+>
65638c
 .fi
65638c
 .SH REFRESHING OBJECTS
65638c
 .PP
65638c
@@ -300,7 +316,7 @@ particularly useful for hosts.
65638c
 .PP
65638c
 Any remote object that can be created can also be destroyed.  This is done by
65638c
 creating a new local object, setting attributes, associating the local and
65638c
-remote object using \fBopen\fR, and then using the \fBremove\fR command. 
65638c
+remote object using \fBopen\fR, and then using the \fBremove\fR command.
65638c
 If the host "some-host" from before was created in error, this could be
65638c
 corrected as follows:
65638c
 .nf
65638c
@@ -312,7 +328,7 @@ hardware-type = 00:00:00:01
65638c
 ip-address = c0:a8:04:28
65638c
 > remove
65638c
 obj: <null>
65638c
-> 
65638c
+>
65638c
 .fi
65638c
 .SH HELP
65638c
 .PP
65638c
diff --git a/dhcpctl/omshell.c b/dhcpctl/omshell.c
65638c
index c42bab1a..9233f50e 100644
65638c
--- a/dhcpctl/omshell.c
65638c
+++ b/dhcpctl/omshell.c
65638c
@@ -321,12 +321,42 @@ main(int argc, char **argv) {
65638c
 		    }
65638c
 		    break;
65638c
 
65638c
+		  case KEY_ALGORITHM:
65638c
+		    /* Algorithm is optional */
65638c
+		    token = next_token (&val, (unsigned *)0, cfile);
65638c
+		    if (token != NAME || !is_identifier(token)) {
65638c
+			printf ("missing or invalid algorithm name\n");
65638c
+			printf ("usage: key-algoritm <algorithm name>\n");
65638c
+			skip_to_semi (cfile);
65638c
+			break;
65638c
+		    }
65638c
+
65638c
+		    s = dmalloc (strlen (val) + 1, MDL);
65638c
+		    if (!s) {
65638c
+			printf ("no memory for algorithm name.\n");
65638c
+			skip_to_semi (cfile);
65638c
+			break;
65638c
+		    }
65638c
+
65638c
+		    strcpy (s, val);
65638c
+		    algorithm = s;
65638c
+
65638c
+		    token = next_token (&val, (unsigned *)0, cfile);
65638c
+		    if (token != END_OF_FILE && token != EOL) {
65638c
+			    printf ("extra information after %s\n", algorithm);
65638c
+			    printf ("usage: key-algorithm <algorithm name>\n");
65638c
+			    skip_to_semi (cfile);
65638c
+			    break;
65638c
+		    }
65638c
+
65638c
+		    break;
65638c
+
65638c
 		  case KEY:
65638c
 		    token = peek_token(&val, (unsigned *)0, cfile);
65638c
 		    if (token == STRING) {
65638c
 			    token = next_token (&val, (unsigned *)0, cfile);
65638c
 			    if (!is_identifier (token)) {
65638c
-				    printf ("usage: key <name> <value>\n");
65638c
+			            printf ("usage: key <name> <value>\n");
65638c
 				    skip_to_semi (cfile);
65638c
 				    break;
65638c
 			    }
65638c
@@ -340,7 +370,7 @@ main(int argc, char **argv) {
65638c
 		    } else {
65638c
 			    s = parse_host_name(cfile);
65638c
 			    if (s == NULL) {
65638c
-				    printf ("usage: key <name> <value>\n");
65638c
+			            printf ("usage: key <name> <value>\n");
65638c
 				    skip_to_semi(cfile);
65638c
 				    break;
65638c
 			    }
65638c
@@ -352,12 +382,14 @@ main(int argc, char **argv) {
65638c
 			    skip_to_semi (cfile);
65638c
 			    break;
65638c
 		    }
65638c
+
65638c
 		    token = next_token (&val, (unsigned *)0, cfile);
65638c
 		    if (token != END_OF_FILE && token != EOL) {
65638c
-			    printf ("usage: key <name> <secret>\n");
65638c
+			    printf ("usage: key <name> <value> {algorithm}\n");
65638c
 			    skip_to_semi (cfile);
65638c
 			    break;
65638c
 		    }
65638c
+
65638c
 		    break;
65638c
 
65638c
 		  case CONNECT:
65638c
diff --git a/includes/dhctoken.h b/includes/dhctoken.h
65638c
index 6fc4df3..ca24d4c 100644
65638c
--- a/includes/dhctoken.h
65638c
+++ b/includes/dhctoken.h
65638c
@@ -374,8 +374,9 @@ enum dhcp_token {
65638c
 	LEASE_ID_FORMAT = 676,
65638c
 	TOKEN_HEX = 677,
65638c
 	TOKEN_OCTAL = 678,
65638c
-	BOOTP_BROADCAST_ALWAYS = 679,
65638c
-	DESTINATION_DESCRIPTOR = 680
65638c
+	KEY_ALGORITHM = 679,
65638c
+	BOOTP_BROADCAST_ALWAYS = 680,
65638c
+	DESTINATION_DESCRIPTOR = 681
65638c
 };
65638c
 
65638c
 #define is_identifier(x)	((x) >= FIRST_TOKEN &&	\