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 @@ ...@@ -9,6 +9,8 @@
package org.etsi.its.adapter; package org.etsi.its.adapter;
import java.math.BigInteger;
import org.etsi.its.adapter.ports.GnPort; import org.etsi.its.adapter.ports.GnPort;
/** /**
...@@ -16,59 +18,108 @@ import org.etsi.its.adapter.ports.GnPort; ...@@ -16,59 +18,108 @@ import org.etsi.its.adapter.ports.GnPort;
*/ */
public interface IManagementLayers { public interface IManagementLayers {
/** /**
* Gets the GeoNetworking beacon header to be sent by Test Adapter for the current component * 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 * @return Beacon header, or null if no Beacon shall be sent
*/ */
public byte[] getGnBeacon(); public byte[] getGnBeacon();
/** /**
* Registers a GN port * Registers a GN port
*/ */
public void registerGnPort(GnPort gnPort); public void registerGnPort(GnPort gnPort);
/** /**
* Gets the GeoNetworking beaconing interval * Gets the GeoNetworking beaconing interval
* @return GeoNetworking beaconing interval in ms * @return GeoNetworking beaconing interval in ms
*/ */
public int getGnBeaconInterval(); public int getGnBeaconInterval();
/** /**
* Gets the GeoNetworking beacon header acting as filter for enqueueing Beacons received from neighbours * 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 * @return Beacon header, or null if no Beacon shall be enqueued
*/ */
public byte[] getGnEnqueueBeacon(); public byte[] getGnEnqueueBeacon();
/** /**
* Inserts or updates a neighbour position vector in Test Adapter internal tables * Inserts or updates a neighbour position vector in Test Adapter internal tables
* @param mid Mid part of the neighbour's GN_Address * @param mid Mid part of the neighbour's GN_Address
* @param timestamp Timestamp of the carrying message * @param timestamp Timestamp of the carrying message
* @param lpv Long position vector of the neighbour * @param lpv Long position vector of the neighbour
*/ */
public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv); public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv);
/** /**
* Sets the link layer address of this component * Sets the link layer address of this component
* param linkLayerAddress Link-layer address (6 bytes) * param linkLayerAddress Link-layer address (6 bytes)
*/ */
public void setLinkLayerAddress(byte[] linkLayerAddress); public void setLinkLayerAddress(byte[] linkLayerAddress);
/** /**
* Gets the link layer address of this component * Gets the link layer address of this component
* @return Link-layer address (6 bytes) * @return Link-layer address (6 bytes)
*/ */
public byte[] getLinkLayerAddress(); 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 * Disable the secured mode
* @return Latitude */
*/ public void unsetSecuredMode();
public byte[] getLatitude();
/**
* 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 * Gets the public key X for signing check
* @return Longitude * @return The public key X
*/ */
public byte[] getLongitude(); 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 @@ ...@@ -10,12 +10,16 @@
package org.etsi.its.adapter; package org.etsi.its.adapter;
import java.io.ByteArrayOutputStream;
import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.etsi.adapter.TERFactory; 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.ByteHelper;
import org.etsi.common.ITuple; import org.etsi.common.ITuple;
import org.etsi.common.Tuple; import org.etsi.common.Tuple;
...@@ -31,12 +35,12 @@ public class Management implements IManagementTA, IManagementLayers { ...@@ -31,12 +35,12 @@ public class Management implements IManagementTA, IManagementLayers {
/** /**
* Instances of Management * Instances of Management
*/ */
private static final ConcurrentMap<String, Management> instances = new ConcurrentHashMap<String, Management>(); private static final ConcurrentMap<String, Management> instances = new ConcurrentHashMap<String, Management>();
/** /**
* GeoNetworking beaconning interval * GeoNetworking beaconning interval
*/ */
private static final int GN_BEACON_INTERVAL = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsBeaconInterval")).getString()); private static final int GN_BEACON_INTERVAL = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsBeaconInterval")).getString());
/** /**
* Maximum time for getting Long position vector (in seconds) * Maximum time for getting Long position vector (in seconds)
...@@ -57,172 +61,229 @@ public class Management implements IManagementTA, IManagementLayers { ...@@ -57,172 +61,229 @@ public class Management implements IManagementTA, IManagementLayers {
* Test system longitude * Test system longitude
*/ */
private static final int longitude = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsLongitude")).getString()); private static final int longitude = Integer.decode(((CharstringValue)TERFactory.getInstance().getTaParameter("TsLongitude")).getString());
/** /**
* Link-layer address of Component * Secured mode status
*/ */
private byte[] linkLayerAddress = null; 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 * Registered GN Port
*/ */
private GnPort gnPort = null; 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 constructor (Multiton pattern)
*/ */
private Management() { private Management() {
//empty
// Check for secured mode settings in TestAdapter configuration file
// FIXME: For debug only: if (TsSecuredMode.equals("true")) {
byte[] mid = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, setupSecuredMode();
(byte)0x00, (byte)0x00}; }
byte[] lpv = new byte[] {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, // 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,
(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);
gnUpdateLocTable(mid, 0, lpv); }
}
/** /**
* Gets the Management instance associated to a component * Gets the Management instance associated to a component
* @param key Component name * @param key Component name
* @return Management instance * @return Management instance
*/ */
public static Management getInstance(String key) { public static Management getInstance(String key) {
if (instances.get(key) == null){ if (instances.get(key) == null){
// Lazily create instance and try to add it to the map // Lazily create instance and try to add it to the map
Management instance = new Management(); Management instance = new Management();
instances.putIfAbsent(key, instance); instances.putIfAbsent(key, instance);
} }
return instances.get(key); return instances.get(key);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startBeaconing(byte[]) * @see org.etsi.its.adapter.IManagementTA#startBeaconing(byte[])
*/ */
@Override @Override
public void startBeaconing(byte[] beaconHeader) { public void startBeaconing(byte[] beaconHeader) {
this.beaconHeader = beaconHeader; this.beaconHeader = beaconHeader;
if(gnPort != null) { if(gnPort != null) {
gnPort.startBeaconning(); gnPort.startBeaconning();
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopBeaconing() * @see org.etsi.its.adapter.IManagementTA#stopBeaconing()
*/ */
@Override @Override
public void stopBeaconing() { public void stopBeaconing() {
this.beaconHeader = null; this.beaconHeader = null;
if(gnPort != null) { if(gnPort != null) {
gnPort.stopBeaconning(); gnPort.stopBeaconning();
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startEnqueueingBeacons(byte[]) * @see org.etsi.its.adapter.IManagementTA#startEnqueueingBeacons(byte[])
*/ */
@Override @Override
public void startEnqueueingBeacons(byte[] beaconHeader) { public void startEnqueueingBeacons(byte[] beaconHeader) {
this.enqueueBeacon = beaconHeader; this.enqueueBeacon = beaconHeader;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopEnqueueingBeacons() * @see org.etsi.its.adapter.IManagementTA#stopEnqueueingBeacons()
*/ */
@Override @Override
public void stopEnqueueingBeacons() { public void stopEnqueueingBeacons() {
this.enqueueBeacon = null; this.enqueueBeacon = null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#startMultipleBeaconing(byte[], int) * @see org.etsi.its.adapter.IManagementTA#startMultipleBeaconing(byte[], int)
*/ */
@Override @Override
public void startMultipleBeaconing(byte[] beaconHeader, int nbNeighbours) { public void startMultipleBeaconing(byte[] beaconHeader, int nbNeighbours) {
/* TODO: Multiple beacons */ /* TODO: Multiple beacons */
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#stopMultipleBeaconing() * @see org.etsi.its.adapter.IManagementTA#stopMultipleBeaconing()
*/ */
@Override @Override
public void stopMultipleBeaconing() { public void stopMultipleBeaconing() {
/* TODO: Multiple beacons */ /* TODO: Multiple beacons */
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementTA#getLongPositionVector(byte[]) * @see org.etsi.its.adapter.IManagementTA#getLongPositionVector(byte[])
*/ */
@Override @Override
public byte[] getLongPositionVector(byte[] targetGnAddress) { public byte[] getLongPositionVector(byte[] targetGnAddress) {
byte[] mid = ByteHelper.extract(targetGnAddress, 2, 6); byte[] mid = ByteHelper.extract(targetGnAddress, 2, 6);
long key = ByteHelper.byteArrayToLong(mid); // System.out.println("getLongPositionVector: Looking for Loc Entry: " + ByteHelper.byteArrayToString(mid));
for(int i = 0; i < GET_LPV_TIMEOUT; ++i) { long key = ByteHelper.byteArrayToLong(mid);
if (locTable.containsKey(key)) { for(int i = 0; i < GET_LPV_TIMEOUT; ++i) {
ITuple<Long, byte[]> entry = locTable.get(key); if (locTable.containsKey(key)) {
return entry.getB(); ITuple<Long, byte[]> entry = locTable.get(key);
} return entry.getB();
try { }
try {
Thread.sleep(GET_LPV_POLL_INTERVAL); Thread.sleep(GET_LPV_POLL_INTERVAL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Do nothing, we do not care // Do nothing, we do not care
} }
} }
return null; return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnBeacon() * @see org.etsi.its.adapter.IManagementLayers#getGnBeacon()
*/ */
@Override @Override
public byte[] getGnBeacon() { public byte[] getGnBeacon() {
return beaconHeader; return beaconHeader;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnBeaconInterval() * @see org.etsi.its.adapter.IManagementLayers#getGnBeaconInterval()
*/ */
@Override @Override
public int getGnBeaconInterval() { public int getGnBeaconInterval() {
return GN_BEACON_INTERVAL; return GN_BEACON_INTERVAL;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getGnEnqueueBeacon() * @see org.etsi.its.adapter.IManagementLayers#getGnEnqueueBeacon()
*/ */
@Override @Override
public byte[] getGnEnqueueBeacon() { public byte[] getGnEnqueueBeacon() {
return enqueueBeacon; return enqueueBeacon;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#gnUpdateLocTable(byte[], long, byte[]) * @see org.etsi.its.adapter.IManagementLayers#gnUpdateLocTable(byte[], long, byte[])
*/ */
@Override @Override
public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv) { public void gnUpdateLocTable(byte[] mid, long timestamp, byte[] lpv) {
// Java does not provide unsigned int // Java does not provide unsigned int
timestamp &= 0xffffffffL; timestamp &= 0xffffffffL;
long key = ByteHelper.byteArrayToLong(mid); long key = ByteHelper.byteArrayToLong(mid);
ITuple<Long, byte[]> entry = locTable.get(key); ITuple<Long, byte[]> entry = locTable.get(key);
if(entry == null || entry.getA() < timestamp) { if(entry == null || entry.getA() < timestamp) {
//ByteHelper.dump("Adding Loc Entry for: ", mid); // System.out.println("gnUpdateLocTable: Adding Loc Entry for: " + ByteHelper.byteArrayToString(mid));
locTable.put(key, new Tuple<Long, byte[]>(timestamp, lpv)); locTable.put(key, new Tuple<Long, byte[]>(timestamp, lpv));
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress() * @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress()
*/ */
@Override @Override
public byte[] getLinkLayerAddress() { public byte[] getLinkLayerAddress() {
return linkLayerAddress; return linkLayerAddress;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress() * @see org.etsi.its.adapter.IManagementLayers#getLinkLayerAddress()
*/ */
@Override @Override
...@@ -230,44 +291,44 @@ public class Management implements IManagementTA, IManagementLayers { ...@@ -230,44 +291,44 @@ public class Management implements IManagementTA, IManagementLayers {