Skip to content

Commit 5f6f914

Browse files
authored
misc fixes - improved logged, Dockerfile (0.3.1) (#2)
* misc fixes: - add Dockerfile - logging: signing: don't print auth token - logging: verify: print domain cert fingerprint, print time ranges used for verification - remove run_in_executor() for verify to match signing - setup.py: update path - ci: add release workflow on version releases * bump version to 0.3.1
1 parent de3dba4 commit 5f6f914

File tree

7 files changed

+93
-24
lines changed

7 files changed

+93
-24
lines changed

.github/workflows/release.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish Docker image
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
push_to_registries:
8+
name: Build authsign Docker image for release and push to Dockerhub
9+
runs-on: ubuntu-latest
10+
steps:
11+
-
12+
name: Check out the repo
13+
uses: actions/checkout@v2
14+
-
15+
name: Docker meta
16+
id: meta
17+
uses: docker/metadata-action@v3
18+
with:
19+
images: webrecorder/authsign
20+
tags: |
21+
type=match,pattern=(\d+\.\d+\.\d+),group=1
22+
-
23+
name: Set up QEMU
24+
uses: docker/setup-qemu-action@v1
25+
-
26+
name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v1
28+
-
29+
name: Login to DockerHub
30+
uses: docker/login-action@v1
31+
with:
32+
username: ${{ secrets.DOCKER_USERNAME }}
33+
password: ${{ secrets.DOCKER_PASSWORD }}
34+
-
35+
name: Build and push
36+
id: docker_build
37+
uses: docker/build-push-action@v2
38+
with:
39+
context: .
40+
push: true
41+
tags: ${{ steps.meta.outputs.tags }}
42+

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3.9
2+
3+
WORKDIR /app
4+
5+
ADD requirements.txt /app
6+
7+
ADD setup.py /app
8+
ADD authsign /app/authsign
9+
10+
ADD README.md /app
11+
ADD log.json /app
12+
13+
RUN python setup.py install
14+
15+
# override by using custom config.yaml, or setting the DOMAIN_OVERRIDE and EMAIL_OVERRIDE
16+
ADD config.sample.yaml config.yaml
17+
18+
CMD uvicorn authsign.main:app --port 8080 --host 0.0.0.0 --log-config /app/log.json
19+

authsign/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"

authsign/main.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from authsign.log import log_message, log_failure
1313

1414

15-
loop = asyncio.get_event_loop()
15+
# loop = asyncio.get_event_loop()
1616
app = FastAPI()
1717

1818
signer = None
@@ -31,6 +31,12 @@ async def startup_event():
3131
if os.environ.get("DOMAIN_OVERRIDE"):
3232
config["signing"]["domain"] = os.environ.get("DOMAIN_OVERRIDE")
3333

34+
if os.environ.get("EMAIL_OVERRIDE"):
35+
config["signing"]["email"] = os.environ.get("EMAIL_OVERRIDE")
36+
37+
if os.environ.get("DATA_OVERRIDE"):
38+
config["signing"]["data"] = os.environ.get("DATA_OVERRIDE")
39+
3440
if os.environ.get("PORT_OVERRIDE"):
3541
config["signing"]["port"] = int(os.environ.get("PORT_OVERRIDE"))
3642

@@ -67,8 +73,14 @@ async def sign_data(sign_req: SignReq, authorization: str = Header(None)):
6773
@app.post("/verify")
6874
async def verify_data(signed_hash: SignedHash):
6975
log_message("Verifying Signed Request...")
70-
result = await loop.run_in_executor(None, verifier, signed_hash)
71-
if result:
72-
return result
76+
# result = await loop.run_in_executor(None, verifier, signed_hash)
77+
# if result:
78+
# return result
79+
try:
80+
result = verifier(signed_hash)
81+
if result:
82+
return result
83+
except Exception as e:
84+
pass
7385

7486
raise HTTPException(status_code=400, detail="Not verified")

authsign/signer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ def __init__(
138138

139139
self.auth_token = auth_token
140140

141-
log_message("Accepting Auth Token: " + str(self.auth_token))
141+
if self.auth_token:
142+
log_message("Auth Token Enabled")
143+
else:
144+
log_message("Auth Token Not Enabled")
142145

143146
self.rootpath = Path(output or "./data")
144147
self.rootpath.mkdir(exist_ok=True)

authsign/verifier.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ def __init__(self, trusted_roots_filename=None):
3434
self.domain_cert_roots = trusted_roots["domain_cert_roots"]
3535
self.timestamp_cert_roots = trusted_roots["timestamp_cert_roots"]
3636

37-
log_message(
38-
"{0} Domain Cert Root(s) Loaded".format(len(self.domain_cert_roots))
39-
)
40-
log_message(
41-
"{0} Timestamp Cert Root(s) Loaded".format(len(self.timestamp_cert_roots))
42-
)
37+
log_message(f"{len(self.domain_cert_roots)} Domain Cert Root(s) Loaded")
38+
log_message(f"{len(self.timestamp_cert_roots)} Timestamp Cert Root(s) Loaded")
4339

4440
def timestamp_verify(self, text, signature, cert_pem):
4541
"""Verify RFC 3161 timestamp given a cert, signature and text
@@ -67,9 +63,7 @@ def check_fingerprint(self, cert, trusted, name):
6763

6864
log_assert(
6965
fingerprint in trusted,
70-
"Trusted {0} Root Cert (sha-256 fingerprint: {1})".format(
71-
name, fingerprint
72-
),
66+
f"Trusted {name} Root Cert (sha-256 fingerprint: {fingerprint})",
7367
)
7468

7569
def __call__(self, signed_req):
@@ -79,7 +73,7 @@ def __call__(self, signed_req):
7973
signed_req = SignedHash(**signed_req)
8074

8175
try:
82-
log_message("Signing Software: " + str(signed_req.software))
76+
log_message(f"Signing Software: {str(signed_req.software)}")
8377

8478
certs = crypto.validate_cert_chain(signed_req.domainCert.encode("ascii"))
8579
log_assert(certs, "Verify certificate chain for domain certificate")
@@ -108,18 +102,19 @@ def __call__(self, signed_req):
108102
)
109103

110104
domain = crypto.get_cert_subject_name(cert)
105+
domain_fingerprint = crypto.get_fingerprint(cert)
106+
111107
log_assert(
112-
domain == signed_req.domain, "Domain Cert Matches Expected: " + domain
108+
domain == signed_req.domain,
109+
f"Domain Cert Matches Expected: '{domain}' (sha-256 fingerprint: {domain_fingerprint})",
113110
)
114111

115112
created = parse_date(signed_req.created)
116113
log_assert(created, "Parsed signature date")
117114

118115
log_assert(
119116
is_time_range_valid(cert.not_valid_before, created, CERT_DURATION),
120-
"Verify domain certificate was created within '{0}' of creation date".format(
121-
str(CERT_DURATION)
122-
),
117+
f"Verify WACZ creation date '{created}' - cert creation date '{cert.not_valid_before}' <= '{CERT_DURATION}'",
123118
)
124119

125120
timestamp = self.timestamp_verify(
@@ -134,9 +129,7 @@ def __call__(self, signed_req):
134129

135130
log_assert(
136131
is_time_range_valid(created, timestamp, STAMP_DURATION),
137-
"Verify time signature created within '{0}' of creation date".format(
138-
str(STAMP_DURATION)
139-
),
132+
f"Verify signed timestamp time '{timestamp}' - WACZ creation date '{created}' <= '{STAMP_DURATION}'",
140133
)
141134

142135
timestamp_certs = crypto.validate_cert_chain(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def read(*names, **kwargs):
2121
long_description_content_type="text/markdown",
2222
author="Webrecorder Software",
2323
author_email="info@webrecorder.net",
24-
url="https://github.com/ikreymer/authsign",
24+
url="https://github.com/webrecorder/authsign",
2525
packages=find_packages(exclude=["tests"]),
2626
install_requires=[
2727
line.strip()

0 commit comments

Comments
 (0)