📄 alltests.cpp
字号:
d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem"; d["IceSSL.VerifyPeer"] = "2"; server = fact->createServer(d); try { IceSSL::CertificatePtr clientCert = IceSSL::Certificate::load(defaultDir + "/c_rsa_nopass_ca1_pub.pem"); server->checkCert(clientCert->getSubjectDN(), clientCert->getIssuerDN()); } catch(const LocalException&) { test(false); } fact->destroyServer(server); comm->destroy(); // // Test IceSSL.VerifyPeer=1. This should fail because the // client doesn't trust the server's CA. // initData.properties->setProperty("IceSSL.CertAuthFile", "cacert2.pem"); initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca2_pub.pem"); initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca2_priv.pem"); comm = initialize(initData); fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); d = createServerProps(defaultDir, defaultHost); d["IceSSL.CertAuthFile"] = "cacert1.pem"; d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem"; d["IceSSL.VerifyPeer"] = "1"; server = fact->createServer(d); try { server->ice_ping(); test(false); } catch(const ProtocolException&) { // Expected. }#ifdef _WIN32 catch(const ConnectionLostException&) { // Expected. }#endif catch(const LocalException&) { test(false); } fact->destroyServer(server); comm->destroy(); // // Test IceSSL.VerifyPeer=1. This should fail because the // server doesn't trust the client's CA. // initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem"); initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca2_pub.pem"); initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca2_priv.pem"); comm = initialize(initData); fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); d = createServerProps(defaultDir, defaultHost); d["IceSSL.CertAuthFile"] = "cacert1.pem"; d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem"; d["IceSSL.VerifyPeer"] = "1"; server = fact->createServer(d); try { server->ice_ping(); test(false); } catch(const ProtocolException&) { // Expected. }#ifdef _WIN32 catch(const ConnectionLostException&) { // Expected. }#endif catch(const LocalException&) { test(false); } fact->destroyServer(server); comm->destroy(); // // Verify that IceSSL.CheckCertName has no effect in a server. // initData.properties = createClientProps(defaultDir, defaultHost); initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem"); initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem"); initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem"); comm = initialize(initData); fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); d = createServerProps(defaultDir, defaultHost); d["IceSSL.CertAuthFile"] = "cacert1.pem"; d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem"; d["IceSSL.CheckCertName"] = "1"; server = fact->createServer(d); try { server->ice_ping(); } catch(const LocalException&) { test(false); } fact->destroyServer(server); comm->destroy(); } cout << "ok" << endl; cout << "testing custom certificate verifier... " << flush; { // // ADH is allowed but will not have a certificate. // InitializationData initData; initData.properties = createClientProps(defaultDir, defaultHost); initData.properties->setProperty("IceSSL.Ciphers", "ADH"); initData.properties->setProperty("IceSSL.VerifyPeer", "0"); CommunicatorPtr comm = initialize(initData); IceSSL::PluginPtr plugin = IceSSL::PluginPtr::dynamicCast(comm->getPluginManager()->getPlugin("IceSSL")); test(plugin); CertificateVerifierIPtr verifier = new CertificateVerifierI; plugin->setCertificateVerifier(verifier); Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); Test::Properties d = createServerProps(defaultDir, defaultHost); d["IceSSL.Ciphers"] = "ADH"; d["IceSSL.VerifyPeer"] = "0"; Test::ServerPrx server = fact->createServer(d); try { string cipherSub = "ADH-"; server->checkCipher(cipherSub); IceSSL::ConnectionInfo info = IceSSL::getConnectionInfo(server->ice_getConnection()); test(info.cipher.compare(0, cipherSub.size(), cipherSub) == 0); } catch(const LocalException&) { test(false); } test(verifier->invoked()); test(!verifier->hadCert()); // // Have the verifier return false. Close the connection explicitly // to force a new connection to be established. // verifier->reset(); verifier->returnValue(false); server->ice_getConnection()->close(false); try { server->ice_ping(); test(false); } catch(const SecurityException&) { // Expected. } catch(const LocalException&) { test(false); } test(verifier->invoked()); test(!verifier->hadCert()); fact->destroyServer(server); comm->destroy(); } { // // Verify that a server certificate is present. // InitializationData initData; initData.properties = createClientProps(defaultDir, defaultHost); initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem"); initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem"); initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem"); initData.properties->setProperty("IceSSL.VerifyPeer", "0"); CommunicatorPtr comm = initialize(initData); IceSSL::PluginPtr plugin = IceSSL::PluginPtr::dynamicCast(comm->getPluginManager()->getPlugin("IceSSL")); test(plugin); CertificateVerifierIPtr verifier = new CertificateVerifierI; plugin->setCertificateVerifier(verifier); Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); Test::Properties d = createServerProps(defaultDir, defaultHost); d["IceSSL.CertAuthFile"] = "cacert1.pem"; d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem"; d["IceSSL.VerifyPeer"] = "2"; Test::ServerPrx server = fact->createServer(d); try { server->ice_ping(); } catch(const LocalException&) { test(false); } test(verifier->invoked()); test(verifier->hadCert()); fact->destroyServer(server); comm->destroy(); } cout << "ok" << endl; cout << "testing protocols... " << flush; { // // This should fail because the client and server have no protocol // in common. // InitializationData initData; initData.properties = createClientProps(defaultDir, defaultHost); initData.properties->setProperty("IceSSL.Ciphers", "ADH"); initData.properties->setProperty("IceSSL.VerifyPeer", "0"); initData.properties->setProperty("IceSSL.Protocols", "ssl3"); CommunicatorPtr comm = initialize(initData); Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); Test::Properties d = createServerProps(defaultDir, defaultHost); d["IceSSL.Ciphers"] = "ADH"; d["IceSSL.VerifyPeer"] = "0"; d["IceSSL.Protocols"] = "tls1"; Test::ServerPrx server = fact->createServer(d); try { server->ice_ping(); test(false); } catch(const ProtocolException&) { // Expected on some platforms. } catch(const ConnectionLostException&) { // Expected on some platforms. } catch(const LocalException&) { test(false); } fact->destroyServer(server); comm->destroy(); // // This should succeed. // comm = initialize(initData); fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); d = createServerProps(defaultDir, defaultHost); d["IceSSL.Ciphers"] = "ADH"; d["IceSSL.VerifyPeer"] = "0"; d["IceSSL.Protocols"] = "tls1, ssl3"; server = fact->createServer(d); try { server->ice_ping(); } catch(const LocalException&) { test(false); } fact->destroyServer(server); comm->destroy(); } cout << "ok" << endl; cout << "testing expired certificates... " << flush; { // // This should fail because the server's certificate is expired. // { IceSSL::CertificatePtr cert = IceSSL::Certificate::load(defaultDir + "/s_rsa_nopass_ca1_exp_pub.pem"); test(!cert->checkValidity()); } InitializationData initData; initData.properties = createClientProps(defaultDir, defaultHost); initData.properties->setProperty("IceSSL.CertAuthFile", "cacert1.pem"); initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_pub.pem"); initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_priv.pem"); CommunicatorPtr comm = initialize(initData); Test::ServerFactoryPrx fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); Test::Properties d = createServerProps(defaultDir, defaultHost); d["IceSSL.CertAuthFile"] = "cacert1.pem"; d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_exp_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_exp_priv.pem"; Test::ServerPrx server = fact->createServer(d); try { server->ice_ping(); test(false); } catch(const ProtocolException&) { // Expected. }#ifdef _WIN32 catch(const ConnectionLostException&) { // Expected. }#endif catch(const LocalException& ex) { cerr << ex << endl; test(false); } fact->destroyServer(server); comm->destroy(); // // This should fail because the client's certificate is expired. // { IceSSL::CertificatePtr cert = IceSSL::Certificate::load(defaultDir + "/c_rsa_nopass_ca1_exp_pub.pem"); test(!cert->checkValidity()); } initData.properties->setProperty("IceSSL.CertFile", "c_rsa_nopass_ca1_exp_pub.pem"); initData.properties->setProperty("IceSSL.KeyFile", "c_rsa_nopass_ca1_exp_priv.pem"); comm = initialize(initData); fact = Test::ServerFactoryPrx::checkedCast(comm->stringToProxy(factoryRef)); test(fact); d = createServerProps(defaultDir, defaultHost); d["IceSSL.CertAuthFile"] = "cacert1.pem"; d["IceSSL.CertFile"] = "s_rsa_nopass_ca1_pub.pem"; d["IceSSL.KeyFile"] = "s_rsa_nopass_ca1_priv.pem"; server = fact->createServer(d); try { server->ice_ping(); test(false); } catch(const ProtocolException&) { // Expected. }#ifdef _WIN32 catch(const ConnectionLostException&) { // Expected. }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -