Skip to content

Commit

Permalink
Merge pull request #238 from crocs-muni:fix/document-hashes-constructors
Browse files Browse the repository at this point in the history
fix CommonCriteriaCert.InternalState constructor
  • Loading branch information
adamjanovsky committed Jun 22, 2022
2 parents 52ead10 + eca01ed commit 81d5a3e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
8 changes: 6 additions & 2 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
30 changes: 18 additions & 12 deletions sec_certs/sample/common_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,32 @@ class InternalState(ComplexSerializableType):
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
Expand All @@ -127,21 +129,25 @@ def __init__(
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:
Expand Down
6 changes: 5 additions & 1 deletion tests/data/test_cc_oop/fictional_cert.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions tests/data/test_cc_oop/toy_dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 11 additions & 17 deletions tests/test_cc_oop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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
Expand Down Expand Up @@ -129,23 +128,18 @@ def test_download_and_convert_pdfs(self):
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())
Expand Down

0 comments on commit 81d5a3e

Please sign in to comment.