Automatically calculate auth data length based on the auth method
Change-Id: I9d21834a160e6f4b2ed086f17cda144493e7c3aa
diff --git a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java
index 69191d3..aca2c76 100644
--- a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java
+++ b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java
@@ -46,8 +46,6 @@
// TODO: need to be configurable
private static final String AUTH_KEY = "onos";
- private static final short AUTH_DATA_LENGTH = 20;
-
// TODO: need to be configurable
private static final short AUTH_METHOD = 1;
@@ -79,11 +77,11 @@
// build temp notify message
NotifyBuilder authNotifyBuilder = new DefaultNotifyBuilder();
authNotifyBuilder.withKeyId(AUTH_METHOD);
- authNotifyBuilder.withAuthDataLength(AUTH_DATA_LENGTH);
+ authNotifyBuilder.withAuthDataLength(valueOf(AUTH_METHOD).getHashLength());
authNotifyBuilder.withNonce(register.getNonce());
authNotifyBuilder.withMapRecords(register.getMapRecords());
- byte[] authData = new byte[AUTH_DATA_LENGTH];
+ byte[] authData = new byte[valueOf(AUTH_METHOD).getHashLength()];
Arrays.fill(authData, (byte) 0);
authNotifyBuilder.withAuthenticationData(authData);
@@ -97,13 +95,13 @@
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
- byte[] sha1AuthData =
- factory.createAuthenticationData(valueOf(register.getKeyId()), AUTH_KEY, bytes);
+ byte[] calcAuthData = factory.createAuthenticationData(
+ valueOf(register.getKeyId()), AUTH_KEY, bytes);
NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
notifyBuilder.withKeyId(AUTH_METHOD);
- notifyBuilder.withAuthDataLength((short) sha1AuthData.length);
- notifyBuilder.withAuthenticationData(sha1AuthData);
+ notifyBuilder.withAuthDataLength((short) calcAuthData.length);
+ notifyBuilder.withAuthenticationData(calcAuthData);
notifyBuilder.withNonce(register.getNonce());
notifyBuilder.withMapRecords(register.getMapRecords());
@@ -123,10 +121,10 @@
}
/**
- * Checks the integrity of the received Map-Register message by calculating
- * authentication data from received Map-Register message.
+ * Checks the integrity of the received map-register message by calculating
+ * authentication data from received map-register message.
*
- * @param register Map-Register message
+ * @param register map-register message
* @return evaluation result
*/
private boolean checkAuthData(LispMapRegister register) {
@@ -154,8 +152,8 @@
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
- byte[] calculatedAuthData =
- factory.createAuthenticationData(valueOf(register.getKeyId()), AUTH_KEY, bytes);
+ byte[] calculatedAuthData = factory.createAuthenticationData(
+ valueOf(register.getKeyId()), AUTH_KEY, bytes);
return Arrays.equals(calculatedAuthData, register.getAuthenticationData());
}
}