Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OR-ing of 2 or 3 predicates only works for ENSURE section with non-conditional predicates #215

Open
rakshitkr opened this issue Feb 3, 2020 · 2 comments

Comments

@rakshitkr
Copy link
Contributor

rakshitkr commented Feb 3, 2020

The below test case verifies the usage of GCMBlockCipher with AEADParameters OR ParametersWithIV. But the test case is failing currently since the ENSURES section in GCMBlockCipher has the conditional predicate generatedGCMBlockCipherMode[this] after Cons;.

@Test
	public void testORingTwoPredicates2() throws GeneralSecurityException, IllegalStateException, InvalidCipherTextException {
		SecureRandom random = new SecureRandom();
		byte[] genSeed = random.generateSeed(128);
		KeyParameter keyParam = new KeyParameter(genSeed);
		byte[] nonce = random.generateSeed(128);
		AEADParameters aeadParam = new AEADParameters(keyParam, 128, nonce);
		Assertions.hasEnsuredPredicate(aeadParam);
		Assertions.mustBeInAcceptingState(aeadParam);
		AESEngine engine = new AESEngine();
		Assertions.hasEnsuredPredicate(engine);
		byte[] input = new byte[100];
		byte[] output = new byte[100];
		
		GCMBlockCipher cipher1 = new GCMBlockCipher(engine);
		cipher1.init(false, aeadParam);
		cipher1.processAADBytes(input, 0, input.length);
		cipher1.doFinal(output, 0);
		Assertions.hasEnsuredPredicate(cipher1);
		Assertions.mustBeInAcceptingState(cipher1);
		
		ParametersWithIV ivParam = new ParametersWithIV(keyParam, genSeed);
		Assertions.hasEnsuredPredicate(ivParam);
		Assertions.mustBeInAcceptingState(ivParam);
		
		GCMBlockCipher cipher2 = new GCMBlockCipher(engine);
		cipher2.init(false, ivParam);
//		cipher2.processAADBytes(input, 0, input.length);
//		cipher2.doFinal(output, 0);
		Assertions.hasEnsuredPredicate(cipher2);
		Assertions.mustNotBeInAcceptingState(cipher2);	
	}

OUTPUT

Expected a predicate for cipher1 (BouncyCastlesUsagePatternTest.testORingTwoPredicates4) @ staticinvoke <test.assertions.Assertions: void hasEnsuredPredicate(java.lang.Object)>(cipher1)
Expected a predicate for cipher2 (BouncyCastlesUsagePatternTest.testORingTwoPredicates4) @ staticinvoke <test.assertions.Assertions: void hasEnsuredPredicate(java.lang.Object)>(cipher2)

However, when this conditional predicate is changed into normal predicate and the method calls in testORingTwoPredicates2 are modified as below, the test case passes. This verifies that the OR operator currently works for rules with non-conditional predicates in ENSURES section

...
		GCMBlockCipher cipher2 = new GCMBlockCipher(engine);
		cipher2.init(false, ivParam);
		cipher2.processAADBytes(input, 0, input.length); // because now `generatedGCMBlockCipherMode` predicate is only generated after `Cons, init, process+, doFinal`
		cipher2.doFinal(output, 0);
		Assertions.hasEnsuredPredicate(cipher2);
		Assertions.mustBeInAcceptingState(cipher2);
...
@rakshitkr
Copy link
Contributor Author

@kruegers I've added test cases for verifying OR-ing predicates in the pull request #214

@rakshitkr
Copy link
Contributor Author

rakshitkr commented Feb 7, 2020

The reason for the above behaviour was because the next method call i.e. init from ORDER section is negating the ensured predicate generatedGCMBlockCipherMode generated after constructor call of GCMBlockCipher. However when the conditional predicate is changed to normal predicate namely generatedGCMBlockCipherMode[this]; then the corresponding predicate is only generated after last method call in ORDER section i.e. doFinal. Since we have Assertions.hasEnsuredPredicate immediately after this method call, both the assertions results to true.

rakshitkr added a commit that referenced this issue Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant