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

Misuses not caught with static fields #163

Closed
enriozuni opened this issue Jun 13, 2019 · 1 comment
Closed

Misuses not caught with static fields #163

enriozuni opened this issue Jun 13, 2019 · 1 comment

Comments

@enriozuni
Copy link
Contributor

enriozuni commented Jun 13, 2019

In various CryptoGuard projects in issue #134 that were headless tested, misuses were not caught in the following scenario from the analysis. The cases include a particular scenario where many methods were used to assign field values. I have listed below the projects and the objects from the JCA that were present in these cases.

CryptoGuard projects and their respective cases

Below are cases that were headless tested. They are grouped according to their project name in CryptoGuard and the JCA object involved.

package example.brokencrypto;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class BrokenCryptoABICase5 {
    public static final String DEFAULT_CRYPTO = "DES/ECB/PKCS5Padding";
    private static char[] CRYPTO;
    private static char[] crypto;
    public void doCrypto() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
        KeyGenerator keyGen = KeyGenerator.getInstance("DES");
        SecretKey key = keyGen.generateKey();
        Cipher cipher = Cipher.getInstance(String.valueOf(crypto));
        cipher.init(Cipher.ENCRYPT_MODE, key);
    }
    private static void go2(){
        CRYPTO = DEFAULT_CRYPTO.toCharArray();
    }
    private static void go3(){
        crypto = CRYPTO;
    }

    public static void main (String [] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
        BrokenCryptoABICase5 bc = new BrokenCryptoABICase5();
        go2();
        go3();
        bc.doCrypto();
    }
}

Findings from the analysis when this case is headless tested are:

in Method: void doCrypto()
		IncompleteOperationError violating CrySL rule for javax.crypto.Cipher (on Object #2b21e883bb899e9f55dccff1bb1aa4bc7b0625183907e1e52896b6889c477e4)
			Operation on object of type javax.crypto.Cipher object not completed. Expected call to javax.crypto.Cipher: void init(int,java.security.cert.Certificate,java.security.SecureRandom), javax.crypto.Cipher: void init(int,java.security.Key), javax.crypto.Cipher: void init(int,java.security.Key,java.security.AlgorithmParameters), javax.crypto.Cipher: void init(int,java.security.Key,java.security.SecureRandom), javax.crypto.Cipher: void init(int,java.security.Key,java.security.spec.AlgorithmParameterSpec), update, javax.crypto.Cipher: void init(int,java.security.Key,java.security.spec.AlgorithmParameterSpec,java.security.SecureRandom), javax.crypto.Cipher: void init(int,java.security.cert.Certificate), javax.crypto.Cipher: void init(int,java.security.Key,java.security.AlgorithmParameters,java.security.SecureRandom), wrap, doFinal
			at statement: virtualinvoke r3.<javax.crypto.Cipher: void init(int,java.security.Key)>(varReplacer25, r2)

		ConstraintError violating CrySL rule for javax.crypto.KeyGenerator (on Object #2a8eb841d92cb688ec3e9b2631b2d3b6000633656fea933823f6f935a18ebb2b)
			First parameter (with value "DES") should be any of {AES, HmacSHA224, HmacSHA256, HmacSHA384, HmacSHA512}
			at statement: r1 = staticinvoke <javax.crypto.KeyGenerator: javax.crypto.KeyGenerator getInstance(java.lang.String)>(varReplacer26)

As seen, no ConstraintError regarding insecure algorithm used in Cipher is reported. Other similar cases in the same project folder include: BrokenCryptoABICase6, BrokenCryptoABICase7, BrokenCryptoABICase8, BrokenCryptoABICase10.

@johspaeth johspaeth changed the title Misuses caught in analysis where many methods were used to assign field values Misuses not caught with static fields Jun 14, 2019
@kruegers
Copy link
Member

kruegers commented May 6, 2020

Closing this as it is a duplicate to #97.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants