Skip to content

Worker recipes

Recipe: CSC remote certificate

A signing worker for a provider that keeps a long-term certificate for each signer behind the Cloud Signature Consortium (CSC) API, with the raw signature format

Public beta. Qualified signatures are available on request, with any qualified trust service provider you choose and at no extra charge during the beta. See Request access. SWP/1 is in beta and may change.

This recipe fits a provider that:

  • keeps a long-term certificate for each signer, issued when they enrolled,
  • speaks the CSC API, the Cloud Signature Consortium’s standard for remote signing, and
  • returns a bare signature value from signatures/signHash.

The signer doesn’t identify again at signing time. They approve one signature, with a PIN or a one-time password (OTP), on a page. Your worker uses the raw signature format, and pauses only authorize. Not sure this is your provider? See Choose your provider’s model.

The flow

Certificate and approval request

CSC remote certificate, part 1: the certificate and the approval request
Signer's browser
SignatureAPI
Your worker
Provider (CSC API)
  1. Signer's browser to SignatureAPI: Finish the ceremony
  2. SignatureAPI to Your worker: POST /v1/credential
  3. Your worker to Provider (CSC API): credentials/list, credentials/info
  4. Provider (CSC API) to Your worker: credentialID, certificate chain, key algorithms
  5. Your worker to SignatureAPI: completed with id, certificates, key_algo_oids
  6. SignatureAPI: Compute the digest
  7. SignatureAPI to Your worker: POST /v1/authorize with the digest and its label
  8. Your worker to SignatureAPI: pending with an action_url

Dashed: a reply, or an asynchronous call such as a webhook.

Approval on your page

CSC remote certificate, part 2: the signer approves on your page
Signer's browser
SignatureAPI
Your worker
Provider (CSC API)
  1. SignatureAPI to Signer's browser: **Authorize your signature**, then redirect
  2. Signer's browser to Your worker: Your approval page shows the label; the signer enters the OTP
  3. Your worker to Provider (CSC API): credentials/authorize with the hash and the OTP
  4. Provider (CSC API) to Your worker: SAD
  5. Your worker to Signer's browser: Redirect to callback_url with a single-use code
  6. Signer's browser to SignatureAPI: GET callback_url
  7. SignatureAPI to Your worker: POST /v1/authorize with callback.code
  8. Your worker to SignatureAPI: completed with an authorization reference
  1. SAD

    The Signature Activation Data: the provider's proof that the signer approved this hash.

Dashed: a reply, or an asynchronous call such as a webhook.

Signing

CSC remote certificate, part 3: the signature
SignatureAPI
Your worker
Provider (CSC API)
  1. SignatureAPI to Your worker: POST /v1/sign with sign_algo_oid
  2. Your worker to Provider (CSC API): signatures/signHash with the SAD and the hash
  3. Provider (CSC API) to Your worker: Raw signature value
  4. Your worker to SignatureAPI: completed with signatures
  5. SignatureAPI: Verify, timestamp and embed in the PDF

Dashed: a reply, or an asynchronous call such as a webhook.

Before you start

  • CSC API access at the provider, and its test environment.
  • A way to find each signer’s credential. SignatureAPI sends the signer’s id, name and email. Your worker maps them to the provider’s user, for example through your own enrollment table keyed by email. CSC doesn’t do this mapping for you.
  • The SWP/1 basics in place: authentication, idempotency and health. See Build a signing worker.

1. credential: look up the certificate

Answer right away. The signer doesn’t need to do anything yet.

  1. Get a service token from the provider, as its CSC profile describes.
  2. Call credentials/list for the signer’s user, and pick their signing credential.
  3. Call credentials/info with "certificates": "chain" and "certInfo": true.
  4. Convert each Base64 DER certificate in cert/certificates to PEM, signer certificate first.
  5. Build key_algo_oids from key/algo. Keep only supported algorithms, and put a SHA-256 one first.
JSON
{
    "status": "completed",
    "credential": {
        "id": "cred_7Qk...",
        "certificates": [
            "-----BEGIN CERTIFICATE-----\n...signer...\n-----END CERTIFICATE-----",
            "-----BEGIN CERTIFICATE-----\n...issuing CA...\n-----END CERTIFICATE-----"
        ],
        "key_algo_oids": ["1.2.840.113549.1.1.11"]
    }
}

id is yours. Use the CSC credentialID, or a handle that maps to it. Leave out signature_format: raw is the default.

If the signer has no credential, answer failed with credential_unavailable. The signer sees your error_description in the ceremony, so write it for them.

2. authorize: get the SAD

CSC calls the approval the Signature Activation Data (SAD). It’s bound to the exact hashes, which is why authorize comes after SignatureAPI computes the digest.

The request carries one digest, its algorithm and a label:

JSON
{
    "credential_id": "cred_7Qk...",
    "digests": [
        {
            "value": "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=",
            "hash_algorithm_oid": "2.16.840.1.101.3.4.2.1",
            "label": "Service Agreement"
        }
    ]
}

CSC offers two ways to get a SAD. Pick the one your provider supports.

The signer types the PIN or OTP on a page your worker hosts.

  1. Store the digests under a new single-use ticket, and answer:

    JSON
    {
        "status": "pending",
        "action_url": "https://signer.example.com/approve?ticket=6b0e...",
        "expires_at": "2026-08-24T16:45:00Z"
    }
  2. On your page, show the label so the signer knows what they approve. Ask for the OTP. If the provider sends the OTP itself, call credentials/sendOTP first.

  3. Call credentials/authorize with credentialID, numSignatures: 1, hashes (the Base64 digest value), hashAlgorithmOID and the OTP. The response holds the SAD.

  4. Mint a single-use code, store the SAD under it, and redirect the browser to callback_url with code appended.

  5. SignatureAPI calls authorize again with "callback": { "code": "..." }. Spend the code and answer:

    JSON
    {
        "status": "completed",
        "authorization": { "reference": "sad_3Fh...", "expires_at": "2026-08-24T16:50:00Z" }
    }

If the signer refuses, or the provider rejects the OTP too many times, redirect to callback_url with error=access_denied and an error_description. The session fails with that description, and the signer can try again from the ceremony.

3. sign: spend the SAD

JSON
{
    "credential_id": "cred_7Qk...",
    "authorization": { "reference": "sad_3Fh..." },
    "digests": [
        { "value": "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "hash_algorithm_oid": "2.16.840.1.101.3.4.2.1" }
    ],
    "sign_algo_oid": "1.2.840.113549.1.1.11"
}
  1. Look up the SAD by authorization.reference, and spend it once.

  2. Call signatures/signHash with credentialID, SAD, hashes, hashAlgorithmOID and signAlgo set to sign_algo_oid.

  3. Return the values in the same order:

    JSON
    { "status": "completed", "signatures": ["MEUCIQD..."] }

Two details decide whether the signature verifies:

  • The input. The digest is already a hash. Don’t hash it again. Some CSC services expect the DER DigestInfo instead of the bare hash for RSA keys. Check how yours behaves with one test signature.
  • The encoding. For ECDSA, return a DER ECDSA-Sig-Value. If your provider returns the compact r‖s form, convert it.

sign must be idempotent. If the response is lost, SignatureAPI retries with the same Idempotency-Key, and you return the stored signatures without calling signHash again.

CSC versions

Providers run different CSC versions, and the field names differ. Version 1.0.4.0 uses hash where version 2 uses hashes, for example, and providers support different authorization modes. credentials/info tells you which modes a credential accepts. Absorbing those differences is your worker’s job: SignatureAPI sends the same SWP/1 requests to every worker.

A provider that returns a CMS

Some providers, or some of their signing modes, return a finished signature instead of a bare value. In CSC that’s signatures/signDoc with documentDigests, signature_format C (CAdES) and signed_envelope_property Detached, which returns the CMS in SignatureObject.

Then switch your worker to cms. The steps above stay the same, with three changes:

  • credential adds "signature_format": "cms", and a max_signature_size that covers the provider’s largest output. The certificates are optional now, but returning them early lets SignatureAPI check that sign used the same certificate.

  • The digest is the SHA-256 of the PDF’s signed byte range. Pass it to the provider as the document digest.

  • sign returns the CMS and the chain:

    JSON
    {
        "status": "completed",
        "signatures": ["MIIGxwYJKoZIhvcNAQcCoIIGuDCC..."],
        "certificates": ["-----BEGIN CERTIFICATE-----\n...signer...", "-----BEGIN CERTIFICATE-----\n...issuing CA..."]
    }

Ask for a basic CAdES level. SignatureAPI replaces any timestamp the provider adds and adds its own revocation data. See Requirements on a CMS signature.

Test it

  • Happy path. A test envelope completes, and a PDF validator shows the signature with your provider’s test certificate.
  • Wrong OTP, then refusal. The ceremony shows your error_description, and Try again starts a new session.
  • The signer walks away. After the connection’s authorization timeout, the session fails with authorization window expired.
  • A repeated sign. In your own tests, send the same sign request twice with one Idempotency-Key. The provider signs once.