Я пытаюсь реализовать взаимную аутентификацию.
У меня ошибка
A call to SSPI failed, see inner exception.
, а внутреннее исключение
The message received was unexpected or badly formatted
на основе исследований. в сети я обнаружил, что могут быть проблемы с SslProtocols , но, как вы можете видеть, я перепробовал все возможные комбинации, и все они дают мне ту же ошибку.
Аутентификация, которую я пытаюсь реализовать именно для этой услуги https://developer.baltics.sebgroup.com/bgw/docs/auth
Baltic Gateway communication uses certificate based authentication (X.509 public key infrastructure (PKI) standard).
Regular HTTPS (HTTP/1.1 over TLS1.2) is used for secured communication.
Certificate for authentication is issued by SEB for which client needs to provide Certificate Signing Request (CSR). Common Name value of the certificate is agreed in BGW service agreement.
private void mutual()
{
try
{
X509Certificate2Collection cCollection = new X509Certificate2Collection();
cCollection.Add(new X509Certificate2("EEBGWTEST.crt"));
string server = "test.api.bgw.baltics.sebgroup.com";
int nPort = 443;
TcpClient client = new TcpClient(server, nPort);
using (SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null))
{
MessageBox.Show("before auth");
try
{
MessageBox.Show("tls");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
sslStream.AuthenticateAsClient(server, cCollection, SslProtocols.Tls, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null) MessageBox.Show(ex.InnerException.Message);
}
try
{
MessageBox.Show("tls11");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
sslStream.AuthenticateAsClient(server, cCollection, SslProtocols.Tls11, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null) MessageBox.Show(ex.InnerException.Message);
}
try
{
MessageBox.Show("tls12");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
sslStream.AuthenticateAsClient(server, cCollection, SslProtocols.Tls12, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null) MessageBox.Show(ex.InnerException.Message);
}
try
{
MessageBox.Show("ssl2");
ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
sslStream.AuthenticateAsClient(server, cCollection, SslProtocols.Ssl2, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null) MessageBox.Show(ex.InnerException.Message);
}
try
{
MessageBox.Show("ssl3");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
sslStream.AuthenticateAsClient(server, cCollection, SslProtocols.Ssl3, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null) MessageBox.Show(ex.InnerException.Message);
}
MessageBox.Show("autentificated");
}
// Disconnect and close the client
client.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
if (ex.InnerException != null) MessageBox.Show(ex.InnerException.Message);
}
}
public bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
Можете ли вы помочь мне решить эту проблему?