mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-12-16 14:52:15 +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
|
// TODO: need to be configurable
|
||||||
private static final String AUTH_KEY = "onos";
|
private static final String AUTH_KEY = "onos";
|
||||||
|
|
||||||
private static final short AUTH_DATA_LENGTH = 20;
|
|
||||||
|
|
||||||
// TODO: need to be configurable
|
// TODO: need to be configurable
|
||||||
private static final short AUTH_METHOD = 1;
|
private static final short AUTH_METHOD = 1;
|
||||||
|
|
||||||
@ -79,11 +77,11 @@ public class LispMapServer {
|
|||||||
// build temp notify message
|
// build temp notify message
|
||||||
NotifyBuilder authNotifyBuilder = new DefaultNotifyBuilder();
|
NotifyBuilder authNotifyBuilder = new DefaultNotifyBuilder();
|
||||||
authNotifyBuilder.withKeyId(AUTH_METHOD);
|
authNotifyBuilder.withKeyId(AUTH_METHOD);
|
||||||
authNotifyBuilder.withAuthDataLength(AUTH_DATA_LENGTH);
|
authNotifyBuilder.withAuthDataLength(valueOf(AUTH_METHOD).getHashLength());
|
||||||
authNotifyBuilder.withNonce(register.getNonce());
|
authNotifyBuilder.withNonce(register.getNonce());
|
||||||
authNotifyBuilder.withMapRecords(register.getMapRecords());
|
authNotifyBuilder.withMapRecords(register.getMapRecords());
|
||||||
|
|
||||||
byte[] authData = new byte[AUTH_DATA_LENGTH];
|
byte[] authData = new byte[valueOf(AUTH_METHOD).getHashLength()];
|
||||||
Arrays.fill(authData, (byte) 0);
|
Arrays.fill(authData, (byte) 0);
|
||||||
authNotifyBuilder.withAuthenticationData(authData);
|
authNotifyBuilder.withAuthenticationData(authData);
|
||||||
|
|
||||||
@ -97,13 +95,13 @@ public class LispMapServer {
|
|||||||
byte[] bytes = new byte[byteBuf.readableBytes()];
|
byte[] bytes = new byte[byteBuf.readableBytes()];
|
||||||
byteBuf.readBytes(bytes);
|
byteBuf.readBytes(bytes);
|
||||||
|
|
||||||
byte[] sha1AuthData =
|
byte[] calcAuthData = factory.createAuthenticationData(
|
||||||
factory.createAuthenticationData(valueOf(register.getKeyId()), AUTH_KEY, bytes);
|
valueOf(register.getKeyId()), AUTH_KEY, bytes);
|
||||||
|
|
||||||
NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
|
NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
|
||||||
notifyBuilder.withKeyId(AUTH_METHOD);
|
notifyBuilder.withKeyId(AUTH_METHOD);
|
||||||
notifyBuilder.withAuthDataLength((short) sha1AuthData.length);
|
notifyBuilder.withAuthDataLength((short) calcAuthData.length);
|
||||||
notifyBuilder.withAuthenticationData(sha1AuthData);
|
notifyBuilder.withAuthenticationData(calcAuthData);
|
||||||
notifyBuilder.withNonce(register.getNonce());
|
notifyBuilder.withNonce(register.getNonce());
|
||||||
notifyBuilder.withMapRecords(register.getMapRecords());
|
notifyBuilder.withMapRecords(register.getMapRecords());
|
||||||
|
|
||||||
@ -123,10 +121,10 @@ public class LispMapServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the integrity of the received Map-Register message by calculating
|
* Checks the integrity of the received map-register message by calculating
|
||||||
* authentication data from received Map-Register message.
|
* authentication data from received map-register message.
|
||||||
*
|
*
|
||||||
* @param register Map-Register message
|
* @param register map-register message
|
||||||
* @return evaluation result
|
* @return evaluation result
|
||||||
*/
|
*/
|
||||||
private boolean checkAuthData(LispMapRegister register) {
|
private boolean checkAuthData(LispMapRegister register) {
|
||||||
@ -154,8 +152,8 @@ public class LispMapServer {
|
|||||||
byte[] bytes = new byte[byteBuf.readableBytes()];
|
byte[] bytes = new byte[byteBuf.readableBytes()];
|
||||||
byteBuf.readBytes(bytes);
|
byteBuf.readBytes(bytes);
|
||||||
|
|
||||||
byte[] calculatedAuthData =
|
byte[] calculatedAuthData = factory.createAuthenticationData(
|
||||||
factory.createAuthenticationData(valueOf(register.getKeyId()), AUTH_KEY, bytes);
|
valueOf(register.getKeyId()), AUTH_KEY, bytes);
|
||||||
return Arrays.equals(calculatedAuthData, register.getAuthenticationData());
|
return Arrays.equals(calculatedAuthData, register.getAuthenticationData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,23 +26,25 @@ package org.onosproject.lisp.msg.authentication;
|
|||||||
public enum LispAuthenticationKeyEnum {
|
public enum LispAuthenticationKeyEnum {
|
||||||
|
|
||||||
/** No authentication. */
|
/** No authentication. */
|
||||||
NONE(0, null),
|
NONE(0, null, 0),
|
||||||
|
|
||||||
/** HMAC SHA1 encryption. */
|
/** HMAC SHA1 encryption. */
|
||||||
SHA1(1, "HmacSHA1"),
|
SHA1(1, "HmacSHA1", 20),
|
||||||
|
|
||||||
/** HMAC SHA256 encryption. */
|
/** HMAC SHA256 encryption. */
|
||||||
SHA256(2, "HmacSHA256"),
|
SHA256(2, "HmacSHA256", 32),
|
||||||
|
|
||||||
/** Unsupported authentication type. */
|
/** Unsupported authentication type. */
|
||||||
UNKNOWN(-1, "UNKNOWN");
|
UNKNOWN(-1, "UNKNOWN", 0);
|
||||||
|
|
||||||
private short keyId;
|
private short keyId;
|
||||||
private String name;
|
private String name;
|
||||||
|
private short length;
|
||||||
|
|
||||||
LispAuthenticationKeyEnum(int keyId, String name) {
|
LispAuthenticationKeyEnum(int keyId, String name, int length) {
|
||||||
this.keyId = (short) keyId;
|
this.keyId = (short) keyId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.length = (short) length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +65,15 @@ public enum LispAuthenticationKeyEnum {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains hash length.
|
||||||
|
*
|
||||||
|
* @return hash length
|
||||||
|
*/
|
||||||
|
public short getHashLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains LISP authentication key enum by providing key identifier.
|
* Obtains LISP authentication key enum by providing key identifier.
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user