我这是怎么产生我的SSL证书,密钥等:SSL证书,而不是通过节俭验证,但是OK通过浏览器
openssl genrsa -out server.key 1024
openssl rsa -in server.key -out new_key.pem
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 10000 -in server.csr -signkey new_key.pem -out server.crt
这工作,我可以在Chrome中看到输出,虽然我得到一个警告我要先获取病毒。
openssl s_server -cert server.crt -www -key new_key.pem
这是服务器的一个片段。我会说实话,我不知道到底是什么每一行正在做,但我有一个好主意:
socketFactory->server(true); // this is the server
socketFactory->authenticate(false); // no auth?
socketFactory->loadCertificate("server.crt");
socketFactory->loadPrivateKey("new_key.pem");
客户端:
socketFactory->loadTrustedCertificates("server.crt");
socketFactory->authenticate(true); //auth? wierd, right? This guy does this:[1]
[1] http://permalink.gmane.org/gmane.comp.lib.thrift.user/1651
如果我在客户端注释掉loadTrustedCertificates
,然后我得到一个SSL未验证的证书异常。 留下这条线,我得到一个auth失败异常。
这里有2个更长的代码片段,这些代码片段可以更好地展示上面的代码片断。
服务器:
shared_ptr<SkullduggeryHandler> handler(new SkullduggeryHandler());
shared_ptr<TBufferedTransportFactory> transportFactory =
shared_ptr<TBufferedTransportFactory>(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
shared_ptr<TProcessor> processor(new SkullduggeryProcessor(handler));
shared_ptr<TSSLSocketFactory> socketFactory =
shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
socketFactory->server(true);
socketFactory->authenticate(false);
socketFactory->loadCertificate("server.crt");
socketFactory->loadPrivateKey("new_key.pem");
shared_ptr<TSSLServerSocket> socket(new TSSLServerSocket(port, socketFactory));
TThreadedServer server(processor,
socket,
transportFactory,
protocolFactory);
server.serve();
客户端:
shared_ptr <TSSLSocketFactory> socketFactory = shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
socketFactory->loadTrustedCertificates("server.crt");
socketFactory->authenticate(false);
shared_ptr <TSSLSocket>socket = socketFactory->createSocket(configuration.ip, configuration.port);
shared_ptr<TBufferedTransport> transport(new TBufferedTransport(socket));
shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
SkullduggeryClient client(protocol);
transport->open();
感谢您抽出宝贵的时间来阅读。如果有明显的错误,我会很高兴听到它。这一直是我现在已经很久的诅咒。太长。