简体   繁体   English

Mono上的WebSocket证书(Mac,C#)

[英]WebSocket Certificate on Mono (Mac, C#)

I am trying to create some sort of Push manager, client side, that will listen to what the server has to say. 我正在尝试创建某种推送管理器(客户端),它将听服务器所说的话。

Nothing hard so... I have written it PC side, thanks to WebSocket4Net, on C#, and it works perfectly. 没什么难的...感谢WebSocket4Net,在C#上,我已经在PC端编写了它,并且效果很好。

But here is the issue...: my application has to work on Mac too, using the same code. 但这是问题所在...:我的应用程序也必须在Mac上使用相同的代码运行。 I use Mono obviously, and the WebSocket4Net lib works. 我显然使用Mono,并且WebSocket4Net lib有效。 Unfortunately, every time I try to open a socket, I have a nice " RemoteCertificateNotAvailable ", followed by a " Invalid certificate received from server ". 不幸的是,每次尝试打开套接字时,我都会看到一个漂亮的“ RemoteCertificateNotAvailable ”,然后是一个“ Invalid certificate received from server ”。

Here is what I have tried, following some advices from the web: 以下是我在网上的一些建议下尝试的方法:

webSocket.AllowUntrustedCertificate = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback = callbackValidation;

The code is basic and looks like the one on the web site of the lib: https://websocket4net.codeplex.com 该代码是基本代码,看起来像lib网站上的代码: https : //websocket4net.codeplex.com

I don't know why these solutions do not work. 我不知道为什么这些解决方案不起作用。 Other posts say this should work, and I have no idea why it doesn't here. 其他帖子说这应该工作,我不知道为什么它不在这里。

It CAN work by manually adding trusted certificates to Mono (mozroots --import --sync), or with certmgr, or something like that. 它可以通过将受信任的证书手动添加到Mono(mozroots --import --sync)或使用certmgr或类似方法来工作。 But I don't want this solution, as it needs to work on any other computer than mine without installing anything. 但是我不想要这种解决方案,因为它需要在我的计算机以外的任何其他计算机上工作,而无需安装任何工具。 I can accept running some command in my application that will install some certificates... Let's say I am interested in these solutions. 我可以接受在我的应用程序中运行一些将安装一些证书的命令...假设我对这些解决方案感兴趣。 But I would rather find a solution implying some lines of C# code. 但是我宁愿找到一个暗示一些C#代码行的解决方案。

So... Does anyone have an idea on how to bypass this problem? 那么...有人绕过这个问题有想法吗?

Okay the creator of the WebSocket4Net lib did a fix in august for that actually. 好的,WebSocket4Net库的创建者实际上在8月对此进行了修复。 System.Net.ServicePointManager.ServerCertificateValidationCallback works now. System.Net.ServicePointManager.ServerCertificateValidationCallback现在可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM