mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-12-15 14:21:29 +01:00
Automatically calculate auth data length based on the auth method
Change-Id: I9d21834a160e6f4b2ed086f17cda144493e7c3aa
This commit is contained in:
parent
f80ffab2eb
commit
51aaca1752
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user