Compare commits

..

11 Commits

Author SHA1 Message Date
083bf20be7
update deps, switching pyhanko to version 0.29
All checks were successful
Build image and push it to registry / build (push) Successful in 1m17s
2025-06-05 13:33:38 +02:00
6626b33c6a
upgrade idea settings 2025-06-05 13:33:38 +02:00
8a3c44c517
test signature with return line 2025-06-05 13:33:38 +02:00
c7a6283e00
Add timezone configuration to Dockerfile
All checks were successful
Build image and push it to registry / build (push) Successful in 1m11s
Included tzdata package and set the timezone to Europe/Paris by creating a symbolic link in /etc/localtime. This ensures the container runs with the correct timezone settings.
2024-11-06 14:46:45 +01:00
0e7d01f0fd
Fix environment password encoding in SignOrchestrator init
All checks were successful
Build image and push it to registry / build (push) Successful in 6m47s
Previously, the `PKCS12_PASSWORD` environment variable was used directly, which could lead to issues when it was not set. This change ensures the password is properly encoded when provided and defaults to `None` if not set.
2024-10-22 16:37:49 +02:00
39b9f7455c
Update README section title for clarity
Changed the title "Préparation pour Vendée" to "Préparation à partir d'un certificat d'horodatage au format pkcs12" for better clarity and specificity. This update helps users understand the section's purpose more easily.
2024-10-22 16:37:31 +02:00
97a2385167
Remove redundant 'TIMESTAMP_URL' environment variable check
All checks were successful
Build image and push it to registry / build (push) Successful in 1m27s
The 'TIMESTAMP_URL' environment variable check was removed from the worker script as it is no longer required. This simplifies the code by eliminating unnecessary validation.
2024-10-22 12:07:08 +02:00
77aaf97d7b
Add new TSA configuration environment variables
All checks were successful
Build image and push it to registry / build (push) Successful in 1m1s
Included 'TSA_CONFIG_PATH', 'TSA_CERT_CHAIN', and 'TSA_KEY_PASSWORD' to the environment variable check in worker.py. This ensures the script validates these new required configurations before proceeding. Added an exception raise in the error handling block for better error management.
2024-10-21 18:53:52 +02:00
dd8c30787a
fix imports
All checks were successful
Build image and push it to registry / build (push) Successful in 1m48s
2024-10-21 18:28:20 +02:00
8c5950b37f Merge pull request 'Allow the signature_index to be None' (#3) from test-ts-sign into main
All checks were successful
Build image and push it to registry / build (push) Successful in 1m40s
Reviewed-on: #3
2024-10-16 07:13:38 +00:00
df2a8d554f Merge pull request 'Create a dedicated timestamper which use the openssl cli and custom certificates' (#2) from test-ts-sign into main
All checks were successful
Build image and push it to registry / build (push) Successful in 1m42s
Reviewed-on: #2
2024-10-11 14:19:51 +00:00
9 changed files with 37 additions and 25 deletions

2
.idea/misc.xml generated
View File

@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.10 (pythonProject)" /> <option name="sdkName" value="Python 3.10 (pythonProject)" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (pythonProject)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 virtualenv at ~/dev/chill/sign-pdf-worker/pythonProject/.venv" project-jdk-type="Python SDK" />
</project> </project>

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/pythonProject/.venv" /> <excludeFolder url="file://$MODULE_DIR$/pythonProject/.venv" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.10 virtualenv at ~/dev/chill/sign-pdf-worker/pythonProject/.venv" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -5,3 +5,6 @@ TIMESTAMP_URL=http://freetsa.org/tsr
QUEUE_IN=to_python_sign QUEUE_IN=to_python_sign
EXCHANGE_OUT=signed_docs EXCHANGE_OUT=signed_docs
OUT_ROUTING_KEY=signed_doc OUT_ROUTING_KEY=signed_doc
TSA_CONFIG_PATH=/home/julien/dev/chill/sign-pdf-worker/ts-authority/rootca.conf
TSA_CERT_CHAIN=/home/julien/dev/chill/sign-pdf-worker/ts-authority/ca/tsa-chain.pem
TSA_KEY_PASSWORD=5678

View File

@ -5,7 +5,10 @@ FROM python:3.10-alpine
WORKDIR /app WORKDIR /app
# add required clis # add required clis
RUN apk add --no-cache openssl RUN apk add --no-cache openssl tzdata
# set timezone
RUN ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime
# Copy requirements.txt to the Docker container # Copy requirements.txt to the Docker container
COPY requirements.txt . COPY requirements.txt .

View File

@ -1,20 +1,22 @@
asn1crypto==1.5.1 asn1crypto==1.5.1
certifi==2024.6.2 certifi==2025.4.26
cffi==1.16.0 cffi==1.17.1
charset-normalizer==3.3.2 charset-normalizer==3.4.2
click==8.1.7 click==8.2.1
cryptography==42.0.8 cryptography==45.0.3
idna==3.7 idna==3.10
lxml==5.4.0
oscrypto==1.3.0 oscrypto==1.3.0
pika==1.3.2 pika==1.3.2
pika-stubs==0.1.3
pycparser==2.22 pycparser==2.22
pyHanko==0.25.0 pyHanko==0.29.0
pyhanko-certvalidator==0.26.3 pyhanko-certvalidator==0.27.0
pypng==0.20220715.0 pypng==0.20220715.0
PyYAML==6.0.1 PyYAML==6.0.2
qrcode==7.4.2 qrcode==8.2
requests==2.32.3 requests==2.32.3
typing_extensions==4.12.2 typing_extensions==4.14.0
tzlocal==5.2 tzlocal==5.3.1
uritools==4.0.3 uritools==5.0.0
urllib3==2.2.2 urllib3==2.4.0

View File

@ -4,11 +4,10 @@ from typing import Optional
from pyhanko import stamp from pyhanko import stamp
from pyhanko.pdf_utils.incremental_writer import IncrementalPdfFileWriter from pyhanko.pdf_utils.incremental_writer import IncrementalPdfFileWriter
from pyhanko.sign import signers, timestamps, fields from pyhanko.sign import signers, fields
from pyhanko_certvalidator import ValidationContext
from typing_extensions import Buffer from typing_extensions import Buffer
from pythonProject.timestamp import LocalOpensslTimestamp from timestamp import LocalOpensslTimestamp
class SignOrchestrator: class SignOrchestrator:

View File

@ -13,9 +13,13 @@ orchestrator = SignOrchestrator('./assets/dummy.p12',
pkcs12_password=None) pkcs12_password=None)
with open('./assets/test.pdf', 'rb') as input: with open('./assets/test.pdf', 'rb') as input:
signed_content = orchestrator.sign(reason="first signer", signature_index=None, signed_content = orchestrator.sign(reason="first\nsigner\nreturn\ntext", signature_index=None,
input_content=input.read(), box_place=(300, 600, 500, 660), on_page=0, input_content=input.read(), box_place=(300, 600, 500, 660), on_page=0,
signer_text="Mme Caroline Diallo") signer_text="""Mme Caroline Diallo
with
return
text
""")
with open('./assets/test_signed_0.pdf', 'wb') as output: with open('./assets/test_signed_0.pdf', 'wb') as output:
output.write(signed_content.read()) output.write(signed_content.read())

View File

@ -12,7 +12,7 @@ logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(os.environ.get('LOG_LEVEL', logging.INFO)) LOGGER.setLevel(os.environ.get('LOG_LEVEL', logging.INFO))
for v in ['AMQP_URL', 'PKCS12_PATH', 'TIMESTAMP_URL', 'QUEUE_IN', 'EXCHANGE_OUT', 'OUT_ROUTING_KEY']: for v in ['AMQP_URL', 'PKCS12_PATH', 'QUEUE_IN', 'EXCHANGE_OUT', 'OUT_ROUTING_KEY', 'TSA_CONFIG_PATH', 'TSA_CERT_CHAIN', 'TSA_KEY_PASSWORD']:
if v not in os.environ: if v not in os.environ:
LOGGER.error('Missing environment variable: %s', v) LOGGER.error('Missing environment variable: %s', v)
raise ValueError('Missing environment variable: ' + v) raise ValueError('Missing environment variable: ' + v)
@ -26,7 +26,7 @@ TSA_CONFIG_PATH = os.environ.get('TSA_CONFIG_PATH')
TSA_CERT_CHAIN = os.environ.get('TSA_CERT_CHAIN') TSA_CERT_CHAIN = os.environ.get('TSA_CERT_CHAIN')
TSA_KEY_PASSWORD = os.environ.get('TSA_KEY_PASSWORD') TSA_KEY_PASSWORD = os.environ.get('TSA_KEY_PASSWORD')
orchestrator = sign.SignOrchestrator(PKCS12_PATH, TSA_CONFIG_PATH, TSA_KEY_PASSWORD, TSA_CERT_CHAIN, pkcs12_password=os.environ.get('PKCS12_PASSWORD', None)) orchestrator = sign.SignOrchestrator(PKCS12_PATH, TSA_CONFIG_PATH, TSA_KEY_PASSWORD, TSA_CERT_CHAIN, pkcs12_password=None if os.environ.get('PKCS12_PASSWORD', None) is None else os.environ.get('PKCS12_PASSWORD').encode())
parameters = pika.URLParameters(DSN) parameters = pika.URLParameters(DSN)
connection = pika.BlockingConnection(parameters) connection = pika.BlockingConnection(parameters)
@ -76,6 +76,7 @@ def on_message(channel, method_frame, header_frame, body):
else: else:
LOGGER.warning(f"first try failed, signatureId: {body_content['signatureId']}") LOGGER.warning(f"first try failed, signatureId: {body_content['signatureId']}")
channel.basic_ack(delivery_tag=method_frame.delivery_tag) channel.basic_ack(delivery_tag=method_frame.delivery_tag)
raise e
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -152,7 +152,7 @@ openssl ts -verify -data /etc/hosts -in /tmp/response.tsr -CAfile ca/root-ca.pem
``` ```
# Préparation pour Vendée # Préparation à partir d'un certificat d'horodatage au format pkcs12
## Extraire les infos ## Extraire les infos