Commit e1c63bb3 authored by garciay's avatar garciay
Browse files

Update ETIS IS ports

parent 598f6a45
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -109,9 +109,9 @@ public class SecurityHelper {
        
        // Check version
        if (decvalue.read() != 2) {
            TERFactory.getInstance().logError("SecurityHelper.checkSecuredProfileAndExtractPayload: Drop packet - Wrong version number");
            if (p_enforceSecurityCheck) {
                // Drop it
                TERFactory.getInstance().logError("SecurityHelper.checkSecuredProfileAndExtractPayload: Drop packet - Wrong version number");
                return null;
            }
        }
@@ -122,13 +122,14 @@ public class SecurityHelper {
        decvalue.read(headerFields, 0, (int) headerFieldsLength);
        ByteArrayOutputStream certificateKeys = new ByteArrayOutputStream();
        if (!checkHeaderfields(headerFields, certificateKeys, p_enforceSecurityCheck, p_itsAidOther, lowerInfo)) {
            TERFactory.getInstance().logError("SecurityHelper.checkSecuredProfileAndExtractPayload: Drop packet - Wrong Headerfields");
            if (p_enforceSecurityCheck) {
                // Drop it
                TERFactory.getInstance().logError("SecurityHelper.checkSecuredProfileAndExtractPayload: Drop packet - Wrong Headerfields");
                return null;
            }
        }
        byte[] aaSigningPublicKeyX = null, aaSigningPublicKeyY = null;
        if (p_enforceSecurityCheck) { 
            byte[] keys = certificateKeys.toByteArray();
            if ((keys[0] == 0x02) || (keys[0] == 0x03)) { // Key length = 32 bytes
                aaSigningPublicKeyX = ByteHelper.extract(keys, 1, 32);
@@ -139,7 +140,10 @@ public class SecurityHelper {
                aaSigningPublicKeyY = ByteHelper.extract(keys, 33, 32);
                TERFactory.getInstance().logDebug("SecurityHelper.checkSecuredProfileAndExtractPayload: aaSigningPublicKeyX:" + ByteHelper.byteArrayToString(aaSigningPublicKeyX));
            }
        }
        // FIXME Add encryption support
//        if (p_enforceSecurityCheck) { 
//        }
        TERFactory.getInstance().logDebug("SecurityHelper.checkSecuredProfileAndExtractPayload: headerFields:" + ByteHelper.byteArrayToString(headerFields));
        // Extract payload, decvalue is updated with the payload
        if (decvalue.read() != 1) {
@@ -261,9 +265,9 @@ public class SecurityHelper {
            Long lKey = ByteHelper.byteArrayToLong(hashedid8);
            TERFactory.getInstance().logDebug("SecurityHelper.checkHeaderfields: Certificate digest with SHA256=" + lKey + " / " + ByteHelper.byteArrayToString(hashedid8));
            if (!_neighborsCertificates.containsKey(lKey) || (_neighborsCertificates.get(lKey) == null)) { //FIXME as long as the cert chain is not complete, it should not be seen as error -> raise CR
                TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - Unknown HahedId8");
                if (p_enforceSecurityCheck) { 
                    // Drop it
                    TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - Unknown HahedId8");
                    return false;
                }
            }
@@ -271,9 +275,10 @@ public class SecurityHelper {
                p_keys.write(_neighborsCertificates.get(lKey).toByteArray());
            } catch (Exception e) {
                // Drop it
                e.printStackTrace();
                //e.printStackTrace();
                if (p_enforceSecurityCheck) { 
                    // Drop it
                    TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: key " + lKey + "_neighbors certificates table");
                    return false;
                }
            }
@@ -316,9 +321,9 @@ public class SecurityHelper {
        long generationTime = ByteHelper.byteArrayToLong(ByteHelper.extract(p_headerfields, signerInfoTypeIndex, Long.SIZE / Byte.SIZE));
        TERFactory.getInstance().logDebug("SecurityHelper.checkHeaderfields: generationTime=" + generationTime);
        if (Math.abs(System.currentTimeMillis() - generationTime) < 1000) {
            TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - GenerationTime out of range");
            if (p_enforceSecurityCheck) { 
                // Drop it
                TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - GenerationTime out of range");
                return false;
            }
        }
@@ -351,9 +356,9 @@ public class SecurityHelper {
                                                                         // TODO Add MAPEM/SPATEM, IVIM & SREM/SSEM
                        (p_headerfields[signerInfoTypeIndex] != p_itsAidOther)
                    ) {
                        TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - Unknown ItsAid value");
                        if (p_enforceSecurityCheck) { 
                            // Drop it
                            TERFactory.getInstance().logError("SecurityHelper.checkHeaderfields: Drop packet - Unknown ItsAid value");
                            return false;
                        }
                    }
+17 −18
Original line number Diff line number Diff line
@@ -392,7 +392,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
                byte[] pl = new byte[2];
                System.arraycopy(commonHdr, 4, pl , 0, 2);
                int payloadLength = ByteHelper.byteArrayToInt(pl);
//                    System.out.println("GnLayer.receive: Message payload length=" + payloadLength);
                    System.out.println("GnLayer.receive: Message payload length=" + payloadLength);
                
                if(headerType == HT_LS) {
                    // Process LS messages
@@ -411,7 +411,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
                            params.put(GN_DEPV, depv);
                            params.put(GN_TYPE, HT_LS);
                            params.put(GN_SUBTYPE, HST_LSREPLY);
                            TERFactory.getInstance().logDebug("GnLayer.receive: Send LS_REPLAY in secured mode");
                            //TERFactory.getInstance().logDebug("GnLayer.receive: Send LS_REPLAY in secured mode");
                            send(null, params);
                        }
                    } else {
@@ -422,7 +422,7 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
                    if(payloadLength > 0) {
                        byte[] mpayload = new byte[payloadLength];
                        System.arraycopy(payload, commonHdr.length + 44/*Topology-Scoped Broadcast*/, mpayload, 0, payloadLength);
//                            System.out.println("GnLayer.receive: Message =" + ByteHelper.byteArrayToString(mpayload));
                        //TERFactory.getInstance().logDebug("GnLayer.receive: Message =" + ByteHelper.byteArrayToString(mpayload));
                        lowerInfo.put(GN_NEXTHEADER, nextHeader);
                        lowerInfo.put(GN_TYPE, headerType);
                        lowerInfo.put(GN_SUBTYPE, headerSubType);
@@ -433,9 +433,8 @@ public class GnLayer extends Layer implements Runnable, IEthernetSpecific {
                }
            } else {
                // Drop it
                // //FIXME as long as the cert chain is not complete, it should not be seen as error -> raise CR
                // FIXME as long as the cert chain is not complete, it should not be seen as error -> raise CR
                //TERFactory.getInstance().logError("GnLayer.receive: Invalid basic header type");
                TERFactory.getInstance().logDebug("GnLayer.receive: Invalid basic header type");
                return;
            }
        }
+3 −3
Original line number Diff line number Diff line
@@ -38,10 +38,10 @@ public class CamPort extends ProtocolPort {
     */
    @Override
    public void receive(byte[] message, Map<String, Object> lowerInfo) {
//        TERFactory.getInstance().logDebug(">>> denmPort.receive: " + ByteHelper.byteArrayToString(message));
//        TERFactory.getInstance().logDebug(">>> CamPort.receive: " + ByteHelper.byteArrayToString(message));
        
        if (message[1] != 0x02) { // Check that received packet has CAM message id
            TERFactory.getInstance().logDebug("camPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
        if (message[1] != 0x02) { // Check that received packet has CAM message id - See ETSI TS 102 894
            TERFactory.getInstance().logDebug("CamPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
            return; // Drop it
        }
        
+3 −3
Original line number Diff line number Diff line
@@ -38,10 +38,10 @@ public class DenmPort extends ProtocolPort {
     */
    @Override
    public void receive(byte[] message, Map<String, Object> lowerInfo) {
//        TERFactory.getInstance().logDebug(">>> denmPort.receive: " + ByteHelper.byteArrayToString(message));
//        TERFactory.getInstance().logDebug(">>> DenmPort.receive: " + ByteHelper.byteArrayToString(message));
        
        if (message[1] != 0x01) { // Check that received packet has DENM message id
            TERFactory.getInstance().logDebug("denmPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
        if (message[1] != 0x01) { // Check that received packet has DENM message id - See ETSI TS 102 894
            TERFactory.getInstance().logDebug("DenmPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
            return; // Drop it
        }
        
+3 −3
Original line number Diff line number Diff line
@@ -38,10 +38,10 @@ public class IvimPort extends ProtocolPort {
     */
    @Override
    public void receive(byte[] message, Map<String, Object> lowerInfo) {
//        TERFactory.getInstance().logDebug(">>> denmPort.receive: " + ByteHelper.byteArrayToString(message));
//        TERFactory.getInstance().logDebug(">>> IvimPort.receive: " + ByteHelper.byteArrayToString(message));
        
        if (message[1] != 0x02) { // Check that received packet has CAM message id
            TERFactory.getInstance().logDebug("ivimPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
        if (message[1] != 0x06) { // Check that received packet has IVIM message id - See ETSI TS 102 894
            TERFactory.getInstance().logDebug("IvimPort.receive: drop packet " + ByteHelper.byteArrayToString(message));
            return; // Drop it
        }
        
Loading