Giter Site home page Giter Site logo

hejsan / weasysign Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 3.0 17 KB

WeasySign is a small simple to use high level library for digitally signing pdf's generated with the WeasyPrint PDF library.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
python digital-signatures electronic-signatures pdf timestamp document-signing

weasysign's Introduction

WeasySign

Digital Signatures for WeasyPrint

WeasySign is a small library intended to be a high level (as in simple to use) library for digitally signing pdf's generated with the WeasyPrint PDF library.

WeasySign currently has adapters for using Self-Signed Certificates and using GlobalSign's DSS API.

This initial version is _very_ much a work made in a stream of consciousness as a reaction to Covid-19 forcing staff to work from home, making printing and hand-signing documents impractical. Therefore you should not expect the code to be neither elegant nor efficient quite yet. For example the helpers.py is a mess of various functions that should probably be made into a better structure.

WeasySign was written by the Division of Information Technology at the University of Iceland (http://uts.hi.is).

Documentation

WeasySign makes use of WeasyPrint's finisher hook. WeasyPrint allows users to pass a finishing function to Document.write_pdf() for post-processing of the PDF file.

from weasyprint import HTML
from weasysign import factory

document = HTML.render()
# To sign the pdf with a self-signed certificate:
signer = factory('selfsigned', cert='/bla/cert.crt', private_key='/bla/cert.key')
document.write_pdf(target='/tmp/my-self-signed-doc.pdf', finisher=signer)

# To sign the pdf using GlobalSigns DSS API:
subject_dn = {'subject_dn': {
  "common_name": "Dunder Mifflin Paper Company, Inc.",
  "organizational_unit": [
    "Angela Martin",
    "Accounting"
  ]
}}
signer = factory('globalsign', cfg_file='/bla/globalsign_config.ini', subject_dn=subject_dn)
document.write_pdf(target='/tmp/my-digitally-signed-doc.pdf', finisher=signer)

The configuration file for the GlobalSign signer is a simple .ini file:

[SSL]
certfile = /some/dir/signatures_globalsign.crt
keyfile = /some/dir/signatures_globalsign.key
keypass = Pam is the office mattress
[API]
url = https://emea.api.dss.globalsign.com:8443
# The endpoint will be appended to the url:
endpoint = /v2
api_key = **********
api_secret = ************************

The private key password can alternatively be passed to the factory constructor:

signer = factory(
  'globalsign',
  cfg_file='/bla/globalsign_config.ini',
  keypass="Pam is the office mattress",
  subject_dn=subject_dn
)

weasysign's People

Contributors

hejsan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

weasysign's Issues

Error is on HTML.render()

Hi,
I am facing error while tying to sign document usign global sign DSS. I am getting below error

Error

File "test.py", line 4, in
document = HTML.render()
TypeError: render() missing 1 required positional argument: 'self'

Code

from weasyprint import HTML
from weasysign import factory

document = HTML.render()

subject_dn = {'subject_dn': {
"common_name": "Dunder Mifflin Paper Company, Inc.",
"organizational_unit": [
"Angela Martin",
"Accounting"
]
}}
signer = factory('globalsign', cfg_file='globalsign_config.ini', subject_dn=subject_dn)
document.write_pdf(target='/tmp/my-digitally-signed-doc.pdf', finisher=signer)

Environment

Ubuntu 18.04.6 LTS
Python 3.8.12
weasyprint 52

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.