Моя среда разнообразен
- Docker: серверы Linux (debian) + window + mac
- Локальная отладка: window + mac
- Локальная отладка: window + mac
li>
Раньше я загружал сертификаты с помощью метода LoadCertificate, например это
Код: Выделить всё
private static X509Certificate2 LoadCertificate(IFileInfo fullChainPem, IFileInfo privKeyPem)
{
// Create the certificate by combining the certificate and the private key
var fullChainPemContent = fullChainPem.ReadAllText();
var privKeyPemContent = privKeyPem.ReadAllText();
var cert = X509Certificate2.CreateFromPem(fullChainPemContent, privKeyPemContent);
// Create an ephemeral copy of the certificate to avoid handle issues
return new X509Certificate2(cert.Export(X509ContentType.Pkcs12));
}
Код: Выделить всё
new X509Certificate2
Итак, я обновил метод для удаления эфемерной копии следующим образом:
Код: Выделить всё
private static X509Certificate2 LoadCertificate(IFileInfo fullChainPem, IFileInfo privKeyPem)
{
// Create the certificate by combining the certificate and the private key
var fullChainPemContent = fullChainPem.ReadAllText();
var privKeyPemContent = privKeyPem.ReadAllText();
return X509Certificate2.CreateFromPem(fullChainPemContent, privKeyPemContent);
// Create an ephemeral copy of the certificate to avoid handle issues
// return new X509Certificate2(cert.Export(X509ContentType.Pkcs12));
}
Этот обновленный код работает в:
- Docker (разработка)
- Docker (производство)
Если я снова включу эфемерная копия (несмотря на предупреждение об устаревании) снова работает. Без этого я получаю следующую ошибку на стороне клиента:
Код: Выделить всё
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
Код: Выделить всё
Connecting to ::1
CONNECTED(000001F0)
E43E0000:error:0A000126:SSL routines::unexpected eof while reading:ssl\record\rec_layer_s3.c:692:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 306 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
This TLS version forbids renegotiation.
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
Ключевые вопросы
strong>
- Почему эта проблема возникает только в режиме отладки?
- >Зачем мне все еще нужна эфемерная копия?
- Как правильно решить эту проблему в .NET 9?
На данный момент я заменил устаревший код следующим:
Код: Выделить всё
X509CertificateLoader.LoadPkcs12(data: cert.Export(X509ContentType.Pkcs12), password: null)
Подробнее здесь: https://stackoverflow.com/questions/792 ... ating-an-e