Commit 033af58d authored by garciay's avatar garciay
Browse files

Major bug fixed in secured beacons

parent 15777646
......@@ -123,12 +123,8 @@ public class GnPort extends ProtocolPort implements Runnable, IEthernetSpecific
basicHeader[0] &= 0xFE;
basicHeader[0] |= 0x02; // Secured mode
// Update the beacon timestamp field
byte[] beacon = ByteHelper.concat(
ByteHelper.extract(p_beacon, 4, 16), // Extract Common Header + GN address
p_tst, // Update the timestamp field
ByteHelper.extract(p_beacon, 20, p_beacon.length - 4 - 20) // Add remaining bytes
);
// Basic Header is not part of signed data
byte[] beacon = ByteHelper.extract(p_beacon, 4, p_beacon.length - 4);
//TERFactory.getInstance().logDebug("GnPort.buildSecuredBeacon (2): " + ByteHelper.byteArrayToString(beacon));
// Prepare the message to be signed
byte[] toBeSignedData = buildToBeSignedData(beacon, p_currentTime, p_sendDigest);
......@@ -225,7 +221,7 @@ public class GnPort extends ProtocolPort implements Runnable, IEthernetSpecific
byte[] signatureBytes;
try {
signatureBytes = CryptoLib.signWithEcdsaNistp256WithSha256(p_toBeSignedData, management.getSigningPrivateKey());
// //TERFactory.getInstance().logDebug("GnPort.signSecuredMessage: signatureBytes=" + ByteHelper.byteArrayToString(signatureBytes));
//TERFactory.getInstance().logDebug("GnPort.signSecuredMessage: signatureBytes=" + ByteHelper.byteArrayToString(signatureBytes));
// Add signature
securedBeaconHeader = ByteHelper.concat(
p_toBeSignedData,
......@@ -297,18 +293,24 @@ public class GnPort extends ProtocolPort implements Runnable, IEthernetSpecific
int sopvPos = 12;
if(headerType != HT_BEACON && !(headerType == HT_TSB && headerSubType == HST_SHB) ) {
sopvPos += 4;
}
System.arraycopy(message, sopvPos, sopv, 0, 24);
}
try {
System.arraycopy(message, sopvPos, sopv, 0, 24);
}
catch (IndexOutOfBoundsException e) { // Decoding issue
return;
}
//TERFactory.getInstance().logDebug("GnPort.receive: sopv=" + ByteHelper.byteArrayToString(sopv));
// Security disable, null will be translated into omit
lowerInfo.put(SecurityHelper.SEC_SSP, null);
lowerInfo.put(SecurityHelper.SEC_ITS_AID, null);
} else if ((basicHdr[0] & 0x0f) == 0x02) { // Secured tag
byte[] payload = SecurityHelper.getInstance().checkSecuredProfileAndExtractPayload(message, basicHdr.length, management.isEnforceSecuredModeSet(), management.getItsAidOther(), lowerInfo);
if (payload != null) {
// //TERFactory.getInstance().logDebug("GnPort.receive: payload=" + ByteHelper.byteArrayToString(payload));
//TERFactory.getInstance().logDebug("GnPort.receive: payload=" + ByteHelper.byteArrayToString(payload));
byte[] commonHdr = new byte[8];
System.arraycopy(payload, 0, commonHdr, 0, 8);
// //TERFactory.getInstance().logDebug("GnPort.receive: commonHdr=" + ByteHelper.byteArrayToString(commonHdr));
//TERFactory.getInstance().logDebug("GnPort.receive: commonHdr=" + ByteHelper.byteArrayToString(commonHdr));
byte[] htHst = new byte[1];
System.arraycopy(commonHdr, 1, htHst, 0, 1);
headerType = (int)(htHst[0] >> 4);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment