I have an issue, I created a certificate using certbot let's encrypt on debian for my subdomain, certificate was issued and ssl works.
I need to use that certificate for my websocket so I converted it .p12 file using command
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out certificate.p12
However, when I try to load .p12 file using
private X509Certificate2 GetCertificate(string certificateName, string certificatePassword)
{
if (certificateName == null || certificatePassword == null) return null;
var certificates = Directory.GetFiles(
Environment.CurrentDirectory,
certificateName,
SearchOption.AllDirectories
);
var certificatePath = certificates.First(path => path.EndsWith(certificateName));
return certificatePath != null ? new X509Certificate2(certificatePath, certificatePassword) : null;
}
it return error
CryptographicException: Unknown private key format
at Mono.Security.X509.PKCS12.AddPrivateKey (Mono.Security.Cryptography.PKCS8+PrivateKeyInfo pki) [0x0006c] in <fed5abf356e4410f878747dcbee46084>:0
at Mono.Security.X509.PKCS12.ReadSafeBag (Mono.Security.ASN1 safeBag) [0x000e5] in <fed5abf356e4410f878747dcbee46084>:0
at Mono.Security.X509.PKCS12.Decode (System.Byte[] data) [0x00242] in <fed5abf356e4410f878747dcbee46084>:0
at Mono.Security.X509.PKCS12..ctor (System.Byte[] data, System.String password) [0x0000d] in <fed5abf356e4410f878747dcbee46084>:0
at System.Security.Cryptography.X509Certificates.X509Certificate2ImplMono.ImportPkcs12 (System.Byte[] rawData, System.String password) [0x00023] in <0f3a92f18c3f4515965ea9093114785a>:0
at System.Security.Cryptography.X509Certificates.X509Certificate2ImplMono.ImportPkcs12 (System.Byte[] rawData, Microsoft.Win32.SafeHandles.SafePasswordHandle password) [0x0001b] in <0f3a92f18c3f4515965ea9093114785a>:0
at System.Security.Cryptography.X509Certificates.X509Certificate2ImplMono..ctor (System.Byte[] rawData, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x0002f] in <0f3a92f18c3f4515965ea9093114785a>:0
at Mono.X509PalImpl.ImportFallback (System.Byte[] data, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x00000] in <0f3a92f18c3f4515965ea9093114785a>:0
at Mono.X509PalImplMono.Import (System.Byte[] data, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x00000] in <0f3a92f18c3f4515965ea9093114785a>:0
at Mono.SystemCertificateProvider.Import (System.Byte[] data, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags, Mono.CertificateImportFlags importFlags) [0x00017] in <0f3a92f18c3f4515965ea9093114785a>:0
at Mono.SystemCertificateProvider.Mono.ISystemCertificateProvider.Import (System.Byte[] data, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags, Mono.CertificateImportFlags importFlags) [0x00000] in <0f3a92f18c3f4515965ea9093114785a>:0
at System.Security.Cryptography.X509Certificates.X509Helper.Import (System.Byte[] rawData, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x00005] in <131fc96242a743e6b00bc8a8663638a3>:0
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor (System.String fileName, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x0003e] in <131fc96242a743e6b00bc8a8663638a3>:0
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor (System.String fileName, System.String password) [0x00000] in <131fc96242a743e6b00bc8a8663638a3>:0
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor (System.String fileName, System.String password) [0x00000] in <0f3a92f18c3f4515965ea9093114785a>:0
at WebSocketListener.WebSocketNetworkListener.GetCertificate (System.String certificateName, System.String certificatePassword) [0x0004b] in C:\Users\Joe\Desktop\Work\unity\Vamps\GameEngine\Assets\Networking\WebGL\WebSocketNetworkListener.cs:133
at WebSocketListener.WebSocketNetworkListener..ctor (DarkRift.Server.NetworkListenerLoadData pluginLoadData) [0x00014] in C:\Users\Joe\Desktop\Work\unity\Vamps\GameEngine\Assets\Networking\WebGL\WebSocketNetworkListener.cs:26
at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
This is implementation of https://github.com/flejmer/DarkRift2-WebSocketListener for unity-webgl socket
Found a solution by generating certificate with option --key-type rsa