Skip to content

Windows: Puma TLS fails with 'Access denied' where DPAPI is unavailable (PFX key import) #130

Closed

Description

@Largo

Puma::MiniSSL on Windows (Src/Libraries/Puma/MiniSsl.cs, LoadCertificate) round-trips the server certificate through a PFX, because SChannel cannot serve with an ephemeral key:

leaf = X509CertificateLoader.LoadPkcs12(ephemeral.Export(X509ContentType.Pfx), null);

With default key-storage flags that import persists the private key in the user's key store, which needs DPAPI. Where DPAPI is not available, the import fails with CryptographicException: Access denied. and puma cannot bind its TLS listener (OpenSSL::X509::CertificateError from ImportPfx). Seen in an OpenSSH session logged in with a public key (no credentials, so DPAPI cannot unlock the user's master key: ProtectedData.Protect also fails "Access is denied"); the same session with a password logon works. The same would likely hit a service account without a loaded profile.

Under such a session the test suite's Puma_Tls1 hangs, and NetHttp_Tls1, NetHttp_TlsVerifyCallback1, NetHttp_PlainNoOpenSsl1, NetHttp_GemNetTls1 and Ssl_NonBlocking1 fail in their certificate setup (NetHttpTlsTests.cs LoadPkcs12). CI is not affected (GitHub runners have a full interactive profile).

Possible fixes: try X509KeyStorageFlags.MachineKeySet (or UserKeySet explicitly) as a fallback when the default import is denied, and make the error say what is missing; in the tests, skip with a clear message when DPAPI is unavailable instead of hanging.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions