Ошибка аутентификации в SSL

437
03 мая 2017, 07:39

Здравствуйте, есть следующий простой пример Smtp клиента с отправкой тестового письма:

    using (var client = new SmtpClient
    {
        Host = "smtp.yandex.ru",
        Port = 25,
        EnableSsl = true,
        Credentials = new NetworkCredential("(-email-)@yandex.ru", "(-pwd-)")
    })
    {
        client.Send(new MailMessage("(-email-)@yandex.ru", "(-email-)", "test_header", "test_msg"));
    }

Данный код генерит следующее исключение на моей машине

System.Net.Mail.SmtpException was unhandled
       HResult=-2146232800
       Message=The handshake failed due to an unexpected packet format.
       Source=System
       StackTrace:
            at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
            at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
            at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
            at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
            at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
            at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
            at System.Net.TlsStream.CallProcessAuthentication(Object state)
            at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
            at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
            at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
            at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
            at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
            at System.Net.Mail.SmtpConnection.Flush()
            at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
            at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
            at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
            at System.Net.Mail.SmtpClient.GetConnection()
            at System.Net.Mail.SmtpClient.Send(MailMessage message)
       InnerException: 
    

Но при этом данный код работает исправно на другой машине в той же сети и никаких исключений не генерится, из чего я делаю вывод, что проблема с окружением на моей локальной машине. Настраивал более детальный логгирование в trace файл. Прикладываю пример этого файла при запуске на моей машине и на машине, где всё работает без ошибок. Нерабочий вариант:

System.Net Verbose: 0 : [7848] SmtpClient::.ctor()
System.Net Information: 0 : [7848] Associating SmtpClient#45410999 with SmtpTransport#49911653
System.Net Verbose: 0 : [7848] Exiting SmtpClient::.ctor()  -> SmtpClient#45410999
System.Net Information: 0 : [7848] Associating MailMessage#66337667 with Message#35489797
System.Net Verbose: 0 : [7848] SmtpClient#45410999::Send(MailMessage#66337667)
System.Net Information: 0 : [7848] SmtpClient#45410999::Send(DeliveryMethod=Network)
System.Net Information: 0 : [7848] Associating SmtpClient#45410999 with MailMessage#66337667
System.Net Information: 0 : [7848] Current OS installation type is 'Client'.
System.Net Verbose: 0 : [7848] ServicePoint#45795543::ServicePoint(smtp.yandex.ru:25)
System.Net Information: 0 : [7848] Associating SmtpTransport#49911653 with SmtpConnection#65677972
System.Net Information: 0 : [7848] Associating SmtpConnection#65677972 with ServicePoint#45795543
System.Net Information: 0 : [7848] SmtpPooledStream#8442299 - Created connection from 192.168.1.159:1357 to 93.158.134.38:25.
System.Net Information: 0 : [7848] Associating SmtpConnection#65677972 with SmtpPooledStream#8442299
System.Net Information: 0 : [7848] TlsStream#10589941::.ctor(host=smtp.yandex.ru, #certs=0)
System.Net Information: 0 : [7848] SecureChannel#31534420::.ctor(hostname=smtp.yandex.ru, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [7848] Enumerating security packages:
System.Net Information: 0 : [7848]     Negotiate
System.Net Information: 0 : [7848]     NegoExtender
System.Net Information: 0 : [7848]     Kerberos
System.Net Information: 0 : [7848]     NTLM
System.Net Information: 0 : [7848]     Schannel
System.Net Information: 0 : [7848]     Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [7848]     WDigest
System.Net Information: 0 : [7848]     TSSSP
System.Net Information: 0 : [7848]     pku2u
System.Net Information: 0 : [7848]     CREDSSP
System.Net Information: 0 : [7848] SecureChannel#31534420 - Left with 0 client certificates to choose from.
System.Net Information: 0 : [7848] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent  = Outbound, scc     = System.Net.SecureCredential)
System.Net Information: 0 : [7848] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [7848] InitializeSecurityContext(In-Buffer length=0, Out-Buffer length=124, returned code=ContinueNeeded).
System.Net Error: 0 : [7848] Exception in SmtpClient#45410999::Send - The handshake failed due to an unexpected packet format..
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.TlsStream.CallProcessAuthentication(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
   at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Mail.SmtpConnection.Flush()
   at System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
   at System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
System.Net Verbose: 0 : [7848] SmtpPooledStream::Dispose #8442299
System.Net Verbose: 0 : [7848] Exiting SmtpPooledStream::Dispose #8442299
System.Net Error: 0 : [7848] Exception in AppDomain#12549444::UnhandledExceptionHandler - Failure sending mail..
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at MomentumM0.Startup.Program.Main(String[] args) in ...

Рабочий вариант:

System.Net Verbose: 0 : [6968] SmtpClient::.ctor()
System.Net Information: 0 : [6968] Associating SmtpClient#2383799 with SmtpTransport#21454193
System.Net Verbose: 0 : [6968] Exiting SmtpClient::.ctor()  -> SmtpClient#2383799
System.Net Information: 0 : [6968] Associating MailMessage#33675143 with Message#34640832
System.Net Verbose: 0 : [6968] SmtpClient#2383799::Send(MailMessage#33675143)
System.Net Information: 0 : [6968] SmtpClient#2383799::Send(DeliveryMethod=Network)
System.Net Information: 0 : [6968] Associating SmtpClient#2383799 with MailMessage#33675143
System.Net Information: 0 : [6968] Текущий тип установки операционной системы: Client.
System.Net Verbose: 0 : [6968] ServicePoint#54444047::ServicePoint(smtp.yandex.ru:25)
System.Net Information: 0 : [6968] Associating SmtpTransport#21454193 with SmtpConnection#20234383
System.Net Information: 0 : [6968] Associating SmtpConnection#20234383 with ServicePoint#54444047
System.Net Information: 0 : [6968] SmtpPooledStream#47891719 - Создано подключение с 192.168.1.84:55647 к 213.180.193.38:25.
System.Net Information: 0 : [6968] Associating SmtpConnection#20234383 with SmtpPooledStream#47891719
System.Net Information: 0 : [6968] TlsStream#28372289::.ctor(host=smtp.yandex.ru, #certs=0)
System.Net Information: 0 : [6968] SecureChannel#54024015::.ctor(hostname=smtp.yandex.ru, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [6968] Список пакетов безопасности:
System.Net Information: 0 : [6968]     Negotiate
System.Net Information: 0 : [6968]     NegoExtender
System.Net Information: 0 : [6968]     Kerberos
System.Net Information: 0 : [6968]     NTLM
System.Net Information: 0 : [6968]     Schannel
System.Net Information: 0 : [6968]     Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [6968]     WDigest
System.Net Information: 0 : [6968]     TSSSP
System.Net Information: 0 : [6968]     pku2u
System.Net Information: 0 : [6968]     LiveSSP
System.Net Information: 0 : [6968]     CREDSSP
System.Net Information: 0 : [6968] SecureChannel#54024015 - Осталось 0 клиентских сертификатов для выбора.
System.Net Information: 0 : [6968] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent  = Outbound, scc     = System.Net.SecureCredential)
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Длина In-Buffer=0, длина Out-Buffer=130, возвращенный код=ContinueNeeded).
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 740570:791a98, targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Счетчик In-Buffers=2, длина Out-Buffer=0, возвращенный код=ContinueNeeded).
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 740570:791a98, targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Счетчик In-Buffers=2, длина Out-Buffer=0, возвращенный код=ContinueNeeded).
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 740570:791a98, targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Счетчик In-Buffers=2, длина Out-Buffer=0, возвращенный код=ContinueNeeded).
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 740570:791a98, targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Счетчик In-Buffers=2, длина Out-Buffer=134, возвращенный код=ContinueNeeded).
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 740570:791a98, targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Счетчик In-Buffers=2, длина Out-Buffer=0, возвращенный код=ContinueNeeded).
System.Net Information: 0 : [6968] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 740570:791a98, targetName = smtp.yandex.ru, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [6968] InitializeSecurityContext(Счетчик In-Buffers=2, длина Out-Buffer=0, возвращенный код=OK).
System.Net Information: 0 : [6968] Удаленный сертификат: [Version]
  V3
[Subject]
  E=pki@yandex-team.ru, CN=smtp.yandex.ru, S=Russian Federation, L=Moscow, OU=ITO, O=Yandex LLC, C=RU
  Simple Name: smtp.yandex.ru
  Email Name: pki@yandex-team.ru
  DNS Name: smtp.yandex.ru
[Issuer]
  CN=Yandex CA, OU=Yandex Certification Authority, O=Yandex LLC, C=RU
  Simple Name: Yandex CA
  DNS Name: Yandex CA
[Serial Number]
  78D75518C92D5DB1F4183697D65820F5
[Not Before]
  12.10.2015 15:41:24
[Not After]
  11.10.2017 15:41:24
[Thumbprint]
  B70E6255E13AC0F3081235B29D4B25D0B8C1C639
[Signature Algorithm]
  sha256RSA(1.2.840.113549.1.1.11)
[Public Key]
  Algorithm: RSA
  Length: 2048
  Key Blob: 30 82 01 0a 02 82 01 01 00 df 75 82 48 c2 34 9d 85 2c 07 74 dc 4d 27 ed 93 1f c8 dc 97 64 a4 9b 89 3a 67 d5 13 0d cc 42 31 b7 bc ae f9 04 83 76 ee ec 45 0f 9d fb 4d 98 11 b1 07 72 97 36 3e f7 8a b6 7a 3c b4 6e dd b3 bb a6 c8 b7 85 b5 8d 45 50 f3 42 57 1d 41 99 96 fc 8b 9c 77 c2 10 96 f3 75 83 00 d9 ef d7 ae d5 f5 a6 44 c4 e1 98 d9 a2 88 a2 b5 02 ....
System.Net Information: 0 : [6968] SecureChannel#54024015 - Пользователь признал удаленный сертификат действительным.
System.Net Information: 0 : [6968] ProcessAuthentication(протокол=Tls, шифр=Aes128 128 разрядов, хэш=Sha1 160 разрядов, обмен ключами=44550 256 разрядов).
System.Net Verbose: 0 : [6968] SmtpLoginAuthenticationModule#13869071::Authenticate()
System.Net Verbose: 0 : [6968] Exiting SmtpLoginAuthenticationModule#13869071::Authenticate() 
System.Net Verbose: 0 : [6968] SmtpLoginAuthenticationModule#13869071::Authenticate()
System.Net Verbose: 0 : [6968] Exiting SmtpLoginAuthenticationModule#13869071::Authenticate() 
System.Net Information: 0 : [6968] HeaderCollection#57712780::Set(Content-Transfer-Encoding=base64)
System.Net Information: 0 : [6968] HeaderCollection#57712780::Set(Content-Transfer-Encoding=quoted-printable)
System.Net Information: 0 : [6968] Associating Message#34640832 with HeaderCollection#49652976
System.Net Information: 0 : [6968] HeaderCollection#49652976::Remove(Content-Type)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Set(MIME-Version=1.0)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Remove(Sender)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Remove(Cc)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Remove(Reply-To)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Remove(Bcc)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Get(MIME-Version)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Get(From)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Get(To)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Get(Date)
System.Net Information: 0 : [6968] HeaderCollection#49652976::Get(Subject)
System.Net Information: 0 : [6968] HeaderCollection#57712780::Get(Content-Type)
System.Net Information: 0 : [6968] HeaderCollection#57712780::Get(Content-Transfer-Encoding)
System.Net Information: 0 : [6968] HeaderCollection#57712780::Get(Content-Transfer-Encoding)
System.Net Information: 0 : [6968] HeaderCollection#57712780::Get(Content-Transfer-Encoding)
System.Net Verbose: 0 : [6968] Exiting SmtpClient#2383799::Send() 
System.Net Verbose: 0 : [6968] ConnectionPool::ForceCleanup
System.Net Verbose: 0 : [6968] SmtpPooledStream::Dispose #47891719
System.Net Verbose: 0 : [6968] Exiting SmtpPooledStream::Dispose #47891719
System.Net Verbose: 0 : [6968] Exiting ConnectionPool::ForceCleanup

Моя единственная догадка почему валится аутентификация связана с отсутсвием нужного Authentication Protocol Security Package-а, т.к. заметил что их кол-во не совпадает на двух машинах(на рабочей есть некие дополнительные LiveSSP и wsAuth). Любые идеи приветствуются, заранее спасибо.

READ ALSO
Неочевидное поведение итераторов

Неочевидное поведение итераторов

В одной книге встретил вот такое высказывание:

345
Процесс не может получить доступ к файлу С#

Процесс не может получить доступ к файлу С#

я делаю файловый менеджер на c#У меня возникла проблема(картинка прилагается)

426
OxyPlot LinearAxis конвертировать значение в DateTime

OxyPlot LinearAxis конвертировать значение в DateTime

Строится график значение по х от 0 до 1000Как конвертировать эти значение в DateTime? Нужно чтоб подписи на шкале были не (0, 100, 200

376