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 69191d3040..aca2c76be2 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 @@ public class LispMapServer { // 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 @@ public class LispMapServer { // 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 @@ public class LispMapServer { 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 @@ public class LispMapServer { } /** - * 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 @@ public class LispMapServer { 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()); } } diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationKeyEnum.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationKeyEnum.java index ecf6c8e663..2bd3df98d2 100644 --- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationKeyEnum.java +++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/authentication/LispAuthenticationKeyEnum.java @@ -26,23 +26,25 @@ package org.onosproject.lisp.msg.authentication; public enum LispAuthenticationKeyEnum { /** No authentication. */ - NONE(0, null), + NONE(0, null, 0), /** HMAC SHA1 encryption. */ - SHA1(1, "HmacSHA1"), + SHA1(1, "HmacSHA1", 20), /** HMAC SHA256 encryption. */ - SHA256(2, "HmacSHA256"), + SHA256(2, "HmacSHA256", 32), /** Unsupported authentication type. */ - UNKNOWN(-1, "UNKNOWN"); + UNKNOWN(-1, "UNKNOWN", 0); private short keyId; private String name; + private short length; - LispAuthenticationKeyEnum(int keyId, String name) { + LispAuthenticationKeyEnum(int keyId, String name, int length) { this.keyId = (short) keyId; this.name = name; + this.length = (short) length; } /** @@ -63,6 +65,15 @@ public enum LispAuthenticationKeyEnum { return name; } + /** + * Obtains hash length. + * + * @return hash length + */ + public short getHashLength() { + return length; + } + /** * Obtains LISP authentication key enum by providing key identifier. *