Статус: Новичок
Группы: Участники
Зарегистрирован: 08.04.2026(UTC) Сообщений: 4 
|
Подскажите, куда копать? Взял код C# для .NET из примера: https://dss.cryptopro.ru/libcore/docs/04-%D0%BF%D1%80%D0%B8%D0%BC%D0%B5%D1%80%D1%8B/04-07-tls-get.htmlМашина под Windows 10. КриптоПро установлен, с лицензиями: CSP 5.0.13600, TSP Client 2.0, OCSP Client 2.0 Проект на VS2022. В проект добавлены пакеты CryptoPro: Цитата:<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <IsPackable>false</IsPackable> </PropertyGroup>
<ItemGroup> <PackageReference Include="CryptoPro.Net.Security" Version="2026.2.18" /> <PackageReference Include="CryptoPro.Security.Cryptography" Version="2026.2.18" /> <PackageReference Include="CryptoPro.Security.Cryptography.Pkcs" Version="2026.2.18" /> <PackageReference Include="CryptoPro.Security.Cryptography.Xml" Version="2026.2.18" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="xunit.v3" Version="3.2.2" /> </ItemGroup>
<ItemGroup> <Using Include="Xunit" /> </ItemGroup>
</Project> Контейнер ключа - в системном реестре. Непонятно только откуда будет браться пароль от контейнера. В любом случае его и не спрашивает и TLS не устанавливает. Падает с ошибкой: Цитата://Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll //'GpbGate_xUnit.exe'(CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.16\System.IO.MemoryMappedFiles.dll'.Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. //System.Net.Http.HttpRequestException: Received an unexpected EOF or 0 bytes from the transport stream. (test.bank.ru:443) // --->System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream. // at CryptoPro.Net.Security.SslStreamEx.< FillHandshakeBufferAsync > g__InternalFillHandshakeBufferAsync | 189_0[TIOAdapter](TIOAdapter adap, ValueTask`1 task, Int32 minSize) // at CryptoPro.Net.Security.SslStreamEx.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter) // at CryptoPro.Net.Security.SslStreamEx.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm) // at CryptoPro.Net.Http.CpHttpHandler.EstablishSslStreamAsync(CpSslClientAuthenticationOptions options, Stream innerStream, Uri originAuthority, CancellationToken cancellationToken) // at CryptoPro.Net.Http.CpHttpHandler.ConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken) // at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) // -- - End of inner exception stack trace-- - // at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken) // at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) // at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) // at System.Net.Http.HttpConnectionPool.InjectNewHttp11ConnectionAsync(QueueItem queueItem) // at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken) // at System.Net.Http.HttpConnectionWaiter`1.WaitForConnectionWithTelemetryAsync(HttpRequestMessage request, HttpConnectionPool pool, Boolean async, CancellationToken requestCancellationToken) // at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) // at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) // at System.Net.Http.HttpClient.< SendAsync > g__Core | 83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) // at GpbGate_xUnit.UnitTest1.Twotls() in D: \Users\s.shirokov\Documents\ProjectsCode\Crypto\GpbGate_xUnit\UnitTest1.cs:line 328
Для проверки выполняю Цитата:csptest -tlsc -server test.bank.ru -user 43d767c8261ccdc8e811df1730c33a0786d071f8 -verbose с тем же сертификатом. Выполняется успешно, выбрасывает окошко для ввода пароля контейнера, выполняет TLS рукопожатие и устанавливает соединение. Цитата:Protocol version: 3.3 ClientHello: RecordLayer: TLS, Len: 116 SessionId: (empty) Cipher Suites: (c1 00) (c1 01) (c1 02) (ff 85) (00 81) 121 bytes of handshake data sent 1460 bytes of handshake data received 1126 bytes of handshake data received 2218 bytes of handshake data sent 31 bytes of handshake data received Handshake was successful SECPKG_ATTR_SESSION_INFO: Reuse: 0, SessionId: 6a14128c26b8bf21e0afe4339abf8c3c0643981cb64197a9e1a2f63955d182f9
SECPKG_ATTR_CIPHER_INFO: Version: 1 SECPKG_ATTR_CIPHER_INFO: Protocol: 303 SECPKG_ATTR_CIPHER_INFO: CipherSuite: ff85, TLS_GOSTR341112_256_WITH_28147_CNT_IMIT SECPKG_ATTR_CIPHER_INFO: BaseCipherSuite: ff85 SECPKG_ATTR_CIPHER_INFO: Cipher: GOST 28147-89, Len: 256, BlockLen: 1 SECPKG_ATTR_CIPHER_INFO: Hash: GR 34.11-2012 256, Len: 256 SECPKG_ATTR_CIPHER_INFO: Exchange: GOST DH 34.10-2012 512, MinLen: 1024, MaxLen: 1024 SECPKG_ATTR_CIPHER_INFO: Certificate: GR 34.10-2012 512, KeyType: 26
SECPKG_ATTR_CONNECTION_INFO: Protocol: 0x800 (TLS 1.2) SECPKG_ATTR_CONNECTION_INFO: Cipher: 0x661e (GOST 28147-89) SECPKG_ATTR_CONNECTION_INFO: Cipher strength: 256 SECPKG_ATTR_CONNECTION_INFO: Hash: 0x8021 (GOST R 34.11-2012 (256)) SECPKG_ATTR_CONNECTION_INFO: Hash strength: 256 SECPKG_ATTR_CONNECTION_INFO: Exch: 0xaa43 (GOST R 34.10-2012 (512) Ephemeral) SECPKG_ATTR_CONNECTION_INFO: Key exchange strength: 1024
SECPKG_ATTR_KEY_INFO: KeySize: 256 SECPKG_ATTR_KEY_INFO: SignatureAlgorithm: 0x2e3d, Name: GOST R 34.11 2012 512 SECPKG_ATTR_KEY_INFO: EncryptAlgorithm: 0x661e, Name: GOST 28147-89
SECPKG_ATTR_SUPPORTED_SIGNATURES: Supported signatures: (ee ee) (ef ef) (ed ed)
|