Skip to content

OpenSSL provider support  #89167

@krwq

Description

@krwq

In #88656 we've added ENGINE support but we've left out providers pending more investigation on issues discovered during implementation. This API was already approved last year but asking for re-approval given time which passed.
Original issue: #55356

Background

ENGINE and providers are plug-in systems for OpenSSL which allow to make custom implementation of some crypto algorithms. That enables scenarios such as using TPM keys.

ENGINE is an old (now deprecated) plug-in system which was the only FIPS approved plugin system until recently. Providers is new plug-in system allowing a bit more flexibility to developers (but also harder to implement).

Proposal

namespace System.Security.Cryptography
{
    public partial class SafeEvpPKeyHandle
    {
        // existing OpenSSL ENGINE APIs (only plugin model for OSSL 1.1, deprectated (but present) in 3.0+)
        // public static SafeEvpPKeyHandle OpenPrivateKeyFromEngine(string engineName, string keyId) => throw null;
        // public static SafeEvpPKeyHandle OpenPublicKeyFromEngine(string engineName, string keyId) => throw null;

        // OpenSSL Providers (new plugin model for OSSL 3.0+)
        public static SafeEvpPKeyHandle OpenKeyFromProvider(string providerName, string keyUri) => throw null;
    }
}

Usage Example

byte[] data = ...;

// For TPM settings refer to provider documentation you're using, i.e. https://github.com/tpm2-software/tpm2-openssl/tree/master
// specific values are just example
using (SafeEvpPKeyHandle priKeyHandle = SafeEvpPKeyHandle.OpenKeyFromProvider("tpm2", "handle:0x81000007"))
using (ECDsa ecdsaPri = new ECDsaOpenSsl(priKeyHandle))
{
    byte[] signature = ecdsaPri.SignData(data, HashAlgorithmName.SHA256);
    // do stuff with signature
    // note: tpm2 does not allow Verify operations, public key needs to be exported and re-imported into new instance
}

Security considerations

Those APIs are not meant to be used with untrusted inputs. Allowing untrusted inputs may potentially allow attacker to use TPM or other private keys in an unintended way. Some providers i.e. "default" allow reading files from arbitrary paths (in order to read the key) which makes it further dangerous to use with untrusted inputs. Additionally providerName may load libraries into the process which adds additional risk (depending on OSSL_PROVIDER_set_default_search_path setting this may or may not be a big issue).

(considerations also apply to already added ENGINE APIs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Securityin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions