- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发一个需要通过套接字与客户端通信的服务器应用程序。在初始数据交换后的连接中间,客户端需要通过套接字建立安全连接。
所以我启动了安全连接,比如调用 StartupSSLHandshake() 方法;
private void StartupSSLHandshake()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
using (var networkStream = new NetworkStream(this.Connection._Socket, true))
{
this.SSLStream = new SslStream(networkStream, false);
try
{
this.SSLStream.AuthenticateAsServer(CertificateHelper.Certificate, true, SslProtocols.Tls, true);
Console.WriteLine("Cipher: {0} strength {1}", SSLStream.CipherAlgorithm, SSLStream.CipherStrength);
Console.WriteLine("Hash: {0} strength {1}", SSLStream.HashAlgorithm, SSLStream.HashStrength);
Console.WriteLine("Key exchange: {0} strength {1}", SSLStream.KeyExchangeAlgorithm, SSLStream.KeyExchangeStrength);
Console.WriteLine("Protocol: {0}", SSLStream.SslProtocol);
}
catch(AuthenticationException e)
{
Logger.FatalException(e, "Certificate exception");
}
}
}
此外,我在运行时使用 http://blogs.msdn.com/b/dcook/archive/2008/11/25/creating-a-self-signed-certificate-in-c.aspx 生成我的服务器证书
这是我的 CertificateHelper 类,它会在需要时生成它:
public static class CertificateHelper
{
public const string SertificateFile = "cert.pfx";
public static X509Certificate Certificate = null;
static CertificateHelper()
{
if (!CertificateExists())
Create();
Certificate = new X509Certificate2(SertificateFile, "mypassword");
}
private static void Create()
{
byte[] certificate = CertificateCreator.CreateSelfSignCertificatePfx("CN=mydomain.org", DateTime.Parse("2011-01-01"), DateTime.Parse("2013-01-01"), "mypassword");
using (var writer = new BinaryWriter(File.Open(SertificateFile, FileMode.Create)))
{
writer.Write(certificate);
}
}
public static bool CertificateExists()
{
return File.Exists(SertificateFile);
}
}
因此,当我尝试针对客户端(可能正在使用 OpenSSL 库)运行它时,无论我尝试什么,我都会得到“客户端和服务器无法通信,因为它们不具备通用算法”异常;
[15.11.2011 11:01:06.771] [Fatal] [Server]: Certificate exception - [Exception] System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm
--- End of inner exception stack trace ---
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
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.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
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.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsServer(X509Certificate serverCertificate, Boolean clientCertificateRequired, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at Server.StartupSSLHandshake() in xyz.cs:line 293
所以我启用了套接字跟踪,这是输出;
System.Net Information: 0 : [4828] SecureChannel#60869981::.ctor(hostname=?124, #clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [4828] Enumerating security packages:
System.Net Information: 0 : [4828] Negotiate
System.Net Information: 0 : [4828] NegoExtender
System.Net Information: 0 : [4828] Kerberos
System.Net Information: 0 : [4828] NTLM
System.Net Information: 0 : [4828] Schannel
System.Net Information: 0 : [4828] Microsoft Unified Security Protocol Provider
System.Net Information: 0 : [4828] WDigest
System.Net Information: 0 : [4828] TSSSP
System.Net Information: 0 : [4828] pku2u
System.Net Information: 0 : [4828] CREDSSP
System.Net.Sockets Verbose: 0 : [4828] Socket#5655257::Receive()
System.Net.Sockets Verbose: 0 : [4828] Data from Socket#5655257::Receive
System.Net.Sockets Verbose: 0 : [4828] 00000000 : 16 03 01 00 3B : ....;
System.Net.Sockets Verbose: 0 : [4828] Exiting Socket#5655257::Receive() -> 5#5
System.Net.Sockets Verbose: 0 : [4828] Socket#5655257::Receive()
System.Net.Sockets Verbose: 0 : [4828] Data from Socket#5655257::Receive
System.Net.Sockets Verbose: 0 : [4828] 00000005 : 01 00 00 37 03 01 4E C2-2A 52 03 2A 4F BC 0F 94 : ...7..N.*R.*O...
System.Net.Sockets Verbose: 0 : [4828] 00000015 : E2 AE B5 1D 99 1A 21 D3-DF 6C 16 47 71 23 D0 F3 : ......!..l.Gq#..
System.Net.Sockets Verbose: 0 : [4828] 00000025 : AD E9 A9 3F 22 E8 00 00-0A 00 8D 00 8B 00 8C 00 : ...?"...........
System.Net.Sockets Verbose: 0 : [4828] 00000035 : 8A 00 FF 01 00 00 04 00-23 00 00 : ........#..
System.Net.Sockets Verbose: 0 : [4828] Exiting Socket#5655257::Receive() -> 59#59
System.Net Information: 0 : [4828] SecureChannel#60869981 - Locating the private key for the certificate: [Version]
V3
[Subject]
CN=mydomain.org
Simple Name: mydomain.org
DNS Name: mydomain.org
[Issuer]
CN=mydomain.org
Simple Name: mydomain.org
DNS Name: mydomain.org
[Serial Number]
2C7ECC7CAEB576AB48F47A5F356D5B61
[Not Before]
01.01.2011 00:00:00
[Not After]
01.01.2013 00:00:00
[Thumbprint]
5DA4607C89339CB550DF52A2608B9ABFBFFC90EB
[Signature Algorithm]
sha1RSA(1.2.840.113549.1.1.5)
[Public Key]
Algorithm: RSA
Length: 1024
Key Blob: 30 81 89 02 81 81 00 a9 e8 b1 cc 71 e5 7e 1a c8 ba bc c9 32 bb e3 b3 f3 66 d6 9b bb 3d b8 41 0d ef 45 06 cc f5 49 bf 10 7a 39 28 60 e5 33 93 b1 d1 78 f6 97 fc 28 c5 cc 66 28 db 43 8a 8e 26 39 cb 84 c9 fe 96 a7 83 e8 f7 03 37 6a 91 fe 36 1c bf 66 5e 1e 2e 41 62 3f 41 ab d9 cf ac 4d 4c cd 79 3d ab 97 9d ce 57 ec 60 bb f8 65 d8 ad 5d 24 0a e2 a0 33 9e 7d 01 41 77 7a 0d 0e 13 36 dc ee 16 eb 35 ab 89 2c 11 02 03 01 00 01
Parameters: 05 00
[Private Key]
Key Store: User
Provider Name: Microsoft Enhanced Cryptographic Pro....
System.Net Information: 0 : [4828] SecureChannel#60869981 - Certificate is of type X509Certificate2 and contains the private key.
System.Net Information: 0 : [4828] AcquireCredentialsHandle(package = Microsoft Unified Security Protocol Provider, intent = Inbound, scc = System.Net.SecureCredential)
System.Net Information: 0 : [4828] AcceptSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), inFlags = MutualAuth, ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitIntegrity)
System.Net Information: 0 : [4828] AcceptSecurityContext(In-Buffer length=64, Out-Buffer length=0, returned code=AlgorithmMismatch).
System.Net.Sockets Verbose: 0 : [4828] Socket#5655257::Dispose()
它告诉我 AlgorithmMismatch;
System.Net 信息:0:[4828] AcceptSecurityContext(缓冲区内长度=64,缓冲区外长度=0,返回代码=AlgorithmMismatch)。
进一步发现客户使用了这款削片机;
SSLStream 是否支持这些?
最佳答案
Windows 不支持任何 TLS_PSK 密码套件,因此服务器与客户端没有共同的算法。如果您可以将客户端配置为使用非基于 PSK 的密码套件,您就可以正常工作。
PSK代表“PreShared Key”,因此这些都是使用共享 key (如密码)建立TLS channel 的证书。此类 TLS 连接不需要证书,但 Windows 不支持此功能。
关于c# - SSLStream.AuthenticateAsServer "The client and server cannot communicate, because they do not possess a common algorithm",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8133967/
本周我将在 Windows Server 2008 上设置一个专用的 SQL Server 2005 机器,并希望将其精简为尽可能简单,同时仍能发挥全部功能。 为此,“服务器核心”选项听起来很有吸引力
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 8 年前。 Improve
我获取了 2014 版本数据库的备份,并尝试在另一台服务器中将其恢复到具有相同名称和登录名的数据库中。此 SQL Server 版本是 2016。 恢复备份文件时,出现此错误: TITLE: Micr
我获取了 2014 版本数据库的备份,并尝试在另一台服务器中将其恢复到具有相同名称和登录名的数据库中。此 SQL Server 版本是 2016。 恢复备份文件时,出现此错误: TITLE: Micr
TFS 是否提供任何增强的方法来存储对 sql server 数据库所做的更改,而不是使用它来对在数据库上执行的 sql 语句的文本文件进行版本控制? 或者我正在寻找的功能是否仅在第 3 方工具(如
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我即将将我的 SQL Server 2012 实例升级到 SQL Server 2014。 我已经克隆了主机 Windows VM 并将其重命名为 foo-2012至 foo-2014 . 重新启动时
我想为 SQL Server 登录授予对数据库的访问权限。我知道 sp_grantdbaccess,但它已被弃用。我可以改用什么以及如何检查登录名是否还没有访问数据库的权限? 场景:UserA 创建数
客户别无选择,只能在接下来的几天内从 sql server 2000 迁移到 2008。测试显示 2005 年的重要功能出现了 Not Acceptable 性能下降,但 2008 年却没有。好消息是
我有一个测试数据库,我需要将其导出到我们客户的测试环境中。 这将是一次性的工作。 我正在使用 SQL Server 2005(我的测试数据库是 SQL Server 2005 Express) 执行此
我需要将一个 CSV 文件导入到 mongoDB 不幸的是我遇到了以下错误: error connecting to host: could not connect to server: se
我以为 R2 是一个补丁/服务包。我一直在寻找下载,但没有看到。因此,我假设 R2 是一个新版本,并且我需要 sqlserver 2008 r2 的安装介质来进行升级? 另外,我需要为新许可证付费吗?
我无法使用 SQL Server Management Studio 连接到 SQL Server。 我有一个连接字符串: 我尝试通过在服务器名中输入 myIP、在登录名中输入 MyID、在密码中
我们希望使用 SQL Server 加密来加密数据库中的几个列。我们还需要在生产和测试环境之间传输数据。看来最好的解决方案是在生产和测试服务器上使用相同的主 key 、证书和对称 key ,以便我可以
有没有可以分析 SQL Server 数据库潜在问题的工具? 例如: a foreign key column that is not indexed 没有 FILL FACTOR 的 uniquei
我正在尝试从我的 SQL 2012 BI 版本建立复制,但我收到一条奇怪的错误消息! "You cannot create a publication from server 'X' because
如果您使用 SQL Server 身份验证 (2005),登录详细信息是否以明文形式通过网络发送? 最佳答案 如您所愿,安全无忧... 您可以相当轻松地配置 SSL,如果您没有受信任的证书,如果您强制
我想将数据从一个表复制到不同服务器之间的另一个表。 如果是在同一服务器和不同的数据库中,我使用了以下 SELECT * INTO DB1..TBL1 FROM DB2..TBL1 (to copy w
我希望得到一些帮助,因为我在这个问题上已经被困了 2 天了! 场景:我可以从我的开发计算机(和其他同事)连接到 SERVER\INSTANCE,但无法从另一个 SQL Server 连接。我得到的错误
我正在尝试从我的 SQL 2012 BI 版本建立复制,但我收到一条奇怪的错误消息! "You cannot create a publication from server 'X' because
我是一名优秀的程序员,十分优秀!