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 @@ ...@@ -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();
} }
...@@ -72,7 +72,7 @@ public class PcapMultiplexer implements Runnable { ...@@ -72,7 +72,7 @@ public class PcapMultiplexer implements Runnable {
} }
device = alldevs.get(ifaceIndex); 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 { ...@@ -84,13 +84,10 @@ public class PcapMultiplexer implements Runnable {
} }
public synchronized void register(Layer client, byte[] macAddress, short frameType) { 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()) { if(clientsToMacs.isEmpty()) {
System.out.println("First Client !");
// Open interface // Open interface
int snaplen = 64 * 1024; // Capture all packets, no truncation int snaplen = 64 * 1024; // Capture all packets, no truncation
int flags = Pcap.MODE_PROMISCUOUS; // capture all packets int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
int timeout = 10; // 10 millis int timeout = 10; // 10 millis
...@@ -106,7 +103,7 @@ public class PcapMultiplexer implements Runnable { ...@@ -106,7 +103,7 @@ public class PcapMultiplexer implements Runnable {
filter = ""; filter = "";
} }
else { else {
System.out.println("Another Client !"); // System.out.println("Another Client !");
filter = filter + " and "; filter = filter + " and ";
} }
...@@ -117,7 +114,7 @@ public class PcapMultiplexer implements Runnable { ...@@ -117,7 +114,7 @@ public class PcapMultiplexer implements Runnable {
} }
filter = filter + "not ether src " + strMacAddress; filter = filter + "not ether src " + strMacAddress;
System.out.println("New filter: " + filter); // System.out.println("New filter: " + filter);
// Apply filter // Apply filter
PcapBpfProgram bpfFilter = new PcapBpfProgram(); PcapBpfProgram bpfFilter = new PcapBpfProgram();
...@@ -125,7 +122,7 @@ public class PcapMultiplexer implements Runnable { ...@@ -125,7 +122,7 @@ public class PcapMultiplexer implements Runnable {
int netmask = 0; int netmask = 0;
int r = pcap.compile(bpfFilter, filter, optimize, netmask); int r = pcap.compile(bpfFilter, filter, optimize, netmask);
if (r != Pcap.OK) { if (r != Pcap.OK) {
System.out.println("Filter error: " + pcap.getErr()); // System.out.println("Filter error: " + pcap.getErr());
} }
pcap.setFilter(bpfFilter); pcap.setFilter(bpfFilter);
...@@ -198,7 +195,7 @@ public class PcapMultiplexer implements Runnable { ...@@ -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 { ...@@ -30,62 +30,63 @@ public class LayerFactory {
/** /**
* Unique instance of the factory * Unique instance of the factory
*/ */
private static LayerFactory instance = new LayerFactory(); private static LayerFactory instance = new LayerFactory();
/** /**
* List of the registered layer types * 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 constructor (Singleton pattern)
*/ */
private LayerFactory() { private LayerFactory() {
// Register the layers // Register the layers
layers.put("BTP", BtpLayer.class); layers.put("BTP", BtpLayer.class);
layers.put("GN", GnLayer.class); layers.put("GN", GnLayer.class);
layers.put("G5", G5Layer.class); layers.put("G5", G5Layer.class);
layers.put("ETH", EthernetLayer.class); layers.put("ETH", EthernetLayer.class);
layers.put("Loopback", LoopbackLayer.class); // layers.put("Loopback", LoopbackLayer.class);
layers.put("Debug", DebugLayer.class); // layers.put("Debug", DebugLayer.class);
layers.put("CamSource", CamSourceLayer.class); // layers.put("CamSource", CamSourceLayer.class);
layers.put("DenmSource", DenmSourceLayer.class); // layers.put("DenmSource", DenmSourceLayer.class);
layers.put("GnSource", GnSourceLayer.class); // layers.put("GnSource", GnSourceLayer.class);
layers.put("BtpSource", BtpSourceLayer.class); // layers.put("BtpSource", BtpSourceLayer.class);
layers.put("Gn6Source", Gn6SourceLayer.class); // layers.put("Gn6Source", Gn6SourceLayer.class);
} }
/** /**
* Gets the unique factory instance * Gets the unique factory instance
* @return LayerFactory instance * @return LayerFactory instance
*/ */
public static LayerFactory getInstance(){ public static LayerFactory getInstance(){
return instance; return instance;
} }
/** /**
* Creates a port of the desired type * Creates a port of the desired type
* @param management Layer management instance * @param management Layer management instance
* @param layerName Name of the layer * @param layerName Name of the layer
* @param lowerStack Lower protocol stack * @param lowerStack Lower protocol stack
* @return Protocol port instance * @return Protocol port instance
*/ */
public Layer createLayer(IManagementLayers management, String layerName, Stack<String> lowerStack) { public Layer createLayer(IManagementLayers management, String layerName, Stack<String> lowerStack) {
Layer layer = null; // System.out.println(">>> LayerFactory.createLayer: " + layerName);
Class<?>[] ctorParams = {IManagementLayers.class, lowerStack.getClass()}; Layer layer = null;
Class<?>[] ctorParams = {IManagementLayers.class, lowerStack.getClass()};
try {
Class<? extends Layer> cls = layers.get(layerName); try {
if (cls == null) { Class<? extends Layer> cls = layers.get(layerName);
throw new RuntimeException("No class registered under " + layerName); if (cls == null) {
} throw new RuntimeException("No class registered under " + layerName);
}
Constructor<? extends Layer> ctor = cls.getConstructor(ctorParams); Constructor<? extends Layer> ctor = cls.getConstructor(ctorParams);
layer = ctor.newInstance(management, lowerStack); layer = ctor.newInstance(management, lowerStack);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
return layer; return layer;
} }
} }
...@@ -17,50 +17,51 @@ import java.util.TreeMap; ...@@ -17,50 +17,51 @@ import java.util.TreeMap;
*/ */
public class ProtocolPortFactory { public class ProtocolPortFactory {
/** /**
* Unique instance of the factory * Unique instance of the factory
*/ */
private static ProtocolPortFactory instance = new ProtocolPortFactory(); private static ProtocolPortFactory instance = new ProtocolPortFactory();
/** /**
* List of the registered protocol port types * List of the registered protocol port types
*/ */
protected Map<String, Class<? extends ProtocolPort>> ports = new TreeMap<String, Class<? extends ProtocolPort>>(); protected Map<String, Class<? extends ProtocolPort>> ports = new TreeMap<String, Class<? extends ProtocolPort>>();
/** /**
* Private constructor (Singleton pattern) * Private constructor (Singleton pattern)
*/ */
private ProtocolPortFactory() { private ProtocolPortFactory() {
// Register the ports - Refer to TTCN-3 component LibIts_TestSystem.ItsSystem for ports name // Register the ports - Refer to TTCN-3 component LibIts_TestSystem.ItsSystem for ports name
ports.put("camPort", CamPort.class); ports.put("camPort", CamPort.class);
ports.put("denmPort", DenmPort.class); ports.put("denmPort", DenmPort.class);
ports.put("btpPort", BtpPort.class); ports.put("btpPort", BtpPort.class);
ports.put("geoNetworkingPort", GnPort.class); ports.put("geoNetworkingPort", GnPort.class);
ports.put("ipv6OverGeoNetworkingPort", Gn6Port.class); ports.put("ipv6OverGeoNetworkingPort", Gn6Port.class);
ports.put("v2gPort", V2GPort.class); ports.put("v2gPort", V2GPort.class);
} }
/** /**
* Gets the unique factory instance * Gets the unique factory instance
* @return ProtocolPortFactory instance * @return ProtocolPortFactory instance
*/ */
public static ProtocolPortFactory getInstance(){ public static ProtocolPortFactory getInstance(){
return instance; return instance;
} }
/** /**
* Creates a port of the desired type * Creates a port of the desired type
* @param portName Name of the port * @param portName Name of the port
* @param componentName Name of the component owning the port instance * @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 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) * @param linkLayerAddress Link-layer address to be used by this port as source address (null if not applicable)
* @return Protocol port instance * @return Protocol port instance
*/ */
public ProtocolPort createPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) { public ProtocolPort createPort(String portName, String componentName, String lowerStackDesc, String linkLayerAddress) {
ProtocolPort port = null; // System.out.println(">>> ProtocolPortFactory.createPort: " + portName + ", " + componentName + ", " + lowerStackDesc + ", " + linkLayerAddress);
Class<?>[] ctorParams = {portName.getClass(), componentName.getClass(), lowerStackDesc.getClass(), linkLayerAddress.getClass()}; ProtocolPort port = null;
Class<?>[] ctorParams = {portName.getClass(), componentName.getClass(), lowerStackDesc.getClass(), linkLayerAddress.getClass()};
try {
try {
Class<? extends ProtocolPort> cls = ports.get(portName); Class<? extends ProtocolPort> cls = ports.get(portName);
if (cls == null) { if (cls == null) {
...@@ -74,6 +75,6 @@ public class ProtocolPortFactory { ...@@ -74,6 +75,6 @@ public class ProtocolPortFactory {
} }
return port; 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() {