Skip to content

SslStreamCertificateContext.Create can fail on Windows when calling process does not have rights to certificate store #108607

Closed
@wfurt

Description

@wfurt

In order to send intermediate certificates we try to add them to Certificate store when OS cannot build full chain without them.
While the X509Store.Open is on try/catch block the actual addition is not and it can fail for various reasons.

Exception = System.Security.Cryptography.CryptographicException: Access is denied.

  at System.Security.Cryptography.X509Certificates.StorePal.Add(ICertificatePal certificate)
   at System.Net.Security.SslStreamCertificateContext..ctor(X509Certificate2 target, ReadOnlyCollection`1 intermediates, SslCertificateTrust trust)
   at System.Net.Security.SslStreamCertificateContext.Create(X509Certificate2 target, X509Certificate2Collection additionalCertificates, Boolean offline, SslCertificateTrust trust, Boolean noOcspFetch)
   at System.Net.Security.SslAuthenticationOptions.UpdateOptions(SslServerAuthenticationOptions sslServerAuthenticationOptions)

Activity

added this to the 10.0.0 milestone on Oct 7, 2024
dotnet-policy-service

dotnet-policy-service commented on Oct 7, 2024

@dotnet-policy-service
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

bartonjs

bartonjs commented on Oct 7, 2024

@bartonjs
Member

I just want to say on record that the state that the reporting machines are in (where they stably succeed at opening the store ReadWrite, and stably fail at actually adding to it) is degenerate, and we shouldn't really cater to it (they should fix their permissions model so that open fails, or writes succeed).

However, since transitory failure (such as a concurrent permissions change) looks the same, we should go ahead and make sure that the calls to Add are in a try.

Which means I support fixing it, but still want them to know they're wrong 😄

self-assigned this
on Apr 30, 2025
locked and limited conversation to collaborators on Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @bartonjs@wfurt@rzikm

    Issue actions

      SslStreamCertificateContext.Create can fail on Windows when calling process does not have rights to certificate store · Issue #108607 · dotnet/runtime