@Test public void testOverwritingWithVeryFarIvIndex() { final byte[] data = MeshParserUtils.toByteArray("0102EE6C0EFF5298ECFF00000034A53312BF9198C86F"); final SecureNetworkBeacon snb = new SecureNetworkBeacon(data); final IvIndex ivIndex = new IvIndex(9, false, Calendar.getInstance()); final Calendar longTimeAgo = Calendar.getInstance(); longTimeAgo.add(Calendar.HOUR, -(42 * 192 + 96)); final Calendar notThatLongTimeAgo = (Calendar) longTimeAgo.clone(); notThatLongTimeAgo.add(Calendar.SECOND, 10); final Calendar longLongTimeAgo = (Calendar) longTimeAgo.clone(); longLongTimeAgo.add(Calendar.SECOND, -10); final boolean result0 = snb.canOverwrite(ivIndex, notThatLongTimeAgo, false, false, false); final boolean result1 = snb.canOverwrite(ivIndex, longTimeAgo, false, false, false); final boolean result2 = snb.canOverwrite(ivIndex, longLongTimeAgo, false, false, false); final boolean result3 = snb.canOverwrite(ivIndex, notThatLongTimeAgo, false, false, true); final boolean result4 = snb.canOverwrite(ivIndex, longTimeAgo, false, false, true); final boolean result5 = snb.canOverwrite(ivIndex, longLongTimeAgo, false, false, true); assertFalse(result0); assertFalse(result1); assertFalse(result2); assertFalse(result3); assertTrue(result4); assertTrue(result5); }
protected boolean canOverwrite(final IvIndex ivIndex, final Calendar updatedAt, final boolean ivRecoveryActive, final boolean isTestMode, final boolean ivRecoveryOver42Allowed) { if ((this.ivIndex.getIvIndex() > ivIndex.getIvIndex() && (ivRecoveryOver42Allowed || this.ivIndex.getIvIndex() <= ivIndex.getIvIndex() + 42)) || (this.ivIndex.getIvIndex() == ivIndex.getIvIndex() && (ivIndex.isIvUpdateActive() || !this.ivIndex.isIvUpdateActive()))) { return isMinimumTimeRequirementCompleted(ivIndex, updatedAt, ivRecoveryActive, isTestMode); } else { return false; } }
SecureNetworkBeacon extends MeshBeacon { protected boolean canOverwrite(final IvIndex ivIndex, final Calendar updatedAt, final boolean ivRecoveryActive, final boolean isTestMode, final boolean ivRecoveryOver42Allowed) { if ((this.ivIndex.getIvIndex() > ivIndex.getIvIndex() && (ivRecoveryOver42Allowed || this.ivIndex.getIvIndex() <= ivIndex.getIvIndex() + 42)) || (this.ivIndex.getIvIndex() == ivIndex.getIvIndex() && (ivIndex.isIvUpdateActive() || !this.ivIndex.isIvUpdateActive()))) { return isMinimumTimeRequirementCompleted(ivIndex, updatedAt, ivRecoveryActive, isTestMode); } else { return false; } } }
SecureNetworkBeacon extends MeshBeacon { protected boolean canOverwrite(final IvIndex ivIndex, final Calendar updatedAt, final boolean ivRecoveryActive, final boolean isTestMode, final boolean ivRecoveryOver42Allowed) { if ((this.ivIndex.getIvIndex() > ivIndex.getIvIndex() && (ivRecoveryOver42Allowed || this.ivIndex.getIvIndex() <= ivIndex.getIvIndex() + 42)) || (this.ivIndex.getIvIndex() == ivIndex.getIvIndex() && (ivIndex.isIvUpdateActive() || !this.ivIndex.isIvUpdateActive()))) { return isMinimumTimeRequirementCompleted(ivIndex, updatedAt, ivRecoveryActive, isTestMode); } else { return false; } } SecureNetworkBeacon(@NonNull final byte[] beaconData); }
SecureNetworkBeacon extends MeshBeacon { protected boolean canOverwrite(final IvIndex ivIndex, final Calendar updatedAt, final boolean ivRecoveryActive, final boolean isTestMode, final boolean ivRecoveryOver42Allowed) { if ((this.ivIndex.getIvIndex() > ivIndex.getIvIndex() && (ivRecoveryOver42Allowed || this.ivIndex.getIvIndex() <= ivIndex.getIvIndex() + 42)) || (this.ivIndex.getIvIndex() == ivIndex.getIvIndex() && (ivIndex.isIvUpdateActive() || !this.ivIndex.isIvUpdateActive()))) { return isMinimumTimeRequirementCompleted(ivIndex, updatedAt, ivRecoveryActive, isTestMode); } else { return false; } } SecureNetworkBeacon(@NonNull final byte[] beaconData); @NonNull @Override String toString(); @Override int getBeaconType(); int getFlags(); boolean isKeyRefreshActive(); byte[] getNetworkId(); IvIndex getIvIndex(); byte[] getAuthenticationValue(); @Override int describeContents(); @Override void writeToParcel(final Parcel dest, final int flags); }
SecureNetworkBeacon extends MeshBeacon { protected boolean canOverwrite(final IvIndex ivIndex, final Calendar updatedAt, final boolean ivRecoveryActive, final boolean isTestMode, final boolean ivRecoveryOver42Allowed) { if ((this.ivIndex.getIvIndex() > ivIndex.getIvIndex() && (ivRecoveryOver42Allowed || this.ivIndex.getIvIndex() <= ivIndex.getIvIndex() + 42)) || (this.ivIndex.getIvIndex() == ivIndex.getIvIndex() && (ivIndex.isIvUpdateActive() || !this.ivIndex.isIvUpdateActive()))) { return isMinimumTimeRequirementCompleted(ivIndex, updatedAt, ivRecoveryActive, isTestMode); } else { return false; } } SecureNetworkBeacon(@NonNull final byte[] beaconData); @NonNull @Override String toString(); @Override int getBeaconType(); int getFlags(); boolean isKeyRefreshActive(); byte[] getNetworkId(); IvIndex getIvIndex(); byte[] getAuthenticationValue(); @Override int describeContents(); @Override void writeToParcel(final Parcel dest, final int flags); static final int BEACON_DATA_LENGTH; static final Parcelable.Creator<SecureNetworkBeacon> CREATOR; }