Skip to content

Commit 6640c30

Browse files
authored
Update README.md
1 parent 54aea73 commit 6640c30

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

Diff for: README.md

+48-46
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,54 @@ The static analysis CogniCrypt<sub>SAST</sub> takes rules written in the specifi
55
and performs a static analysis based on the specification of the rules. CrySL is a domain-specific language (DSL) designed to encode usage specifications for cryptographic
66
libaries (e.g., the [JCA](https://docs.oracle.com/en/java/javase/14/security/java-cryptography-architecture-jca-reference-guide.html) in particular). More information on CrySL and the static analysis may be found in [this paper](http://drops.dagstuhl.de/opus/volltexte/2018/9215/).
77

8+
## Running CognitCrypt<sub>SAST</sub>
9+
10+
Let's assume we have the following program with some violations:
11+
12+
```java
13+
import java.security.GeneralSecurityException;
14+
import javax.crypto.KeyGenerator;
15+
import javax.crypto.SecretKey;
16+
import javax.crypto.spec.SecretKeySpec;
17+
import javax.crypto.Cipher;
18+
19+
public class Example {
20+
21+
public static void main(String[] args) throws GeneralSecurityException {
22+
// Constraint Error: "DES" is not allowed
23+
KeyGenerator generator = KeyGenerator.getInstance("DES"); // r0
24+
25+
// Constraint Error: Key size of 64 is not allowed
26+
generator.init(64);
27+
28+
// KeyGenerator is not correctly initialized
29+
// RequiredPredicateEror: Generated key is not secure
30+
SecretKey key = generator.generateKey(); // r1
31+
32+
// Constraint Error: "DES" is not allowed
33+
Cipher cipher = Cipher.getInstance("DES"); // r2
34+
35+
// RequiredPredicateError: "key" is not securely generated
36+
cipher.init(Cipher.ENCRYPT_MODE, key);
37+
38+
// IncompleteOperationError: Cipher object is not used
39+
}
40+
}
41+
```
42+
43+
Using the [JCA rules](https://github.com/CROSSINGTUD/Crypto-API-Rules/tree/master/JavaCryptographicArchitecture/src), we execute the following command on a compiled version of this program:
44+
45+
```bash
46+
java -jar HeadlessJavaScanner-x.y.z-jar-with-dependencies.jar --appPath ./Examples.jar --rulesDir ./JCA-CrySL-rules.zip --reportFormat CMD --reportPath ./output/ --visualization
47+
```
48+
49+
CogniCrypt<sub>SAST</sub> runs the analysis and prints a report to the command line. In total, it reports 3 `ConstraintErrors`, 2 `RequiredPredicateErrors` and 1 `IncompleteOperationError`, and their positions in the original programs. Additionally, since we use `--visualization`, it creates the following image `visualization.png` in the directory `./output/`:
50+
51+
![visualization.png](misc/visualization.png)
52+
53+
You can see that two `ConstraintErrors` on the object `r0` (KeyGenerator) cause a `RequiredPredicateError` on the object `r1` (SecretKey) which in turn causes a `RequiredPredicateError` on the object `r2` (Cipher). Additionally, there is another `ConstraintError` and `IncompleteOperationError` on the Cipher object. Note that the variables and statements correspond to the intermediate representation Jimple. You can match the variables to the command line output that lists all analyzed objects.
54+
55+
856
## Structure
957
We provide the implementation of the static analysis of CogniCrypt in:
1058
* `CryptoAnalysis` contains the components for the actual analysis
@@ -129,49 +177,3 @@ We hare happy for every contribution from the community!
129177
* [Contributing](CONTRIBUTING.md) for details on issues and merge requests.
130178
* [Coding Guidles](CODING.md) for this project.
131179
132-
## Running CognitCrypt<sub>SAST</sub>
133-
134-
Let's assume we have the following program with some violations:
135-
136-
```java
137-
import java.security.GeneralSecurityException;
138-
import javax.crypto.KeyGenerator;
139-
import javax.crypto.SecretKey;
140-
import javax.crypto.spec.SecretKeySpec;
141-
import javax.crypto.Cipher;
142-
143-
public class Example {
144-
145-
public static void main(String[] args) throws GeneralSecurityException {
146-
// Constraint Error: "DES" is not allowed
147-
KeyGenerator generator = KeyGenerator.getInstance("DES"); // r0
148-
149-
// Constraint Error: Key size of 64 is not allowed
150-
generator.init(64);
151-
152-
// KeyGenerator is not correctly initialized
153-
// RequiredPredicateEror: Generated key is not secure
154-
SecretKey key = generator.generateKey(); // r1
155-
156-
// Constraint Error: "DES" is not allowed
157-
Cipher cipher = Cipher.getInstance("DES"); // r2
158-
159-
// RequiredPredicateError: "key" is not securely generated
160-
cipher.init(Cipher.ENCRYPT_MODE, key);
161-
162-
// IncompleteOperationError: Cipher object is not used
163-
}
164-
}
165-
```
166-
167-
Using the [JCA rules](https://github.com/CROSSINGTUD/Crypto-API-Rules/tree/master/JavaCryptographicArchitecture/src), we execute the following command on a compiled version of this program:
168-
169-
```bash
170-
java -jar HeadlessJavaScanner-x.y.z-jar-with-dependencies.jar --appPath ./Examples.jar --rulesDir ./JCA-CrySL-rules.zip --reportFormat CMD --reportPath ./output/ --visualization
171-
```
172-
173-
CogniCrypt<sub>SAST</sub> runs the analysis and prints a report to the command line. In total, it reports 3 `ConstraintErrors`, 2 `RequiredPredicateErrors` and 1 `IncompleteOperationError`, and their positions in the original programs. Additionally, since we use `--visualization`, it creates the following image `visualization.png` in the directory `./output/`:
174-
175-
![visualization.png](misc/visualization.png)
176-
177-
You can see that two `ConstraintErrors` on the object `r0` (KeyGenerator) cause a `RequiredPredicateError` on the object `r1` (SecretKey) which in turn causes a `RequiredPredicateError` on the object `r2` (Cipher). Additionally, there is another `ConstraintError` and `IncompleteOperationError` on the Cipher object. Note that the variables and statements correspond to the intermediate representation Jimple. You can match the variables to the command line output that lists all analyzed objects.

0 commit comments

Comments
 (0)