aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamjanovsky2022-06-22 20:40:57 +0200
committerGitHub2022-06-22 20:40:57 +0200
commit81d5a3e023ac30b63fb42f99588166d5052b5492 (patch)
tree22669e4f0cc8db87856f8327c2f9bd4316324bdc
parent52ead1014c58a26509e5992089d735b199293384 (diff)
parenteca01edd4cc9f62ddae9bc400cea9a9f0ac51cd9 (diff)
downloadsec-certs-0.1.0.tar.gz
sec-certs-0.1.0.tar.zst
sec-certs-0.1.0.zip
Merge pull request #238 from crocs-muni:fix/document-hashes-constructors0.1.0
fix CommonCriteriaCert.InternalState constructor
-rw-r--r--docs/quickstart.md8
-rw-r--r--sec_certs/sample/common_criteria.py30
-rw-r--r--tests/data/test_cc_oop/fictional_cert.json6
-rw-r--r--tests/data/test_cc_oop/toy_dataset.json12
-rw-r--r--tests/test_cc_oop.py28
5 files changed, 50 insertions, 34 deletions
diff --git a/docs/quickstart.md b/docs/quickstart.md
index bcf34231..88bfac42 100644
--- a/docs/quickstart.md
+++ b/docs/quickstart.md
@@ -61,7 +61,9 @@ It may be handy to create a shared folder between your host machine and the dock
```bash
mkdir seccerts-data && \
-docker run -it --mount type=bind,source="$(pwd)"/seccerts-data/,target=/home/user/data seccerts/sec-certs
+docker run -it \
+--mount type=bind,source="$(pwd)"/seccerts-data/,target=/home/user/data \
+seccerts/sec-certs
```
The folder should be accessible on your machine on `./seccerts-data` path; from docker on `/home/user/data` path.
@@ -71,7 +73,9 @@ The folder should be accessible on your machine on `./seccerts-data` path; from
You can also use our docker image to serve `jupyter notebook` instance that you can access from your device. Run
```bash
-docker run --rm -it -p 8888:8888 seccerts/sec-certs jupyter notebook --no-browser --ip 0.0.0.0 --NotebookApp.token='' --notebook-dir="/home/user/"
+docker run --rm -it -p 8888:8888 \
+seccerts/sec-certs jupyter notebook \
+--no-browser --ip 0.0.0.0 --NotebookApp.token='' --notebook-dir="/home/user/"
```
Now, you should be able to access the notebook at `localhost:8888` from your machine. Navigate to `/home/user/sec-certs/notebooks/examples` to see some example notebooks.
diff --git a/sec_certs/sample/common_criteria.py b/sec_certs/sample/common_criteria.py
index ac4163f4..ca935c02 100644
--- a/sec_certs/sample/common_criteria.py
+++ b/sec_certs/sample/common_criteria.py
@@ -95,30 +95,32 @@ class CommonCriteriaCert(
report_convert_ok: bool
st_extract_ok: bool
report_extract_ok: bool
+
errors: List[str]
- st_pdf_path: Path
- report_pdf_path: Path
st_pdf_hash: Optional[str]
report_pdf_hash: Optional[str]
- st_txt_path: Path
- report_txt_path: Path
st_txt_hash: Optional[str]
report_txt_hash: Optional[str]
+ st_pdf_path: Path
+ report_pdf_path: Path
+ st_txt_path: Path
+ report_txt_path: Path
+
def __init__(
self,
st_download_ok: bool = True,
report_download_ok: bool = True,
- st_pdf_hash: Optional[str] = None,
- report_pdf_hash: Optional[str] = None,
st_convert_ok: bool = True,
report_convert_ok: bool = True,
- st_txt_hash: Optional[str] = None,
- report_txt_hash: Optional[str] = None,
st_extract_ok: bool = True,
report_extract_ok: bool = True,
errors: Optional[List[str]] = None,
+ st_pdf_hash: Optional[str] = None,
+ report_pdf_hash: Optional[str] = None,
+ st_txt_hash: Optional[str] = None,
+ report_txt_hash: Optional[str] = None,
):
self.st_download_ok = st_download_ok
self.report_download_ok = report_download_ok
@@ -127,21 +129,25 @@ class CommonCriteriaCert(
self.st_extract_ok = st_extract_ok
self.report_extract_ok = report_extract_ok
self.errors = errors if errors else []
+ self.st_pdf_hash = st_pdf_hash
+ self.report_pdf_hash = report_pdf_hash
+ self.st_txt_hash = st_txt_hash
+ self.report_txt_hash = report_txt_hash
@property
def serialized_attributes(self) -> List[str]:
return [
"st_download_ok",
"report_download_ok",
- "st_pdf_hash",
- "report_pdf_hash",
"st_convert_ok",
"report_convert_ok",
- "st_txt_hash",
- "report_txt_hash",
"st_extract_ok",
"report_extract_ok",
"errors",
+ "st_pdf_hash",
+ "report_pdf_hash",
+ "st_txt_hash",
+ "report_txt_hash",
]
def report_is_ok_to_download(self, fresh: bool = True) -> bool:
diff --git a/tests/data/test_cc_oop/fictional_cert.json b/tests/data/test_cc_oop/fictional_cert.json
index 441ae7d2..7d74759c 100644
--- a/tests/data/test_cc_oop/fictional_cert.json
+++ b/tests/data/test_cc_oop/fictional_cert.json
@@ -42,7 +42,11 @@
"report_convert_ok": true,
"st_extract_ok": true,
"report_extract_ok": true,
- "errors": []
+ "errors": [],
+ "st_pdf_hash": null,
+ "report_pdf_hash": null,
+ "st_txt_hash": null,
+ "report_txt_hash": null
},
"pdf_data": {
"_type": "PdfData",
diff --git a/tests/data/test_cc_oop/toy_dataset.json b/tests/data/test_cc_oop/toy_dataset.json
index 740ddf1b..91669453 100644
--- a/tests/data/test_cc_oop/toy_dataset.json
+++ b/tests/data/test_cc_oop/toy_dataset.json
@@ -49,7 +49,11 @@
"report_convert_ok": true,
"st_extract_ok": true,
"report_extract_ok": true,
- "errors": []
+ "errors": [],
+ "st_pdf_hash": null,
+ "report_pdf_hash": null,
+ "st_txt_hash": null,
+ "report_txt_hash": null
},
"pdf_data": {
"_type": "PdfData",
@@ -126,7 +130,11 @@
"report_convert_ok": true,
"st_extract_ok": true,
"report_extract_ok": true,
- "errors": []
+ "errors": [],
+ "st_pdf_hash": null,
+ "report_pdf_hash": null,
+ "st_txt_hash": null,
+ "report_txt_hash": null
},
"pdf_data": {
"_type": "PdfData",
diff --git a/tests/test_cc_oop.py b/tests/test_cc_oop.py
index d2809fbe..5e4d86dc 100644
--- a/tests/test_cc_oop.py
+++ b/tests/test_cc_oop.py
@@ -9,7 +9,6 @@ from typing import ClassVar
from unittest import TestCase
import sec_certs.constants as constants
-import sec_certs.helpers as helpers
import tests.data.test_cc_oop
from sec_certs.config.configuration import config
from sec_certs.dataset import CCDataset
@@ -129,23 +128,18 @@ class TestCommonCriteriaOOP(TestCase):
dset.download_all_pdfs()
dset.convert_all_pdfs()
- actual_report_pdf_hashes = {
- key: helpers.get_sha256_filepath(val.state.report_pdf_path) for key, val in dset.certs.items()
- }
- actual_target_pdf_hashes = {
- key: helpers.get_sha256_filepath(val.state.st_pdf_path) for key, val in dset.certs.items()
- }
+ for cert in dset:
+ self.assertEqual(
+ cert.state.report_pdf_hash,
+ self.template_report_pdf_hashes[cert.dgst],
+ f"Hash of PDF certification report for CommonCriteriaCert with digest {cert.dgst} deviates from template.",
+ )
- self.assertEqual(
- actual_report_pdf_hashes,
- self.template_report_pdf_hashes,
- "Hashes of downloaded pdfs (sample report) do not the template",
- )
- self.assertEqual(
- actual_target_pdf_hashes,
- self.template_target_pdf_hashes,
- "Hashes of downloaded pdfs (security target) do not match the template",
- )
+ self.assertEqual(
+ cert.state.st_pdf_hash,
+ self.template_target_pdf_hashes[cert.dgst],
+ f"Hash of PDF security target for CommonCriteriaCert with digest {cert.dgst} deviates from template.",
+ )
self.assertTrue(dset["309ac2fd7f2dcf17"].state.report_txt_path.exists())
self.assertTrue(dset["309ac2fd7f2dcf17"].state.st_txt_path.exists())