hcot-cli 0.1.2__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hcot_cli-0.2.0/PKG-INFO +126 -0
- hcot_cli-0.2.0/README.md +99 -0
- hcot_cli-0.2.0/hcot-cli/hcot/__init__.py +6 -0
- hcot_cli-0.2.0/hcot-cli/hcot/cli.py +147 -0
- hcot_cli-0.2.0/hcot-cli/hcot/crypto.py +42 -0
- hcot_cli-0.2.0/hcot-cli/hcot/docker.py +19 -0
- hcot_cli-0.2.0/hcot-cli/hcot/log.py +76 -0
- hcot_cli-0.2.0/hcot-cli/hcot/policy.py +54 -0
- hcot_cli-0.2.0/hcot-cli/hcot_cli.egg-info/PKG-INFO +126 -0
- hcot_cli-0.2.0/hcot-cli/hcot_cli.egg-info/SOURCES.txt +16 -0
- {hcot_cli-0.1.2 → hcot_cli-0.2.0/hcot-cli}/hcot_cli.egg-info/requires.txt +0 -1
- hcot_cli-0.2.0/hcot-cli/hcot_cli.egg-info/top_level.txt +1 -0
- hcot_cli-0.2.0/setup.py +33 -0
- hcot_cli-0.2.0/tests/test_cli.py +93 -0
- hcot_cli-0.1.2/PKG-INFO +0 -60
- hcot_cli-0.1.2/README.md +0 -27
- hcot_cli-0.1.2/hcot_cli.egg-info/PKG-INFO +0 -60
- hcot_cli-0.1.2/hcot_cli.egg-info/SOURCES.txt +0 -9
- hcot_cli-0.1.2/hcot_cli.egg-info/top_level.txt +0 -1
- hcot_cli-0.1.2/setup.py +0 -38
- {hcot_cli-0.1.2 → hcot_cli-0.2.0}/LICENSE +0 -0
- {hcot_cli-0.1.2 → hcot_cli-0.2.0/hcot-cli}/hcot_cli.egg-info/dependency_links.txt +0 -0
- {hcot_cli-0.1.2 → hcot_cli-0.2.0/hcot-cli}/hcot_cli.egg-info/entry_points.txt +0 -0
- {hcot_cli-0.1.2 → hcot_cli-0.2.0}/setup.cfg +0 -0
hcot_cli-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hcot-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Hybrid Chain of Trust (HCoT) – file signing, verification, policy checks and a hash-chained decision log
|
|
5
|
+
Home-page: https://github.com/Cloudexpert-JQ/hcot
|
|
6
|
+
Author: Jamshir Qureshi
|
|
7
|
+
Author-email: llmaideveloper@gmail.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Security
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: cryptography>=41.0.0
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
# HCoT CLI – Hybrid Chain of Trust
|
|
29
|
+
|
|
30
|
+
[](https://opensource.org/licenses/MIT)
|
|
31
|
+
[](https://www.python.org/downloads/)
|
|
32
|
+
|
|
33
|
+
`hcot` is a small, open-source command-line tool that demonstrates part of the
|
|
34
|
+
**Hybrid Chain of Trust (HCoT)** pattern: check an artifact before it is
|
|
35
|
+
deployed, enforce a simple policy, and record every decision in a
|
|
36
|
+
tamper-evident log.
|
|
37
|
+
|
|
38
|
+
Paper describing the pattern:
|
|
39
|
+
Qureshi, J. (2025). *A Secure and Integrated Approach to Software Code and
|
|
40
|
+
Docker Image Signing: Introducing the Hybrid Chain of Trust (HCoT) Algorithm.*
|
|
41
|
+
International Journal of Artificial Intelligence and Machine Learning, 5(2),
|
|
42
|
+
16–22. doi:[10.51483/IJAIML.5.2.2025.16-22](https://doi.org/10.51483/IJAIML.5.2.2025.16-22)
|
|
43
|
+
|
|
44
|
+
## Why
|
|
45
|
+
|
|
46
|
+
Attacks on open-source software supply chains have grown fast: Sonatype's
|
|
47
|
+
8th State of the Software Supply Chain report (October 2022) found a 742%
|
|
48
|
+
average annual increase in software supply chain attacks since 2019.
|
|
49
|
+
|
|
50
|
+
## What it does (each item is covered by a test in `tests/`)
|
|
51
|
+
|
|
52
|
+
| Feature | Command |
|
|
53
|
+
|---|---|
|
|
54
|
+
| Sign a file with an RSA key (SHA-256, PKCS#1 v1.5) | `hcot sign FILE --private-key priv.pem` |
|
|
55
|
+
| Verify a file's signature and apply the policy; exit code 0 = pass, 1 = fail | `hcot verify FILE --public-key pub.pem` |
|
|
56
|
+
| Reject a file that is unsigned, modified after signing, or signed with another key | `hcot verify ...` |
|
|
57
|
+
| Check that a local Docker image comes from an allowed registry | `hcot verify IMAGE --type docker` |
|
|
58
|
+
| Record every decision in a hash-chained log (`hcot_chain.log`) | automatic |
|
|
59
|
+
| Detect edits, deletions or reordering inside the log | `hcot verify-log` |
|
|
60
|
+
|
|
61
|
+
## Scope and limits (read before relying on it)
|
|
62
|
+
|
|
63
|
+
- **Not a full implementation of the paper.** It does not do AI code
|
|
64
|
+
analysis, decentralized key management or encrypted bundles.
|
|
65
|
+
- **No vulnerability scanning.** Earlier versions (0.1.x) sent file hashes to
|
|
66
|
+
the OSV API, which does not look up vulnerabilities by file hash, so that
|
|
67
|
+
feature was removed. Use a dedicated scanner (e.g. OSV-Scanner, Trivy, Grype).
|
|
68
|
+
- **Docker images:** checks the registry only, using the local image ID from
|
|
69
|
+
`docker inspect`. It does not verify image signatures or inspect layers;
|
|
70
|
+
use Sigstore cosign for image signing and verification.
|
|
71
|
+
- **The log is tamper-evident, not tamper-proof:** someone who can rewrite
|
|
72
|
+
the whole file can recompute every hash. Logs from 0.1.x versions do not
|
|
73
|
+
pass `verify-log` (the hash format changed in 0.2.0).
|
|
74
|
+
- Keys are plain RSA PEM files you manage yourself; there is no key
|
|
75
|
+
transparency or certificate chain.
|
|
76
|
+
|
|
77
|
+
HCoT combines well-known primitives; it builds on ideas from Sigstore,
|
|
78
|
+
in-toto and SLSA, which are the production-grade tools for these tasks.
|
|
79
|
+
|
|
80
|
+
## Install
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install hcot-cli # once 0.2.0 is published
|
|
84
|
+
# or from source:
|
|
85
|
+
git clone https://github.com/Cloudexpert-JQ/hcot && cd hcot && pip install .
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Requires Python 3.10+ and the `cryptography` package. Docker is needed only for
|
|
89
|
+
`--type docker`.
|
|
90
|
+
|
|
91
|
+
## Quick start
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out priv.pem
|
|
95
|
+
openssl rsa -in priv.pem -pubout -out pub.pem
|
|
96
|
+
echo "hello" > app.bin
|
|
97
|
+
|
|
98
|
+
hcot sign app.bin --private-key priv.pem
|
|
99
|
+
hcot verify app.bin --public-key pub.pem # PASS, exit 0
|
|
100
|
+
echo "tamper" >> app.bin
|
|
101
|
+
hcot verify app.bin --public-key pub.pem # FAIL, exit 1
|
|
102
|
+
hcot verify-log # OK: Log intact
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Policy
|
|
106
|
+
|
|
107
|
+
Optional `hcot_policy.json` in the working directory (or set `HCOT_POLICY_FILE`):
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"allowed_registries": ["docker.io", "gcr.io", "ghcr.io"],
|
|
112
|
+
"block_untrusted_signatures": true
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The log path can be set with `HCOT_LOG_FILE`.
|
|
117
|
+
|
|
118
|
+
## Tests
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install pytest && pytest -q
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
hcot_cli-0.2.0/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# HCoT CLI – Hybrid Chain of Trust
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
|
|
6
|
+
`hcot` is a small, open-source command-line tool that demonstrates part of the
|
|
7
|
+
**Hybrid Chain of Trust (HCoT)** pattern: check an artifact before it is
|
|
8
|
+
deployed, enforce a simple policy, and record every decision in a
|
|
9
|
+
tamper-evident log.
|
|
10
|
+
|
|
11
|
+
Paper describing the pattern:
|
|
12
|
+
Qureshi, J. (2025). *A Secure and Integrated Approach to Software Code and
|
|
13
|
+
Docker Image Signing: Introducing the Hybrid Chain of Trust (HCoT) Algorithm.*
|
|
14
|
+
International Journal of Artificial Intelligence and Machine Learning, 5(2),
|
|
15
|
+
16–22. doi:[10.51483/IJAIML.5.2.2025.16-22](https://doi.org/10.51483/IJAIML.5.2.2025.16-22)
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
Attacks on open-source software supply chains have grown fast: Sonatype's
|
|
20
|
+
8th State of the Software Supply Chain report (October 2022) found a 742%
|
|
21
|
+
average annual increase in software supply chain attacks since 2019.
|
|
22
|
+
|
|
23
|
+
## What it does (each item is covered by a test in `tests/`)
|
|
24
|
+
|
|
25
|
+
| Feature | Command |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Sign a file with an RSA key (SHA-256, PKCS#1 v1.5) | `hcot sign FILE --private-key priv.pem` |
|
|
28
|
+
| Verify a file's signature and apply the policy; exit code 0 = pass, 1 = fail | `hcot verify FILE --public-key pub.pem` |
|
|
29
|
+
| Reject a file that is unsigned, modified after signing, or signed with another key | `hcot verify ...` |
|
|
30
|
+
| Check that a local Docker image comes from an allowed registry | `hcot verify IMAGE --type docker` |
|
|
31
|
+
| Record every decision in a hash-chained log (`hcot_chain.log`) | automatic |
|
|
32
|
+
| Detect edits, deletions or reordering inside the log | `hcot verify-log` |
|
|
33
|
+
|
|
34
|
+
## Scope and limits (read before relying on it)
|
|
35
|
+
|
|
36
|
+
- **Not a full implementation of the paper.** It does not do AI code
|
|
37
|
+
analysis, decentralized key management or encrypted bundles.
|
|
38
|
+
- **No vulnerability scanning.** Earlier versions (0.1.x) sent file hashes to
|
|
39
|
+
the OSV API, which does not look up vulnerabilities by file hash, so that
|
|
40
|
+
feature was removed. Use a dedicated scanner (e.g. OSV-Scanner, Trivy, Grype).
|
|
41
|
+
- **Docker images:** checks the registry only, using the local image ID from
|
|
42
|
+
`docker inspect`. It does not verify image signatures or inspect layers;
|
|
43
|
+
use Sigstore cosign for image signing and verification.
|
|
44
|
+
- **The log is tamper-evident, not tamper-proof:** someone who can rewrite
|
|
45
|
+
the whole file can recompute every hash. Logs from 0.1.x versions do not
|
|
46
|
+
pass `verify-log` (the hash format changed in 0.2.0).
|
|
47
|
+
- Keys are plain RSA PEM files you manage yourself; there is no key
|
|
48
|
+
transparency or certificate chain.
|
|
49
|
+
|
|
50
|
+
HCoT combines well-known primitives; it builds on ideas from Sigstore,
|
|
51
|
+
in-toto and SLSA, which are the production-grade tools for these tasks.
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install hcot-cli # once 0.2.0 is published
|
|
57
|
+
# or from source:
|
|
58
|
+
git clone https://github.com/Cloudexpert-JQ/hcot && cd hcot && pip install .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Requires Python 3.10+ and the `cryptography` package. Docker is needed only for
|
|
62
|
+
`--type docker`.
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out priv.pem
|
|
68
|
+
openssl rsa -in priv.pem -pubout -out pub.pem
|
|
69
|
+
echo "hello" > app.bin
|
|
70
|
+
|
|
71
|
+
hcot sign app.bin --private-key priv.pem
|
|
72
|
+
hcot verify app.bin --public-key pub.pem # PASS, exit 0
|
|
73
|
+
echo "tamper" >> app.bin
|
|
74
|
+
hcot verify app.bin --public-key pub.pem # FAIL, exit 1
|
|
75
|
+
hcot verify-log # OK: Log intact
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Policy
|
|
79
|
+
|
|
80
|
+
Optional `hcot_policy.json` in the working directory (or set `HCOT_POLICY_FILE`):
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"allowed_registries": ["docker.io", "gcr.io", "ghcr.io"],
|
|
85
|
+
"block_untrusted_signatures": true
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The log path can be set with `HCOT_LOG_FILE`.
|
|
90
|
+
|
|
91
|
+
## Tests
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install pytest && pytest -q
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Hybrid Chain of Trust (HCoT) CLI.
|
|
4
|
+
|
|
5
|
+
Implements a subset of the HCoT pattern described in Qureshi (2025),
|
|
6
|
+
doi:10.51483/IJAIML.5.2.2025.16-22: file signing and verification, a
|
|
7
|
+
pre-deployment policy check, and a hash-chained decision log. It does NOT
|
|
8
|
+
implement the paper's AI code analysis, decentralized key management or
|
|
9
|
+
encrypted bundles. See README "Scope".
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import sys
|
|
15
|
+
from . import __version__
|
|
16
|
+
from .crypto import compute_file_sha256, sign_data, verify_signature
|
|
17
|
+
from .log import init_log, append_to_log, verify_log
|
|
18
|
+
from .policy import evaluate_policy
|
|
19
|
+
from .docker import get_image_hash
|
|
20
|
+
from cryptography.hazmat.primitives.serialization import load_pem_private_key, load_pem_public_key
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def generate_signature(filepath: str, private_key_pem: str) -> str:
|
|
24
|
+
"""Sign a file with an RSA private key (PEM). Writes <file>.sig."""
|
|
25
|
+
try:
|
|
26
|
+
key = load_pem_private_key(private_key_pem.encode(), password=None)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
raise Exception(f"Invalid private key: {e}")
|
|
29
|
+
with open(filepath, "rb") as f:
|
|
30
|
+
data = f.read()
|
|
31
|
+
sig_path = filepath + ".sig"
|
|
32
|
+
with open(sig_path, "wb") as sf:
|
|
33
|
+
sf.write(sign_data(key, data))
|
|
34
|
+
return sig_path
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def verify_file(filepath: str, public_key_pem: str = None):
|
|
38
|
+
artifact_hash = compute_file_sha256(filepath)
|
|
39
|
+
signature_valid = False
|
|
40
|
+
sig_file = filepath + ".sig"
|
|
41
|
+
if public_key_pem:
|
|
42
|
+
try:
|
|
43
|
+
with open(sig_file, "rb") as sf:
|
|
44
|
+
signature = sf.read()
|
|
45
|
+
except FileNotFoundError:
|
|
46
|
+
signature = None
|
|
47
|
+
if signature is not None:
|
|
48
|
+
public_key = load_pem_public_key(public_key_pem.encode())
|
|
49
|
+
with open(filepath, "rb") as f:
|
|
50
|
+
data = f.read()
|
|
51
|
+
signature_valid = verify_signature(public_key, data, signature)
|
|
52
|
+
policy_ok, policy_msg = evaluate_policy({"artifact_hash": artifact_hash, "signature_valid": signature_valid})
|
|
53
|
+
init_log()
|
|
54
|
+
block = append_to_log(artifact_hash, "PASS" if policy_ok else "FAIL")
|
|
55
|
+
return {
|
|
56
|
+
"status": "PASS" if policy_ok else "FAIL",
|
|
57
|
+
"hash": artifact_hash,
|
|
58
|
+
"policy_message": policy_msg,
|
|
59
|
+
"log_block": block,
|
|
60
|
+
"signature_valid": signature_valid,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def verify_docker_image(image_name: str):
|
|
65
|
+
try:
|
|
66
|
+
artifact_hash = get_image_hash(image_name)
|
|
67
|
+
except Exception as e:
|
|
68
|
+
return {"status": "FAIL", "error": str(e)}
|
|
69
|
+
policy_ok, policy_msg = evaluate_policy({"image_name": image_name})
|
|
70
|
+
init_log()
|
|
71
|
+
block = append_to_log(artifact_hash, "PASS" if policy_ok else "FAIL")
|
|
72
|
+
return {
|
|
73
|
+
"status": "PASS" if policy_ok else "FAIL",
|
|
74
|
+
"hash": artifact_hash,
|
|
75
|
+
"policy_message": policy_msg,
|
|
76
|
+
"log_block": block,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def main():
|
|
81
|
+
parser = argparse.ArgumentParser(prog="hcot", description="Hybrid Chain of Trust (HCoT) verification tool")
|
|
82
|
+
parser.add_argument("--version", action="version", version=f"hcot {__version__}")
|
|
83
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
84
|
+
|
|
85
|
+
v = subparsers.add_parser("verify", help="Verify a file (signature + policy) or a local Docker image (registry policy)")
|
|
86
|
+
v.add_argument("artifact", help="Path to file, or image name with --type docker")
|
|
87
|
+
v.add_argument("--type", choices=["file", "docker"], default="file")
|
|
88
|
+
v.add_argument("--output", choices=["json", "text"], default="text")
|
|
89
|
+
v.add_argument("--public-key", help="PEM public key for signature verification")
|
|
90
|
+
|
|
91
|
+
s = subparsers.add_parser("sign", help="Sign a file with an RSA private key (writes <file>.sig)")
|
|
92
|
+
s.add_argument("artifact", help="Path to file")
|
|
93
|
+
s.add_argument("--private-key", required=True, help="PEM private key")
|
|
94
|
+
|
|
95
|
+
subparsers.add_parser("verify-log", help="Check that the decision log has not been edited, reordered or truncated in the middle")
|
|
96
|
+
|
|
97
|
+
args = parser.parse_args()
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
if args.command == "sign":
|
|
101
|
+
with open(args.private_key, "r") as f:
|
|
102
|
+
sig_path = generate_signature(args.artifact, f.read())
|
|
103
|
+
print(f"Signature written to {sig_path}")
|
|
104
|
+
sys.exit(0)
|
|
105
|
+
|
|
106
|
+
if args.command == "verify-log":
|
|
107
|
+
ok, msg = verify_log()
|
|
108
|
+
print(("OK: " if ok else "TAMPERED: ") + msg)
|
|
109
|
+
sys.exit(0 if ok else 1)
|
|
110
|
+
|
|
111
|
+
if args.command != "verify":
|
|
112
|
+
parser.print_help()
|
|
113
|
+
sys.exit(2)
|
|
114
|
+
|
|
115
|
+
if args.type == "docker":
|
|
116
|
+
result = verify_docker_image(args.artifact)
|
|
117
|
+
else:
|
|
118
|
+
pub_key = None
|
|
119
|
+
if args.public_key:
|
|
120
|
+
with open(args.public_key, "r") as f:
|
|
121
|
+
pub_key = f.read()
|
|
122
|
+
result = verify_file(args.artifact, pub_key)
|
|
123
|
+
|
|
124
|
+
if args.output == "json":
|
|
125
|
+
print(json.dumps(result, indent=2, default=str))
|
|
126
|
+
else:
|
|
127
|
+
if result.get("status") == "PASS":
|
|
128
|
+
print(f"PASS: {args.artifact} — {result.get('policy_message')}")
|
|
129
|
+
else:
|
|
130
|
+
print(f"FAIL: {result.get('error') or result.get('policy_message', 'Unknown error')}")
|
|
131
|
+
print(f" SHA-256 / image ID: {result.get('hash', 'N/A')}")
|
|
132
|
+
if "signature_valid" in result:
|
|
133
|
+
print(f" Signature valid: {result['signature_valid']}")
|
|
134
|
+
if result.get("log_block"):
|
|
135
|
+
print(f" Log block: {result['log_block']['index']} at {result['log_block']['timestamp']}")
|
|
136
|
+
|
|
137
|
+
sys.exit(0 if result.get("status") == "PASS" else 1)
|
|
138
|
+
|
|
139
|
+
except SystemExit:
|
|
140
|
+
raise
|
|
141
|
+
except Exception as e:
|
|
142
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
143
|
+
sys.exit(1)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if __name__ == "__main__":
|
|
147
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
from cryptography.hazmat.primitives import hashes, serialization
|
|
3
|
+
from cryptography.hazmat.primitives.asymmetric import rsa, padding
|
|
4
|
+
from cryptography.hazmat.backends import default_backend
|
|
5
|
+
|
|
6
|
+
def compute_sha256(data: bytes) -> str:
|
|
7
|
+
return hashlib.sha256(data).hexdigest()
|
|
8
|
+
|
|
9
|
+
def compute_file_sha256(filepath: str) -> str:
|
|
10
|
+
sha256 = hashlib.sha256()
|
|
11
|
+
with open(filepath, 'rb') as f:
|
|
12
|
+
for block in iter(lambda: f.read(65536), b''):
|
|
13
|
+
sha256.update(block)
|
|
14
|
+
return sha256.hexdigest()
|
|
15
|
+
|
|
16
|
+
def generate_keypair():
|
|
17
|
+
private_key = rsa.generate_private_key(
|
|
18
|
+
public_exponent=65537,
|
|
19
|
+
key_size=2048,
|
|
20
|
+
backend=default_backend()
|
|
21
|
+
)
|
|
22
|
+
public_key = private_key.public_key()
|
|
23
|
+
return private_key, public_key
|
|
24
|
+
|
|
25
|
+
def sign_data(private_key, data: bytes) -> bytes:
|
|
26
|
+
return private_key.sign(
|
|
27
|
+
data,
|
|
28
|
+
padding.PKCS1v15(),
|
|
29
|
+
hashes.SHA256()
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def verify_signature(public_key, data: bytes, signature: bytes) -> bool:
|
|
33
|
+
try:
|
|
34
|
+
public_key.verify(
|
|
35
|
+
signature,
|
|
36
|
+
data,
|
|
37
|
+
padding.PKCS1v15(),
|
|
38
|
+
hashes.SHA256()
|
|
39
|
+
)
|
|
40
|
+
return True
|
|
41
|
+
except Exception:
|
|
42
|
+
return False
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_image_hash(image_name: str) -> str:
|
|
5
|
+
"""Return the local image ID (sha256:...) via `docker inspect`.
|
|
6
|
+
|
|
7
|
+
Requires Docker and an image that is already pulled. This is the image ID,
|
|
8
|
+
not a registry digest, and no layer-by-layer inspection is done.
|
|
9
|
+
"""
|
|
10
|
+
try:
|
|
11
|
+
result = subprocess.run(
|
|
12
|
+
["docker", "inspect", "--format", "{{.Id}}", image_name],
|
|
13
|
+
capture_output=True, text=True,
|
|
14
|
+
)
|
|
15
|
+
except FileNotFoundError:
|
|
16
|
+
raise Exception("Docker is not installed or not on PATH")
|
|
17
|
+
if result.returncode != 0:
|
|
18
|
+
raise Exception(f"Image {image_name} not found locally")
|
|
19
|
+
return result.stdout.strip()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Append-only, hash-chained decision log.
|
|
2
|
+
|
|
3
|
+
Each block's hash covers its index, timestamp, previous_hash and data, so
|
|
4
|
+
editing, deleting or reordering any block breaks verification
|
|
5
|
+
(`hcot verify-log`). This is tamper-evident, not tamper-proof: anyone who can
|
|
6
|
+
rewrite the whole file can recompute every hash. Store the file somewhere
|
|
7
|
+
append-only or anchor the latest hash elsewhere if that matters to you.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
from datetime import datetime, timezone
|
|
13
|
+
from .crypto import compute_sha256
|
|
14
|
+
|
|
15
|
+
LOG_FILE = os.environ.get("HCOT_LOG_FILE", "hcot_chain.log")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _block_hash(block: dict) -> str:
|
|
19
|
+
body = {k: block[k] for k in ("index", "timestamp", "previous_hash", "data")}
|
|
20
|
+
return compute_sha256(json.dumps(body, sort_keys=True).encode())
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def init_log(path: str = None):
|
|
24
|
+
path = path or LOG_FILE
|
|
25
|
+
if not os.path.exists(path):
|
|
26
|
+
genesis = {
|
|
27
|
+
"index": 0,
|
|
28
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
29
|
+
"previous_hash": "0" * 64,
|
|
30
|
+
"data": "HCoT Genesis Block",
|
|
31
|
+
}
|
|
32
|
+
genesis["hash"] = _block_hash(genesis)
|
|
33
|
+
with open(path, "w") as f:
|
|
34
|
+
json.dump([genesis], f, indent=2)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def append_to_log(artifact_hash: str, status: str, signature: str = None, path: str = None):
|
|
38
|
+
path = path or LOG_FILE
|
|
39
|
+
with open(path, "r") as f:
|
|
40
|
+
chain = json.load(f)
|
|
41
|
+
prev_block = chain[-1]
|
|
42
|
+
block = {
|
|
43
|
+
"index": prev_block["index"] + 1,
|
|
44
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
45
|
+
"previous_hash": prev_block["hash"],
|
|
46
|
+
"data": {
|
|
47
|
+
"artifact_hash": artifact_hash,
|
|
48
|
+
"status": status,
|
|
49
|
+
"signature": signature,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
block["hash"] = _block_hash(block)
|
|
53
|
+
chain.append(block)
|
|
54
|
+
with open(path, "w") as f:
|
|
55
|
+
json.dump(chain, f, indent=2)
|
|
56
|
+
return block
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def verify_log(path: str = None):
|
|
60
|
+
"""Return (ok, message). Checks every block's hash and link."""
|
|
61
|
+
path = path or LOG_FILE
|
|
62
|
+
if not os.path.exists(path):
|
|
63
|
+
return False, f"Log file {path} not found"
|
|
64
|
+
with open(path, "r") as f:
|
|
65
|
+
chain = json.load(f)
|
|
66
|
+
if not chain:
|
|
67
|
+
return False, "Log is empty"
|
|
68
|
+
for i, block in enumerate(chain):
|
|
69
|
+
if block.get("index") != i:
|
|
70
|
+
return False, f"Block {i}: index is {block.get('index')}, expected {i}"
|
|
71
|
+
if block.get("hash") != _block_hash(block):
|
|
72
|
+
return False, f"Block {i}: hash does not match its contents"
|
|
73
|
+
expected_prev = "0" * 64 if i == 0 else chain[i - 1]["hash"]
|
|
74
|
+
if block.get("previous_hash") != expected_prev:
|
|
75
|
+
return False, f"Block {i}: previous_hash does not match block {i - 1}"
|
|
76
|
+
return True, f"Log intact: {len(chain)} blocks"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
POLICY_FILE = os.environ.get("HCOT_POLICY_FILE", "hcot_policy.json")
|
|
5
|
+
|
|
6
|
+
DEFAULT_POLICY = {
|
|
7
|
+
# Registries a container image may come from (checked against the
|
|
8
|
+
# normalized registry host; short names like "nginx" mean docker.io).
|
|
9
|
+
"allowed_registries": ["docker.io", "gcr.io", "ghcr.io"],
|
|
10
|
+
# Files must carry a valid RSA signature (`hcot sign` / --public-key).
|
|
11
|
+
"block_untrusted_signatures": True,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def load_policy():
|
|
16
|
+
"""Load the policy file if present; otherwise use the built-in defaults.
|
|
17
|
+
|
|
18
|
+
Unlike earlier versions, this never writes a policy file as a side effect.
|
|
19
|
+
"""
|
|
20
|
+
if os.path.exists(POLICY_FILE):
|
|
21
|
+
with open(POLICY_FILE, "r") as f:
|
|
22
|
+
policy = json.load(f)
|
|
23
|
+
merged = dict(DEFAULT_POLICY)
|
|
24
|
+
merged.update(policy)
|
|
25
|
+
return merged
|
|
26
|
+
return dict(DEFAULT_POLICY)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def image_registry(image_name: str) -> str:
|
|
30
|
+
"""Return the registry host for an image reference (Docker's rules)."""
|
|
31
|
+
first = image_name.split("/")[0]
|
|
32
|
+
if "/" not in image_name:
|
|
33
|
+
return "docker.io"
|
|
34
|
+
if "." in first or ":" in first or first == "localhost":
|
|
35
|
+
return first
|
|
36
|
+
return "docker.io"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def evaluate_policy(artifact_info: dict, policy: dict = None):
|
|
40
|
+
"""Return (ok, message).
|
|
41
|
+
|
|
42
|
+
- Files: require a valid signature when block_untrusted_signatures is true.
|
|
43
|
+
- Images: require an allowed registry. Image signatures are not checked by
|
|
44
|
+
this tool; use a dedicated tool such as Sigstore cosign for that.
|
|
45
|
+
"""
|
|
46
|
+
policy = policy or load_policy()
|
|
47
|
+
if "image_name" in artifact_info:
|
|
48
|
+
registry = image_registry(artifact_info["image_name"])
|
|
49
|
+
if registry not in policy.get("allowed_registries", []):
|
|
50
|
+
return False, f"Registry '{registry}' not allowed by policy"
|
|
51
|
+
return True, "Policy satisfied (registry allowed; image signature not checked)"
|
|
52
|
+
if policy.get("block_untrusted_signatures", True) and not artifact_info.get("signature_valid", False):
|
|
53
|
+
return False, "Untrusted signature – policy violation"
|
|
54
|
+
return True, "Policy satisfied"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hcot-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Hybrid Chain of Trust (HCoT) – file signing, verification, policy checks and a hash-chained decision log
|
|
5
|
+
Home-page: https://github.com/Cloudexpert-JQ/hcot
|
|
6
|
+
Author: Jamshir Qureshi
|
|
7
|
+
Author-email: llmaideveloper@gmail.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Security
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: cryptography>=41.0.0
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
# HCoT CLI – Hybrid Chain of Trust
|
|
29
|
+
|
|
30
|
+
[](https://opensource.org/licenses/MIT)
|
|
31
|
+
[](https://www.python.org/downloads/)
|
|
32
|
+
|
|
33
|
+
`hcot` is a small, open-source command-line tool that demonstrates part of the
|
|
34
|
+
**Hybrid Chain of Trust (HCoT)** pattern: check an artifact before it is
|
|
35
|
+
deployed, enforce a simple policy, and record every decision in a
|
|
36
|
+
tamper-evident log.
|
|
37
|
+
|
|
38
|
+
Paper describing the pattern:
|
|
39
|
+
Qureshi, J. (2025). *A Secure and Integrated Approach to Software Code and
|
|
40
|
+
Docker Image Signing: Introducing the Hybrid Chain of Trust (HCoT) Algorithm.*
|
|
41
|
+
International Journal of Artificial Intelligence and Machine Learning, 5(2),
|
|
42
|
+
16–22. doi:[10.51483/IJAIML.5.2.2025.16-22](https://doi.org/10.51483/IJAIML.5.2.2025.16-22)
|
|
43
|
+
|
|
44
|
+
## Why
|
|
45
|
+
|
|
46
|
+
Attacks on open-source software supply chains have grown fast: Sonatype's
|
|
47
|
+
8th State of the Software Supply Chain report (October 2022) found a 742%
|
|
48
|
+
average annual increase in software supply chain attacks since 2019.
|
|
49
|
+
|
|
50
|
+
## What it does (each item is covered by a test in `tests/`)
|
|
51
|
+
|
|
52
|
+
| Feature | Command |
|
|
53
|
+
|---|---|
|
|
54
|
+
| Sign a file with an RSA key (SHA-256, PKCS#1 v1.5) | `hcot sign FILE --private-key priv.pem` |
|
|
55
|
+
| Verify a file's signature and apply the policy; exit code 0 = pass, 1 = fail | `hcot verify FILE --public-key pub.pem` |
|
|
56
|
+
| Reject a file that is unsigned, modified after signing, or signed with another key | `hcot verify ...` |
|
|
57
|
+
| Check that a local Docker image comes from an allowed registry | `hcot verify IMAGE --type docker` |
|
|
58
|
+
| Record every decision in a hash-chained log (`hcot_chain.log`) | automatic |
|
|
59
|
+
| Detect edits, deletions or reordering inside the log | `hcot verify-log` |
|
|
60
|
+
|
|
61
|
+
## Scope and limits (read before relying on it)
|
|
62
|
+
|
|
63
|
+
- **Not a full implementation of the paper.** It does not do AI code
|
|
64
|
+
analysis, decentralized key management or encrypted bundles.
|
|
65
|
+
- **No vulnerability scanning.** Earlier versions (0.1.x) sent file hashes to
|
|
66
|
+
the OSV API, which does not look up vulnerabilities by file hash, so that
|
|
67
|
+
feature was removed. Use a dedicated scanner (e.g. OSV-Scanner, Trivy, Grype).
|
|
68
|
+
- **Docker images:** checks the registry only, using the local image ID from
|
|
69
|
+
`docker inspect`. It does not verify image signatures or inspect layers;
|
|
70
|
+
use Sigstore cosign for image signing and verification.
|
|
71
|
+
- **The log is tamper-evident, not tamper-proof:** someone who can rewrite
|
|
72
|
+
the whole file can recompute every hash. Logs from 0.1.x versions do not
|
|
73
|
+
pass `verify-log` (the hash format changed in 0.2.0).
|
|
74
|
+
- Keys are plain RSA PEM files you manage yourself; there is no key
|
|
75
|
+
transparency or certificate chain.
|
|
76
|
+
|
|
77
|
+
HCoT combines well-known primitives; it builds on ideas from Sigstore,
|
|
78
|
+
in-toto and SLSA, which are the production-grade tools for these tasks.
|
|
79
|
+
|
|
80
|
+
## Install
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install hcot-cli # once 0.2.0 is published
|
|
84
|
+
# or from source:
|
|
85
|
+
git clone https://github.com/Cloudexpert-JQ/hcot && cd hcot && pip install .
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Requires Python 3.10+ and the `cryptography` package. Docker is needed only for
|
|
89
|
+
`--type docker`.
|
|
90
|
+
|
|
91
|
+
## Quick start
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out priv.pem
|
|
95
|
+
openssl rsa -in priv.pem -pubout -out pub.pem
|
|
96
|
+
echo "hello" > app.bin
|
|
97
|
+
|
|
98
|
+
hcot sign app.bin --private-key priv.pem
|
|
99
|
+
hcot verify app.bin --public-key pub.pem # PASS, exit 0
|
|
100
|
+
echo "tamper" >> app.bin
|
|
101
|
+
hcot verify app.bin --public-key pub.pem # FAIL, exit 1
|
|
102
|
+
hcot verify-log # OK: Log intact
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Policy
|
|
106
|
+
|
|
107
|
+
Optional `hcot_policy.json` in the working directory (or set `HCOT_POLICY_FILE`):
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"allowed_registries": ["docker.io", "gcr.io", "ghcr.io"],
|
|
112
|
+
"block_untrusted_signatures": true
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The log path can be set with `HCOT_LOG_FILE`.
|
|
117
|
+
|
|
118
|
+
## Tests
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install pytest && pytest -q
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
hcot-cli/hcot/__init__.py
|
|
5
|
+
hcot-cli/hcot/cli.py
|
|
6
|
+
hcot-cli/hcot/crypto.py
|
|
7
|
+
hcot-cli/hcot/docker.py
|
|
8
|
+
hcot-cli/hcot/log.py
|
|
9
|
+
hcot-cli/hcot/policy.py
|
|
10
|
+
hcot-cli/hcot_cli.egg-info/PKG-INFO
|
|
11
|
+
hcot-cli/hcot_cli.egg-info/SOURCES.txt
|
|
12
|
+
hcot-cli/hcot_cli.egg-info/dependency_links.txt
|
|
13
|
+
hcot-cli/hcot_cli.egg-info/entry_points.txt
|
|
14
|
+
hcot-cli/hcot_cli.egg-info/requires.txt
|
|
15
|
+
hcot-cli/hcot_cli.egg-info/top_level.txt
|
|
16
|
+
tests/test_cli.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hcot
|
hcot_cli-0.2.0/setup.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
with open("README.md", "r", encoding="utf-8") as f:
|
|
5
|
+
long_description = f.read()
|
|
6
|
+
|
|
7
|
+
with open("hcot-cli/hcot/__init__.py", encoding="utf-8") as f:
|
|
8
|
+
version = re.search(r'__version__ = "([^"]+)"', f.read()).group(1)
|
|
9
|
+
|
|
10
|
+
setup(
|
|
11
|
+
name="hcot-cli",
|
|
12
|
+
version=version,
|
|
13
|
+
author="Jamshir Qureshi",
|
|
14
|
+
author_email="llmaideveloper@gmail.com",
|
|
15
|
+
description="Hybrid Chain of Trust (HCoT) – file signing, verification, policy checks and a hash-chained decision log",
|
|
16
|
+
long_description=long_description,
|
|
17
|
+
long_description_content_type="text/markdown",
|
|
18
|
+
url="https://github.com/Cloudexpert-JQ/hcot",
|
|
19
|
+
# The package lives in hcot-cli/hcot; without package_dir the published
|
|
20
|
+
# wheel contained no code (0.1.0–0.1.2).
|
|
21
|
+
package_dir={"": "hcot-cli"},
|
|
22
|
+
packages=find_packages(where="hcot-cli"),
|
|
23
|
+
install_requires=["cryptography>=41.0.0"],
|
|
24
|
+
entry_points={"console_scripts": ["hcot=hcot.cli:main"]},
|
|
25
|
+
python_requires=">=3.10",
|
|
26
|
+
classifiers=[
|
|
27
|
+
"Development Status :: 3 - Alpha",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"Topic :: Security",
|
|
30
|
+
"License :: OSI Approved :: MIT License",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
],
|
|
33
|
+
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""End-to-end tests: every README claim has a test here."""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from cryptography.hazmat.primitives import serialization
|
|
9
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
10
|
+
|
|
11
|
+
SRC = os.path.join(os.path.dirname(__file__), "..", "hcot-cli")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def run(args, cwd):
|
|
15
|
+
env = dict(os.environ, PYTHONPATH=os.path.abspath(SRC))
|
|
16
|
+
return subprocess.run([sys.executable, "-m", "hcot.cli", *args], cwd=cwd, env=env,
|
|
17
|
+
capture_output=True, text=True)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture
|
|
21
|
+
def ws(tmp_path):
|
|
22
|
+
key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
|
|
23
|
+
(tmp_path / "priv.pem").write_bytes(key.private_bytes(
|
|
24
|
+
serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()))
|
|
25
|
+
(tmp_path / "pub.pem").write_bytes(key.public_key().public_bytes(
|
|
26
|
+
serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo))
|
|
27
|
+
(tmp_path / "app.bin").write_bytes(b"hello artifact\n")
|
|
28
|
+
return tmp_path
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_signed_file_passes(ws):
|
|
32
|
+
assert run(["sign", "app.bin", "--private-key", "priv.pem"], ws).returncode == 0
|
|
33
|
+
r = run(["verify", "app.bin", "--public-key", "pub.pem"], ws)
|
|
34
|
+
assert r.returncode == 0 and "PASS" in r.stdout
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_tampered_file_rejected(ws):
|
|
38
|
+
run(["sign", "app.bin", "--private-key", "priv.pem"], ws)
|
|
39
|
+
with open(ws / "app.bin", "ab") as f:
|
|
40
|
+
f.write(b"x")
|
|
41
|
+
r = run(["verify", "app.bin", "--public-key", "pub.pem"], ws)
|
|
42
|
+
assert r.returncode == 1 and "Untrusted signature" in r.stdout
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_unsigned_file_rejected(ws):
|
|
46
|
+
r = run(["verify", "app.bin", "--public-key", "pub.pem"], ws)
|
|
47
|
+
assert r.returncode == 1
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_wrong_key_rejected(ws):
|
|
51
|
+
run(["sign", "app.bin", "--private-key", "priv.pem"], ws)
|
|
52
|
+
other = rsa.generate_private_key(public_exponent=65537, key_size=2048).public_key()
|
|
53
|
+
(ws / "other.pem").write_bytes(other.public_bytes(
|
|
54
|
+
serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo))
|
|
55
|
+
assert run(["verify", "app.bin", "--public-key", "other.pem"], ws).returncode == 1
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_log_intact_then_tamper_detected(ws):
|
|
59
|
+
run(["sign", "app.bin", "--private-key", "priv.pem"], ws)
|
|
60
|
+
run(["verify", "app.bin", "--public-key", "pub.pem"], ws)
|
|
61
|
+
run(["verify", "app.bin"], ws)
|
|
62
|
+
assert run(["verify-log"], ws).returncode == 0
|
|
63
|
+
log = ws / "hcot_chain.log"
|
|
64
|
+
chain = json.loads(log.read_text())
|
|
65
|
+
chain[2]["data"]["status"] = "PASS" # rewrite a FAIL as PASS
|
|
66
|
+
log.write_text(json.dumps(chain))
|
|
67
|
+
r = run(["verify-log"], ws)
|
|
68
|
+
assert r.returncode == 1 and "TAMPERED" in r.stdout
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_deleted_block_detected(ws):
|
|
72
|
+
for _ in range(3):
|
|
73
|
+
run(["verify", "app.bin"], ws)
|
|
74
|
+
log = ws / "hcot_chain.log"
|
|
75
|
+
chain = json.loads(log.read_text())
|
|
76
|
+
del chain[1]
|
|
77
|
+
log.write_text(json.dumps(chain))
|
|
78
|
+
assert run(["verify-log"], ws).returncode == 1
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_registry_policy():
|
|
82
|
+
sys.path.insert(0, os.path.abspath(SRC))
|
|
83
|
+
from hcot.policy import evaluate_policy, image_registry
|
|
84
|
+
assert image_registry("nginx") == "docker.io"
|
|
85
|
+
assert image_registry("library/nginx") == "docker.io"
|
|
86
|
+
assert image_registry("ghcr.io/org/app:1") == "ghcr.io"
|
|
87
|
+
assert evaluate_policy({"image_name": "nginx"})[0] is True
|
|
88
|
+
assert evaluate_policy({"image_name": "evil.example.com/app"})[0] is False
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_no_policy_file_written(ws):
|
|
92
|
+
run(["verify", "app.bin"], ws)
|
|
93
|
+
assert not (ws / "hcot_policy.json").exists()
|
hcot_cli-0.1.2/PKG-INFO
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: hcot-cli
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: Hybrid Chain of Trust (HCoT) – software supply chain verification
|
|
5
|
-
Home-page: https://github.com/Cloudexpert-JQ/hcot
|
|
6
|
-
Author: Jamshir Qureshi
|
|
7
|
-
Author-email: llmaideveloper@gmail.com
|
|
8
|
-
Classifier: Development Status :: 4 - Beta
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: Topic :: Security
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Requires-Python: >=3.8
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
License-File: LICENSE
|
|
21
|
-
Requires-Dist: cryptography>=41.0.0
|
|
22
|
-
Requires-Dist: requests>=2.25.0
|
|
23
|
-
Dynamic: author
|
|
24
|
-
Dynamic: author-email
|
|
25
|
-
Dynamic: classifier
|
|
26
|
-
Dynamic: description
|
|
27
|
-
Dynamic: description-content-type
|
|
28
|
-
Dynamic: home-page
|
|
29
|
-
Dynamic: license-file
|
|
30
|
-
Dynamic: requires-dist
|
|
31
|
-
Dynamic: requires-python
|
|
32
|
-
Dynamic: summary
|
|
33
|
-
|
|
34
|
-
# 🔗 HCoT CLI – Hybrid Chain of Trust
|
|
35
|
-
|
|
36
|
-
[](https://opensource.org/licenses/MIT)
|
|
37
|
-
[](https://badge.fury.io/py/hcot-cli)
|
|
38
|
-
[](https://www.python.org/downloads/)
|
|
39
|
-
|
|
40
|
-
**HCoT CLI** is a free, open‑source command‑line tool that implements the **Hybrid Chain of Trust (HCoT)** framework – a unified pre‑deployment security architecture for software supply chains.
|
|
41
|
-
|
|
42
|
-
> 📄 **Peer‑reviewed paper:**
|
|
43
|
-
> Qureshi, J. (2025). *A Secure and Integrated Approach to Software Code and Docker Image Signing: Introducing the Hybrid Chain of Trust (HCoT) Algorithm*.
|
|
44
|
-
> *International Journal of Artificial Intelligence and Machine Learning*, 5(2), 16–22.
|
|
45
|
-
> DOI: [10.51483/IJAIML.5.2.2025.16-22](https://doi.org/10.51483/IJAIML.5.2.2025.16-22)
|
|
46
|
-
|
|
47
|
-
## 🚀 Why HCoT?
|
|
48
|
-
|
|
49
|
-
Software supply chain attacks increased **742% in the last three years** (Sonatype, 2025). HCoT addresses this by:
|
|
50
|
-
|
|
51
|
-
- ✅ **Cryptographic verification** (SHA‑256 + RSA signatures)
|
|
52
|
-
- ✅ **Tamper‑evident blockchain log** (append‑only, chained hashes)
|
|
53
|
-
- ✅ **Real‑time vulnerability scanning** (via OSV API)
|
|
54
|
-
- ✅ **Policy enforcement** (registries, signatures, CVSS thresholds)
|
|
55
|
-
- ✅ **Docker image support** (layer inspection + integrity check)
|
|
56
|
-
|
|
57
|
-
## 📦 Installation
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
pip install hcot-cli
|
hcot_cli-0.1.2/README.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# 🔗 HCoT CLI – Hybrid Chain of Trust
|
|
2
|
-
|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://badge.fury.io/py/hcot-cli)
|
|
5
|
-
[](https://www.python.org/downloads/)
|
|
6
|
-
|
|
7
|
-
**HCoT CLI** is a free, open‑source command‑line tool that implements the **Hybrid Chain of Trust (HCoT)** framework – a unified pre‑deployment security architecture for software supply chains.
|
|
8
|
-
|
|
9
|
-
> 📄 **Peer‑reviewed paper:**
|
|
10
|
-
> Qureshi, J. (2025). *A Secure and Integrated Approach to Software Code and Docker Image Signing: Introducing the Hybrid Chain of Trust (HCoT) Algorithm*.
|
|
11
|
-
> *International Journal of Artificial Intelligence and Machine Learning*, 5(2), 16–22.
|
|
12
|
-
> DOI: [10.51483/IJAIML.5.2.2025.16-22](https://doi.org/10.51483/IJAIML.5.2.2025.16-22)
|
|
13
|
-
|
|
14
|
-
## 🚀 Why HCoT?
|
|
15
|
-
|
|
16
|
-
Software supply chain attacks increased **742% in the last three years** (Sonatype, 2025). HCoT addresses this by:
|
|
17
|
-
|
|
18
|
-
- ✅ **Cryptographic verification** (SHA‑256 + RSA signatures)
|
|
19
|
-
- ✅ **Tamper‑evident blockchain log** (append‑only, chained hashes)
|
|
20
|
-
- ✅ **Real‑time vulnerability scanning** (via OSV API)
|
|
21
|
-
- ✅ **Policy enforcement** (registries, signatures, CVSS thresholds)
|
|
22
|
-
- ✅ **Docker image support** (layer inspection + integrity check)
|
|
23
|
-
|
|
24
|
-
## 📦 Installation
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
pip install hcot-cli
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: hcot-cli
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: Hybrid Chain of Trust (HCoT) – software supply chain verification
|
|
5
|
-
Home-page: https://github.com/Cloudexpert-JQ/hcot
|
|
6
|
-
Author: Jamshir Qureshi
|
|
7
|
-
Author-email: llmaideveloper@gmail.com
|
|
8
|
-
Classifier: Development Status :: 4 - Beta
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: Topic :: Security
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
-
Requires-Python: >=3.8
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
License-File: LICENSE
|
|
21
|
-
Requires-Dist: cryptography>=41.0.0
|
|
22
|
-
Requires-Dist: requests>=2.25.0
|
|
23
|
-
Dynamic: author
|
|
24
|
-
Dynamic: author-email
|
|
25
|
-
Dynamic: classifier
|
|
26
|
-
Dynamic: description
|
|
27
|
-
Dynamic: description-content-type
|
|
28
|
-
Dynamic: home-page
|
|
29
|
-
Dynamic: license-file
|
|
30
|
-
Dynamic: requires-dist
|
|
31
|
-
Dynamic: requires-python
|
|
32
|
-
Dynamic: summary
|
|
33
|
-
|
|
34
|
-
# 🔗 HCoT CLI – Hybrid Chain of Trust
|
|
35
|
-
|
|
36
|
-
[](https://opensource.org/licenses/MIT)
|
|
37
|
-
[](https://badge.fury.io/py/hcot-cli)
|
|
38
|
-
[](https://www.python.org/downloads/)
|
|
39
|
-
|
|
40
|
-
**HCoT CLI** is a free, open‑source command‑line tool that implements the **Hybrid Chain of Trust (HCoT)** framework – a unified pre‑deployment security architecture for software supply chains.
|
|
41
|
-
|
|
42
|
-
> 📄 **Peer‑reviewed paper:**
|
|
43
|
-
> Qureshi, J. (2025). *A Secure and Integrated Approach to Software Code and Docker Image Signing: Introducing the Hybrid Chain of Trust (HCoT) Algorithm*.
|
|
44
|
-
> *International Journal of Artificial Intelligence and Machine Learning*, 5(2), 16–22.
|
|
45
|
-
> DOI: [10.51483/IJAIML.5.2.2025.16-22](https://doi.org/10.51483/IJAIML.5.2.2025.16-22)
|
|
46
|
-
|
|
47
|
-
## 🚀 Why HCoT?
|
|
48
|
-
|
|
49
|
-
Software supply chain attacks increased **742% in the last three years** (Sonatype, 2025). HCoT addresses this by:
|
|
50
|
-
|
|
51
|
-
- ✅ **Cryptographic verification** (SHA‑256 + RSA signatures)
|
|
52
|
-
- ✅ **Tamper‑evident blockchain log** (append‑only, chained hashes)
|
|
53
|
-
- ✅ **Real‑time vulnerability scanning** (via OSV API)
|
|
54
|
-
- ✅ **Policy enforcement** (registries, signatures, CVSS thresholds)
|
|
55
|
-
- ✅ **Docker image support** (layer inspection + integrity check)
|
|
56
|
-
|
|
57
|
-
## 📦 Installation
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
pip install hcot-cli
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
hcot_cli-0.1.2/setup.py
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
|
|
3
|
-
with open("README.md", "r", encoding="utf-8") as f:
|
|
4
|
-
long_description = f.read()
|
|
5
|
-
|
|
6
|
-
setup(
|
|
7
|
-
name="hcot-cli",
|
|
8
|
-
version="0.1.2", # Increment version
|
|
9
|
-
author="Jamshir Qureshi",
|
|
10
|
-
author_email="llmaideveloper@gmail.com",
|
|
11
|
-
description="Hybrid Chain of Trust (HCoT) – software supply chain verification",
|
|
12
|
-
long_description=long_description,
|
|
13
|
-
long_description_content_type="text/markdown",
|
|
14
|
-
url="https://github.com/Cloudexpert-JQ/hcot",
|
|
15
|
-
packages=find_packages(),
|
|
16
|
-
install_requires=[
|
|
17
|
-
"cryptography>=41.0.0",
|
|
18
|
-
"requests>=2.25.0",
|
|
19
|
-
],
|
|
20
|
-
entry_points={
|
|
21
|
-
"console_scripts": [
|
|
22
|
-
"hcot=hcot.cli:main",
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
python_requires=">=3.8",
|
|
26
|
-
classifiers=[
|
|
27
|
-
"Development Status :: 4 - Beta",
|
|
28
|
-
"Intended Audience :: Developers",
|
|
29
|
-
"Topic :: Security",
|
|
30
|
-
"License :: OSI Approved :: MIT License",
|
|
31
|
-
"Programming Language :: Python :: 3",
|
|
32
|
-
"Programming Language :: Python :: 3.8",
|
|
33
|
-
"Programming Language :: Python :: 3.9",
|
|
34
|
-
"Programming Language :: Python :: 3.10",
|
|
35
|
-
"Programming Language :: Python :: 3.11",
|
|
36
|
-
"Programming Language :: Python :: 3.12",
|
|
37
|
-
],
|
|
38
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|