a029eb
diff --git a/omapip/connection.c b/omapip/connection.c
a029eb
index a74becc..56826a5 100644
a029eb
--- a/omapip/connection.c
a029eb
+++ b/omapip/connection.c
a029eb
@@ -46,6 +46,9 @@ extern omapi_array_t *trace_listeners;
a029eb
 #endif
a029eb
 static isc_result_t omapi_connection_connect_internal (omapi_object_t *);
a029eb
 
a029eb
+static isc_result_t ctring_from_attribute(omapi_object_t *obj, char *attr_name,
a029eb
+                                          char **cstr);
a029eb
+
a029eb
 OMAPI_OBJECT_ALLOC (omapi_connection,
a029eb
 		    omapi_connection_object_t, omapi_type_connection)
a029eb
 
a029eb
@@ -765,64 +768,41 @@ isc_result_t omapi_connection_reaper (omapi_object_t *h)
a029eb
 }
a029eb
 
a029eb
 static isc_result_t make_dst_key (dst_key_t **dst_key, omapi_object_t *a) {
a029eb
-	omapi_value_t *name      = (omapi_value_t *)0;
a029eb
-	omapi_value_t *algorithm = (omapi_value_t *)0;
a029eb
-	omapi_value_t *key       = (omapi_value_t *)0;
a029eb
-	char *name_str = NULL;
a029eb
+	omapi_value_t *key = 0;
a029eb
+	char *name_str = 0;
a029eb
+	char *algorithm_str = 0;
a029eb
 	isc_result_t status = ISC_R_SUCCESS;
a029eb
 
a029eb
-	if (status == ISC_R_SUCCESS)
a029eb
-		status = omapi_get_value_str
a029eb
-			(a, (omapi_object_t *)0, "name", &name);
a029eb
-
a029eb
-	if (status == ISC_R_SUCCESS)
a029eb
-		status = omapi_get_value_str
a029eb
-			(a, (omapi_object_t *)0, "algorithm", &algorithm);
a029eb
-
a029eb
-	if (status == ISC_R_SUCCESS)
a029eb
-		status = omapi_get_value_str
a029eb
-			(a, (omapi_object_t *)0, "key", &key);
a029eb
-
a029eb
+	/* Get the key name as a C string. */
a029eb
+	status = ctring_from_attribute(a, "name", &name_str);
a029eb
 	if (status == ISC_R_SUCCESS) {
a029eb
-		if ((algorithm->value->type != omapi_datatype_data &&
a029eb
-		     algorithm->value->type != omapi_datatype_string) ||
a029eb
-		    strncasecmp((char *)algorithm->value->u.buffer.value,
a029eb
-				NS_TSIG_ALG_HMAC_MD5 ".",
a029eb
-				algorithm->value->u.buffer.len) != 0) {
a029eb
-			status = DHCP_R_INVALIDARG;
a029eb
+		/* Get the algorithm name as a C string. */
a029eb
+		status = ctring_from_attribute(a, "algorithm", &algorithm_str);
a029eb
+		if (status == ISC_R_SUCCESS) {
a029eb
+			/* Get the key secret value */
a029eb
+			status = omapi_get_value_str(a, 0, "key", &key);
a029eb
+			if (status == ISC_R_SUCCESS) {
a029eb
+				/* Now let's try and create the key */
a029eb
+				status = isclib_make_dst_key(
a029eb
+						name_str,
a029eb
+						algorithm_str,
a029eb
+						key->value->u.buffer.value,
a029eb
+						key->value->u.buffer.len,
a029eb
+						dst_key);
a029eb
+
a029eb
+				if (*dst_key == NULL) {
a029eb
+					status = ISC_R_NOMEMORY;
a029eb
+				}
a029eb
+			}
a029eb
 		}
a029eb
 	}
a029eb
 
a029eb
-	if (status == ISC_R_SUCCESS) {
a029eb
-		name_str = dmalloc (name -> value -> u.buffer.len + 1, MDL);
a029eb
-		if (!name_str)
a029eb
-			status = ISC_R_NOMEMORY;
a029eb
-	}
a029eb
-
a029eb
-	if (status == ISC_R_SUCCESS) {
a029eb
-		memcpy (name_str,
a029eb
-			name -> value -> u.buffer.value,
a029eb
-			name -> value -> u.buffer.len);
a029eb
-		name_str [name -> value -> u.buffer.len] = 0;
a029eb
-
a029eb
-		status = isclib_make_dst_key(name_str,
a029eb
-					     DHCP_HMAC_MD5_NAME,
a029eb
-					     key->value->u.buffer.value,
a029eb
-					     key->value->u.buffer.len,
a029eb
-					     dst_key);
a029eb
-
a029eb
-		if (*dst_key == NULL)
a029eb
-			status = ISC_R_NOMEMORY;
a029eb
-	}
a029eb
-
a029eb
 	if (name_str)
a029eb
 		dfree (name_str, MDL);
a029eb
+	if (algorithm_str)
a029eb
+		dfree (algorithm_str, MDL);
a029eb
 	if (key)
a029eb
 		omapi_value_dereference (&key, MDL);
a029eb
-	if (algorithm)
a029eb
-		omapi_value_dereference (&algorithm, MDL);
a029eb
-	if (name)
a029eb
-		omapi_value_dereference (&name, MDL);
a029eb
 
a029eb
 	return status;
a029eb
 }
a029eb
@@ -1105,3 +1085,50 @@ isc_result_t omapi_connection_stuff_values (omapi_object_t *c,
a029eb
 								m -> inner);
a029eb
 	return ISC_R_SUCCESS;
a029eb
 }
a029eb
+
a029eb
+/* @brief Fetches the value of an attribute in an object as an allocated
a029eb
+ * C string
a029eb
+ *
a029eb
+ * @param obj ompapi object containing the desire attribute
a029eb
+ * @param attr_name  name of the desired attribute
a029eb
+ * @param[out] cstr pointer in which to place the allocated C string's address
a029eb
+ *
a029eb
+ * Caller is responsible for freeing (via dfree) the allocated string.
a029eb
+ *
a029eb
+ * @return ISC_R_SUCCESS if successful, otherwise indicates the type of failure
a029eb
+*/
a029eb
+static isc_result_t ctring_from_attribute(omapi_object_t *obj, char *attr_name,
a029eb
+                                          char **cstr) {
a029eb
+	isc_result_t status = ISC_R_SUCCESS;
a029eb
+	omapi_value_t *attr = 0;
a029eb
+
a029eb
+	/* Find the attribute in the object. */
a029eb
+	status = omapi_get_value_str(obj, (omapi_object_t *)0, attr_name,
a029eb
+                                 &attr);
a029eb
+	if (status != ISC_R_SUCCESS) {
a029eb
+		return (status);
a029eb
+	}
a029eb
+
a029eb
+	/* Got it, let's make sure it's either data or string type. */
a029eb
+	if (attr->value->type != omapi_datatype_data &&
a029eb
+            attr->value->type != omapi_datatype_string) {
a029eb
+		return (DHCP_R_INVALIDARG);
a029eb
+        }
a029eb
+
a029eb
+	/* Make a C string from the attribute value. */
a029eb
+	*cstr = dmalloc (attr->value->u.buffer.len + 1, MDL);
a029eb
+	if (!(*cstr)) {
a029eb
+		status = ISC_R_NOMEMORY;
a029eb
+        } else {
a029eb
+	        memcpy (*cstr, attr->value->u.buffer.value,
a029eb
+		            attr->value->u.buffer.len);
a029eb
+	        (*cstr)[attr->value->u.buffer.len] = 0;
a029eb
+	}
a029eb
+
a029eb
+	/* Get rid of the attribute reference */
a029eb
+	if (attr) {
a029eb
+		omapi_value_dereference (&attr, MDL);
a029eb
+	}
a029eb
+
a029eb
+	return (status);
a029eb
+}