Commit 4a7a5d77 authored by berge's avatar berge

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();
}
......@@ -72,7 +72,7 @@ public class PcapMultiplexer implements Runnable {
}
device = alldevs.get(ifaceIndex);
System.out.println("Listening: " + device.getName());
// System.out.println("Listening: " + device.getName());
}
/**
......@@ -84,13 +84,10 @@ public class PcapMultiplexer implements Runnable {
}
public synchronized void register(Layer client, byte[] macAddress, short frameType) {
// System.out.println(">>>PcapMultiplexer.registering: " + frameType);
System.out.println("Registering client, " + frameType);
if(clientsToMacs.isEmpty()) {
System.out.println("First Client !");
// Open interface
int snaplen = 64 * 1024; // Capture all packets, no truncation
int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
int timeout = 10; // 10 millis
......@@ -106,7 +103,7 @@ public class PcapMultiplexer implements Runnable {
filter = "";
}
else {
System.out.println("Another Client !");
// System.out.println("Another Client !");
filter = filter + " and ";
}
......@@ -117,7 +114,7 @@ public class PcapMultiplexer implements Runnable {
}
filter = filter + "not ether src " + strMacAddress;
System.out.println("New filter: " + filter);
// System.out.println("New filter: " + filter);
// Apply filter
PcapBpfProgram bpfFilter = new PcapBpfProgram();
......@@ -125,7 +122,7 @@ public class PcapMultiplexer implements Runnable {
int netmask = 0;
int r = pcap.compile(bpfFilter, filter, optimize, netmask);
if (r != Pcap.OK) {
System.out.println("Filter error: " + pcap.getErr());
// System.out.println("Filter error: " + pcap.getErr());
}
pcap.setFilter(bpfFilter);
......@@ -198,7 +195,7 @@ public class PcapMultiplexer implements Runnable {
}
}
}
}
};
......
/**
* @author ETSI / STF481 / Yann Garcia
* @version $URL$
* $Id$
*/
package org.etsi.its.adapter;
import java.io.ByteArrayInputStream;
import org.etsi.ttcn.common.ByteHelper;
public class TlsHelper {
private static TlsHelper Instance = new TlsHelper();
public static TlsHelper getInstance() { return Instance; }
private TlsHelper() {
}
public byte[] size2tls(final int length) {
byte[] result = null;
if (length < 128) { // One byte length
result = new byte[] { (byte)length };
} else {
long lv = length;
long bitLen = bitLength(lv);
long byteLen = byteLength(bitLen);
long flags = (long) ((byteLen | 1) << (byteLen * Byte.SIZE - bitLength(byteLen) - 1));
long len = (long) (byteLen << (byteLen * Byte.SIZE - bitLength(byteLen) - 1));
if ((flags & lv) != 0) { // We can encode the length on the MSB part
byteLen += 1;
len = (long) (byteLen << (byteLen * Byte.SIZE - bitLength(byteLen)) - 1);
}
result = ByteHelper.longToByteArray((long)(lv | len), (int) byteLen);
}
return result;
}
public long tls2size(final ByteArrayInputStream buf) {
// Sanity check
if (buf.available() == 0) {
return 0;
}
// Read the first byte
byte msb = (byte) buf.read();
if ((msb & 0x80) == 0x00) { // Integer < 128
return msb;
} else {
// Decode the length. The encoding of the length shall use at most 7 bits set to 1 (see Draft ETSI TS 103 097 V1.1.14 Clause 4.1 Presentation Language Table 1/8)
byte bit;
byte byteLen = 1;
do {
bit = (byte) ((byte) (msb << byteLen++) & 0x80);
} while (bit != 0x00);
// Set the IntX length
byte[] data = new byte[byteLen - 1];
buf.read(data, 0, byteLen - 1);
byte[] length = ByteHelper.concat(new byte[] { msb }, data);
length[0] &= (byte)(Math.pow(2.0, 8 - byteLen + 1) - 1);
long lv = ByteHelper.byteArrayToLong(length);
return lv;
}
}
public long bitLength(final long value) {
return (long) Math.ceil(Math.log(value) / Math.log(2));
}
public long byteLength(final long value) {
double d = value; // Convert int to double
return (long) Math.ceil(d / Byte.SIZE);
}
} // End of class TlsHelper
......@@ -30,62 +30,63 @@ public class LayerFactory {
/**
* Unique instance of the factory
*/
private static LayerFactory instance = new LayerFactory();
/**
private static LayerFactory instance = new LayerFactory();
/**
* List of the registered layer types
*/
protected Map<String, Class<? extends Layer>> layers = new TreeMap<String, Class<? extends Layer>>();
/**
protected Map<String, Class<? extends Layer>> layers = new TreeMap<String, Class<? extends Layer>>();
/**
* Private constructor (Singleton pattern)
*/
private LayerFactory() {
// Register the layers
layers.put("BTP", BtpLayer.class);
layers.put("GN", GnLayer.class);
layers.put("G5", G5Layer.class);
layers.put("ETH", EthernetLayer.class);
layers.put("Loopback", LoopbackLayer.class);
layers.put("Debug", DebugLayer.class);
layers.put("CamSource", CamSourceLayer.class);
layers.put("DenmSource", DenmSourceLayer.class);
layers.put("GnSource", GnSourceLayer.class);
layers.put("BtpSource", BtpSourceLayer.class);
layers.put("Gn6Source", Gn6SourceLayer.class);
}
private LayerFactory() {
// Register the layers
layers.put("BTP", BtpLayer.class);
layers.put("GN", GnLayer.class);
layers.put("G5", G5Layer.class);
layers.put("ETH", EthernetLayer.class);
// layers.put("Loopback", LoopbackLayer.class);
// layers.put("Debug", DebugLayer.class);
// layers.put("CamSource", CamSourceLayer.class);
// layers.put("DenmSource", DenmSourceLayer.class);
// layers.put("GnSource", GnSourceLayer.class);
// layers.put("BtpSource", BtpSourceLayer.class);
// layers.put("Gn6Source", Gn6SourceLayer.class);
}
/**
/**
* Gets the unique factory instance
* @return LayerFactory instance
*/
public static LayerFactory getInstance(){
return instance;
}
public static LayerFactory getInstance(){
return instance;
}
/**
/**
* Creates a port of the desired type
* @param management Layer management instance
* @param layerName Name of the layer
* @param lowerStack Lower protocol stack
* @return Protocol port instance
*/
public Layer createLayer(IManagementLayers management, String layerName, Stack<String> lowerStack) {
Layer layer = null;
Class<?>[] ctorParams = {IManagementLayers.class, lowerStack.getClass()};
try {
Class<? extends Layer> cls = layers.get(layerName);
if (cls == null) {
throw new RuntimeException("No class registered under " + layerName);
}
public Layer createLayer(IManagementLayers management, String layerName, Stack<String> lowerStack) {
// System.out.println(">>> LayerFactory.createLayer: " + layerName);
Layer layer = null;
Class<?>[] ctorParams = {IManagementLayers.class, lowerStack.getClass()};
try {
Class<? extends Layer> cls = layers.get(layerName);
if (cls == null) {
throw new RuntimeException("No class registered under " + layerName);
}
Constructor<? extends Layer> ctor = cls.getConstructor(ctorParams);
layer = ctor.newInstance(management, lowerStack);
} catch (Exception ex) {
ex.printStackTrace();
}
return layer;
}
}
}
......@@ -17,50 +17,51 @@ import java.util.TreeMap;
*/
public class ProtocolPortFactory {
/**
* Unique instance of the factory
*/
private static ProtocolPortFactory instance = new ProtocolPortFactory();
/**
* List of the registered protocol port types
*/
protected Map<String, Class<? extends ProtocolPort>> ports = new TreeMap<String, Class<? extends ProtocolPort>>();
/**
* Private constructor (Singleton pattern)
*/
private ProtocolPortFactory() {
// Register the ports - Refer to TTCN-3 component LibIts_TestSystem.ItsSystem for ports name
ports.put("camPort", CamPort.class);
ports.put("denmPort", DenmPort.class);
ports.put("btpPort", BtpPort.class);
ports.put("geoNetworkingPort", GnPort.class);
ports.put("ipv6OverGeoNetworkingPort", Gn6Port.class);
ports.put("v2gPort", V2GPort.class);
}
/**
* Unique instance of the factory
*/
private static ProtocolPortFactory instance = new ProtocolPortFactory();
/**
* List of the registered protocol port types
*/
protected Map<String, Class<? extends ProtocolPort>> ports = new TreeMap<String, Class<? extends ProtocolPort>>();
/**
* Private constructor (Singleton pattern)
*/
private ProtocolPortFactory() {
// Register the ports - Refer to TTCN-3 component LibIts_TestSystem.ItsSystem for ports name
ports.put("camPort", CamPort.class);
ports.put("denmPort", DenmPort.class);
ports.put("btpPort", BtpPort.class);
ports.put("geoNetworkingPort", GnPort.class);
ports.put("ipv6OverGeoNetworkingPort", Gn6Port.class);
ports.put("v2gPort", V2GPort.class);
}
/**
* Gets the unique factory instance
* @return ProtocolPortFactory instance
*/
public static ProtocolPortFactory getInstance(){
return instance;
}
/**
* Gets the unique factory instance
* @return ProtocolPortFactory instance
*/
public static ProtocolPortFactory getInstance(){
return instance;
}
/**
* Creates a port of the desired type
* @param portName Name of the port
* @param componentName Name of the component owning the port instance
* @param lowerStackDesc Description of the lower protocol stack of the port in the form "Layer/Layer/Layer/..."
* @param linkLayerAddress Link-layer address to be used by this port as source address (null if not applicable)
* @return Protocol port instance
*/
public ProtocolPort createPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
ProtocolPort port = null;
Class<?>[] ctorParams = {portName.getClass(), componentName.getClass(), lowerStackDesc.getClass(), linkLayerAddress.getClass()};
try {
/**
* Creates a port of the desired type
* @param portName Name of the port
* @param componentName Name of the component owning the port instance
* @param lowerStackDesc Description of the lower protocol stack of the port in the form "Layer/Layer/Layer/..."
* @param linkLayerAddress Link-layer address to be used by this port as source address (null if not applicable)
* @return Protocol port instance
*/
public ProtocolPort createPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
// System.out.println(">>> ProtocolPortFactory.createPort: " + portName + ", " + componentName + ", " + lowerStackDesc + ", " + linkLayerAddress);
ProtocolPort port = null;
Class<?>[] ctorParams = {portName.getClass(), componentName.getClass(), lowerStackDesc.getClass(), linkLayerAddress.getClass()};
try {
Class<? extends ProtocolPort> cls = ports.get(portName);
if (cls == null) {
......@@ -74,6 +75,6 @@ public class ProtocolPortFactory {
}
return port;
}
}
}
\ No newline at end of file
package org.etsi.certificates;
import org.etsi.certificates.io.CertificatesIO;
import org.etsi.certificates.io.ICertificatesIO;
public class CertificatesIOFactory {
/**
* The single instance of this class.
*/
private static CertificatesIOFactory _instance = new CertificatesIOFactory();
/**
* The single instance of the class CertificatesIO.
*/
private static ICertificatesIO _certIO = new CertificatesIO();
/**
* Accessor to the single instance of this class.
* @return The single instance of this class.
*/
public static ICertificatesIO getInstance() {
return _instance._certIO;
}
/**
* Internal ctor (For invocation by subclass constructors, typically implicit)
*/
private CertificatesIOFactory() {
}
} // End of class CertificatesIOFactory
/**
* @author ETSI / STF481 / Yann Garcia
* @version $URL$
* $Id:
*/
package org.etsi.certificates;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public final class Helpers {
/**
* A single instance of this class
*/
private static Helpers instance;
/**
* Synchronization object to provide single access to the instance
*/
private static Object _sync = new Object();
/**
* Provide the access to a single instance of this class
* @return A single instance of this class
*/
public static Helpers getInstance() {
if (instance == null) {
synchronized(_sync) {
if (instance == null) {
instance = new Helpers();
}
}
}
return instance;
}
/**
* Internal ctor
*/
private Helpers() {
}
/**
* Convert an array of strings to one string
* @param list string list
* @param separator 'separator' string between each element
* @return string list items concatenated into a string
*/
public String arrayToString(String[] list, String separator) {
StringBuffer result = new StringBuffer();
if (list.length > 0) {
result.append(list[0]);
for (int i = 1; i < list.length; i++) {
result.append(separator);
result.append(list[i]);
}
}
return result.toString();
}
/**
* Recursively walk a directory tree and return a List of all Files found; the List is sorted using File.compareTo().
* @param startingDir is a valid directory, which can be read.
*/
public List<File> getFileListing(File startingDir) throws FileNotFoundException {
validateDirectory(startingDir);
List<File> result = getFileListingNoSort(startingDir);
Collections.sort(result);
return result;
}
private List<File> getFileListingNoSort(File startingDir) throws FileNotFoundException {
List<File> result = new ArrayList<File>();
File[] filesAndDirs = startingDir.listFiles();
List<File> filesDirs = Arrays.asList(filesAndDirs);
for (File file : filesDirs) {
if (file.isDirectory() && ((file.getName().indexOf(".svn") != -1)
|| (file.getName().indexOf("._.DS_Store") != -1)
|| (file.getName().indexOf(".DS_Store") != -1))) { // For debug purpose only
// Skip svn files
continue;
}
result.add(file); // always add, even if directory
if (!file.isFile()) {
//must be a directory