简体   繁体   English

在.NET Compact Framework 3.5上实现TLS 1.2

[英]Implement TLS 1.2 on .NET Compact Framework 3.5

I invested practically a whole working day in figuring out how to approach the task mentioned in the title best. 我花了整整一个工作日来确定如何处理标题中提到的最佳任务。

Here is what I found out so far: 这是我到目前为止发现的:

  1. There's at least one library that offers TLS 1.2 for .NET CF out of the box. 至少有一个库为开箱即用的.NET CF提供TLS 1.2。 The downside: they charge for a license. 缺点:他们收取许可费。 In case someone's interested in this easy solution, Rebex Library 如果有人对这个简单的解决方案感兴趣, Rebex Library

  2. There are several SSL/TLS libraries out there that allow to communicate with the server on a lower level. 有几个SSL / TLS库允许在较低级别与服务器通信。 My approach was to get to compile the BouncyCastle library for the .NET Compact Framework which I accomplished. 我的方法是为我完成的.NET Compact Framework编译BouncyCastle库。

From here on out I found an article that showed me how to implement the BouncyCastle interfaces and how to put the pieces together. 从现在开始,我发现了一篇文章,向我展示了如何实现BouncyCastle接口以及如何将各个部分组合在一起。 See Making HTTPS call in C# with the BouncyCastle library for more information. 有关详细信息,请参阅使用BouncyCastle库在C#中进行HTTPS调用 This is pretty much how my code looks right now. 这几乎就是我的代码现在的样子。

I accomplished to establish a connection with the server and sent a request and I also got the expected response. 我完成了与服务器建立连接并发送请求,我也得到了预期的响应。 I then wanted to leverage the HttpWebRequest class so I don't have to code the HTTP requests myself. 然后我想利用HttpWebRequest类,所以我不必自己编写HTTP请求。 Or so I thought. 或者我想。 Not possible. 不可能。 HttpWebRequest doesn't have public constructors. HttpWebRequest没有公共构造函数。 Therefore I cannot inherit from that class. 因此我无法继承该课程。 I also tried using RestSharp for example but this is also only relying on the WebRequest class. 我也尝试过使用RestSharp,但这也只是依赖于WebRequest类。 Basically all the HTTP clients available out there take the Uri and then open a stream themselves. 基本上所有可用的HTTP客户端都使用Uri,然后自己打开一个流。 Not a single one seems to take an already open stream and writes to it or offers to drop in some crypto API to use instead of what the platform offers by default (other than the mentioned Rebex library of course). 没有一个似乎采用已经打开的流并写入它或提供放入一些加密API而不是平台默认提供的内容(当然除了提到的Rebex库)。

So my question is: is there any HTTP client that can write HTTP commands to an already open stream or at least give me a string representation of what I set on it? 所以我的问题是:是否有任何HTTP客户端可以将HTTP命令写入已经打开的流中,或者至少给我一个字符串表示我在其上设置的内容? Or do I have to really code something like that myself even though there's a ton of these implementations out there already? 或者我必须自己编写类似的东西,即使已经有大量的这些实现了吗? Or am I completely missing a point and it can be solved way easier? 或者我完全错过了一点,它可以更容易解决?

Based upon your research, could you setup a kind of proxy within your CF app? 根据您的研究,您可以在CF应用程序中设置一种代理吗?

Use HttpWebRequest and response in the rest of your app, but direct them to your internal proxy (at 127.0.0.1). 在应用程序的其余部分使用HttpWebRequest和响应,但将它们指向您的内部代理(127.0.0.1)。

The proxy would deal with the TLS connection, and then it uses a socket listener to intercept the HTTP requests from your HttpWebRequest, but is doesn't need to parse them out, just forward them along your already open socket. 代理将处理TLS连接,然后它使用套接字侦听器拦截来自HttpWebRequest的HTTP请求,但是不需要解析它们,只需将它们沿着已经打开的套接字转发。 Likewise, return TCP traffic would be sent back from the real host and to the local socket (again it is not parsed, just treated as a buffer). 同样,返回TCP流量将从真实主机发送回本地套接字(同样,它不会被解析,只被视为缓冲区)。

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

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