-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIriusRiskWeaknessInfo.java
87 lines (74 loc) · 3.29 KB
/
IriusRiskWeaknessInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2012-2020 Continuum Security. All rights reserved
*/
import com.iriusrisk.ApiException;
import com.iriusrisk.api.ProductsApi;
import com.iriusrisk.model.Component;
import com.iriusrisk.model.ComponentControl;
import com.iriusrisk.model.ComponentUseCase;
import com.iriusrisk.model.ComponentUseCaseThreatShort;
import com.iriusrisk.model.ComponentWeakness;
import com.iriusrisk.model.Product;
import com.iriusrisk.model.ProductShort;
import com.iriusrisk.model.RiskSummary;
import com.iriusrisk.model.Threat;
import com.iriusrisk.model.ThreatControl;
import com.iriusrisk.model.ThreatShort;
import com.iriusrisk.model.ThreatWeakness;
import com.squareup.okhttp.OkHttpClient;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.List;
/**
* This is an example of how to use IriusRisk Client Lib to create a custom output from a countermeasure list
*/
public class IriusRiskWeaknessInfo {
public static void main(String[] args) {
System.out.println("New IriusRisk instance");
ProductsApi apiInstance = new ProductsApi();
// You must define the scheme://host:port/api/v1 from your IriusRisk instance
// i.e.: https://server.com:5445/api/v1
OkHttpClient httpClient = new OkHttpClient();
String proxyHost = System.getProperty("proxy.host");
if (proxyHost != null) {
int proxyPort = Integer.parseInt(System.getProperty("proxy.port"));
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
httpClient.setProxy(proxy);
}
apiInstance.getApiClient().setBasePath("<scheme://host:port>/api/v1");
apiInstance.getApiClient().setHttpClient(httpClient);
apiInstance.getApiClient().setVerifyingSsl(false);
String apiToken = "<api-token>";
try {
// Given the product and the threat ref
String productRef = "test";
String threatRef = "UNAUTHORIZED-CONNECTION";
// We get the weakness refs corresponding to a threat
List<ComponentWeakness> weaknesses = apiInstance.productsRefGet(apiToken, productRef).getComponents().get(0).getWeaknesses();
Product product = apiInstance.productsRefGet(apiToken, productRef);
List<String> weaknessRefs = new ArrayList<String>();
for (Component component : product.getComponents()) {
for (ComponentUseCase usecase : component.getUsecases()) {
for (Threat threat : usecase.getThreats()) {
if (threat.getRef().equals(threatRef)) {
for (ThreatWeakness weakness : threat.getWeaknesses()) {
weaknessRefs.add(weakness.getRef());
}
}
}
}
}
for (Component component : product.getComponents()) {
for(ComponentWeakness s : component.getWeaknesses()) {
if(weaknessRefs.contains(s.getRef())){
System.out.println(s);
}
}
}
} catch (ApiException e) {
System.err.println("Exception when calling API");
e.printStackTrace();
}
}
}