При выполнении аутентификации клиента с использованием цепочки сертификатов в C# .net 9.0 Server (Apache /PHP) возвращает: < /p>
ssl_client_verify: не удастся: невозможно подтвердить конфигурацию первого сертификата < /p>
< /blockquote>
.SSLCACertificateFile "conf/ssl.crt/testrootca-crt.pem"
< /code>
Однако при использовании эквивалентного клиента Java или Python сервер успешно проверяет сертификат и отчеты PHP: < /p>
ssl_client_verify: успех < /p>
< /blockquote>
, где могло бы быть проблемой. сети /> желаемое поведение
PHP -сервер выводит состояние проверки ($ _server ["ssl_client_verify"]). Статус проверки всегда должен содержать успех, а не неудачный: невозможно проверить первый сертификат < /p>
c# console app: < /p>
using System;
using System.Data.SqlTypes;
using System.Net.Http;
using System.Runtime.ConstrainedExecution;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
// Hello3
//
class Program
{
// Hauptprogramm
static async Task Main()
{
// Load Client Certifikate
// EC
//string certpath = "C:\\temp\\CAItest\\signed.p12";
// RSA
string certpath = "C:\\Austausch\\SSLneu2\\client-chain.p12";
Console.WriteLine(certpath);
byte[] rawCert = File.ReadAllBytes(certpath);
X509Certificate2Collection certificateCollection = X509CertificateLoader.LoadPkcs12Collection(
rawCert,
"David",
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet
);
Console.WriteLine("List content of Collection");
foreach (X509Certificate2 c in certificateCollection) Console.WriteLine($"{c.Subject} - HasPrivateKey={c.HasPrivateKey}");
Console.WriteLine($"Number of Certifikates in PFX: {certificateCollection.Count}");
var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
// Accept all Server Certifikates
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
handler.ClientCertificates.AddRange(certificateCollection);
using HttpClient client = new HttpClient(handler);
string url = "https://localhost/mbbsim/test4.php?params=dotnet"; // Call PHP test mock
try
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode(); // Exception, wenn der Statuscode nicht erfolgreich ist
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine($"Request-Fehler: {e.Message}");
}
}
}
< /code>
Код для сервера на основе PHP: < /p>
menno
< /code>
В настоящее время нет исключений. PHP /8.2.12
Intellij Idea 2024.3.4.1 (EdiTion Edition) JDK 1.8 < /p>
Используемые сертификаты (созданные с помощью OpenSSL 64bit): < /p>
Клиент (C# или Java) < /p>
client-chain.p12 - certificate chain with client certificate with private Key and intermediate CA certificate
testrootca-crt.pem - self signed root certificate
< /code>
Сервер config (apache) < /p>
SSLCertificateFile "conf/ssl.crt/apache-chain-crt.pem" - certificate chain with server certificate with private Key and intermediate CA certificate
SSLCertificateKeyFile "conf/ssl.key/apache-key.pem" - private Key of Apache Server
SSLCACertificateFile "conf/ssl.crt/testrootca-crt.pem" - CA certificate for client authentication (self signed root certificate)
Подробнее здесь: https://stackoverflow.com/questions/797 ... cate-chain