Skip to main content

pysapsso2 — decode, verify and generate SAP SSO tickets (MYSAPSSO2)

A pure Python library for SAP Logon and Assertion tickets — the single sign-on tokens carried in the MYSAPSSO2 cookie and in .sap shortcut files. It decodes, verifies and generates them. The tickets are accepted by:

  • SAP NetWeaver ABAP (SAP GUI, Webdynpro/Fiori, Web Services)
  • SAP NetWeaver Java (Web)

This library is an open-source alternative to SAPSSOEXT (304450 - Single-Sign-On with SAP logon tickets in non-SAP systems)

Installation

pip install pysapsso2

Generate a SAP shortcut (.sap file)

cf. examples/generate_shortcut.py

Decode a MYSAPSSO2 cookie

from pysapsso2 import SapTicket

ticket = SapTicket.from_b64(cookie_value)
print(ticket.user, ticket.source_sid, ticket.source_client, ticket.expires_at)

Verify a MYSAPSSO2 ticket signature

from pysapsso2 import SapTicket, SapTicketHandler

ticket = SapTicket.from_b64(cookie_value)
handler = SapTicketHandler("SSO", "000", certificate=trusted_cert_pem)
handler.verify(ticket)  # raises SignatureError / CertificateError

verify() checks, in order:

  1. the payload digest against the message_digest signed attribute,
  2. that the ticket names the supplied certificate as its signer,
  3. that the certificate is within its validity period (check_certificate_validity=False to skip, at_time= to pin the moment),
  4. the signature over the signed attributes.

The certificate must come from the caller. A ticket may embed a certificate, but anybody can embed one they hold the key for, so it is never used as a trust anchor. pysapsso2.crypto.get_dsa_key() exposes the embedded key for inspection only.

Signing algorithms

Key Key sizes Digest
DSA 1024 – 4096 sha1, sha256
RSA (PKCS#1 v1.5) 1024 – 4096 sha1, sha256
ECDSA P-256, P-384, P-521 sha1, sha256

Every combination in the table was accepted by a live SAP NetWeaver ABAP system.

DSA with sha1 is the default, because that is what SAPSSOEXT emits. Use it if you need a ticket that SAPSSOEXT can also read. Otherwise prefer RSA or ECDSA with sha256.

Pick the algorithm on the handler:

from Crypto.PublicKey import RSA
from pysapsso2 import SapTicketHandler

handler = SapTicketHandler(
    "SSO",
    "000",
    private_key=RSA.import_key(key_pem),
    certificate=cert_pem,
    digest_algorithm="sha256",
)
ticket = handler.new("DEMOUSER")

digest_algorithm defaults to "sha1". The handler picks the signer from the key type. You can also build the signer yourself with pysapsso2.DsaSigner, pysapsso2.RsaSigner or pysapsso2.signer_for_key() and pass it as private_key; the handler's digest_algorithm is then ignored, because the signer carries its own.

Verification needs no configuration. verify() reads the digest algorithm from the ticket and the key algorithm from the certificate.

Development

This project uses uv.

# Create the virtualenv and install the project with its dev dependencies
uv sync

# Run the tests / linter
uv run pytest
uv run ruff check

# Run an example
uv run examples/generate_shortcut.py

# Build the sdist and wheel
uv build

tests/keys/ holds throwaway self-signed keys, one pair per row of the algorithm matrix. They are committed, so a clone runs the suite straight away. To replace them, or to add a key size or curve, run pwsh tools/make_test_keys.ps1 -Force. It needs openssl; on Windows it falls back to the one shipped with Git.

sapsso2.key and sapsso2.crt are the exception: the script never touches them. That key signed the SAPSSOEXT reference ticket pinned in tests/test_sapticket.py, so a regenerated key would not verify that signature.

Further reading

  • docs/sapssoext.md — developer notes: signing a ticket with SAPSSOEXT itself, and running the interop suite (uv run pytest -m oracle) against it.
  • docs/interop.md records what SAP actually does with a ticket, measured rather than quoted: which keys and digests each consumer signs and validates, the DSA subgroup rule, the error pairs, and the validity and base64 behaviour.

Metadata

Release files for pysapsso2 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysapsso2 1.1.1
File Size Uploaded
pysapsso2-1.1.1.tar.gz 72.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysapsso2 1.1.1
File Interpreter ABI Platform
pysapsso2-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 90.5 kB

Release files / pysapsso2-1.1.1.tar.gz

Download URL pysapsso2-1.1.1.tar.gz
Size 72.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ea803cf64b6516092e9490bdbc46828138da5ff2f4bd28a94df944aee416eca9
BLAKE2b-256 checksum
How to use checksums
5d018942bad4dfa2547f4e0bf75e8ab438e5d766c32f55ae4ee887c432c7226c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pysapsso2-1.1.1-py3-none-any.whl

Download URL pysapsso2-1.1.1-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f14e49307ad64a032318864275424aa9c956dd87ca396d6991a36596a2a9c3d
BLAKE2b-256 checksum
How to use checksums
3bd10807c8529cc09f7045d07cc95e48a87834f89224eb2a2e7b10580fa087d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page