这是我生成我的SSL证书,密钥等:
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证书例外。 随着该行留在,我得到一个身份验证失败例外。
这里有两个长得多的代码片段,是把上面的代码片段更好的角度。
服务器:
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();
感谢您抽时间阅读。 如果有明显的错误,我会很高兴听到它。 这一直是我的存在性的祸根太久了。 太长。