Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I generate the Identity Server signing certificate

Tags:

In the identity server samples we find code like this in Startup.cs

var certFile = env.ApplicationBasePath + "\\idsrv3test.pfx";

var signingCertificate = new X509Certificate2(certFile, "idsrv3test");

How would I go about replacing this for production scenarios?

like image 594
sunil Avatar asked Mar 08 '16 23:03

sunil


People also ask

How do I change my identity server signing certificate?

Updating the Identity Signing CertificateOpen Manage Computer Certificates app, from Start->Run->type certlm. msc and OK. Go to the personal node and locate the certificate. Open the certificate and go to the 'Details' tab and get the thumbprint.

What is AddDeveloperSigningCredential?

By default, Identity Server uses Temporary Signing Certificate to sign the JWT tokens via this method: .AddDeveloperSigningCredential() Once Identity Server starts/restarts, a temporary key is created and make all the keys created before invalid.


2 Answers

For the record, the code proposed in the image posted by RuSs:

options.SigningCertificate = LoadCertificate();

public X509Certificate2 LoadCertificate()
{
    string thumbPrint = "104A19DB7AEA7B438F553461D8155C65BBD6E2C0";
    // Starting with the .NET Framework 4.6, X509Store implements IDisposable.
    // On older .NET, store.Close should be called.
    using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
    {
        store.Open(OpenFlags.ReadOnly);
        var certCollection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbPrint, validOnly: false);
        if (certCollection.Count == 0)
            throw new Exception("No certificate found containing the specified thumbprint.");

        return certCollection[0];
    }
}
like image 98
Eric Boumendil Avatar answered Sep 27 '22 20:09

Eric Boumendil


Get a dedicated cert - either via your PKI or self-generate one:

http://brockallen.com/2015/06/01/makecert-and-creating-ssl-or-signing-certificates/

Import the key pair into the Windows certificate store, and load it from there at runtime.

To step up security, some people deploy the keys to a dedicated device (called an HSM) or to a dedicated machine (e.g. behind a firewall). The ITokenSigningService allows moving the actual token signing to that separate machine.

like image 28
leastprivilege Avatar answered Sep 27 '22 20:09

leastprivilege