Commit 4a7a5d77 authored by berge's avatar berge
Browse files

Merged branches/Security/javasrc (r1425-1803) to trunk.

This completes cleaning operation of r1821 by re-inserting non-STF455 specific changes in trunk
parent 7c515cdb
......@@ -9,6 +9,8 @@
package org.etsi.its.adapter;
import java.math.BigInteger;
import org.etsi.its.adapter.ports.GnPort;
/**
......@@ -16,59 +18,108 @@ import org.etsi.its.adapter.ports.GnPort;
*/
public interface IManagementLayers {
/**
* Gets the GeoNetworking beacon header to be sent by Test Adapter for the current component
* @return Beacon header, or null if no Beacon shall be sent
*/
public byte[] getGnBeacon();
/**
* Registers a GN port
*/
public void registerGnPort(GnPort gnPort);
/**
* Gets the GeoNetworking beacon header to be sent by Test Adapter for the current component
* @return Beacon header, or null if no Beacon shall be sent
*/
public byte[] getGnBeacon();
/**
* Registers a GN port
*/
public void registerGnPort(GnPort gnPort);
/**
* Gets the GeoNetworking beaconing interval
* @return GeoNetworking beaconing interval in ms
*/
public int getGnBeaconInterval();
/**
* Gets the GeoNetworking beaconing interval
* @return GeoNetworking beaconing interval in ms
*/
public int getGnBeaconInterval();
/**
* Gets the GeoNetworking beacon header acting as filter for enqueueing Beacons received from neighbours
* @return Beacon header, or null if no Beacon shall be enqueued
*/
public byte[] getGnEnqueueBeacon();
/**
* Inserts or updates a neighbour position vector in Test Adapter internal tables
* @param mid Mid part of the neighbour's GN_Address
* @param timestamp Timestamp of the carrying message
* @param lpv Long position vector of the neighbour
*/
public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv);
/**
* Gets the GeoNetworking beacon header acting as filter for enqueueing Beacons received from neighbours
* @return Beacon header, or null if no Beacon shall be enqueued
*/
public byte[] getGnEnqueueBeacon();
/**
* Inserts or updates a neighbour position vector in Test Adapter internal tables
* @param mid Mid part of the neighbour's GN_Address
* @param timestamp Timestamp of the carrying message
* @param lpv Long position vector of the neighbour
*/
public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv);
/**
/**
* Sets the link layer address of this component
* param linkLayerAddress Link-layer address (6 bytes)
*/
public void setLinkLayerAddress(byte[] linkLayerAddress);
/**
* Gets the link layer address of this component
* @return Link-layer address (6 bytes)
*/
public byte[] getLinkLayerAddress();
/**
* Gets the link layer address of this component
* @return Link-layer address (6 bytes)
*/
public byte[] getLinkLayerAddress();
/**
* Gets the latitude of this component
* @return Latitude
*/
public byte[] getLatitude();
/**
* Gets the Longitude of this component
* @return Longitude
*/
public byte[] getLongitude();
/**
* Enable the secured mode
* @param securityData data required to execute the signing process on beacons
*/
public void setSecuredMode(final byte[] securityData);
/**
* Gets the latitude of this component
* @return Latitude
*/
public byte[] getLatitude();
/**
* Disable the secured mode
*/
public void unsetSecuredMode();
/**
* Gets the secured mode status
* @return true if secured mode is set, false otherwise
*/
public boolean isSecuredModeSet();
/**
* Gets the private key for signing process
* @return The private key
*/
public BigInteger getSigningPrivateKey();
/**
* Gets the Longitude of this component
* @return Longitude
*/
public byte[] getLongitude();
/**
* Gets the public key X for signing check
* @return The public key X
*/
public byte[] getSigningPublicKeyX();
/**
* Gets the public key Y for signing check
* @return The public key Y
*/
public byte[] getSigningPublicKeyY();
/**
* Gets the AT certificate value
* @return The AT certificate value
* @remark It shall not be used when secured mode is set by the test execution
*/
byte[] getAtCertificate();
/**
* Gets the Hashed8 value from the AT certificate
* @return The Hashed8 value
* @remark It shall not be used when secured mode is set by the test execution
*/
byte[] getAtCertificateDigest();
}
......@@ -10,12 +10,16 @@
package org.etsi.its.adapter;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.etsi.adapter.TERFactory;
import org.etsi.certificates.CertificatesIOFactory;
import org.etsi.certificates.io.ICertificatesIO;
import org.etsi.common.ByteHelper;
import org.etsi.common.ITuple;
import org.etsi.common.Tuple;
......@@ -31,12 +35,12 @@ public class Management implements IManagementTA, IManagementLayers {
/**
* Instances of Management
*/
private static final ConcurrentMap<String, Management> instances = new ConcurrentHashMap<String, Management>();
/**
* GeoNetworking beaconning interval
*/
private static final int GN_BEACON_INTERVAL = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsBeaconInterval")).getString());
private static final ConcurrentMap<String, Management> instances = new ConcurrentHashMap<String, Management>();
/**
* GeoNetworking beaconning interval
*/
private static final int GN_BEACON_INTERVAL = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsBeaconInterval")).getString());
/**
* Maximum time for getting Long position vector (in seconds)
......@@ -57,172 +61,229 @@ public class Management implements IManagementTA, IManagementLayers {
* Test system longitude
*/
private static final int longitude = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsLongitude")).getString());
/**
* Link-layer address of Component
*/
private byte[] linkLayerAddress = null;
/**
* Secured mode status
*/
private static final String TsSecuredMode = ((CharstringValue)TERFactory.getInstance().getTaParameter("TsSecuredMode")).getString();
/**
* Secured root path to access certificates & private keys
*/
private static final String TsSecuredRootPath = ((CharstringValue)TERFactory.getInstance().getTaParameter("TsSecuredRootPath")).getString();
/**
* Secured configuration identifier
*/
private static final String TsSecuredConfiId = ((CharstringValue)TERFactory.getInstance().getTaParameter("TsSecuredConfiId")).getString();
/**
* Link-layer address of Component
*/
private byte[] linkLayerAddress = null;
/**
* Registered GN Port
*/
private GnPort gnPort = null;
/**
/**
* Registered GN Port
*/
private GnPort gnPort = null;
/**
* Set to true is secured mode is set
*/
private boolean securedMode = false;
/**
* The certificate identifier to used
*/
private String certificateId = "TA_CERT_A";
/**
* The AT certificate
*/
private byte[] atCertificate = null;
/**
* The certificate digest to used
*/
private byte[] atCertificateDigest = null;
/**
* The private signing key to used
*/
private byte[] signingPrivateKey = null;
/**
* The public signing key X to used
*/
private byte[] signingPublicKeyX = null;
/**
* The public signing key Y to used
*/
private byte[] signingPublicKeyY = null;
// private byte[] toBeSignedDataDigest = null;
// private byte[] toBeSignedDataCertificate = null;
/**
* Private constructor (Multiton pattern)
*/
private Management() {
//empty
// FIXME: For debug only:
byte[] mid = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00};
byte[] lpv = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
private Management() {
// Check for secured mode settings in TestAdapter configuration file
if (TsSecuredMode.equals("true")) {
setupSecuredMode();
}
// For debug only:
byte[] mid = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00};
byte[] lpv = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00};
gnUpdateLocTable(mid, 0, lpv);
}
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00};
gnUpdateLocTable(mid, 0, lpv);
}
/**
/**
* Gets the Management instance associated to a component
* @param key Component name
* @return Management instance
*/
public static Management getInstance(String key) {
if (instances.get(key) == null){
// Lazily create instance and try to add it to the map
Management instance = new Management();
instances.putIfAbsent(key, instance);
}
return instances.get(key);
}
public static Management getInstance(String key) {
if (instances.get(key) == null){
// Lazily create instance and try to add it to the map
Management instance = new Management();
instances.putIfAbsent(key, instance);
}
return instances.get(key);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startBeaconing(byte[])
*/
@Override
public void startBeaconing(byte[] beaconHeader) {
this.beaconHeader = beaconHeader;
if(gnPort != null) {
gnPort.startBeaconning();
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopBeaconing()
*/
@Override
public void stopBeaconing() {
this.beaconHeader = null;
if(gnPort != null) {
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startBeaconing(byte[])
*/
@Override
public void startBeaconing(byte[] beaconHeader) {
this.beaconHeader = beaconHeader;
if(gnPort != null) {
gnPort.startBeaconning();
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopBeaconing()
*/
@Override
public void stopBeaconing() {
this.beaconHeader = null;
if(gnPort != null) {
gnPort.stopBeaconning();
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startEnqueueingBeacons(byte[])
*/
@Override
public void startEnqueueingBeacons(byte[] beaconHeader) {
this.enqueueBeacon = beaconHeader;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopEnqueueingBeacons()
*/
@Override
public void stopEnqueueingBeacons() {
this.enqueueBeacon = null;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startMultipleBeaconing(byte[], int)
*/
@Override
public void startMultipleBeaconing(byte[] beaconHeader, int nbNeighbours) {
/* TODO: Multiple beacons */
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopMultipleBeaconing()
*/
@Override
public void stopMultipleBeaconing() {
/* TODO: Multiple beacons */
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startEnqueueingBeacons(byte[])
*/
@Override
public void startEnqueueingBeacons(byte[] beaconHeader) {
this.enqueueBeacon = beaconHeader;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopEnqueueingBeacons()
*/
@Override
public void stopEnqueueingBeacons() {
this.enqueueBeacon = null;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startMultipleBeaconing(byte[], int)
*/
@Override
public void startMultipleBeaconing(byte[] beaconHeader, int nbNeighbours) {
/* TODO: Multiple beacons */
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopMultipleBeaconing()
*/
@Override
public void stopMultipleBeaconing() {
/* TODO: Multiple beacons */
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#getLongPositionVector(byte[])
*/
@Override
public byte[] getLongPositionVector(byte[] targetGnAddress) {
byte[] mid = ByteHelper.extract(targetGnAddress, 2, 6);
long key = ByteHelper.byteArrayToLong(mid);
for(int i = 0; i < GET_LPV_TIMEOUT; ++i) {
if (locTable.containsKey(key)) {
ITuple<Long, byte[]> entry = locTable.get(key);
return entry.getB();
}
try {
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#getLongPositionVector(byte[])
*/
@Override
public byte[] getLongPositionVector(byte[] targetGnAddress) {
byte[] mid = ByteHelper.extract(targetGnAddress, 2, 6);
// System.out.println("getLongPositionVector: Looking for Loc Entry: " + ByteHelper.byteArrayToString(mid));
long key = ByteHelper.byteArrayToLong(mid);
for(int i = 0; i < GET_LPV_TIMEOUT; ++i) {
if (locTable.containsKey(key)) {
ITuple<Long, byte[]> entry = locTable.get(key);
return entry.getB();
}
try {
Thread.sleep(GET_LPV_POLL_INTERVAL);
} catch (InterruptedException e) {
// Do nothing, we do not care
}
}
return null;
}
}
return null;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnBeacon()
*/
@Override
public byte[] getGnBeacon() {
return beaconHeader;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnBeaconInterval()
*/
@Override
public int getGnBeaconInterval() {
return GN_BEACON_INTERVAL;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnBeacon()
*/
@Override
public byte[] getGnBeacon() {
return beaconHeader;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnBeaconInterval()
*/
@Override
public int getGnBeaconInterval() {
return GN_BEACON_INTERVAL;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnEnqueueBeacon()
*/
@Override
public byte[] getGnEnqueueBeacon() {
return enqueueBeacon;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnEnqueueBeacon()
*/
@Override
public byte[] getGnEnqueueBeacon() {
return enqueueBeacon;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#gnUpdateLocTable(byte[], long, byte[])
*/
@Override
public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv) {
// Java does not provide unsigned int
timestamp &= 0xffffffffL;
long key = ByteHelper.byteArrayToLong(mid);
ITuple<Long, byte[]> entry = locTable.get(key);
if(entry == null || entry.getA() < timestamp) {
//ByteHelper.dump("Adding Loc Entry for: ", mid);
locTable.put(key, new Tuple<Long, byte[]>(timestamp, lpv));
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#gnUpdateLocTable(byte[], long, byte[])
*/
@Override
public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv) {
// Java does not provide unsigned int
timestamp &= 0xffffffffL;
long key = ByteHelper.byteArrayToLong(mid);
ITuple<Long, byte[]> entry = locTable.get(key);
if(entry == null || entry.getA() < timestamp) {
// System.out.println("gnUpdateLocTable: Adding Loc Entry for: " + ByteHelper.byteArrayToString(mid));
locTable.put(key, new Tuple<Long, byte[]>(timestamp, lpv));
}
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress()
*/
@Override
public byte[] getLinkLayerAddress() {
return linkLayerAddress;
}
/* (non-Javadoc)
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress()
*/
@Override
public byte[] getLinkLayerAddress() {
return linkLayerAddress;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress()
*/
@Override
......@@ -230,44 +291,44 @@ public class Management implements IManagementTA, IManagementLayers {
this.linkLayerAddress = linkLayerAddress;
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLatitude()
*/
@Override
public byte[] getLatitude() {
return ByteHelper.intToByteArray(latitude, 4);
}
/* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLatitude()
*/
@Override
public byte[] getLatitude() {
return ByteHelper.intToByteArray(latitude, 4);