Skip to content

Commit 3964f2d

Browse files
APPENG-3181: Feature Add C support to transitive tool (#104)
* feat: Add C/C++ support to transitive code search tool - Add C language support and enhance function parsing capabilities - Implement singleton pattern for RPMDependencyManager - Add container source download for C/C++ dependencies - Add C extended segmenter class with comprehensive testing - Add new Function Name Locator tool with fuzzy matching - Enhance transitive code search with assistant tool - Add C/C++ function parsers and language support - Add comprehensive test suite for C code analysis - Improve function name extraction and parsing - Add source RPM downloader for C/C++ dependencies - Update configuration files for NIM and OpenAI endpoints - Fix various bugs and improve code quality - Add proper documentation and type hints - Clean up imports and remove debug prints This commit consolidates 39 individual commits that add comprehensive C/C++ language support to the vulnerability analysis toolchain. * update docs, kustomize service config, tests and rpm downloader support UT * review fix move C_DEP_LIBS_NAME locaiton * fixed review comments * Add cache for std lib names for lang python,go,java,javascript * Update src/vuln_analysis/utils/standard_library_cache.py Co-authored-by: Zvi Grinberg <[email protected]> * fix indentation * add persistance to cache * code review comments * add comments and update docker for bsdtar app to be install in image * update docfile * small improvments * handle invalid utf-8 files --------- Co-authored-by: Zvi Grinberg <[email protected]>
1 parent db77db8 commit 3964f2d

37 files changed

+8376
-189
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ RUN apt-get update && apt-get install -y \
3333
git \
3434
git-lfs \
3535
wget \
36+
skopeo \
37+
libarchive-tools \
3638
&& apt-get clean \
39+
&& rm -rf /var/lib/apt/lists/* \
3740
&& update-ca-certificates
3841

42+
3943
RUN curl -L -X GET https://go.dev/dl/go1.24.1.linux-amd64.tar.gz -o /tmp/go1.24.1.linux-amd64.tar.gz \
4044
&& tar -C /usr/local -xzf /tmp/go1.24.1.linux-amd64.tar.gz \
4145
&& rm /tmp/go1.24.1.linux-amd64.tar.gz

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ To run the workflow you need to obtain API keys for the following APIs. These wi
216216
- Click on your account in the top right, select "Setup" from the dropdown.
217217
- Click the "Generate Personal Key" option and then the "+ Generate Personal Key" button to create your API key.
218218
- This will be used in the `NVIDIA_API_KEY` environment variable.
219+
- REDHAT container registry (Recommended but not compulsory)
220+
- To get source images from a Red Hat container registry using registry service account tokens. You will need to create a [registry service account](https://access.redhat.com/terms-based-registry/)
221+
- Steps:
222+
- Sign in to the registry service accout
223+
- Press on New service Account Button
224+
- Fill the Name (ex. 'test-case') and Description fields and Click the Create botton
225+
- Token user name for example '11008101|test-case' for REGISTRY_REDHAT_USERNAME environment variable
226+
- Token password a long string for REGISTRY_REDHAT_PASSWORD environment variable
227+
219228

220229
The workflow can be configured to use other LLM services as well, see the [Customizing the LLM models](#customizing-the-llm-models) section for more info.
221230

kustomize/README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,47 @@ export NVIDIA_API_BASE=http://YOUR_SELF_HOSTED_OPENAI_LLM_ADDRESSS/v1
3838
export PYTHONUNBUFFERED=1
3939
export SERPAPI_API_KEY=YOUR_SERPAPI_KEY
4040
export SUMMARIZE_MODEL_NAME=hugging-quants/Meta-Llama-3.1-70B-Instruct-AWQ-INT4
41+
export REGISTRY_REDHAT_USERNAME="your_username"
42+
export REGISTRY_REDHAT_PASSWORD="your_password_or_token"
4143
```
4244

4345
6. **Run the Application**: After a successful installation, run the application.
44-
4546
```shell
4647
nat --log-level debug serve --config_file=src/vuln_analysis/configs/config-http-openai.yml --host 0.0.0.0 --port 26466
4748
```
4849

50+
### Container Source Download Configuration
51+
52+
For C/C++ projects, you can enable container source download to extract RPM dependencies from Red Hat container registries. This feature uses skopeo to download container source layers and automatically extracts RPM packages, excluding the main application RPMs to focus on dependencies only.
53+
**Required Environment Variables:**
54+
# Enable container source download mode (default behavior )
55+
export USE_CONTAINER_SOURCES=true
56+
57+
**How it works:**
58+
1. Downloads container source layers using skopeo
59+
2. Extracts RPM packages from the downloaded layers
60+
3. Filters out main application RPMs (e.g., `postgresql-*` for PostgreSQL containers)
61+
4. Copies dependency RPMs to the standard RPM cache directory
62+
63+
64+
**Prerequisites:**
65+
- `skopeo` must be installed on the system
66+
- Valid Red Hat registry credentials
67+
- Network access to `registry.redhat.io`
68+
69+
4970
## Deploy And Run On OCP
5071

51-
1. Create a `base/secrets.env` file containing the API keys for external services `ExploitIQ` might use. Not all keys are mandatory. Refer to the main [README](../README.md) for details.
72+
1. Create a `base/secrets.env` file containing the API keys for external services `ExploitIQ` might use. Not all keys are mandatory. Refer to the main [README](../README.md#obtain-api-keys) for details on how to create the Red Hat credentials and other API keys.
5273

5374
```shell
5475
cat > base/secrets.env << EOF
5576
nvd_api_key=you_api_key
5677
serpapi_api_key=your_api_key
5778
nvidia_api_key=your_api_key
5879
ghsa_api_key=your_api_key
80+
registry_redhat_username=your_registry_username
81+
registry_redhat_password=your_registry_pass_token
5982
EOF
6083
```
6184

kustomize/base/excludes.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
"pom.xml",
1818
"build.gradle"
1919
],
20+
"C": [
21+
"**/tests/**/*",
22+
"**/test/**/*",
23+
"**/demos/**/*",
24+
"**/examples/**/*",
25+
"**/samples/**/*",
26+
"**/doc/**/*",
27+
"**/docs/**/*"
28+
],
2029
"JavaScript": [
2130
"node_modules/**/*",
2231
"dist/**/*",

kustomize/base/exploit-iq-config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ functions:
3232
base_git_dir: ${EXPLOIT_IQ_DATA_DIR:-/exploit-iq-data/}git
3333
base_vdb_dir: ${EXPLOIT_IQ_DATA_DIR:-/exploit-iq-data/}vdb
3434
base_code_index_dir: ${EXPLOIT_IQ_DATA_DIR:-/exploit-iq-data/}code_index
35-
base_pickle_dir: ${EXPLOIT_IQ_DATA_DIR:-/exploit-iq-data/}pickle
35+
base_pickle_dir: ${EXPLOIT_IQ_DATA_DIR:-/exploit-iq-data/}pickle
36+
base_rpm_dir: ${EXPLOIT_IQ_DATA_DIR:-/exploit-iq-data/}rpms
3637
ignore_code_embedding: true
3738
cve_fetch_intel:
3839
_type: cve_fetch_intel
@@ -59,6 +60,8 @@ functions:
5960
Calling Function Name Extractor:
6061
_type: calling_function_name_extractor
6162
enable_functions_usage_search: true
63+
Package and Function Locator:
64+
_type: package_and_function_locator
6265
Container Image Code QA System:
6366
_type: local_vdb_retriever
6467
embedder_name: nim_embedder
@@ -89,6 +92,7 @@ functions:
8992
- Internet Search
9093
- Transitive code search tool
9194
- Calling Function Name Extractor
95+
- Package and Function Locator
9296
max_concurrency: null
9397
max_iterations: 10
9498
prompt_examples: false

kustomize/base/exploit_iq_service.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ spec:
7979
value: EXPLOIT_IQ
8080
- name: NGC_API_KEY
8181
value: EXPLOIT_IQ
82+
- name: REGISTRY_REDHAT_PASSWORD
83+
valueFrom:
84+
secretKeyRef:
85+
key: registry_redhat_password
86+
name: exploit-iq-secret
87+
- name: REGISTRY_REDHAT_USERNAME
88+
valueFrom:
89+
secretKeyRef:
90+
key: registry_redhat_username
91+
name: exploit-iq-secret
8292
- name: CVE_DETAILS_BASE_URL
8393
value: http://nginx-cache:8080/cve-details
8494
- name: CWE_DETAILS_BASE_URL

kustomize/base/includes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
"public/**/*",
4949
"assets/**/*"
5050
],
51+
"C":[
52+
"**/*.c",
53+
"**/*.h"
54+
],
5155
"Dockerfile": [
5256
"Dockerfile*",
5357
"docker-compose.yml",

kustomize/config-http-openai-local.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ functions:
3737
base_vdb_dir: .cache/am_cache/vdb
3838
base_code_index_dir: .cache/am_cache/code_index
3939
base_pickle_dir: .cache/am_cache/pickle
40+
base_rpm_dir: .cache/am_cache/rpms
4041
ignore_code_embedding: true
4142
cve_fetch_intel:
4243
_type: cve_fetch_intel
@@ -60,6 +61,8 @@ functions:
6061
Calling Function Name Extractor:
6162
_type: calling_function_name_extractor
6263
enable_functions_usage_search: true
64+
Package and Function Locator:
65+
_type: package_and_function_locator
6366
Container Image Code QA System:
6467
_type: local_vdb_retriever
6568
embedder_name: nim_embedder
@@ -90,6 +93,7 @@ functions:
9093
- Internet Search
9194
- Transitive code search tool
9295
- Calling Function Name Extractor
96+
- Package and Function Locator
9397
max_concurrency: null
9498
max_iterations: 10
9599
prompt_examples: false

0 commit comments

Comments
 (0)