Skip to content

v0.2.1: tRFC/qRFC submit, EC keys for SNC, every source an observation - #65

Merged
randomstr1ng merged 13 commits into
mainfrom
feat/snc-ec
Nov 12, 2026
Merged

randomstr1ng merged 13 commits into
mainfrom
feat/snc-ec

Conversation

@randomstr1ng

@randomstr1ng randomstr1ng commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Release 0.2.1. Closes #36 and #64. Full list in the CHANGELOG.md 0.2.1 entry.

Fixed

  • tRFC and qRFC submits work (tRFC/qRFC submit: ARFC_DEST_SHIP is called with parameters it does not declare #36). call_transactional() now sends what the reference client sends, byte for byte: the call serialized into ARFC_DEST_SHIP's DATA table, with the TID, function and queue name in a STATE row. Both row layouts come from the server's metadata. The function's own parameters are now sent (before, they were dropped). confirm_tid() sends API_CLEAR_TID.
    • Rebuilt byte for byte from reference captures in tests/golden/trfc/trfc_reference.json.
    • Checked live by reading the server's own tables back: the call is recorded as executed, a qRFC call lands in the inbound queue, a resubmit with the same TID is not run twice, and the confirm clears the TID. Works over TCP and SNC.
  • Table rows are sent at the structure's padded width. The rule (end of the last field, rounded up to the largest field alignment) was checked against the width the server reports for about 750 structures.
  • Tables the caller sends come back with the server's changes. The server answers with row edits (append, insert, change, delete) keyed by the client's DM id, or with the whole table after a sort or a clear. These used to be dropped, along with tables it left untouched. Every kind of edit was captured from a purpose-built function module and replays from tests/golden/serialization/table_delta.json; for example, STFC_STRUCTURE's RFCTABLE now comes back with both rows.
  • Data types: INT8, UTCLONG and DATN/TIMN are confirmed by capture. UTCLONG parameters and DATN/TIMN structure fields used to be dropped. STRING now carries its terminating NUL in both directions.
  • Logon: the logon frame's length field is computed instead of being a constant.
  • connect_async() resolves message-server groups the same way connect() does.
  • SNC partner names: SN= is read as serialNumber, matching how the SNC frame header encodes it.
  • Yes/no parameters (Native SNC (snc_pse) rejects non-RSA PSE keys — only RSA supported (EC SAPSYS PSEs blocked) #64) such as snc_sso="0" are no longer read by truthiness.

Added

Evidence and docs

  • Code comments and docs cite only captures, fixtures or live probes, or are labelled [ASSUMED]. They no longer cite SAP-internal names or SDK headers. New captures settled the negative packed-decimal sign and the password scramble instead of relabelling them.
  • Every doc page was checked against the code and fixtures, giving about 140 corrections.
  • Status labels are gone from the docs: a fact without a label cites its source where it is stated.
  • Private lab addresses and host names are gone from fixtures and docs. They were replaced with documentation values, keeping every binary fixture the same length.
  • tests/test_repo_hygiene.py enforces all of the above.

Testing

  • Offline: 1591 tests pass; ruff and mypy (Linux and Windows) are clean; the strict docs build passes.
  • Live, against an S/4HANA system: the integration suite, tRFC/qRFC, EC and RSA SNC logons, the new type captures, and every kind of table edit compared with the reference client.

Known gaps (not part of this PR)

PSEs with ECDSA keys (P-256, P-384, P-521), as sapgenpse -a ECDSA and
current SAP systems create them, were refused ("only RSA keys are
supported"). They now load, sign the handshake, and EC server
certificates and EC-signed chains are verified.

- pse.py: an EC key object (id-ecPublicKey + curve, BIT STRING holding an
  RFC 5915 ECPrivateKey) is returned as PKCS#8. New fixtures pse_ec_*
  from sapgenpse, checked against its own export_p8; a DSA PSE fixture
  shows other key types are refused clearly.
- secgss.py: signature ids 00000606/00000506/00000206 = ECDSA with
  SHA-512/384/256. Established against CommonCryptoLib as the acceptor
  with an EC key: offered exactly one id, it signed with that algorithm
  and aborted for every other id it lists. AlgorithmIdentifier carries
  the OID without parameters; the BIT STRING holds 00 || DER
  Ecdsa-Sig-Value, as the reference client sends it. The client signs
  with the first id in the server's list its key can use (RFC 6979
  deterministic ECDSA via ecdsa) and now offers the ECDSA ids after the
  RSA ones, in the reference client's order.
- Fixtures secgss_ec_loopback (EC/EC, plus the reference client's own
  tokens) and secgss_ec_client_rsa_server (EC P-384 client, RSA server)
  replay byte for byte, records included. Every combination of RSA and
  EC P-256/384/521 keys on both sides completed a handshake with
  CommonCryptoLib. The new AuthRequest was confirmed live: RSA logon to
  S/4HANA still succeeds.
- The two older replays pin the RSA-only list they were recorded with;
  the test checks that list against the recorded token. Fixtures are
  unchanged.
)

snc_sso="0" counted as on: the password was dropped and the logon used
the SNC identity. snc_sso, snc_kerberos, ws_tls_verify, ms_use_http,
strict_params and allow_restricted_logon now accept True/False, 1/0 and
the NW RFC SDK strings "1"/"0"; anything else raises TypeError before a
connection is opened. Changelog entries for this and the EC support.
Two comments in snc.py and one in a test named internal functions of the
SAP libraries as the source of a fact. Cite the evidence the facts rest
on instead: the eye-catcher seen in every captured frame (golden fixture
snc_frame_headers.json) and the bare DN accepted in live snc_lib logons.
…t [ASSUMED]

Comments and docs that cited "protocol analysis" or named internal
functions, symbols or constants of SAP binaries now cite the capture,
golden fixture or live probe behind the fact. Where none exists, the
fact is labelled [ASSUMED] with what would settle it:

- RFC types 31-40: only INT8 = 31 with 8 bytes was seen (A4H metadata
  for GET_TASK_INFO, 2026-11-12); no standard remote-enabled module on
  A4H uses the others. The docs had called them confirmed; the fixtures
  already said synthetic/[ASSUMED].
- SAP LZ4 wRFC frames, the inbound 0x5001 parameter block: no capture.
- TID character set beyond hex: live TIDs are hex; a probe is blocked
  by issue #36 (a tRFC submit fails before the TID is checked).
- PROGRAM_ID limits: a live registration probe could not read the
  result back.

Rechecked against the captures on the way: GW_INFO (224 bytes) and
GW_DONE (80 bytes) fields, with bytes 78:80 carrying the gateway's
connection index rather than a fixed 0x0004; the GW_CONNECT reply
carries 0x06 at [21]; TABLE parameters report type 5 in live metadata;
0x0303/0x0304/0x0305 all appear in live responses. The TID section of
trfc.md now describes the observed hex form instead of an unverified
encoding.

tests/test_repo_hygiene.py fails if such references come back.
Behaviour is unchanged. Changelog: 0.2.1.
call_transactional() sent the TID, function and queue as parameters
ARFC_DEST_SHIP does not declare, so every submit was refused with
"Field TID did not have a value", and the function's own parameters
were never sent.

The submit is now 0x0504 followed by ARFC_DEST_SHIP with two tables:
STATE (ARFCRSTATE), one row per call carrying the TID, function and,
for qRFC, the queue name in ARFCRESERV; and DATA (ARFCRDATA), the call
serialized with the logon's header and cut into 1785-byte pieces. Both
row layouts come from the server's metadata. confirm_tid() sends
API_CLEAR_TID after 0x0513. Rebuilt byte for byte from captures of the
reference client (tests/golden/trfc/trfc_reference.json); live, the
server records each call as executed, queues qRFC calls in TRFCQIN,
ignores a resubmit of the same TID and forgets it on confirm, over TCP
and SNC.

Table rows are now sent at the structure's padded width (end of the
last field rounded up to its alignment), which matched X030L-TABLEN for
all 357 flat structures of a live sample. Queue names are limited to
24 characters, the server's queue column, which silently cut longer
names.
A purpose-built function module with INT8, UTCLONG, DATN and TIMN
parameters, called by the reference client, settles their encoding
(tests/golden/serialization/int8_utclong.json):

- INT8 is signed 64-bit little-endian (was [ASSUMED]).
- UTCLONG is 0 for initial, otherwise 1 + 100 ns ticks since
  0001-01-01 on the Julian calendar before 1582-10-15 and Gregorian
  after it. Its metadata code 'p' was unknown, so UTCLONG parameters
  were dropped from the interface. Values are now
  YYYY-MM-DDTHH:MM:SS.fffffff strings (or datetime), None if initial.
- DATN and TIMN travel as DATE and TIME; as unknown dictionary types
  they were dropped from structure layouts.

The structure alignment table is now measured for every DDIC type
against X030L-TABLEN (D34* align to 16, string references to 4), and
table decoding accepts rows a server sends packed to the end of the
last field. Types 33-40 stay [ASSUMED]: kernel 793 has no dictionary
type for them.
About 60 comments cited "SDK type definitions", some with header line
numbers, and several fixture notes and docs named internal functions of
SAP binaries. API-parity notes now name the public SDK function they
mirror; wire facts cite a capture or are labelled [ASSUMED] (the RFC
server's return codes 3 and 16; analysis-only TLV tags).

Settled by new live captures of the reference client instead:
- packed decimal: 0x0D is negative, 0x0C zero/positive
  (tests/golden/serialization/bcd_sign.json);
- the 0x0117 password scramble reproduces the reference client's
  records (tests/golden/handshake/password_scramble.json, dummy
  passwords against a non-existent user);
- UnitID and TID lengths.

Removes tests/golden/framing/trfc_call_request.{bin,json}: a synthetic
fixture of the old tRFC format, used by no test and contradicted by the
tRFC captures in tests/golden/trfc/. The hygiene test now also scans
fixture JSON and catches header line references.
Private addresses of the development lab (192.168.88.x, 10.20.30.x, and
one message-server entry) and the capture host's name appeared in
fixtures, tests and docs. They are replaced with documentation
addresses (198.51.100.x / 192.0.2.x) and host1. Binary fixtures keep
their byte length: ASCII and UTF-16LE text, raw IPv4 bytes and the
8-character address prefixes some GW frames carry are each substituted
with a value of the same length, so every offset and length field is
unchanged. The hygiene test now rejects these addresses in text and in
any binary fixture. History is not rewritten.
Six independent reviews compared each doc claim with the implementation,
the golden fixtures and the tests; about 140 corrections followed (offsets
re-read from captures, hex examples regenerated, stale statements removed,
cookbook examples fixed, unsourced claims labelled [ASSUMED] or removed).

Status labels (CONFIRMED, RESOLVED, PARTIAL, UNCONFIRMED, [UNKNOWN]) are
gone: an unlabelled fact cites its source inline, [ASSUMED] marks an
inference, open items sit under Known Gaps. Enforced by the hygiene test
and written down in CLAUDE.md and methodology.md.

Code fixes the reviews surfaced:
- STRING is UTF-8 plus a terminating NUL (live capture,
  string_xstring.json); the NUL was returned to the caller and not sent.
  The synthetic type_string/type_xstring fixtures that encoded the
  disproved layout are removed; type_bcd.json's value corrected to what
  its bytes encode.
- The logon frame's footer length is computed instead of a constant.
- connect_async() takes msserv/ms_http_port/ms_use_http and resolves
  groups like connect().
- SN in a built-in SNC partner name is serialNumber, as in the frame
  header's SNC name.
- Stale code comments brought in line with the captures.
@gitguardian

gitguardian Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@randomstr1ng randomstr1ng self-assigned this Nov 12, 2026
@randomstr1ng randomstr1ng added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 12, 2026
…pplied

A TABLES parameter the caller filled and the function module then
changed was missing from the result, and so was one it left alone. The
server does not send such a table back: it sends a section per table
(0x0331 .. 0x0336, keyed by the DM id the client assigned) holding the
edits in order -- 0x0333 [op, dm, row] + 0x0334 row for append (4),
insert (6) and change (7), 0x0332 [5, dm, row] for delete -- or the
whole table under 0x0335 after a sort or a clear.

The table is now rebuilt from the rows sent plus those edits, and an
untouched one is returned as sent, as the reference client does. Every
kind of edit was captured from a purpose-built function module and
replays from tests/golden/serialization/table_delta.json; an edit
outside that set raises. STFC_STRUCTURE's RFCTABLE now comes back with
both rows (live test added).
tests/golden/ holds throwaway test keys, recorded ephemeral key-exchange
keys and encrypted SNC records; all high-entropy, none a credential for a
real system. Every new fixture raised a Generic High Entropy Secret alert.
@randomstr1ng
randomstr1ng merged commit 682017d into main Nov 12, 2026
15 of 16 checks passed
@randomstr1ng
randomstr1ng deleted the feat/snc-ec branch November 12, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

1 participant