Skip to content

fix(sspi): remove stale rewrite docs and harden credential diagnostics - #178

Merged
Richard Markiewicz (thenextman) merged 1 commit into
masterfrom
rdmw/kerb-cert-logon-review-followup
Aug 7, 2026
Merged

fix(sspi): remove stale rewrite docs and harden credential diagnostics#178
Richard Markiewicz (thenextman) merged 1 commit into
masterfrom
rdmw/kerb-cert-logon-review-followup

Conversation

@thenextman

Copy link
Copy Markdown
Member

Follow-up to #177, addressing review comments.

Stale documentation for a rewrite that no longer exists

#177 removed the Base CSP → KSP provider rewrite, but left behind a README section and a doc comment above sspi_CreatePackedCertificateLogon that still describe it. Both are removed here.

To be explicit, since the review suggested implementing the rewrite instead: that would regress the fix. The credential that works names Microsoft Base Smart Card Crypto Provider with KeySpec = 1 — the legacy CAPI provider — and the KSP retarget was in the arm that failed during testing. The claim was wrong, not the code.

The README text is replaced with something accurate and more useful: the credential is passed through as CredPackAuthenticationBufferW produced it, and the provider and container names it records are resolved by the server through the redirected reader — so the same smart card middleware must be installed on both ends. A mismatch surfaces as "the key container does not exist on the smart card", which is a real failure mode and easy to misattribute to the client.

Dead code

sspi_TryGetCspInfo lost its last caller when the rewrite was removed and is deleted.

Bounded credential dump

sspi_GetLocalAllocSizeAsDword returns 0 when the incoming pSpnegoCred is not a LocalAlloc block, which is common — a reconnect passes such a buffer. Zero disables the extent check in sspi_ResolvePackedField, so walking the blob would then trust CspDataLength alone and could read past the credential.

MsRdpEx_CanReadUnsafePtr still guarded every access, so this could not fault or touch unmapped memory; the exposure was logging bytes beyond the allocation. Now the fixed-size header is still reported and only the CspData walk is skipped when the size is unknown, which keeps the diagnostic useful in exactly the reconnect case that produces it.

Thread-safe environment initialisation

MsRdpEx_PcapEnvInit guarded initialisation with a plain bool while writing shared globals, including a strcpy_s into g_PcapFilePath. It is reached from
AcquireCredentialsHandleW and from the message paths, both of which run concurrently on several connection worker threads.

This race predates #177 — the message-path caller is older and hotter — and the written values are idempotent, so impact was minimal. It is now InitOnceExecuteOnce, matching the two existing uses in the same file.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes obsolete SSPI rewrite documentation and hardens credential diagnostics and environment initialization.

Changes:

  • Replaces stale smart-card provider rewrite documentation.
  • Removes dead CSP lookup code.
  • Bounds credential parsing and serializes environment initialization.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
README.md Documents current credential and middleware behavior.
dll/Sspi.cpp Removes dead code and hardens diagnostics and initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dll/Sspi.cpp
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@thenextman
Richard Markiewicz (thenextman) force-pushed the rdmw/kerb-cert-logon-review-followup branch from 91e5348 to ef66c4a Compare August 7, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants