请考虑以下代码:
require 'net/https'
uri = URI.parse("https://host/index.html")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.path)
response = http.request(request)
Run Code Online (Sandbox Code Playgroud)
其中https://host/index.html是服务器上的证书无效的有效地址.
在旧版本的ruby(特别是1.8.7-p334和1.9.2-p180)上,这段代码运行正常.在所有最新版本(1.8.7-p352,1.9.2-p290和1.9.3-p0)中,它抛出以下异常:
OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=unknown state
Run Code Online (Sandbox Code Playgroud)
在最后一行.
更改verify_mode以OpenSSL::SSL::VERIFY_PEER准确提供错误,表明它正在尝试验证证书,尽管设置.
我如何说服ruby忽略无效证书并连接?
我有一个测试环境,使用Ruby通过https连接驱动服务器.由于最新版本的Ruby拒绝连接到具有无效证书的https服务器(请参阅我之前的这个问题)并且我想开始使用更新版本的Ruby,我正在尝试设置有效的证书.
我已创建了一个要使用的CA证书(有多个服务器正在测试,因此这似乎更容易),并且已成功使用它来签署已安装在服务器上并正在使用的新证书.我已将CA证书添加到浏览器商店,它(浏览器)现在将连接到服务器而无需投诉.所以我相信我的证书是有效的并且设置正确.
我知道Ruby不会使用与浏览器相同的商店.我使用此处提供的CA文件来测试连接到其他(公共)服务器(使用该Net::HTTP#ca_file=方法设置),这也有效.
我无法工作的是Ruby使用我的证书连接到我的服务器.我已经尝试了各种方法将它指向我的证书(包括将我的证书添加到上面链接的文件),它总是给出相同的错误:
SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (OpenSSL::SSL::SSLError)
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能说服Ruby接受我的证书并连接到我的服务器?
我使用的代码是:
require 'net/https'
uri = URI.parse("https://hostname/index.html")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = "My CA cert file"
request = Net::HTTP::Get.new(uri.path)
response = http.request(request)
Run Code Online (Sandbox Code Playgroud)
我假设这是错误的.我想知道的是,我该怎么做才能使用我的CA证书?
我正在尝试编写一个简单的(玩具)程序,它使用NSFilePresenter和NSFileCoordinator方法来监视文件的变化.
该程序包含一个文本视图,用于加载(硬编码)文本文件和一个按钮,该文件将保存文件并进行任何更改.我的想法是我有两个实例正在运行,并且在一个实例中保存将导致另一个实例重新加载已更改的文件.
加载和保存文件工作正常,但从不调用NSFilePresenter方法.它都基于一个名为FileManager的类,它实现了NSFilePresenter协议.代码如下:
接口:
@interface FileManager : NSObject <NSFilePresenter>
@property (unsafe_unretained) IBOutlet NSTextView *textView;
- (void) saveFile;
- (void) reloadFile;
@end
Run Code Online (Sandbox Code Playgroud)
执行:
@implementation FileManager
{
NSOperationQueue* queue;
NSURL* fileURL;
}
- (id) init {
self = [super init];
if (self) {
self->queue = [NSOperationQueue new];
self->fileURL = [NSURL URLWithString:@"/Users/Jonathan/file.txt"];
[NSFileCoordinator addFilePresenter:self];
}
return self;
}
- (NSURL*) presentedItemURL {
NSLog(@"presentedItemURL");
return self->fileURL;
}
- (NSOperationQueue*) presentedItemOperationQueue {
NSLog(@"presentedItemOperationQueue");
return self->queue;
}
- (void) saveFile {
NSFileCoordinator* coordinator = [[NSFileCoordinator alloc] …Run Code Online (Sandbox Code Playgroud)