Changing the X.509 Embedded Self-Signed Certificate (idsrv3test.pfx) to IdentityServer.v3

I ended up setting up IdentityServer.v3 with IdentityManager and everything works pretty much the way I want. It remains only to replace the X.509 certificate with its own self-signed. I am using the code here to download my inline certificate. What I am doing is copying my .pfx file to the configuration folder and changing the certificate name and password for this pfx file in the Cert.cs file. In addition, I set "Build Action: Embedded Resource" and "Copy to Output Directory: do not copy" to the new properties of the pfx file.

When I post my solution, I get a widespread application error.

The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Security.Cryptography.CryptographicException: The system cannot find the file specified.

Is there a specific way to create a pfx file? I created my files makecert.exeand pvk2pfx.exe. In addition, I use this certificate to secure the domain that hosts IDSRV3. Without affecting the certificate configuration, both IdentityServer.v3 and IdentityManager work without errors.

What am I missing here?

+4
source share
1 answer

-, . (!) , IIS . " " "".. , , - IIS .

, Windows, , .

public static X509Certificate2 GetCert()
{
    X509Certificate2 cert = FindCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySerialNumber, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); // serial number is a 32 digit GUID without any white spaces or dashes. It can be found from details of cert file

    return cert;
}

static X509Certificate2 FindCertificate(StoreLocation location, StoreName name, X509FindType findType, string findValue)
{
    X509Store store = new X509Store(name, location);
    try {
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection col = store.Certificates.Find(findType, findValue, false);
        return col[0]; }
    finally
    {
        store.Close();
    }
}

, Windows .pfx.

, , , .

: , , , CASE. MMC, , VS UPPER CASE.

+3

Source: https://habr.com/ru/post/1568483/


All Articles