Skip to content

tda-dsc-signer

A GTK4 app and CLI that signs PDFs, MCA style forms included, with an Indian DSC token on Linux. How it works and exactly what is verified.

On this page

A government style form, an Indian USB token and a Linux desktop: three things nobody had introduced to each other. tda-dsc-signer is the introduction. It signs PDFs with a DSC token on Linux from a native GTK4 window or the command line, and it talks to the token over PKCS#11, with no Java and no browser plugin in the middle.

The signer in MCA mode with two form signature fields, one matched to the attached token and one waiting for someone else
A synthetic form and a fake token. Field 2 is yours to sign, field 1 belongs to somebody else.

The first commit is dated 3 October 2026, and version 0.1.0 was released the next day. The code is public, GPL-3.0-or-later, and packaged on the AUR.

Two ways to sign with a DSC token on Linux

A Digital Signature Certificate lives on a small USB token. The private key stays inside it. To sign, a program loads the vendor’s PKCS#11 library, asks which certificates are present, logs in with your PIN and hands the token something to sign. So the job is mostly diplomacy between a PDF library, a smart card stack and a driver you did not write.

General modeMCA mode
Forany PDFforms with empty signature fields
You choosepage, box, signerwhich matched fields to sign
Visibleyes, or invisibleinside the field

In general mode you draw a box, pick the signer, enter the PIN and save. Several boxes with different signers can go in one run.

Two visible signature boxes placed on one synthetic page, each assigned to a different signer
General mode: two boxes, two signers, one run.

The same work from a terminal:

bash
tda-dsc-signer                  # the window
tda-dsc-signer list             # certificates on attached tokens, no PIN needed
tda-dsc-signer fields FORM.pdf  # which field wants which token
tda-dsc-signer sign FORM.pdf --all-fields

The input file is never overwritten, and an existing output is refused unless you force it.

The field name knows who should sign

MCA style forms name their signature fields sigfield<N>_<PAN>. An Indian DSC carries the SHA-256 of the holder’s PAN as the certificate’s subject serial number. Put those two facts next to each other and the matching writes itself:

src/tda_dsc_signer/pan.pypython
def pan_hash(pan):
    return hashlib.sha256(pan.upper().encode()).hexdigest()
flowchart TD
    A["Field name ends in a PAN"] --> B["SHA-256 of that PAN"]
    C["Each certificate on the attached tokens"] --> D["Its subject serial number"]
    B --> E{"Same value?"}
    D --> E
    E -->|"one is equal"| F["Field is ticked: you may sign it"]
    E -->|"all differ"| G["Field stays empty: someone else must sign"]

The saved file goes to the next director, who repeats the exercise, so the signatures chain one run after another. Signing a PAN named field with a certificate that does not match is refused before any login to the token, unless you override it explicitly.

The vendor driver gets its own process

The vendor library is native code of unknown temperament, so it is loaded only inside a separate Python process, one per driver. It never enters the process that draws your window.

flowchart TD
    subgraph app["The app process"]
        UI["GTK4 window or CLI"]
    end
    subgraph helper["Helper process, one per driver"]
        S["Checks, login, PDF signing"]
        L["Vendor PKCS#11 library"]
        S --> L
    end
    UI <-->|"JSON lines over stdin and stdout"| helper
    L <--> T["USB token: the key stays inside"]

That one pipe carries four verbs: ping, enumerate, present, sign. Requests are never logged, because one of them carries the PIN. Drivers that like to print to standard output are redirected away from the protocol.

Each request has a timeout. A hung helper is killed and started again on the next call, and a sign request is never sent twice. The helper also takes an exclusive lock per driver before loading it, because two programs cannot share one: the second silently sees no token. A second copy of the signer gets a clear “driver busy” error naming the holder.

Everything odd about flaky drivers lives in one file. The one I verified against sleeps about seven seconds on its first call and sometimes returns an empty answer to a lookup that should succeed. So lookups retry. Login never does.

One signing action, one login

Everything that can fail without logging in (parsing, page numbers, output path, field checks) runs first. Why spend a PIN attempt on a typo in a file name?

sequenceDiagram
    participant A as App
    participant H as Helper
    participant T as Token
    A->>H: sign request with file, certificate and PIN
    H->>H: check the PDF, output path and fields
    alt a check fails
        H-->>A: typed error, no login made
    else all checks pass
        H->>T: log in, exactly once
        H->>T: find the key and sign, lookups may retry
        H-->>A: finished file, moved into place
        A->>A: verify the saved signature
    end

A token counts wrong PINs, and the counter is not forgiving. The signer behaves accordingly:

SituationWhat the signer does
An ordinary signing actionone login, never retried
The token reports it is lockedrefuses before any attempt
The token reports a final tryasks for explicit confirmation
A quick retry after a wrong PINasks first, even from another process

The record behind the retry rule is a small file per token holding a time and a count, never the PIN. The tool keeps its own memory of wrong PINs, so that caution does not depend on the token warning you.

Saving a PIN is off by default. If you turn it on, per token, it stays in memory for the session or goes to the system keyring. There is no plaintext fallback.

The settings screen with three PIN choices per token: ask every time, remember until the app closes, or the system keyring
PIN options, chosen token by token.

Separate answers, not one green tick

After signing, the app reports separate rows for whether the document is unmodified, whether the signature is valid and whether the issuer is trusted. One green tick for the lot would be friendlier and far less informative.

The only trust anchor is the CCA India 2022 root, pinned by SHA-256 and checked on every load, written to a private trust database that no browser shares.

Verified and not verified

Read this before trusting any of the above. Verified: signing and verifying with an InnaIT token on real hardware, PKCS#11 signing against SoftHSM and a fake token GUI harness, and the trust bundle hashes. Not verified: whether the MCA portal accepts the output and which format it expects, and any token other than InnaIT.

The tests do not need a real token: SoftHSM provides a throwaway one, and the GUI runs against fake tokens on a private virtual display, so no real PIN is anywhere near them.

Install and where it stands

Clone the repository and run make install with Python 3.12 or newer, GTK4, poppler-glib, PyGObject, pcsclite, ccid, git, make, uv and your token vendor’s driver present.

The step by step version is in using a DSC USB token on Linux. The latest release at the time of writing, 0.1.1 from 29 October 2026, updates locked dependencies.

For a much smaller first package from the same author, there is a program that prints a name. It had a gentler relationship with hardware.