Skip to content
New issue

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

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

Already on GitHub? # to your account

Required parameter is not generated properly #11

Open
rakshitkr opened this issue Dec 7, 2020 · 3 comments
Open

Required parameter is not generated properly #11

rakshitkr opened this issue Dec 7, 2020 · 3 comments
Labels
bug Something isn't working develop ruleset

Comments

@rakshitkr
Copy link
Collaborator

rakshitkr commented Dec 7, 2020

@Test
	public void keyPairGeneratorValidTest4() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

		BigInteger q = null;

		DSAParameterSpec dSAParameterSpec0 = new DSAParameterSpec(BigInteger.valueOf(2), q, BigInteger.valueOf(1));
		Assertions.hasEnsuredPredicate(dSAParameterSpec0);
		Assertions.mustBeInAcceptingState(dSAParameterSpec0);

		KeyPairGenerator keyPairGenerator0 = KeyPairGenerator.getInstance("RSA");
		keyPairGenerator0.initialize(dSAParameterSpec0); // RSAKeyGenParameterSpec must be generated
		KeyPair keyPair = keyPairGenerator0.generateKeyPair();
		Assertions.hasEnsuredPredicate(keyPair);
		Assertions.mustBeInAcceptingState(keyPairGenerator0);

	}
@Test
	public void keyPairGeneratorValidTest5() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {

		BigInteger q = null;

		DSAParameterSpec dSAParameterSpec0 = new DSAParameterSpec(BigInteger.valueOf(2), q, BigInteger.valueOf(1));
		Assertions.hasEnsuredPredicate(dSAParameterSpec0);
		Assertions.mustBeInAcceptingState(dSAParameterSpec0);

		KeyPairGenerator keyPairGenerator0 = KeyPairGenerator.getInstance("RSA");
		keyPairGenerator0.initialize(dSAParameterSpec0, (SecureRandom) null); // RSAKeyGenParameterSpec must be generated
		KeyPair keyPair = keyPairGenerator0.generateKeyPair();
		Assertions.hasEnsuredPredicate(keyPair);
		Assertions.mustBeInAcceptingState(keyPairGenerator0);

	}
@rakshitkr rakshitkr added bug Something isn't working develop ruleset labels Dec 7, 2020
@rakshitkr
Copy link
Collaborator Author

Transformation string is generated incorrect because currently the test generator does not support two step generation for handling the below constraint type. Two step generation is needed because the class type of key is known only after the generation of init method.

instanceOf[key, java.security.PublicKey] || instanceOf[key, java.security.PrivateKey] || instanceOf[cert, java.security.cert.Certificate]|| encmode in {3, 4} => alg(transformation) in {"RSA"};

Cipher cipher0 = Cipher.getInstance("RSA"); // wrong transformation string is generated
cipher0.init(1, secretKey);
byte[] pre_ciphertext = cipher0.update(pre_plaintext);
Assertions.hasEnsuredPredicate(pre_ciphertext);
Assertions.mustNotBeInAcceptingState(cipher0);
pBEKeySpec0.clearPassword();
Assertions.mustBeInAcceptingState(pBEKeySpec0);

Following test cases have the above issue

  • cipherInvalidTest23
  • cipherInvalidTest24
  • cipherInvalidTest25
  • cipherInvalidTest26
  • cipherInvalidTest27
  • cipherInvalidTest28
  • cipherValidTest13()
  • cipherValidTest14()
  • cipherValidTest15()
  • cipherValidTest16()
  • cipherValidTest17()
  • cipherValidTest18()
  • cipherValidTest26()
  • cipherValidTest27()
  • cipherValidTest28()
  • cipherValidTest29()
  • cipherValidTest30()
  • cipherValidTest31()

@rakshitkr
Copy link
Collaborator Author

rakshitkr commented Dec 13, 2020

Test generator does not recognize negated predicates like below in the REQUIRES section. Thus it generates the code from the associated specification. (for the below case it is Cipher)

REQUIRES
    !encrypted[output1, _];
	@Test
	public void macInvalidTest9() throws IllegalStateException, BadPaddingException, NoSuchPaddingException,
			IllegalBlockSizeException, NoSuchAlgorithmException, InvalidKeyException, ShortBufferException {

		Certificate cert = null;
		byte[] plainText = null;
		byte[] pre_plaintext = null;

		Cipher cipher0 = Cipher.getInstance("RSA");
		cipher0.init(1, cert);
		byte[] pre_ciphertext = cipher0.update(pre_plaintext);
		byte[] cipherText = cipher0.doFinal(plainText);
		Assertions.hasEnsuredPredicate(cipherText);
		Assertions.mustBeInAcceptingState(cipher0);

		int outOffset = 0;

		Mac mac0 = Mac.getInstance("HmacMD5");
		mac0.doFinal(cipherText, outOffset);
		Assertions.notHasEnsuredPredicate(cipherText); // FAILS
		Assertions.mustNotBeInAcceptingState(mac0);

	}

	@Test
	public void macInvalidTest22() throws IllegalStateException, BadPaddingException, NoSuchPaddingException,
			IllegalBlockSizeException, NoSuchAlgorithmException, InvalidKeyException, ShortBufferException {

		Certificate cert = null;
		byte[] plainText = null;
		byte[] pre_plaintext = null;

		Cipher cipher0 = Cipher.getInstance("RSA");
		cipher0.init(1, cert);
		byte[] pre_ciphertext = cipher0.update(pre_plaintext);
		byte[] cipherText = cipher0.doFinal(plainText);
		Assertions.hasEnsuredPredicate(cipherText);
		Assertions.mustBeInAcceptingState(cipher0);

		int outOffset = 0;
		byte inp = 0;

		Mac mac0 = Mac.getInstance("HmacMD5");
		mac0.update(inp);
		mac0.doFinal(cipherText, outOffset);
		Assertions.notHasEnsuredPredicate(cipherText); // FAILS
		Assertions.mustNotBeInAcceptingState(mac0);

	}

@rakshitkr
Copy link
Collaborator Author

rakshitkr commented Dec 13, 2020

CONSTRAINTS
	offset < len;
@Test
	public void macValidTest10() throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException {

		int offset = 0;
		int len = 0; // initialised with incorrect value
		byte[] pre_input = null;
		Key key = null;

		Mac mac0 = Mac.getInstance("HmacMD5");
		mac0.init(key);
		mac0.update(pre_input, offset, len);
		byte[] output1 = mac0.doFinal();
		Assertions.hasEnsuredPredicate(output1); // FAILS
		Assertions.mustBeInAcceptingState(mac0);

	}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working develop ruleset
Projects
None yet
Development

No branches or pull requests

1 participant