GithubHelp home page GithubHelp logo

Comments (3)

rakshitkr avatar rakshitkr commented on July 28, 2024

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()

from cognicrypt_testgen.

rakshitkr avatar rakshitkr commented on July 28, 2024

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);

	}

from cognicrypt_testgen.

rakshitkr avatar rakshitkr commented on July 28, 2024
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);

	}

from cognicrypt_testgen.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.