+
+
+using Poco::Net::SecureServerSocket;
+using Poco::Net::HTTPRequestHandler;
+using Poco::Net::HTTPRequestHandlerFactory;
+using Poco::Net::HTTPServer;
+using Poco::Net::HTTPServerRequest;
+using Poco::Net::HTTPServerResponse;
+using Poco::Net::HTTPServerParams;
+using Poco::Timestamp;
+using Poco::DateTimeFormatter;
+using Poco::DateTimeFormat;
+using Poco::SharedPtr;
+using Poco::Util::ServerApplication;
+using Poco::Util::Application;
+using Poco::Util::Option;
+using Poco::Util::OptionSet;
+using Poco::Util::HelpFormatter;
+using Poco::Net::SSLManager;
+using Poco::Net::Context;
+using Poco::Net::KeyConsoleHandler;
+using Poco::Net::PrivateKeyPassphraseHandler;
+using Poco::Net::InvalidCertificateHandler;
+using Poco::Net::AcceptCertificateHandler;
+
+
+class TimeRequestHandler: public HTTPRequestHandler
+ /// Return a HTML document with the current date and time.
+{
+public:
+ TimeRequestHandler(const std::string& format):
+ _format(format)
+ {
+ }
+
+ void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ Application& app = Application::instance();
+ app.logger().information("Request from " + request.clientAddress().toString());
+
+ Timestamp now;
+ std::string dt(DateTimeFormatter::format(now, _format));
+
+ response.setChunkedTransferEncoding(true);
+ response.setContentType("text/html");
+
+ std::ostream& ostr = response.send();
+ ostr << "HTTPTimeServer powered by C++ Portable Components";
+ ostr << "";
+ ostr << "";
+ ostr << dt;
+ ostr << "
";
+ }
+
+private:
+ std::string _format;
+};
+
+
+class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
+{
+public:
+ TimeRequestHandlerFactory(const std::string& format):
+ _format(format)
+ {
+ }
+
+ HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
+ {
+ if (request.getURI() == "/")
+ return new TimeRequestHandler(_format);
+ else
+ return 0;
+ }
+
+private:
+ std::string _format;
+};
+
+
+class HTTPSTimeServer: public Poco::Util::ServerApplication
+ /// The main application class.
+ ///
+ /// This class handles command-line arguments and
+ /// configuration files.
+ /// Start the HTTPTimeServer executable with the help
+ /// option (/help on Windows, --help on Unix) for
+ /// the available command line options.
+ ///
+ /// To use the sample configuration file (HTTPTimeServer.properties),
+ /// copy the file to the directory where the HTTPTimeServer executable
+ /// resides. If you start the debug version of the HTTPTimeServer
+ /// (HTTPTimeServerd[.exe]), you must also create a copy of the configuration
+ /// file named HTTPTimeServerd.properties. In the configuration file, you
+ /// can specify the port on which the server is listening (default
+ /// 9980) and the format of the date/time string sent back to the client.
+ ///
+ /// To test the TimeServer you can use any web browser (https://localhost:9980/).
+{
+public:
+ HTTPSTimeServer(): _helpRequested(false)
+ {
+ }
+
+ ~HTTPSTimeServer()
+ {
+ }
+
+protected:
+ void initialize(Application& self)
+ {
+ loadConfiguration(); // load default configuration files, if present
+ ServerApplication::initialize(self);
+ }
+
+ void uninitialize()
+ {
+ ServerApplication::uninitialize();
+ }
+
+ void defineOptions(OptionSet& options)
+ {
+ ServerApplication::defineOptions(options);
+
+ options.addOption(
+ Option("help", "h", "display help information on command line arguments")
+ .required(false)
+ .repeatable(false));
+ }
+
+ void handleOption(const std::string& name, const std::string& value)
+ {
+ ServerApplication::handleOption(name, value);
+
+ if (name == "help")
+ _helpRequested = true;
+ }
+
+ void displayHelp()
+ {
+ HelpFormatter helpFormatter(options());
+ helpFormatter.setCommand(commandName());
+ helpFormatter.setUsage("OPTIONS");
+ helpFormatter.setHeader("A web server that serves the current date and time.");
+ helpFormatter.format(std::cout);
+ }
+
+ int main(const std::vector& args)
+ {
+ if (_helpRequested)
+ {
+ displayHelp();
+ }
+ else
+ {
+ // get parameters from configuration file
+ unsigned short port = (unsigned short) config().getInt("HTTPTimeServer.port", 9980);
+ std::string format(config().getString("HTTPTimeServer.format", DateTimeFormat::SORTABLE_FORMAT));
+
+ // set-up a server socket
+ SecureServerSocket svs(port);
+ // set-up a HTTPServer instance
+ HTTPServer srv(new TimeRequestHandlerFactory(format), svs, new HTTPServerParams);
+ // start the HTTPServer
+ srv.start();
+ // wait for CTRL-C or kill
+ waitForTerminationRequest();
+ // Stop the HTTPServer
+ srv.stop();
+ }
+ return Application::EXIT_OK;
+ }
+
+private:
+ bool _helpRequested;
+};
+
+
+int main(int argc, char** argv)
+{
+ HTTPSTimeServer app;
+ return app.run(argc, argv);
+}
diff --git a/NetSSL_OpenSSL/samples/Makefile b/NetSSL_OpenSSL/samples/Makefile
new file mode 100644
index 000000000..31c2fccf0
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile
+#
+# $Id: //poco/1.3/NetSSL_OpenSSL/samples/Makefile#1 $
+#
+# Makefile for Poco NetSSL Samples
+#
+
+.DEFAULT all:
+ $(MAKE) -C HTTPSTimeServer $(MAKECMDGOALS)
+ $(MAKE) -C download $(MAKECMDGOALS)
diff --git a/NetSSL_OpenSSL/samples/download/Makefile b/NetSSL_OpenSSL/samples/download/Makefile
new file mode 100644
index 000000000..ad455cfae
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/Makefile
@@ -0,0 +1,19 @@
+#
+# Makefile
+#
+# $Id: //poco/Main/template/sample.make#4 $
+#
+# Makefile for Poco download
+#
+
+include $(POCO_BASE)/build/rules/global
+
+SYSLIBS += -lssl -lcrypto -ldl
+
+objects = download
+
+target = download
+target_version = 1
+target_libs = PocoNetSSL PocoNet PocoUtil PocoXML PocoFoundation
+
+include $(POCO_BASE)/build/rules/exec
diff --git a/NetSSL_OpenSSL/samples/download/any.pem b/NetSSL_OpenSSL/samples/download/any.pem
new file mode 100644
index 000000000..b17a97568
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/any.pem
@@ -0,0 +1,48 @@
+-----BEGIN CERTIFICATE-----
+MIICaDCCAdECCQCzfxSsk7yaLjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB
+VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV
+BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA
+aW5mLmNvbTAeFw0wNjAzMDExMzA3MzFaFw0wNjAzMzExMzA3MzFaMH4xCzAJBgNV
+BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExETAPBgNVBAcTCFN0IEpha29iMRww
+GgYDVQQKExNBcHBsaWVkIEluZm9ybWF0aWNzMQowCAYDVQQDFAEqMR4wHAYJKoZI
+hvcNAQkBFg9pbmZvQGFwcGluZi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
+AoGBAJHGyXDHyCYoWz+65ltNwwZbhwOGnxr9P1WMATuFJh0bPBZxKbZRdbTm9KhZ
+OlvsEIsfgiYdsxURYIqXfEgISYLZcZY0pQwGEOmB+0NeC/+ENSfOlNSthx6zSVlc
+zhJ7+dJOGwepHAiLr1fRuc5jogYLraE+lKTnqAAFfzwvti77AgMBAAEwDQYJKoZI
+hvcNAQEFBQADgYEAY/ZoeY1ukkEJX7259NeoVM0oahlulWV0rlCqyaeosOiDORPT
+m6X1w/5MTCf9VyaD1zukoSZ4QqNVjHFXcXidbB7Tgt3yRuZ5PC5LIFCDPv9mgPne
+mUA70yfctNfza2z3ZiQ6NDkW3mZX+1tmxYIrJQIrkVeYeqf1Gh2nyZrUMcE=
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: DES-EDE3-CBC,E7AE93C9E49184EA
+
+A2IqzNcWs+I5vzV+i+woDk56+yr58eU0Onw8eEvXkLjnSc58JU4327IF7yUbKWdW
+Q7BYGGOkVFiZ7ANOwviDg5SUhxRDWCcW8dS6/p1vfdQ1C3qj2OwJjkpg0aDBIzJn
+FzgguT3MF3ama77vxv0S3kOfmCj62MLqPGpj5pQ0/1hefRFbL8oAX8bXUN7/rmGM
+Zc0QyzFZv2iQ04dY/6TNclwKPB4H0On4K+8BMs3PRkWA0clCaQaFO2+iwnk3XZfe
++MsKUEbLCpAQeYspYv1cw38dCdWq1KTP5aJk+oXgwjfX5cAaPTz74NTqTIsCcaTD
+3vy7ukJYFlDR9Kyo7z8rMazYrKJslhnuRH0BhK9st9McwL957j5tZmrKyraCcmCx
+dMAGcsis1va3ayYZpIpFqA4EhYrTM+6N8ZRfUap20+b5IQwHfTQDejUhL6rBwy7j
+Ti5yD83/itoOMyXq2sV/XWfVD5zk/P5iv22O1EAQMhhnPB9K/I/JhuSGQJfn3cNh
+ykOUYT0+vDeSeEVa+FVEP1W35G0alTbKbNs5Tb8KxJ3iDJUxokM//SvPXZy9hOVX
+Y05imB04J15DaGbAHlNzunhuJi7121WV/JRXZRW9diE6hwpD8rwqi3FMuRUmy7U9
+aFA5poKRAYlo9YtZ3YpFyjGKB6MfCQcB2opuSnQ/gbugV41m67uQ4CDwWLaNRkTb
+GlsMBNcHnidg15Bsat5HaB7l250ukrI13Uw1MYdDUzaS3gPfw9aC4F2w0p3U+DPH
+80/zePxtroR7T4/+rI136Rl+aMXDMOEGCX1TVP8rjuZzuRyUSUKC8Q==
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB
+VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV
+BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA
+aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV
+BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP
+MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW
+C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN
+Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm
+k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W
+jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB
+AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a
++ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO
+M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP
+-----END CERTIFICATE-----
diff --git a/NetSSL_OpenSSL/samples/download/download.vmsbuild b/NetSSL_OpenSSL/samples/download/download.vmsbuild
new file mode 100644
index 000000000..7bfad4474
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/download.vmsbuild
@@ -0,0 +1,8 @@
+#
+# sample.vmsbuild
+#
+# $Id: //poco/Main/template/sample.vmsbuild#3 $
+#
+EXE=download
+download
+
diff --git a/NetSSL_OpenSSL/samples/download/download_vs71.vcproj b/NetSSL_OpenSSL/samples/download/download_vs71.vcproj
new file mode 100644
index 000000000..19f683e64
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/download_vs71.vcproj
@@ -0,0 +1,145 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NetSSL_OpenSSL/samples/download/download_vs80.vcproj b/NetSSL_OpenSSL/samples/download/download_vs80.vcproj
new file mode 100644
index 000000000..87956a5f4
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/download_vs80.vcproj
@@ -0,0 +1,210 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NetSSL_OpenSSL/samples/download/rootcert.pem b/NetSSL_OpenSSL/samples/download/rootcert.pem
new file mode 100644
index 000000000..c26aeb244
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/rootcert.pem
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB
+VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV
+BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA
+aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV
+BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP
+MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW
+C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN
+Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm
+k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W
+jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB
+AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a
++ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO
+M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP
+-----END CERTIFICATE-----
diff --git a/NetSSL_OpenSSL/samples/download/src/download.cpp b/NetSSL_OpenSSL/samples/download/src/download.cpp
new file mode 100644
index 000000000..da24907a4
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/download/src/download.cpp
@@ -0,0 +1,109 @@
+//
+// download.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/samples/download/src/download.cpp#1 $
+//
+// This sample demonstrates the URIStreamOpener class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/URIStreamOpener.h"
+#include "Poco/StreamCopier.h"
+#include "Poco/Path.h"
+#include "Poco/URI.h"
+#include "Poco/SharedPtr.h"
+#include "Poco/Exception.h"
+#include "Poco/Net/HTTPStreamFactory.h"
+#include "Poco/Net/HTTPSStreamFactory.h"
+#include "Poco/Net/FTPStreamFactory.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Net/KeyConsoleHandler.h"
+#include "Poco/Net/ConsoleCertificateHandler.h"
+#include
+#include
+
+
+using Poco::URIStreamOpener;
+using Poco::StreamCopier;
+using Poco::Path;
+using Poco::URI;
+using Poco::SharedPtr;
+using Poco::Exception;
+using Poco::Net::HTTPStreamFactory;
+using Poco::Net::HTTPSStreamFactory;
+using Poco::Net::FTPStreamFactory;
+using Poco::Net::SSLManager;
+using Poco::Net::Context;
+using Poco::Net::KeyConsoleHandler;
+using Poco::Net::PrivateKeyPassphraseHandler;
+using Poco::Net::InvalidCertificateHandler;
+using Poco::Net::ConsoleCertificateHandler;
+
+
+int main(int argc, char** argv)
+{
+ HTTPStreamFactory::registerFactory();
+ HTTPSStreamFactory::registerFactory();
+ FTPStreamFactory::registerFactory();
+
+ if (argc != 2)
+ {
+ Path p(argv[0]);
+ std::cerr << "usage: " << p.getBaseName() << " " << std::endl;
+ std::cerr << " Download to standard output." << std::endl;
+ std::cerr << " Works with http, https, ftp and file URIs." << std::endl;
+ return 1;
+ }
+
+ // Note: we must create the passphrase handler prior Context
+ SharedPtr ptrConsole = new KeyConsoleHandler(false); // ask the user via console for the pwd
+ SharedPtr ptrCert = new ConsoleCertificateHandler(false); // ask the user via console
+ SharedPtr ptrContext = new Context("any.pem", "rootcert.pem", false, Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
+ SSLManager::instance().initializeClient(ptrConsole, ptrCert, ptrContext);
+
+ // init of server part is not required, but we keep the code here as an example
+ /*
+ ptrConsole = new KeyConsoleHandler(true); // ask the user via console for the pwd
+ ptrCert = new ConsoleCertificateHandler(true); // ask the user via console
+ ptrContext = new Context("any.pem", "rootcert.pem", true, Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
+ SSLManager::instance().initializeServer(ptrConsole, ptrCert, ptrContext);
+ */
+ try
+ {
+ URI uri(argv[1]);
+ std::auto_ptr pStr(URIStreamOpener::defaultOpener().open(uri));
+ StreamCopier::copyStream(*pStr.get(), std::cout);
+ }
+ catch (Exception& exc)
+ {
+ std::cerr << exc.displayText() << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/NetSSL_OpenSSL/samples/samples_vs71.sln b/NetSSL_OpenSSL/samples/samples_vs71.sln
new file mode 100644
index 000000000..6e3306a16
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/samples_vs71.sln
@@ -0,0 +1,29 @@
+Microsoft Visual Studio Solution File, Format Version 8.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HTTPSTimeServer", "HTTPSTimeServer\HTTPSTimeServer_vs71.vcproj", "{7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "download", "download\download_vs71.vcproj", "{22F6B2E6-A532-4156-A49A-835A21BFF3F6}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ debug_shared = debug_shared
+ release_shared = release_shared
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.debug_shared.ActiveCfg = debug_shared|Win32
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.debug_shared.Build.0 = debug_shared|Win32
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.release_shared.ActiveCfg = release_shared|Win32
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.release_shared.Build.0 = release_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.debug_shared.ActiveCfg = debug_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.debug_shared.Build.0 = debug_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.release_shared.ActiveCfg = release_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.release_shared.Build.0 = release_shared|Win32
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
diff --git a/NetSSL_OpenSSL/samples/samples_vs80.sln b/NetSSL_OpenSSL/samples/samples_vs80.sln
new file mode 100644
index 000000000..2ec513e8a
--- /dev/null
+++ b/NetSSL_OpenSSL/samples/samples_vs80.sln
@@ -0,0 +1,25 @@
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HTTPSTimeServer", "HTTPSTimeServer\HTTPSTimeServer_vs80.vcproj", "{7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "download", "download\download_vs80.vcproj", "{22F6B2E6-A532-4156-A49A-835A21BFF3F6}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ debug_shared|Win32 = debug_shared|Win32
+ release_shared|Win32 = release_shared|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.debug_shared|Win32.Build.0 = debug_shared|Win32
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.release_shared|Win32.ActiveCfg = release_shared|Win32
+ {7C4285ED-F0BC-4CBA-B1F0-61FCB7FA26C4}.release_shared|Win32.Build.0 = release_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.debug_shared|Win32.Build.0 = debug_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.release_shared|Win32.ActiveCfg = release_shared|Win32
+ {22F6B2E6-A532-4156-A49A-835A21BFF3F6}.release_shared|Win32.Build.0 = release_shared|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/NetSSL_OpenSSL/src/AcceptCertificateHandler.cpp b/NetSSL_OpenSSL/src/AcceptCertificateHandler.cpp
new file mode 100644
index 000000000..e2c333687
--- /dev/null
+++ b/NetSSL_OpenSSL/src/AcceptCertificateHandler.cpp
@@ -0,0 +1,58 @@
+//
+// AcceptCertificateHandler.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/AcceptCertificateHandler.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: AcceptCertificateHandler
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/AcceptCertificateHandler.h"
+#include "Poco/Net/CertificateHandlerFactory.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+AcceptCertificateHandler::AcceptCertificateHandler(bool server):InvalidCertificateHandler(server)
+{
+}
+
+
+AcceptCertificateHandler::~AcceptCertificateHandler()
+{
+}
+
+
+POCO_REGISTER_CHFACTORY(NetSSL_API, AcceptCertificateHandler)
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/CertificateHandlerFactory.cpp b/NetSSL_OpenSSL/src/CertificateHandlerFactory.cpp
new file mode 100644
index 000000000..6d897c1ff
--- /dev/null
+++ b/NetSSL_OpenSSL/src/CertificateHandlerFactory.cpp
@@ -0,0 +1,66 @@
+//
+// CertificateHandlerFactory.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/CertificateHandlerFactory.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: CertificateHandlerFactory
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/CertificateHandlerFactory.h"
+#include "Poco/Net/SSLManager.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+CertificateHandlerFactory::CertificateHandlerFactory()
+{
+}
+
+
+CertificateHandlerFactory::~CertificateHandlerFactory()
+{
+}
+
+
+CertificateHandlerFactoryRegistrar::CertificateHandlerFactoryRegistrar(const std::string& name, CertificateHandlerFactory* pFactory)
+{
+ SSLManager::instance().certificateHandlerFactoryMgr().setFactory(name, pFactory);
+}
+
+
+CertificateHandlerFactoryRegistrar::~CertificateHandlerFactoryRegistrar()
+{
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/CertificateHandlerFactoryMgr.cpp b/NetSSL_OpenSSL/src/CertificateHandlerFactoryMgr.cpp
new file mode 100644
index 000000000..eed5365b4
--- /dev/null
+++ b/NetSSL_OpenSSL/src/CertificateHandlerFactoryMgr.cpp
@@ -0,0 +1,85 @@
+//
+// CertificateHandlerFactoryMgr.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/CertificateHandlerFactoryMgr.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: CertificateHandlerFactoryMgr
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/CertificateHandlerFactoryMgr.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+CertificateHandlerFactoryMgr::CertificateHandlerFactoryMgr()
+{
+}
+
+
+CertificateHandlerFactoryMgr::~CertificateHandlerFactoryMgr()
+{
+}
+
+
+void CertificateHandlerFactoryMgr::setFactory(const std::string& name, CertificateHandlerFactory* pFactory)
+{
+ bool success = _factories.insert(make_pair(name, Poco::SharedPtr(pFactory))).second;
+ if (!success)
+ delete pFactory;
+ poco_assert(success);
+}
+
+
+bool CertificateHandlerFactoryMgr::hasFactory(const std::string& name) const
+{
+ return _factories.find(name) != _factories.end();
+}
+
+
+const CertificateHandlerFactory* CertificateHandlerFactoryMgr::getFactory(const std::string& name) const
+{
+ FactoriesMap::const_iterator it = _factories.find(name);
+ if (it != _factories.end())
+ return it->second;
+ else
+ return 0;
+}
+
+
+void CertificateHandlerFactoryMgr::removeFactory(const std::string& name)
+{
+ _factories.erase(name);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/ConsoleCertificateHandler.cpp b/NetSSL_OpenSSL/src/ConsoleCertificateHandler.cpp
new file mode 100644
index 000000000..ce5400c9d
--- /dev/null
+++ b/NetSSL_OpenSSL/src/ConsoleCertificateHandler.cpp
@@ -0,0 +1,78 @@
+//
+// ConsoleCertificateHandler.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/ConsoleCertificateHandler.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: ConsoleCertificateHandler
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/ConsoleCertificateHandler.h"
+#include
+#include "Poco/Net/CertificateHandlerFactory.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+ConsoleCertificateHandler::ConsoleCertificateHandler(bool server):InvalidCertificateHandler(server)
+{
+}
+
+
+ConsoleCertificateHandler::~ConsoleCertificateHandler()
+{
+}
+
+
+void ConsoleCertificateHandler::onInvalidCertificate(const void*, VerificationErrorArgs& errorCert)
+{
+ const X509Certificate& aCert = errorCert.certificate();
+ std::cout << " Certificate:\n";
+ std::cout << "----------------\n";
+ std::cout << " IssuerName: \t" << aCert.issuerName() << "\n";
+ std::cout << " SubjectName:\t" << aCert.subjectName() << "\n\n";
+ std::cout << "The certificate yielded the error: " << errorCert.errorMessage() << "\n\n";
+ std::cout << "The error occurred at in the certificate chain at position " << errorCert.errorDepth() << "\n";
+ std::cout << "Accept the certificate? (y,n)";
+ char c;
+ std::cin >> c;
+ if (c == 'y' || c == 'Y')
+ errorCert.setIgnoreError(true);
+ else
+ errorCert.setIgnoreError(false);
+}
+
+
+POCO_REGISTER_CHFACTORY(NetSSL_API, ConsoleCertificateHandler)
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/Context.cpp b/NetSSL_OpenSSL/src/Context.cpp
new file mode 100644
index 000000000..de24d132e
--- /dev/null
+++ b/NetSSL_OpenSSL/src/Context.cpp
@@ -0,0 +1,129 @@
+//
+// Context.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/Context.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: Context
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/Context.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Net/SSLException.h"
+#include "Poco/File.h"
+#include
+#include
+#include
+#include
+
+
+using Poco::File;
+
+
+namespace Poco {
+namespace Net {
+
+
+Context::Context(
+ const std::string& privateKeyFile,
+ const std::string& caLocation,
+ bool isServerContext,
+ VerificationMode verMode,
+ int verificationDepth,
+ bool loadCAFromDefaultPath,
+ const std::string& cypherList):_pSSLContext(0), _mode(verMode), _server(isServerContext)
+{
+
+ _pSSLContext = SSL_CTX_new(SSLv23_method());
+ SSL_CTX_set_default_passwd_cb(_pSSLContext, &SSLManager::privateKeyPasswdCallback);
+
+ File aFile(caLocation);
+ int errCode = 0;
+ if (aFile.isDirectory())
+ errCode = SSL_CTX_load_verify_locations(_pSSLContext, 0, caLocation.c_str());
+ else
+ errCode = SSL_CTX_load_verify_locations(_pSSLContext, caLocation.c_str(), 0);
+ if (errCode != 1)
+ {
+ SSL_CTX_free(_pSSLContext);
+ _pSSLContext = 0;
+ throw SSLContextException(std::string("Failed to load CA file/directory from ") + caLocation);
+ }
+
+ if (loadCAFromDefaultPath)
+ {
+ errCode = SSL_CTX_set_default_verify_paths(_pSSLContext);
+ if (errCode != 1)
+ {
+ SSL_CTX_free(_pSSLContext);
+ _pSSLContext = 0;
+ throw SSLContextException(std::string("Failed to load CA file/directory from default location"));
+ }
+ }
+
+ errCode = SSL_CTX_use_certificate_chain_file(_pSSLContext, privateKeyFile.c_str());
+ if (errCode != 1)
+ {
+ SSL_CTX_free(_pSSLContext);
+ _pSSLContext = 0;
+ throw SSLContextException(std::string("Error loading certificate from file ") + privateKeyFile);
+ }
+ File tmp(privateKeyFile);
+ poco_assert (tmp.exists());
+ errCode = SSL_CTX_use_PrivateKey_file(_pSSLContext, privateKeyFile.c_str(), SSL_FILETYPE_PEM);
+ if (errCode != 1)
+ {
+ SSL_CTX_free(_pSSLContext);
+ _pSSLContext = 0;
+ throw SSLContextException(std::string("Error loading private key from file ") + privateKeyFile);
+ }
+ int flags = (int)verMode;
+ if (verMode == VERIFY_STRICT || verMode == VERIFY_ONCE)
+ flags |= SSL_VERIFY_PEER;
+ if (serverContext())
+ SSL_CTX_set_verify(_pSSLContext, flags, &SSLManager::verifyServerCallback);
+ else
+ SSL_CTX_set_verify(_pSSLContext, flags, &SSLManager::verifyClientCallback);
+ SSL_CTX_set_verify_depth(_pSSLContext, verificationDepth);
+ SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);
+}
+
+
+Context::~Context()
+{
+ if (_pSSLContext)
+ {
+ SSL_CTX_free(_pSSLContext);
+ _pSSLContext = 0;
+ }
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/HTTPSClientSession.cpp b/NetSSL_OpenSSL/src/HTTPSClientSession.cpp
new file mode 100644
index 000000000..6c6ebbb8b
--- /dev/null
+++ b/NetSSL_OpenSSL/src/HTTPSClientSession.cpp
@@ -0,0 +1,175 @@
+//
+// HTTPSClientSession.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/HTTPSClientSession.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: HTTPSClient
+// Module: HTTPSClientSession
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Net/SecureStreamSocketImpl.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/Net/HTTPHeaderStream.h"
+#include "Poco/Net/HTTPStream.h"
+#include "Poco/Net/HTTPFixedLengthStream.h"
+#include "Poco/Net/HTTPChunkedStream.h"
+#include "Poco/Net/NetException.h"
+#include "Poco/NumberFormatter.h"
+
+
+using Poco::NumberFormatter;
+using Poco::IllegalStateException;
+
+
+namespace Poco {
+namespace Net {
+
+
+HTTPSClientSession::HTTPSClientSession():
+ HTTPClientSession(SecureStreamSocket())
+{
+ setPort(Utility::HTTPS_PORT);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const SecureStreamSocket& socket):
+ HTTPClientSession(socket)
+{
+ setPort(Utility::HTTPS_PORT);
+}
+
+
+HTTPSClientSession::HTTPSClientSession(const std::string& host, Poco::UInt16 port):
+ HTTPClientSession(SecureStreamSocket())
+{
+ setHost(host);
+ setPort(port);
+}
+
+
+HTTPSClientSession::~HTTPSClientSession()
+{
+}
+
+
+std::ostream& HTTPSClientSession::sendRequest(HTTPRequest& request)
+{
+ deleteResponseStream();
+
+ bool keepAlive = getKeepAlive();
+ if (connected() && !keepAlive)
+ close();
+ if (!connected())
+ reconnect();
+ request.setKeepAlive(keepAlive);
+ request.setHost(getHost(), getPort());
+
+ {
+ HTTPHeaderOutputStream hos(*this);
+ setReconnect(keepAlive);
+ request.write(hos);
+ setReconnect(false);
+ setExpectResponseBody(request.getMethod() != HTTPRequest::HTTP_HEAD);
+ }
+ if (request.getChunkedTransferEncoding())
+ setRequestStream(new HTTPChunkedOutputStream(*this));
+ else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
+ setRequestStream(new HTTPFixedLengthOutputStream(*this, request.getContentLength()));
+ else if (request.getMethod() == HTTPRequest::HTTP_GET || request.getMethod() == HTTPRequest::HTTP_HEAD)
+ setRequestStream(new HTTPFixedLengthOutputStream(*this, 0));
+ else
+ setRequestStream(new HTTPOutputStream(*this));
+
+ return *getRequestStream();
+}
+
+
+std::istream& HTTPSClientSession::receiveResponse(HTTPResponse& response)
+{
+ deleteRequestStream();
+
+ do
+ {
+ response.clear();
+ HTTPHeaderInputStream his(*this);
+ try
+ {
+ response.read(his);
+ }
+ catch (MessageException&)
+ {
+ if (networkException())
+ networkException()->rethrow();
+ else
+ throw;
+ }
+ }
+ while (response.getStatus() == HTTPResponse::HTTP_CONTINUE);
+
+ if (!getExpectResponseBody())
+ setResponseStream(new HTTPFixedLengthInputStream(*this, 0));
+ else if (response.getChunkedTransferEncoding())
+ setResponseStream(new HTTPChunkedInputStream(*this));
+ else if (response.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
+ setResponseStream(new HTTPFixedLengthInputStream(*this, response.getContentLength()));
+ else
+ setResponseStream(new HTTPInputStream(*this));
+
+ return *getResponseStream();
+}
+
+
+std::string HTTPSClientSession::getHostInfo() const
+{
+ std::string result("https://");
+ result.append(getHost());
+ result.append(":");
+ result.append(NumberFormatter::format(getPort()));
+ return result;
+}
+
+
+void HTTPSClientSession::connect(const SocketAddress& address)
+{
+ if (!getProxyHost().empty())
+ {
+ StreamSocket& aSock = socket();
+ SecureStreamSocketImpl* pImplSock = dynamic_cast(aSock.impl());
+ poco_check_ptr (pImplSock);
+ pImplSock->setTunnelEndPoint(getHost(), getPort());
+ }
+ HTTPSession::connect(address);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/HTTPSSessionInstantiator.cpp b/NetSSL_OpenSSL/src/HTTPSSessionInstantiator.cpp
new file mode 100644
index 000000000..fe4b5e6bb
--- /dev/null
+++ b/NetSSL_OpenSSL/src/HTTPSSessionInstantiator.cpp
@@ -0,0 +1,77 @@
+//
+// HTTPSSessionInstantiator.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/HTTPSSessionInstantiator.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: HTTPSClient
+// Module: HTTPSSessionInstantiator
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/HTTPSSessionInstantiator.h"
+#include "Poco/Net/HTTPSessionFactory.h"
+#include "Poco/Net/HTTPSClientSession.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+HTTPSSessionInstantiator::HTTPSSessionInstantiator()
+{
+}
+
+
+HTTPSSessionInstantiator::~HTTPSSessionInstantiator()
+{
+}
+
+
+HTTPClientSession* HTTPSSessionInstantiator::createClientSession(const Poco::URI& uri)
+{
+ poco_assert (uri.getScheme() == "https");
+ HTTPSClientSession* pSession = new HTTPSClientSession(uri.getHost(), uri.getPort());
+ pSession->setProxy(proxyHost(), proxyPort());
+ return pSession;
+}
+
+
+void HTTPSSessionInstantiator::registerInstantiator()
+{
+ HTTPSessionFactory::defaultFactory().registerProtocol("https", new HTTPSSessionInstantiator);
+}
+
+
+void HTTPSSessionInstantiator::unregisterInstantiator()
+{
+ HTTPSessionFactory::defaultFactory().unregisterProtocol("https");
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/HTTPSStreamFactory.cpp b/NetSSL_OpenSSL/src/HTTPSStreamFactory.cpp
new file mode 100644
index 000000000..41ca73078
--- /dev/null
+++ b/NetSSL_OpenSSL/src/HTTPSStreamFactory.cpp
@@ -0,0 +1,128 @@
+//
+// HTTPSStreamFactory.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/HTTPSStreamFactory.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: HTTPSClient
+// Module: HTTPSStreamFactory
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/HTTPSStreamFactory.h"
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/HTTPIOStream.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/Net/NetException.h"
+#include "Poco/URI.h"
+#include "Poco/URIStreamOpener.h"
+#include "Poco/UnbufferedStreamBuf.h"
+
+
+using Poco::URIStreamFactory;
+using Poco::URI;
+using Poco::URIStreamOpener;
+using Poco::UnbufferedStreamBuf;
+
+
+namespace Poco {
+namespace Net {
+
+
+HTTPSStreamFactory::HTTPSStreamFactory():
+ _proxyPort(HTTPSession::HTTP_PORT)
+{
+}
+
+
+HTTPSStreamFactory::HTTPSStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort):
+ _proxyHost(proxyHost),
+ _proxyPort(proxyPort)
+{
+}
+
+
+HTTPSStreamFactory::~HTTPSStreamFactory()
+{
+}
+
+
+std::istream* HTTPSStreamFactory::open(const URI& uri)
+{
+ poco_assert (uri.getScheme() == "https");
+
+ URI resolvedURI(uri);
+ HTTPClientSession* pSession = 0;
+ try
+ {
+ int redirects = 0;
+ do
+ {
+ pSession = new HTTPSClientSession(resolvedURI.getHost(), resolvedURI.getPort());
+ pSession->setProxy(_proxyHost, _proxyPort);
+ std::string path = resolvedURI.getPathAndQuery();
+ if (path.empty()) path = "/";
+ HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
+ pSession->sendRequest(req);
+ HTTPResponse res;
+ std::istream& rs = pSession->receiveResponse(res);
+ bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||
+ res.getStatus() == HTTPResponse::HTTP_FOUND ||
+ res.getStatus() == HTTPResponse::HTTP_SEE_OTHER);
+ if (moved)
+ {
+ resolvedURI.resolve(res.get("Location"));
+ delete pSession;
+ ++redirects;
+ }
+ else if (res.getStatus() == HTTPResponse::HTTP_OK)
+ {
+ return new HTTPResponseStream(rs, pSession);
+ }
+ else throw HTTPException(res.getReason(), uri.toString());
+ }
+ while (redirects < MAX_REDIRECTS);
+ throw HTTPException("Too many redirects", uri.toString());
+ }
+ catch (...)
+ {
+ delete pSession;
+ throw;
+ }
+}
+
+
+void HTTPSStreamFactory::registerFactory()
+{
+ std::string https("https");
+ URIStreamOpener::defaultOpener().registerStreamFactory(https, new HTTPSStreamFactory);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/InvalidCertificateHandler.cpp b/NetSSL_OpenSSL/src/InvalidCertificateHandler.cpp
new file mode 100644
index 000000000..6697b8f89
--- /dev/null
+++ b/NetSSL_OpenSSL/src/InvalidCertificateHandler.cpp
@@ -0,0 +1,67 @@
+//
+// InvalidCertificateHandler.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/InvalidCertificateHandler.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: InvalidCertificateHandler
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/InvalidCertificateHandler.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Delegate.h"
+
+
+using Poco::Delegate;
+
+
+namespace Poco {
+namespace Net {
+
+
+InvalidCertificateHandler::InvalidCertificateHandler(bool handleErrorsOnServerSide): _handleErrorsOnServerSide(handleErrorsOnServerSide)
+{
+ if (_handleErrorsOnServerSide)
+ SSLManager::instance().ServerVerificationError += Delegate(this, &InvalidCertificateHandler::onInvalidCertificate);
+ else
+ SSLManager::instance().ClientVerificationError += Delegate(this, &InvalidCertificateHandler::onInvalidCertificate);
+}
+
+
+InvalidCertificateHandler::~InvalidCertificateHandler()
+{
+ if (_handleErrorsOnServerSide)
+ SSLManager::instance().ServerVerificationError -= Delegate(this, &InvalidCertificateHandler::onInvalidCertificate);
+ else
+ SSLManager::instance().ClientVerificationError -= Delegate(this, &InvalidCertificateHandler::onInvalidCertificate);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/KeyConsoleHandler.cpp b/NetSSL_OpenSSL/src/KeyConsoleHandler.cpp
new file mode 100644
index 000000000..99308aec0
--- /dev/null
+++ b/NetSSL_OpenSSL/src/KeyConsoleHandler.cpp
@@ -0,0 +1,66 @@
+//
+// KeyConsoleHandler.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/KeyConsoleHandler.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: KeyConsoleHandler
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/KeyConsoleHandler.h"
+#include "Poco/Net/PrivateKeyFactory.h"
+#include
+
+
+namespace Poco {
+namespace Net {
+
+
+KeyConsoleHandler::KeyConsoleHandler(bool server):PrivateKeyPassphraseHandler(server)
+{
+}
+
+
+KeyConsoleHandler::~KeyConsoleHandler()
+{
+}
+
+
+void KeyConsoleHandler::onPrivateKeyRequested(const void* pSender, std::string& privateKey)
+{
+ std::cout << "Please enter the pass-phrase for the private key: ";
+ std::cin >> privateKey;
+}
+
+
+POCO_REGISTER_KEYFACTORY(NetSSL_API, KeyConsoleHandler)
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/KeyFileHandler.cpp b/NetSSL_OpenSSL/src/KeyFileHandler.cpp
new file mode 100644
index 000000000..195c1d7bc
--- /dev/null
+++ b/NetSSL_OpenSSL/src/KeyFileHandler.cpp
@@ -0,0 +1,79 @@
+//
+// KeyFileHandler.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/KeyFileHandler.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: KeyFileHandler
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/KeyFileHandler.h"
+#include "Poco/Net/PrivateKeyFactory.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/File.h"
+#include "Poco/Util/LayeredConfiguration.h"
+#include "Poco/Util/Application.h"
+#include "Poco/Util/OptionException.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+const std::string KeyFileHandler::CFG_PRIV_KEY_FILE("privateKeyPassphraseHandler.options.password");
+
+
+KeyFileHandler::KeyFileHandler(bool server):PrivateKeyPassphraseHandler(server)
+{
+}
+
+
+KeyFileHandler::~KeyFileHandler()
+{
+}
+
+
+void KeyFileHandler::onPrivateKeyRequested(const void* pSender, std::string& privateKey)
+{
+ Poco::Util::LayeredConfiguration& config = Poco::Util::Application::instance().config();
+ std::string prefix = serverSide() ? SSLManager::CFG_SERVER_PREFIX : SSLManager::CFG_CLIENT_PREFIX;
+ if (!config.hasProperty(prefix+CFG_PRIV_KEY_FILE))
+ {
+ throw Poco::Util::EmptyOptionException(std::string("Missing Configuration Entry: ") + prefix+CFG_PRIV_KEY_FILE);
+ }
+
+ privateKey = config.getString(prefix+CFG_PRIV_KEY_FILE);
+}
+
+
+POCO_REGISTER_KEYFACTORY(NetSSL_API,KeyFileHandler)
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/PrivateKeyFactory.cpp b/NetSSL_OpenSSL/src/PrivateKeyFactory.cpp
new file mode 100644
index 000000000..5e340372e
--- /dev/null
+++ b/NetSSL_OpenSSL/src/PrivateKeyFactory.cpp
@@ -0,0 +1,66 @@
+//
+// PrivateKeyFactory.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/PrivateKeyFactory.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: PrivateKeyFactory
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/PrivateKeyFactory.h"
+#include "Poco/Net/SSLManager.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+PrivateKeyFactory::PrivateKeyFactory()
+{
+}
+
+
+PrivateKeyFactory::~PrivateKeyFactory()
+{
+}
+
+
+PrivateKeyFactoryRegistrar::PrivateKeyFactoryRegistrar(const std::string& name, PrivateKeyFactory* pFactory)
+{
+ SSLManager::instance().privateKeyFactoryMgr().setFactory(name, pFactory);
+}
+
+
+PrivateKeyFactoryRegistrar::~PrivateKeyFactoryRegistrar()
+{
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/PrivateKeyFactoryMgr.cpp b/NetSSL_OpenSSL/src/PrivateKeyFactoryMgr.cpp
new file mode 100644
index 000000000..ee5a07d20
--- /dev/null
+++ b/NetSSL_OpenSSL/src/PrivateKeyFactoryMgr.cpp
@@ -0,0 +1,85 @@
+//
+// PrivateKeyFactoryMgr.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/PrivateKeyFactoryMgr.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: PrivateKeyFactoryMgr
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/PrivateKeyFactoryMgr.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+PrivateKeyFactoryMgr::PrivateKeyFactoryMgr()
+{
+}
+
+
+PrivateKeyFactoryMgr::~PrivateKeyFactoryMgr()
+{
+}
+
+
+void PrivateKeyFactoryMgr::setFactory(const std::string& name, PrivateKeyFactory* pFactory)
+{
+ bool success = _factories.insert(make_pair(name, Poco::SharedPtr(pFactory))).second;
+ if (!success)
+ delete pFactory;
+ poco_assert(success);
+}
+
+
+bool PrivateKeyFactoryMgr::hasFactory(const std::string& name) const
+{
+ return _factories.find(name) != _factories.end();
+}
+
+
+const PrivateKeyFactory* PrivateKeyFactoryMgr::getFactory(const std::string& name) const
+{
+ FactoriesMap::const_iterator it = _factories.find(name);
+ if (it != _factories.end())
+ return it->second;
+ else
+ return 0;
+}
+
+
+void PrivateKeyFactoryMgr::removeFactory(const std::string& name)
+{
+ _factories.erase(name);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/PrivateKeyPassphraseHandler.cpp b/NetSSL_OpenSSL/src/PrivateKeyPassphraseHandler.cpp
new file mode 100644
index 000000000..5f2e1f128
--- /dev/null
+++ b/NetSSL_OpenSSL/src/PrivateKeyPassphraseHandler.cpp
@@ -0,0 +1,61 @@
+//
+// PrivateKeyPassphraseHandler.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/PrivateKeyPassphraseHandler.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: PrivateKeyPassphraseHandler
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/PrivateKeyPassphraseHandler.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Delegate.h"
+
+
+using Poco::Delegate;
+
+
+namespace Poco {
+namespace Net {
+
+
+PrivateKeyPassphraseHandler::PrivateKeyPassphraseHandler(bool onServerSide): _serverSide(onServerSide)
+{
+ SSLManager::instance().PrivateKeyPassPhrase += Delegate(this, &PrivateKeyPassphraseHandler::onPrivateKeyRequested);
+}
+
+
+PrivateKeyPassphraseHandler::~PrivateKeyPassphraseHandler()
+{
+ SSLManager::instance().PrivateKeyPassPhrase -= Delegate(this, &PrivateKeyPassphraseHandler::onPrivateKeyRequested);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SSLException.cpp b/NetSSL_OpenSSL/src/SSLException.cpp
new file mode 100644
index 000000000..edb5dcbbb
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SSLException.cpp
@@ -0,0 +1,50 @@
+//
+// SSLException.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SSLException.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: SSLException
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SSLException.h"
+#include
+
+
+namespace Poco {
+namespace Net {
+
+
+POCO_IMPLEMENT_EXCEPTION(SSLException, NetException, "SSLException")
+POCO_IMPLEMENT_EXCEPTION(SSLContextException, SSLException, "SSLContextException")
+POCO_IMPLEMENT_EXCEPTION(InvalidCertificateException, SSLException, "InvalidCertificateException")
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SSLInitializer.cpp b/NetSSL_OpenSSL/src/SSLInitializer.cpp
new file mode 100644
index 000000000..e26ad44bb
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SSLInitializer.cpp
@@ -0,0 +1,146 @@
+//
+// SSLInitializer.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SSLInitializer.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: SSLInitializer
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SSLInitializer.h"
+#include "Poco/Net/KeyConsoleHandler.h"
+#include "Poco/Net/KeyFileHandler.h"
+#include "Poco/RandomStream.h"
+#include "Poco/Thread.h"
+#include
+#include
+#include
+
+
+using Poco::RandomInputStream;
+using Poco::Thread;
+using Poco::FastMutex;
+
+
+namespace Poco {
+namespace Net {
+
+
+FastMutex* SSLInitializer::_mutexes(0);
+int SSLInitializer::_rc(0);
+
+
+static SSLInitializer initializer;
+
+
+SSLInitializer::SSLInitializer()
+{
+ initialize();
+}
+
+
+SSLInitializer::~SSLInitializer()
+{
+ uninitialize();
+}
+
+
+void SSLInitializer::initialize()
+{
+ if (++_rc == 1)
+ {
+ poco_assert (1 == SSL_library_init()); // always returns 1
+ SSL_load_error_strings();
+
+ char seed[SEEDSIZE];
+ RandomInputStream rnd;
+ rnd.read(seed, sizeof(seed));
+ RAND_seed(seed, SEEDSIZE);
+
+ int nMutexes = CRYPTO_num_locks();
+ _mutexes = new FastMutex[nMutexes];
+ CRYPTO_set_locking_callback(&SSLInitializer::lock);
+ CRYPTO_set_id_callback(&SSLInitializer::id);
+ CRYPTO_set_dynlock_create_callback(&SSLInitializer::dynlockCreate);
+ CRYPTO_set_dynlock_lock_callback(&SSLInitializer::dynlock);
+ CRYPTO_set_dynlock_destroy_callback(&SSLInitializer::dynlockDestroy);
+ }
+}
+
+
+void SSLInitializer::uninitialize()
+{
+ if (--_rc == 0)
+ {
+ delete [] _mutexes;
+ }
+}
+
+
+void SSLInitializer::lock(int mode, int n, const char* file, int line)
+{
+ if (mode & CRYPTO_LOCK)
+ _mutexes[n].lock();
+ else
+ _mutexes[n].unlock();
+}
+
+
+unsigned long SSLInitializer::id()
+{
+ Thread* pThread = Thread::current();
+ return pThread ? pThread->id() : 0;
+}
+
+
+struct CRYPTO_dynlock_value* SSLInitializer::dynlockCreate(const char* file, int line)
+{
+ return new CRYPTO_dynlock_value;
+}
+
+
+void SSLInitializer::dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line)
+{
+ poco_check_ptr (lock);
+
+ if (mode & CRYPTO_LOCK)
+ lock->_mutex.lock();
+ else
+ lock->_mutex.unlock();
+}
+
+
+void SSLInitializer::dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line)
+{
+ delete lock;
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SSLManager.cpp b/NetSSL_OpenSSL/src/SSLManager.cpp
new file mode 100644
index 000000000..c872caffb
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SSLManager.cpp
@@ -0,0 +1,305 @@
+//
+// SSLManager.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SSLManager.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: SSLManager
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Net/Context.h"
+#include "Poco/Net/Utility.h"
+#include "Poco/Net/PrivateKeyPassphraseHandler.h"
+#include "Poco/Net/SSLInitializer.h"
+#include "Poco/SingletonHolder.h"
+#include "Poco/Delegate.h"
+#include "Poco/Util/Application.h"
+#include "Poco/Util/OptionException.h"
+#include "Poco/Util/LayeredConfiguration.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+const std::string SSLManager::CFG_PRIV_KEY_FILE("privateKeyFile");
+const std::string SSLManager::CFG_CA_LOCATION("caConfig");
+const std::string SSLManager::CFG_VER_MODE("verificationMode");
+const Context::VerificationMode SSLManager::VAL_VER_MODE(Context::VERIFY_STRICT);
+const std::string SSLManager::CFG_VER_DEPTH("verificationDepth");
+const int SSLManager::VAL_VER_DEPTH(9);
+const std::string SSLManager::CFG_ENABLE_DEFAULT_CA("loadDefaultCAFile");
+const bool SSLManager::VAL_ENABLE_DEFAULT_CA(false);
+const std::string SSLManager::CFG_CYPHER_LIST("cypherList");
+const std::string SSLManager::VAL_CYPHER_LIST("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
+const std::string SSLManager::CFG_DELEGATE_HANDLER("privateKeyPassphraseHandler.name");
+const std::string SSLManager::VAL_DELEGATE_HANDLER("KeyConsoleHandler");
+const std::string SSLManager::CFG_CERTIFICATE_HANDLER("invalidCertificateHandler.name");
+const std::string SSLManager::VAL_CERTIFICATE_HANDLER("ConsoleCertificateHandler");
+const std::string SSLManager::CFG_SERVER_PREFIX("openSSL.server.");
+const std::string SSLManager::CFG_CLIENT_PREFIX("openSSL.client.");
+
+
+SSLManager::SSLManager()
+{
+ SSLInitializer::initialize();
+}
+
+
+SSLManager::~SSLManager()
+{
+ PrivateKeyPassPhrase.clear();
+ ClientVerificationError.clear();
+ ServerVerificationError.clear();
+ _ptrServerPassPhraseHandler = 0;
+ _ptrServerCertificateHandler = 0;
+ _ptrDefaultServerContext = 0;
+ _ptrClientPassPhraseHandler = 0;
+ _ptrClientCertificateHandler = 0;
+ _ptrDefaultClientContext = 0;
+ SSLInitializer::uninitialize();
+}
+
+
+SSLManager& SSLManager::instance()
+{
+ static Poco::SingletonHolder singleton;
+ return *singleton.get();
+}
+
+
+void SSLManager::initializeServer(PrivateKeyPassphraseHandlerPtr& ptrPassPhraseHandler, InvalidCertificateHandlerPtr& ptrHandler, ContextPtr ptrContext)
+{
+ _ptrServerPassPhraseHandler = ptrPassPhraseHandler;
+ _ptrServerCertificateHandler = ptrHandler;
+ _ptrDefaultServerContext = ptrContext;
+}
+
+
+void SSLManager::initializeClient(PrivateKeyPassphraseHandlerPtr& ptrPassPhraseHandler, InvalidCertificateHandlerPtr& ptrHandler, ContextPtr ptrContext)
+{
+ _ptrClientPassPhraseHandler = ptrPassPhraseHandler;
+ _ptrClientCertificateHandler = ptrHandler;
+ _ptrDefaultClientContext = ptrContext;
+}
+
+
+SSLManager::ContextPtr SSLManager::defaultServerContext()
+{
+ if (!_ptrDefaultServerContext)
+ initDefaultContext(true);
+
+ return _ptrDefaultServerContext;
+}
+
+
+SSLManager::ContextPtr SSLManager::defaultClientContext()
+{
+ if (!_ptrDefaultClientContext)
+ initDefaultContext(false);
+
+ return _ptrDefaultClientContext;
+}
+
+
+SSLManager::PrivateKeyPassphraseHandlerPtr SSLManager::serverPassPhraseHandler()
+{
+ if (!_ptrServerPassPhraseHandler)
+ initPassPhraseHandler(true);
+
+ return _ptrServerPassPhraseHandler;
+}
+
+
+SSLManager::PrivateKeyPassphraseHandlerPtr SSLManager::clientPassPhraseHandler()
+{
+ if (!_ptrClientPassPhraseHandler)
+ initPassPhraseHandler(false);
+
+ return _ptrClientPassPhraseHandler;
+}
+
+
+SSLManager::InvalidCertificateHandlerPtr SSLManager::serverCertificateHandler()
+{
+ if (!_ptrServerCertificateHandler)
+ initCertificateHandler(true);
+
+ return _ptrServerCertificateHandler;
+}
+
+
+SSLManager::InvalidCertificateHandlerPtr SSLManager::clientCertificateHandler()
+{
+ if (!_ptrClientCertificateHandler)
+ initCertificateHandler(false);
+
+ return _ptrClientCertificateHandler;
+}
+
+
+int SSLManager::verifyCallback(bool server, int ok, X509_STORE_CTX* pStore)
+{
+ if (!ok)
+ {
+ X509* pCert = X509_STORE_CTX_get_current_cert(pStore);
+ X509Certificate x509(pCert);
+ int depth = X509_STORE_CTX_get_error_depth(pStore);
+ int err = X509_STORE_CTX_get_error(pStore);
+ std::string error(X509_verify_cert_error_string(err));
+ VerificationErrorArgs args(x509, depth, err, error);
+ if (server)
+ SSLManager::instance().ServerVerificationError.notify(&SSLManager::instance(), args);
+ else
+ SSLManager::instance().ClientVerificationError.notify(&SSLManager::instance(), args);
+ ok = args.getIgnoreError() ? 1 : 0;
+ }
+
+ return ok;
+}
+
+
+int SSLManager::privateKeyPasswdCallback(char* pBuf, int size, int flag, void* userData)
+{
+ std::string pwd;
+ SSLManager::instance().PrivateKeyPassPhrase.notify(&SSLManager::instance(), pwd);
+
+ strncpy(pBuf, (char *)(pwd.c_str()), size);
+ pBuf[size - 1] = '\0';
+ if (size > pwd.length())
+ size = (int) pwd.length();
+
+ return size;
+}
+
+
+void SSLManager::initDefaultContext(bool server)
+{
+ if (server && _ptrDefaultServerContext) return;
+ if (!server && _ptrDefaultClientContext) return;
+
+ initEvents(server);
+
+ Poco::Util::LayeredConfiguration& config = Poco::Util::Application::instance().config();
+ std::string prefix = server ? CFG_SERVER_PREFIX : CFG_CLIENT_PREFIX;
+ if (!config.hasProperty(prefix+CFG_PRIV_KEY_FILE))
+ {
+ throw Poco::Util::EmptyOptionException(std::string("Missing Configuration Entry: ") + prefix+CFG_PRIV_KEY_FILE);
+ }
+ // mandatory options
+ std::string privKeyFile = config.getString(prefix+CFG_PRIV_KEY_FILE);
+ std::string caLocation = config.getString(prefix+CFG_CA_LOCATION);
+
+ // optional options for which we have defaults defined
+ Context::VerificationMode verMode = VAL_VER_MODE;
+ if (config.hasProperty(prefix+CFG_VER_MODE))
+ {
+ // either: none, relaxed, strict, once
+ std::string mode = config.getString(prefix+CFG_VER_MODE);
+ verMode = Utility::convertVerificationMode(mode);
+ }
+
+ int verDepth = config.getInt(prefix+CFG_VER_DEPTH, VAL_VER_DEPTH);
+ bool loadDefCA = config.getBool(prefix+CFG_ENABLE_DEFAULT_CA, VAL_ENABLE_DEFAULT_CA);
+ std::string cypherList = config.getString(prefix+CFG_CYPHER_LIST, VAL_CYPHER_LIST);
+ if (server)
+ {
+ _ptrDefaultServerContext = new Context(privKeyFile, caLocation, server, verMode, verDepth, loadDefCA, cypherList);
+ }
+ else
+ {
+ _ptrDefaultClientContext = new Context(privKeyFile, caLocation, server, verMode, verDepth, loadDefCA, cypherList);
+ }
+}
+
+
+void SSLManager::initEvents(bool server)
+{
+ initPassPhraseHandler(server);
+ initCertificateHandler(server);
+}
+
+
+void SSLManager::initPassPhraseHandler(bool server)
+{
+ if (server && _ptrServerPassPhraseHandler) return;
+ if (!server && _ptrClientPassPhraseHandler) return;
+
+ std::string prefix = server ? CFG_SERVER_PREFIX : CFG_CLIENT_PREFIX;
+ Poco::Util::LayeredConfiguration& config = Poco::Util::Application::instance().config();
+
+ std::string className(config.getString(prefix+CFG_DELEGATE_HANDLER, VAL_DELEGATE_HANDLER));
+
+ const PrivateKeyFactory* pFactory = 0;
+ if (privateKeyFactoryMgr().hasFactory(className))
+ {
+ pFactory = privateKeyFactoryMgr().getFactory(className);
+ }
+
+ if (pFactory)
+ {
+ if (server)
+ _ptrServerPassPhraseHandler = pFactory->create(server);
+ else
+ _ptrClientPassPhraseHandler = pFactory->create(server);
+ }
+ else throw Poco::Util::UnknownOptionException(std::string("No PassPhrasehandler known with the name ") + className);
+}
+
+
+void SSLManager::initCertificateHandler(bool server)
+{
+ if (server && _ptrServerCertificateHandler) return;
+ if (!server && _ptrClientCertificateHandler) return;
+
+ std::string prefix = server ? CFG_SERVER_PREFIX : CFG_CLIENT_PREFIX;
+ Poco::Util::LayeredConfiguration& config = Poco::Util::Application::instance().config();
+
+ std::string className(config.getString(prefix+CFG_CERTIFICATE_HANDLER, VAL_CERTIFICATE_HANDLER));
+
+ const CertificateHandlerFactory* pFactory = 0;
+ if (certificateHandlerFactoryMgr().hasFactory(className))
+ {
+ pFactory = certificateHandlerFactoryMgr().getFactory(className);
+ }
+
+ if (pFactory)
+ {
+ if (server)
+ _ptrServerCertificateHandler = pFactory->create(true);
+ else
+ _ptrClientCertificateHandler = pFactory->create(false);
+ }
+ else throw Poco::Util::UnknownOptionException(std::string("No InvalidCertificate handler known with the name ") + className);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SecureServerSocket.cpp b/NetSSL_OpenSSL/src/SecureServerSocket.cpp
new file mode 100644
index 000000000..e634f4daa
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SecureServerSocket.cpp
@@ -0,0 +1,113 @@
+//
+// SecureServerSocket.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SecureServerSocket.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLSockets
+// Module: SecureServerSocket
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SecureServerSocket.h"
+#include "Poco/Net/SecureServerSocketImpl.h"
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Exception.h"
+
+
+using Poco::InvalidArgumentException;
+
+
+namespace Poco {
+namespace Net {
+
+
+SecureServerSocket::SecureServerSocket():
+ ServerSocket(new SecureServerSocketImpl, true)
+{
+}
+
+
+SecureServerSocket::SecureServerSocket(const Socket& socket):
+ ServerSocket(socket)
+{
+ if (!dynamic_cast(impl()))
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+}
+
+
+SecureServerSocket::SecureServerSocket(const SocketAddress& address, int backlog):
+ ServerSocket(new SecureServerSocketImpl, true)
+{
+ impl()->bind(address, true);
+ impl()->listen(backlog);
+}
+
+
+SecureServerSocket::SecureServerSocket(Poco::UInt16 port, int backlog):
+ ServerSocket(new SecureServerSocketImpl, true)
+{
+ IPAddress wildcardAddr;
+ SocketAddress address(wildcardAddr, port);
+ impl()->bind(address, true);
+ impl()->listen(backlog);
+}
+
+
+SecureServerSocket::~SecureServerSocket()
+{
+}
+
+
+SecureServerSocket& SecureServerSocket::operator = (const Socket& socket)
+{
+ if (&socket != this)
+ {
+ if (dynamic_cast(socket.impl()))
+ ServerSocket::operator = (socket);
+ else
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+ }
+ return *this;
+}
+
+
+StreamSocket SecureServerSocket::acceptConnection(SocketAddress& clientAddr)
+{
+ return SecureStreamSocket(impl()->acceptConnection(clientAddr));
+}
+
+
+StreamSocket SecureServerSocket::acceptConnection()
+{
+ SocketAddress clientAddr;
+ return SecureStreamSocket(impl()->acceptConnection(clientAddr));
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SecureServerSocketImpl.cpp b/NetSSL_OpenSSL/src/SecureServerSocketImpl.cpp
new file mode 100644
index 000000000..0f12b5ebd
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SecureServerSocketImpl.cpp
@@ -0,0 +1,131 @@
+//
+// SecureServerSocketImpl.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SecureServerSocketImpl.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLSockets
+// Module: SecureServerSocketImpl
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SecureServerSocketImpl.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+SecureServerSocketImpl::SecureServerSocketImpl()
+{
+}
+
+
+SecureServerSocketImpl::~SecureServerSocketImpl()
+{
+}
+
+
+SocketImpl* SecureServerSocketImpl::acceptConnection(SocketAddress& clientAddr)
+{
+ return _socket.acceptConnection(clientAddr);
+}
+
+
+void SecureServerSocketImpl::connect(const SocketAddress& address)
+{
+ _socket.connect(address);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureServerSocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
+{
+ _socket.connect(address, timeout);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureServerSocketImpl::connectNB(const SocketAddress& address)
+{
+ _socket.connectNB(address);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
+{
+ _socket.bind(address, reuseAddress);
+}
+
+
+void SecureServerSocketImpl::listen(int backlog)
+{
+ _socket.listen(backlog);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureServerSocketImpl::close()
+{
+ invalidate();
+ _socket.close();
+}
+
+
+int SecureServerSocketImpl::sendBytes(const void* buffer, int length, int flags)
+{
+ return _socket.sendBytes(buffer, length, flags);
+}
+
+
+int SecureServerSocketImpl::receiveBytes(void* buffer, int length, int flags)
+{
+ return _socket.receiveBytes(buffer, length, flags);
+}
+
+
+int SecureServerSocketImpl::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
+{
+ return _socket.sendTo(buffer, length, address, flags);
+}
+
+
+int SecureServerSocketImpl::receiveFrom(void* buffer, int length, SocketAddress& address, int flags)
+{
+ return _socket.receiveFrom(buffer, length, address, flags);
+}
+
+
+void SecureServerSocketImpl::sendUrgent(unsigned char data)
+{
+ return _socket.sendUrgent(data);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SecureSocketImpl.cpp b/NetSSL_OpenSSL/src/SecureSocketImpl.cpp
new file mode 100644
index 000000000..3ee4e7dd0
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SecureSocketImpl.cpp
@@ -0,0 +1,603 @@
+//
+// SecureSocketImpl.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SecureSocketImpl.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLSockets
+// Module: SecureSocketImpl
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SecureSocketImpl.h"
+#include "Poco/Net/SSLException.h"
+#include "Poco/Net/SSLManager.h"
+#include "Poco/Net/Utility.h"
+#include "Poco/Net/SecureStreamSocketImpl.h"
+#include "Poco/Net/StreamSocketImpl.h"
+#include "Poco/Net/NetException.h"
+#include "Poco/Net/DNS.h"
+#include "Poco/NumberFormatter.h"
+#include "Poco/NumberParser.h"
+#include "Poco/String.h"
+#include "Poco/RegularExpression.h"
+#include
+#include
+
+
+using Poco::IOException;
+using Poco::TimeoutException;
+using Poco::InvalidArgumentException;
+using Poco::NumberFormatter;
+using Poco::Timespan;
+
+
+// workaround for C++-incompatible macro
+#define POCO_BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(void*)((n)?"a":NULL))
+
+
+
+namespace Poco {
+namespace Net {
+
+
+SecureSocketImpl::SecureSocketImpl():_pBIO(0), _pSSL(0)
+{
+}
+
+
+SecureSocketImpl::SecureSocketImpl(SSL *pSSL): _pSSL(pSSL)
+{
+ poco_check_ptr (_pSSL);
+
+ _pBIO = SSL_get_rbio(_pSSL);
+ poco_check_ptr (_pBIO);
+ int tmpSocket = 0;
+ BIO_get_fd(_pBIO, &tmpSocket);
+ setSockfd(tmpSocket);
+
+}
+
+
+SecureSocketImpl::~SecureSocketImpl()
+{
+ close();
+}
+
+
+SocketImpl* SecureSocketImpl::acceptConnection(SocketAddress& clientAddr)
+{
+ poco_assert (sockfd() != POCO_INVALID_SOCKET);
+ poco_check_ptr (_pBIO);
+
+ BIO* pClient = 0;
+ int rc = 0;
+
+ do
+ {
+ rc = BIO_do_accept(_pBIO);
+ }
+ while (rc <= 0 && _socket.lastError() == POCO_EINTR);
+
+ if (rc > 0)
+ {
+ pClient = BIO_pop(_pBIO);
+ poco_check_ptr (pClient);
+
+ SSL* pSSL = SSL_new(SSLManager::instance().defaultServerContext()->sslContext());
+ if (pSSL)
+ {
+ SSL_set_accept_state(pSSL);
+ SSL_set_bio(pSSL, pClient, pClient);
+ int err = SSL_accept(pSSL);
+
+ if (err > 0)
+ {
+ SecureStreamSocketImpl* pSI = new SecureStreamSocketImpl(pSSL);
+ clientAddr = pSI->peerAddress();
+ std::string clientName = clientAddr.host().toString();
+
+ if (X509_V_OK != postConnectionCheck(true, pSSL, clientName))
+ {
+ delete pSI;
+ pSI = 0;
+ SSL_shutdown(pSSL);
+ SSL_free(pSSL);
+ pClient = 0;
+ SocketImpl::error("postConnectionCheck failed"); // will throw
+ }
+
+ return pSI;
+ }
+ else
+ {
+ std::string errMsg = Utility::convertSSLError(pSSL, err);
+ SSL_shutdown(pSSL);
+ SSL_free(pSSL);
+ SocketImpl::error(std::string("failed to acceptConnection: ") + errMsg);
+ }
+ }
+ else
+ {
+ BIO_free(pClient);
+ }
+
+ }
+ SocketImpl::error(); // will throw
+ return 0;
+}
+
+
+void SecureSocketImpl::connect(const SocketAddress& address)
+{
+ if (sockfd() == POCO_INVALID_SOCKET)
+ {
+ if (!_pBIO)
+ _pBIO = BIO_new(BIO_s_connect());
+ }
+
+ int rc = 0;
+ do
+ {
+ BIO_set_conn_hostname(_pBIO, address.host().toString().c_str());
+ int tmp = address.port();
+ BIO_set_conn_int_port(_pBIO, &tmp);
+ rc = BIO_do_connect(_pBIO); // returns 1 in case of ok!
+ }
+ while (rc != 1 && _socket.lastError() == POCO_EINTR);
+
+ if (rc != 1) SocketImpl::error(address.toString());
+
+ establishTunnel();
+ connectSSL(address);
+ poco_check_ptr (_pSSL);
+}
+
+
+void SecureSocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
+{
+ poco_assert (sockfd() == POCO_INVALID_SOCKET);
+ poco_assert (_pSSL == 0);
+ poco_assert (_pBIO == 0);
+
+ _pBIO = BIO_new(BIO_s_connect());
+ POCO_BIO_set_nbio_accept(_pBIO, 1); // set nonblocking
+
+ try
+ {
+ BIO_set_conn_hostname(_pBIO, address.host().toString().c_str());
+ int tmp = address.port();
+ BIO_set_conn_int_port(_pBIO, &tmp);
+ int rc = BIO_do_connect(_pBIO); // returns 1 in case of ok!
+
+ if (rc != 1)
+ {
+ if (_socket.lastError() != POCO_EINPROGRESS && _socket.lastError() != POCO_EWOULDBLOCK)
+ SocketImpl::error(address.toString());
+ if (!_socket.poll(timeout, SocketImpl::SELECT_READ | SocketImpl::SELECT_WRITE))
+ throw Poco::TimeoutException("connect timed out", address.toString());
+ int err = _socket.socketError();
+ if (err != 0) SocketImpl::error(err);
+ }
+
+ establishTunnel();
+ connectSSL(address);
+ poco_check_ptr (_pSSL);
+ }
+ catch (Poco::Exception&)
+ {
+ POCO_BIO_set_nbio_accept(_pBIO, 0);
+ throw;
+ }
+ POCO_BIO_set_nbio_accept(_pBIO, 0);
+}
+
+
+void SecureSocketImpl::connectNB(const SocketAddress& address)
+{
+ if (sockfd() == POCO_INVALID_SOCKET)
+ {
+ if(!_pBIO)
+ _pBIO = BIO_new(BIO_s_connect());
+ }
+
+ POCO_BIO_set_nbio_accept(_pBIO, 1); //setnonBlocking
+ BIO_set_conn_hostname(_pBIO, address.host().toString().c_str());
+ int tmp = address.port();
+ BIO_set_conn_int_port(_pBIO, &tmp);
+
+ int rc = BIO_do_connect(_pBIO); // returns 1 in case of ok!
+
+ if (rc != 1)
+ {
+ if (_socket.lastError() != POCO_EINPROGRESS && _socket.lastError() != POCO_EWOULDBLOCK)
+ SocketImpl::error(address.toString());
+ }
+ else
+ {
+ int tmpSocket=0;
+ BIO_get_fd(_pBIO,&tmpSocket);
+ poco_assert (-1 != tmpSocket);
+ setSockfd(tmpSocket);
+ establishTunnel();
+ connectSSL(address);
+ poco_check_ptr (_pSSL);
+ }
+}
+
+
+void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
+{
+ _socket.bind(address, reuseAddress);
+}
+
+
+void SecureSocketImpl::listen(int backlog)
+{
+ _socket.listen(backlog);
+ _pBIO = BIO_new (BIO_s_accept());
+ BIO_set_fd(_pBIO, (int)sockfd(), BIO_CLOSE);
+}
+
+
+void SecureSocketImpl::close()
+{
+ if (_pSSL)
+ {
+ if (SSL_get_shutdown(_pSSL) & SSL_RECEIVED_SHUTDOWN)
+ {
+ SSL_shutdown(_pSSL);
+ }
+ else
+ {
+ SSL_clear(_pSSL);
+ }
+ SSL_free(_pSSL); // frees _pBIO
+ _pSSL = 0;
+ _pBIO = 0;
+ }
+
+ if (_pBIO)
+ {
+ BIO_free_all(_pBIO); //free all, even BIOs for pending connections
+ _pBIO = 0;
+ }
+ invalidate(); // the socket is already invalid, although the fd still contains a meaningful value, correct that
+}
+
+
+int SecureSocketImpl::sendBytes(const void* buffer, int length, int flags)
+{
+ poco_assert (sockfd() != POCO_INVALID_SOCKET);
+ poco_check_ptr (_pSSL);
+
+ int rc;
+ do
+ {
+ rc = SSL_write(_pSSL, buffer, length);
+ if (rc < 0)
+ {
+ std::string errMsg = Utility::convertSSLError(_pSSL, rc);
+ }
+ }
+ while (rc < 0 && _socket.lastError() == POCO_EINTR);
+ if (rc < 0) SocketImpl::error();
+ return rc;
+}
+
+
+int SecureSocketImpl::receiveBytes(void* buffer, int length, int flags)
+{
+ poco_assert (sockfd() != POCO_INVALID_SOCKET);
+ poco_check_ptr (_pSSL);
+
+#if defined(POCO_BROKEN_TIMEOUTS)
+ Poco::Timespan recvTimeout = _socket.getReceiveTimeout();
+ if (recvTimeout.totalMicroseconds() != 0)
+ {
+ if (!_socket.poll(recvTimeout, SocketImpl::SELECT_READ))
+ throw TimeoutException();
+ }
+#endif
+
+ int rc;
+ do
+ {
+ rc = SSL_read(_pSSL, buffer, length);
+ if (rc <= 0)
+ {
+ switch (SSL_get_error(_pSSL, rc))
+ {
+ case SSL_ERROR_ZERO_RETURN:
+ // connection closed
+ close();
+ break;
+ case SSL_ERROR_NONE:
+ case SSL_ERROR_WANT_WRITE: //renegotiation
+ case SSL_ERROR_WANT_READ: //renegotiation
+ default:
+ ;
+ }
+ }
+ }
+ while (rc < 0 && _socket.lastError() == POCO_EINTR);
+ if (rc < 0)
+ {
+ if (_socket.lastError() == POCO_EAGAIN || _socket.lastError() == POCO_ETIMEDOUT)
+ throw TimeoutException();
+ else
+ SocketImpl::error("failed to read bytes");
+ }
+ return rc;
+}
+
+
+int SecureSocketImpl::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
+{
+ throw NetException("sendTo not possible with SSL");
+}
+
+
+int SecureSocketImpl::receiveFrom(void* buffer, int length, SocketAddress& address, int flags)
+{
+ throw NetException("receiveFrom not possible with SSL");
+}
+
+
+void SecureSocketImpl::sendUrgent(unsigned char data)
+{
+ // SSL doesn't support out-of-band data
+ sendBytes(reinterpret_cast(&data), sizeof(data));
+}
+
+
+long SecureSocketImpl::postConnectionCheck(bool server, SSL* pSSL, const std::string& hostName)
+{
+ static std::string locHost("127.0.0.1");
+
+ SSLManager& mgr = SSLManager::instance();
+ Context::VerificationMode mode = server? mgr.defaultServerContext()->verificationMode() : mgr.defaultClientContext()->verificationMode();
+ if (hostName == locHost && mode != Context::VERIFY_STRICT)
+ return X509_V_OK;
+
+ X509* cert = 0;
+ X509_NAME* subj = 0;
+ char* host = const_cast(hostName.c_str());
+
+ int extcount=0;
+
+ if (mode == Context::VERIFY_NONE) // should we allow none on the client side?
+ {
+ return X509_V_OK;
+ }
+
+ cert = SSL_get_peer_certificate(pSSL);
+
+ // note: the check is used by the client, so as long we don't set None at the client we reject
+ // cases where no certificate/incomplete info is presented by the server
+ if ((!cert || !host) && mode != Context::VERIFY_NONE)
+ {
+ if (cert)
+ X509_free(cert);
+ return X509_V_ERR_APPLICATION_VERIFICATION;
+ }
+
+ bool ok = false;
+
+ if ((extcount = X509_get_ext_count(cert)) > 0)
+ {
+ for (int i = 0; i < extcount && !ok; ++i)
+ {
+ const char* extstr = 0;
+ X509_EXTENSION* ext;
+ ext = X509_get_ext(cert, i);
+ extstr = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext)));
+
+ if (!strcmp(extstr, "subjectAltName"))
+ {
+ X509V3_EXT_METHOD* meth = X509V3_EXT_get(ext);
+ if (!meth)
+ break;
+
+#if OPENSSL_VERSION_NUMBER >= 0x00908000
+ const unsigned char* pData = ext->value->data;
+ const unsigned char** ppData = &pData;
+#else
+ unsigned char* pData = ext->value->data;
+ unsigned char** ppData = &pData;
+#endif
+ STACK_OF(CONF_VALUE)* val = meth->i2v(meth, meth->d2i(0, ppData, ext->value->length), 0);
+
+ for (int j = 0; j < sk_CONF_VALUE_num(val) && !ok; ++j)
+ {
+ CONF_VALUE* nval = sk_CONF_VALUE_value(val, j);
+ if (!strcmp(nval->name, "DNS") && !strcmp(nval->value, host))
+ {
+ ok = true;
+ }
+ }
+ }
+ }
+ }
+
+ char data[256];
+ if (!ok && (subj = X509_get_subject_name(cert)) && X509_NAME_get_text_by_NID(subj, NID_commonName, data, 256) > 0)
+ {
+ data[255] = 0;
+
+ std::string strData(data); // commonName can contain wildcards like *.appinf.com
+ try
+ {
+ // two cases: strData contains wildcards or not
+ if (SecureSocketImpl::containsWildcards(strData))
+ {
+ // a compare by IPAddress is not possible with wildcards
+ // only allow compare by name
+ const HostEntry& heData = DNS::resolve(hostName);
+ ok = SecureSocketImpl::matchByAlias(strData, heData);
+ }
+ else
+ {
+ // it depends on hostname if we compare by IP or by alias
+ IPAddress ip;
+ if (IPAddress::tryParse(hostName, ip))
+ {
+ // compare by IP
+ const HostEntry& heData = DNS::resolve(strData);
+ const HostEntry::AddressList& addr = heData.addresses();
+ HostEntry::AddressList::const_iterator it = addr.begin();
+ HostEntry::AddressList::const_iterator itEnd = addr.end();
+ for (; it != itEnd && !ok; ++it)
+ {
+ ok = (*it == ip);
+ }
+ }
+ else
+ {
+ // compare by name
+ const HostEntry& heData = DNS::resolve(hostName);
+ ok = SecureSocketImpl::matchByAlias(strData, heData);
+ }
+ }
+ }
+ catch(HostNotFoundException&)
+ {
+ if (cert)
+ X509_free(cert);
+ return X509_V_ERR_APPLICATION_VERIFICATION;
+ }
+ }
+
+ if (cert)
+ X509_free(cert);
+
+ // we already have a verify callback registered so no need to ask twice SSL_get_verify_result(pSSL);
+ if (ok)
+ return X509_V_OK;
+
+ return X509_V_ERR_APPLICATION_VERIFICATION;
+}
+
+
+void SecureSocketImpl::connectSSL(const SocketAddress& address)
+{
+ if (!_pSSL)
+ {
+ _pSSL = SSL_new(SSLManager::instance().defaultClientContext()->sslContext());
+ SSL_set_bio(_pSSL, _pBIO, _pBIO);
+ }
+ std::string errMsg;
+
+ int ret = SSL_connect(_pSSL);
+
+ if (ret <= 0)
+ {
+ errMsg = Utility::convertSSLError(_pSSL, ret);
+ throw SSLException(errMsg);
+ }
+
+ std::string serverName = address.host().toString();
+ long errCode = 0;
+ if (_endHost.empty())
+ postConnectionCheck(false, _pSSL, serverName);
+ else
+ postConnectionCheck(false, _pSSL, _endHost);
+ bool err = false;
+
+ if (errCode != X509_V_OK)
+ {
+ err = true;
+ errMsg = Utility::convertCertificateError(errCode);
+ }
+ else
+ {
+ int tmpSocket=0;
+ BIO_get_fd(_pBIO,&tmpSocket);
+ poco_assert (-1 != tmpSocket);
+ setSockfd(tmpSocket);
+ }
+
+ if (err)
+ {
+ SSL_free(_pSSL); // dels _pBIO too
+ _pSSL = 0;
+ _pBIO = 0;
+ invalidate();
+ throw InvalidCertificateException(errMsg);
+ }
+}
+
+
+void SecureSocketImpl::establishTunnel()
+{
+ if (!_endHost.empty())
+ {
+ poco_check_ptr (_pBIO);
+ // send CONNECT proxyHost:proxyPort HTTP/1.0\r\n\r\n
+ std::string connect("CONNECT ");
+ connect.append(_endHost);
+ connect.append(":");
+ connect.append(Poco::NumberFormatter::format(_endPort));
+ connect.append(" HTTP/1.0\r\n\r\n");
+ int rc = BIO_write(_pBIO, (const void*) connect.c_str(), (int)(connect.length()*sizeof(char)));
+ if (rc != connect.length())
+ throw SSLException("Failed to establish connection to proxy");
+ // get the response
+ char resp[512];
+ rc = BIO_read(_pBIO, resp, 512*sizeof(char));
+ std::string response(resp);
+ if (response.find("200") == std::string::npos)
+ throw SSLException("Failed to establish connection to proxy");
+ }
+}
+
+
+bool SecureSocketImpl::containsWildcards(const std::string& commonName)
+{
+ return (commonName.find('*') != std::string::npos || commonName.find('?') != std::string::npos);
+}
+
+
+bool SecureSocketImpl::matchByAlias(const std::string& alias, const HostEntry& heData)
+{
+ // compare by name
+ Poco::RegularExpression expr(alias);
+ bool found = false;
+ const HostEntry::AliasList& aliases = heData.aliases();
+ HostEntry::AliasList::const_iterator it = aliases.begin();
+ HostEntry::AliasList::const_iterator itEnd = aliases.end();
+ for (; it != itEnd && !found; ++it)
+ {
+ found = expr.match(*it);
+ }
+
+ return found;
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SecureStreamSocket.cpp b/NetSSL_OpenSSL/src/SecureStreamSocket.cpp
new file mode 100644
index 000000000..c3092861e
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SecureStreamSocket.cpp
@@ -0,0 +1,94 @@
+//
+// SecureStreamSocket.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SecureStreamSocket.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLSockets
+// Module: SecureStreamSocket
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Net/SecureStreamSocketImpl.h"
+#include "Poco/Net/SocketImpl.h"
+#include "Poco/Exception.h"
+
+
+using Poco::InvalidArgumentException;
+
+
+namespace Poco {
+namespace Net {
+
+
+SecureStreamSocket::SecureStreamSocket():
+ StreamSocket(new SecureStreamSocketImpl)
+{
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const SocketAddress& address):
+ StreamSocket(new SecureStreamSocketImpl)
+{
+ connect(address);
+}
+
+
+SecureStreamSocket::SecureStreamSocket(const Socket& socket):
+ StreamSocket(socket)
+{
+ if (!dynamic_cast(impl()))
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+}
+
+
+SecureStreamSocket::SecureStreamSocket(SocketImpl* pImpl):
+ StreamSocket(pImpl)
+{
+ if (!dynamic_cast(impl()))
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+}
+
+
+SecureStreamSocket::~SecureStreamSocket()
+{
+}
+
+
+SecureStreamSocket& SecureStreamSocket::operator = (const Socket& socket)
+{
+ if (dynamic_cast(socket.impl()))
+ StreamSocket::operator = (socket);
+ else
+ throw InvalidArgumentException("Cannot assign incompatible socket");
+ return *this;
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp b/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp
new file mode 100644
index 000000000..d59a2e517
--- /dev/null
+++ b/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp
@@ -0,0 +1,145 @@
+//
+// SecureStreamSocketImpl.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/SecureStreamSocketImpl.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLSockets
+// Module: SecureStreamSocketImpl
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/SecureStreamSocketImpl.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+SecureStreamSocketImpl::SecureStreamSocketImpl()
+{
+}
+
+
+SecureStreamSocketImpl::SecureStreamSocketImpl(SSL* _pSSL): _socket(_pSSL)
+{
+ setSockfd(_socket.sockfd());
+}
+
+
+SecureStreamSocketImpl::~SecureStreamSocketImpl()
+{
+}
+
+
+SocketImpl* SecureStreamSocketImpl::acceptConnection(SocketAddress& clientAddr)
+{
+ return _socket.acceptConnection(clientAddr);
+}
+
+
+void SecureStreamSocketImpl::connect(const SocketAddress& address)
+{
+ _socket.connect(address);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureStreamSocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
+{
+ _socket.connect(address, timeout);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureStreamSocketImpl::connectNB(const SocketAddress& address)
+{
+ _socket.connectNB(address);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureStreamSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
+{
+ _socket.bind(address, reuseAddress);
+}
+
+
+void SecureStreamSocketImpl::listen(int backlog)
+{
+ _socket.listen(backlog);
+ setSockfd(_socket.sockfd());
+}
+
+
+void SecureStreamSocketImpl::close()
+{
+ invalidate();
+ _socket.close();
+}
+
+
+int SecureStreamSocketImpl::sendBytes(const void* buffer, int length, int flags)
+{
+ const char* p = reinterpret_cast(buffer);
+ int remaining = length;
+ while (remaining > 0)
+ {
+ int n = _socket.sendBytes(p, length, flags);
+ p += n;
+ remaining -= n;
+ }
+ return length;
+}
+
+
+int SecureStreamSocketImpl::receiveBytes(void* buffer, int length, int flags)
+{
+ return _socket.receiveBytes(buffer, length, flags);
+}
+
+
+int SecureStreamSocketImpl::sendTo(const void* buffer, int length, const SocketAddress& address, int flags)
+{
+ return _socket.sendTo(buffer, length, address, flags);
+}
+
+
+int SecureStreamSocketImpl::receiveFrom(void* buffer, int length, SocketAddress& address, int flags)
+{
+ return _socket.receiveFrom(buffer, length, address, flags);
+}
+
+
+void SecureStreamSocketImpl::sendUrgent(unsigned char data)
+{
+ return _socket.sendUrgent(data);
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/Utility.cpp b/NetSSL_OpenSSL/src/Utility.cpp
new file mode 100644
index 000000000..c7d18f7db
--- /dev/null
+++ b/NetSSL_OpenSSL/src/Utility.cpp
@@ -0,0 +1,135 @@
+//
+// Utility.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/Utility.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: Utility
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/Utility.h"
+#include "Poco/String.h"
+#include "Poco/Util/OptionException.h"
+#include
+
+
+namespace Poco {
+namespace Net {
+
+
+int Utility::HTTPS_PORT = 443;
+
+
+Context::VerificationMode Utility::convertVerificationMode(const std::string& vMode)
+{
+ std::string mode = Poco::toLower(vMode);
+ Context::VerificationMode verMode = Context::VERIFY_STRICT;
+
+ if (mode == "none")
+ verMode = Context::VERIFY_NONE;
+ else if (mode == "relaxed")
+ verMode = Context::VERIFY_RELAXED;
+ else if (mode == "strict")
+ verMode = Context::VERIFY_STRICT;
+ else if (mode == "once")
+ verMode = Context::VERIFY_ONCE;
+ else
+ throw Poco::Util::OptionException(std::string("Wrong value >") + vMode + std::string("< for a verificationMode. Can only be none, relaxed, strict or once."));
+
+ return verMode;
+}
+
+
+std::string Utility::convertCertificateError(long errCode)
+{
+ std::string errMsg(X509_verify_cert_error_string(errCode));
+ return errMsg;
+}
+
+
+std::string Utility::convertSSLError(SSL* pSSL, int errCode)
+{
+
+ std::string errMsg;
+ if (errCode > 0) return "no error";
+
+ int connectErr = SSL_get_error(pSSL, errCode);
+ long lErr = 0;
+ char buf[512];
+
+ switch (connectErr)
+ {
+ case SSL_ERROR_ZERO_RETURN:
+ // connection closed
+ errMsg = "connection closed by server";
+ break;
+ case SSL_ERROR_WANT_READ:
+ errMsg = "want read";
+ break;
+ case SSL_ERROR_WANT_WRITE:
+ errMsg = "want write";
+ break;
+ case SSL_ERROR_WANT_CONNECT:
+ errMsg = "want connect";
+ break;
+ case SSL_ERROR_WANT_ACCEPT:
+ errMsg = "want accept";
+ break;
+ case SSL_ERROR_WANT_X509_LOOKUP:
+ errMsg = "want lookup";
+ break;
+ case SSL_ERROR_SYSCALL:
+ errMsg = "syscall";
+ break;
+ case SSL_ERROR_SSL:
+ lErr = ERR_get_error();
+ if (errCode == 0)
+ {
+ errMsg = "EOF was observed";
+ }
+ else if (errCode == -1)
+ {
+ errMsg = "The underlying BIO reported an I/O error";
+ }
+ else
+ {
+ ERR_error_string_n(lErr, buf, 512);
+ errMsg = buf;
+ }
+ break;
+ default:
+ errMsg = "none";
+ }
+
+ return errMsg;
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/VerificationErrorArgs.cpp b/NetSSL_OpenSSL/src/VerificationErrorArgs.cpp
new file mode 100644
index 000000000..1427f9a71
--- /dev/null
+++ b/NetSSL_OpenSSL/src/VerificationErrorArgs.cpp
@@ -0,0 +1,59 @@
+//
+// VerificationErrorArgs.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/VerificationErrorArgs.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: VerificationErrorArgs
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/VerificationErrorArgs.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+VerificationErrorArgs::VerificationErrorArgs(const X509Certificate& cert, int errDepth, int errNum, const std::string& errMsg):
+ _cert(cert),
+ _errorDepth(errDepth),
+ _errorNumber(errNum),
+ _errorMessage(errMsg),
+ _ignoreError(false)
+{
+}
+
+
+VerificationErrorArgs::~VerificationErrorArgs()
+{
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/src/X509Certificate.cpp b/NetSSL_OpenSSL/src/X509Certificate.cpp
new file mode 100644
index 000000000..00ed23f84
--- /dev/null
+++ b/NetSSL_OpenSSL/src/X509Certificate.cpp
@@ -0,0 +1,66 @@
+//
+// X509Certificate.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/src/X509Certificate.cpp#1 $
+//
+// Library: NetSSL_OpenSSL
+// Package: SSLCore
+// Module: X509Certificate
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/Net/X509Certificate.h"
+
+
+namespace Poco {
+namespace Net {
+
+
+X509Certificate::X509Certificate(X509* pCert):_pCert(pCert)
+{
+ poco_check_ptr(_pCert);
+ initialize();
+}
+
+
+X509Certificate::~X509Certificate()
+{
+}
+
+
+void X509Certificate::initialize()
+{
+ char data[256];
+ X509_NAME_oneline(X509_get_issuer_name(_pCert), data, 256);
+ _issuerName = data;
+ X509_NAME_oneline(X509_get_subject_name(_pCert), data, 256);
+ _subjectName = data;
+}
+
+
+} } // namespace Poco::Net
diff --git a/NetSSL_OpenSSL/testsuite/Makefile b/NetSSL_OpenSSL/testsuite/Makefile
new file mode 100644
index 000000000..eba98121a
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/Makefile
@@ -0,0 +1,21 @@
+#
+# Makefile
+#
+# $Id: //poco/Main/template/TestSuite.make#3 $
+#
+# Makefile for Poco NetSSL testsuite
+#
+
+include $(POCO_BASE)/build/rules/global
+
+SYSLIBS += -lssl -lcrypto -ldl
+
+objects = NetSSLTestSuite Driver \
+ HTTPSClientSessionTest HTTPSClientTestSuite HTTPSServerTest HTTPSServerTestSuite \
+ HTTPSStreamFactoryTest HTTPSTestServer TCPServerTest TCPServerTestSuite
+
+target = testrunner
+target_version = 1
+target_libs = PocoNetSSL PocoNet PocoUtil PocoXML PocoFoundation CppUnit
+
+include $(POCO_BASE)/build/rules/exec
diff --git a/NetSSL_OpenSSL/testsuite/TestSuite.vmsbuild b/NetSSL_OpenSSL/testsuite/TestSuite.vmsbuild
new file mode 100644
index 000000000..32d8d588f
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/TestSuite.vmsbuild
@@ -0,0 +1,9 @@
+#
+# TestSuite.vmsbuild
+#
+# $Id: //poco/Main/template/TestSuite.vmsbuild#3 $
+#
+EXE=TestRunner
+OpenSSLTestSuite
+Driver
+
diff --git a/NetSSL_OpenSSL/testsuite/TestSuite.xml b/NetSSL_OpenSSL/testsuite/TestSuite.xml
new file mode 100644
index 000000000..ed8b08790
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/TestSuite.xml
@@ -0,0 +1,42 @@
+
+
+
+ ${application.configDir}any.pem
+ ${application.configDir}rootcert.pem
+ none
+ 9
+ true
+ ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH
+
+ KeyFileHandler
+
+ test
+
+
+
+ AcceptCertificateHandler
+
+
+
+
+
+ ${application.configDir}any.pem
+ ${application.configDir}rootcert.pem
+ relaxed
+ 9
+ true
+ ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH
+
+ KeyFileHandler
+
+ test
+
+
+
+ AcceptCertificateHandler
+
+
+
+
+
+
diff --git a/NetSSL_OpenSSL/testsuite/TestSuite_vs71.vcproj b/NetSSL_OpenSSL/testsuite/TestSuite_vs71.vcproj
new file mode 100644
index 000000000..43f4b61c4
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/TestSuite_vs71.vcproj
@@ -0,0 +1,263 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NetSSL_OpenSSL/testsuite/TestSuite_vs80.vcproj b/NetSSL_OpenSSL/testsuite/TestSuite_vs80.vcproj
new file mode 100644
index 000000000..1c60f9173
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/TestSuite_vs80.vcproj
@@ -0,0 +1,345 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/NetSSL_OpenSSL/testsuite/any.pem b/NetSSL_OpenSSL/testsuite/any.pem
new file mode 100644
index 000000000..b17a97568
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/any.pem
@@ -0,0 +1,48 @@
+-----BEGIN CERTIFICATE-----
+MIICaDCCAdECCQCzfxSsk7yaLjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB
+VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV
+BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA
+aW5mLmNvbTAeFw0wNjAzMDExMzA3MzFaFw0wNjAzMzExMzA3MzFaMH4xCzAJBgNV
+BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExETAPBgNVBAcTCFN0IEpha29iMRww
+GgYDVQQKExNBcHBsaWVkIEluZm9ybWF0aWNzMQowCAYDVQQDFAEqMR4wHAYJKoZI
+hvcNAQkBFg9pbmZvQGFwcGluZi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
+AoGBAJHGyXDHyCYoWz+65ltNwwZbhwOGnxr9P1WMATuFJh0bPBZxKbZRdbTm9KhZ
+OlvsEIsfgiYdsxURYIqXfEgISYLZcZY0pQwGEOmB+0NeC/+ENSfOlNSthx6zSVlc
+zhJ7+dJOGwepHAiLr1fRuc5jogYLraE+lKTnqAAFfzwvti77AgMBAAEwDQYJKoZI
+hvcNAQEFBQADgYEAY/ZoeY1ukkEJX7259NeoVM0oahlulWV0rlCqyaeosOiDORPT
+m6X1w/5MTCf9VyaD1zukoSZ4QqNVjHFXcXidbB7Tgt3yRuZ5PC5LIFCDPv9mgPne
+mUA70yfctNfza2z3ZiQ6NDkW3mZX+1tmxYIrJQIrkVeYeqf1Gh2nyZrUMcE=
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: DES-EDE3-CBC,E7AE93C9E49184EA
+
+A2IqzNcWs+I5vzV+i+woDk56+yr58eU0Onw8eEvXkLjnSc58JU4327IF7yUbKWdW
+Q7BYGGOkVFiZ7ANOwviDg5SUhxRDWCcW8dS6/p1vfdQ1C3qj2OwJjkpg0aDBIzJn
+FzgguT3MF3ama77vxv0S3kOfmCj62MLqPGpj5pQ0/1hefRFbL8oAX8bXUN7/rmGM
+Zc0QyzFZv2iQ04dY/6TNclwKPB4H0On4K+8BMs3PRkWA0clCaQaFO2+iwnk3XZfe
++MsKUEbLCpAQeYspYv1cw38dCdWq1KTP5aJk+oXgwjfX5cAaPTz74NTqTIsCcaTD
+3vy7ukJYFlDR9Kyo7z8rMazYrKJslhnuRH0BhK9st9McwL957j5tZmrKyraCcmCx
+dMAGcsis1va3ayYZpIpFqA4EhYrTM+6N8ZRfUap20+b5IQwHfTQDejUhL6rBwy7j
+Ti5yD83/itoOMyXq2sV/XWfVD5zk/P5iv22O1EAQMhhnPB9K/I/JhuSGQJfn3cNh
+ykOUYT0+vDeSeEVa+FVEP1W35G0alTbKbNs5Tb8KxJ3iDJUxokM//SvPXZy9hOVX
+Y05imB04J15DaGbAHlNzunhuJi7121WV/JRXZRW9diE6hwpD8rwqi3FMuRUmy7U9
+aFA5poKRAYlo9YtZ3YpFyjGKB6MfCQcB2opuSnQ/gbugV41m67uQ4CDwWLaNRkTb
+GlsMBNcHnidg15Bsat5HaB7l250ukrI13Uw1MYdDUzaS3gPfw9aC4F2w0p3U+DPH
+80/zePxtroR7T4/+rI136Rl+aMXDMOEGCX1TVP8rjuZzuRyUSUKC8Q==
+-----END RSA PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB
+VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV
+BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA
+aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV
+BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP
+MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW
+C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN
+Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm
+k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W
+jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB
+AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a
++ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO
+M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP
+-----END CERTIFICATE-----
diff --git a/NetSSL_OpenSSL/testsuite/rootcert.pem b/NetSSL_OpenSSL/testsuite/rootcert.pem
new file mode 100644
index 000000000..c26aeb244
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/rootcert.pem
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB
+VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV
+BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA
+aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV
+BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP
+MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW
+C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN
+Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm
+k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W
+jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB
+AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a
++ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO
+M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP
+-----END CERTIFICATE-----
diff --git a/NetSSL_OpenSSL/testsuite/src/Driver.cpp b/NetSSL_OpenSSL/testsuite/src/Driver.cpp
new file mode 100644
index 000000000..658e27c7c
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/Driver.cpp
@@ -0,0 +1,84 @@
+//
+// Driver.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/Driver.cpp#1 $
+//
+// Console-based test driver for Poco NetSSL.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "CppUnit/TestRunner.h"
+#include "NetSSLTestSuite.h"
+#include "Poco/Util/Application.h"
+#include "Poco/Net/HTTPStreamFactory.h"
+#include "Poco/Net/HTTPSStreamFactory.h"
+#include
+
+
+class NetSSLApp: public Poco::Util::Application
+{
+public:
+ NetSSLApp()
+ {
+ }
+
+ ~NetSSLApp()
+ {
+ }
+
+protected:
+ void initialize(Poco::Util::Application& self)
+ {
+ loadConfiguration(); // load default configuration files, if present
+ Poco::Util::Application::initialize(self);
+ }
+};
+
+
+int main(int ac, char **av)
+{
+ Poco::Net::HTTPStreamFactory::registerFactory();
+ Poco::Net::HTTPSStreamFactory::registerFactory();
+ NetSSLApp app;
+ try
+ {
+ app.init(1, av);
+ }
+ catch (Poco::Exception& exc)
+ {
+ std::cout << exc.displayText() << std::endl;
+ return 1;
+ }
+
+ std::vector args;
+ for (int i = 0; i < ac; ++i)
+ args.push_back(std::string(av[i]));
+ CppUnit::TestRunner runner;
+ runner.addTest("NetSSLTestSuite", NetSSLTestSuite::suite());
+ return runner.run(args) ? 0 : 1;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp b/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp
new file mode 100644
index 000000000..4c8cca61e
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp
@@ -0,0 +1,306 @@
+//
+// HTTPSClientSessionTest.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "HTTPSClientSessionTest.h"
+#include "CppUnit/TestCaller.h"
+#include "CppUnit/TestSuite.h"
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/StreamCopier.h"
+#include "Poco/Exception.h"
+#include "HTTPSTestServer.h"
+#include
+#include
+#include
+
+
+using Poco::Net::HTTPSClientSession;
+using Poco::Net::HTTPRequest;
+using Poco::Net::HTTPResponse;
+using Poco::Net::HTTPMessage;
+using Poco::StreamCopier;
+
+
+HTTPSClientSessionTest::HTTPSClientSessionTest(const std::string& name): CppUnit::TestCase(name)
+{
+}
+
+
+HTTPSClientSessionTest::~HTTPSClientSessionTest()
+{
+}
+
+
+void HTTPSClientSessionTest::testGetSmall()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_GET, "/small");
+ s.sendRequest(request);
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length());
+ assert (response.getContentType() == "text/plain");
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == HTTPSTestServer::SMALL_BODY);
+}
+
+
+void HTTPSClientSessionTest::testGetLarge()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
+ s.sendRequest(request);
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length());
+ assert (response.getContentType() == "text/plain");
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == HTTPSTestServer::LARGE_BODY);
+}
+
+
+void HTTPSClientSessionTest::testHead()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large");
+ s.sendRequest(request);
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length());
+ assert (response.getContentType() == "text/plain");
+ std::ostringstream ostr;
+ assert (StreamCopier::copyStream(rs, ostr) == 0);
+}
+
+
+void HTTPSClientSessionTest::testPostSmallIdentity()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
+ std::string body("this is a random request body\r\n0\r\n");
+ request.setContentLength((int) body.length());
+ s.sendRequest(request) << body;
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getContentLength() == body.length());
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == body);
+}
+
+
+void HTTPSClientSessionTest::testPostLargeIdentity()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
+ std::string body(8000, 'x');
+ body.append("\r\n0\r\n");
+ request.setContentLength((int) body.length());
+ s.sendRequest(request) << body;
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getContentLength() == body.length());
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == body);
+}
+
+
+void HTTPSClientSessionTest::testPostSmallChunked()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
+ std::string body("this is a random request body");
+ request.setChunkedTransferEncoding(true);
+ s.sendRequest(request) << body;
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getChunkedTransferEncoding());
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == body);
+}
+
+
+void HTTPSClientSessionTest::testPostLargeChunked()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
+ std::string body(16000, 'x');
+ request.setChunkedTransferEncoding(true);
+ s.sendRequest(request) << body;
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (response.getChunkedTransferEncoding());
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == body);
+}
+
+
+void HTTPSClientSessionTest::testPostSmallClose()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
+ std::string body("this is a random request body");
+ s.sendRequest(request) << body;
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (!response.getChunkedTransferEncoding());
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == body);
+}
+
+
+void HTTPSClientSessionTest::testPostLargeClose()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
+ std::string body(8000, 'x');
+ s.sendRequest(request) << body;
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ assert (!response.getChunkedTransferEncoding());
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str() == body);
+}
+
+
+void HTTPSClientSessionTest::testKeepAlive()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("localhost", srv.port());
+ s.setKeepAlive(true);
+ HTTPRequest request(HTTPRequest::HTTP_HEAD, "/keepAlive", HTTPMessage::HTTP_1_1);
+ s.sendRequest(request);
+ HTTPResponse response;
+ std::istream& rs1 = s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length());
+ assert (response.getContentType() == "text/plain");
+ assert (response.getKeepAlive());
+ std::ostringstream ostr1;
+ assert (StreamCopier::copyStream(rs1, ostr1) == 0);
+
+ request.setMethod(HTTPRequest::HTTP_GET);
+ request.setURI("/small");
+ s.sendRequest(request);
+ std::istream& rs2 = s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPSTestServer::SMALL_BODY.length());
+ assert (response.getKeepAlive());
+ std::ostringstream ostr2;
+ StreamCopier::copyStream(rs2, ostr2);
+ assert (ostr2.str() == HTTPSTestServer::SMALL_BODY);
+
+ request.setMethod(HTTPRequest::HTTP_GET);
+ request.setURI("/large");
+ s.sendRequest(request);
+ std::istream& rs3 = s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ assert (response.getChunkedTransferEncoding());
+ assert (response.getKeepAlive());
+ std::ostringstream ostr3;
+ int n = StreamCopier::copyStream(rs3, ostr3);
+ assert (ostr3.str() == HTTPSTestServer::LARGE_BODY);
+
+ request.setMethod(HTTPRequest::HTTP_HEAD);
+ request.setURI("/large");
+ s.sendRequest(request);
+ std::istream& rs4= s.receiveResponse(response);
+ assert (response.getContentLength() == HTTPSTestServer::LARGE_BODY.length());
+ assert (response.getContentType() == "text/plain");
+ assert (!response.getKeepAlive());
+ std::ostringstream ostr4;
+ assert (StreamCopier::copyStream(rs4, ostr4) == 0);
+}
+
+
+void HTTPSClientSessionTest::testProxy()
+{
+ HTTPSTestServer srv;
+ HTTPSClientSession s("wwws.appinf.com");
+ s.setProxy("proxy.aon.at", 8080);
+ HTTPRequest request(HTTPRequest::HTTP_GET, "/");
+ s.sendRequest(request);
+ HTTPResponse response;
+ std::istream& rs = s.receiveResponse(response);
+ std::ostringstream ostr;
+ StreamCopier::copyStream(rs, ostr);
+ assert (ostr.str().length() > 0);
+}
+
+
+void HTTPSClientSessionTest::setUp()
+{
+}
+
+
+void HTTPSClientSessionTest::tearDown()
+{
+}
+
+
+CppUnit::Test* HTTPSClientSessionTest::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPSClientSessionTest");
+
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testGetSmall);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testGetLarge);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testHead);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallIdentity);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeIdentity);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallChunked);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeChunked);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostSmallClose);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testPostLargeClose);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testKeepAlive);
+ CppUnit_addTest(pSuite, HTTPSClientSessionTest, testProxy);
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h b/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h
new file mode 100644
index 000000000..689bd87a0
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h
@@ -0,0 +1,70 @@
+//
+// HTTPSClientSessionTest.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSClientSessionTest.h#1 $
+//
+// Definition of the HTTPSClientSessionTest class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef HTTPSClientSessionTest_INCLUDED
+#define HTTPSClientSessionTest_INCLUDED
+
+
+#include "Poco/Net/Net.h"
+#include "CppUnit/TestCase.h"
+
+
+class HTTPSClientSessionTest: public CppUnit::TestCase
+{
+public:
+ HTTPSClientSessionTest(const std::string& name);
+ ~HTTPSClientSessionTest();
+
+ void testGetSmall();
+ void testGetLarge();
+ void testHead();
+ void testPostSmallIdentity();
+ void testPostLargeIdentity();
+ void testPostSmallChunked();
+ void testPostLargeChunked();
+ void testPostSmallClose();
+ void testPostLargeClose();
+ void testKeepAlive();
+ void testProxy();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+private:
+};
+
+
+#endif // HTTPSClientSessionTest_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.cpp b/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.cpp
new file mode 100644
index 000000000..f162c4850
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.cpp
@@ -0,0 +1,46 @@
+//
+// HTTPSClientTestSuite.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "HTTPSClientTestSuite.h"
+#include "HTTPSClientSessionTest.h"
+#include "HTTPSStreamFactoryTest.h"
+
+
+CppUnit::Test* HTTPSClientTestSuite::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPSClientTestSuite");
+
+ pSuite->addTest(HTTPSClientSessionTest::suite());
+ pSuite->addTest(HTTPSStreamFactoryTest::suite());
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.h b/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.h
new file mode 100644
index 000000000..264186194
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.h
@@ -0,0 +1,49 @@
+//
+// HTTPSClientTestSuite.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSClientTestSuite.h#1 $
+//
+// Definition of the HTTPSClientTestSuite class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef HTTPSClientTestSuite_INCLUDED
+#define HTTPSClientTestSuite_INCLUDED
+
+
+#include "CppUnit/TestSuite.h"
+
+
+class HTTPSClientTestSuite
+{
+public:
+ static CppUnit::Test* suite();
+};
+
+
+#endif // HTTPSClientTestSuite_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.cpp b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.cpp
new file mode 100644
index 000000000..519b63e62
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.cpp
@@ -0,0 +1,421 @@
+//
+// HTTPSServerTest.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "HTTPSServerTest.h"
+#include "CppUnit/TestCaller.h"
+#include "CppUnit/TestSuite.h"
+#include "Poco/Net/HTTPServer.h"
+#include "Poco/Net/HTTPServerParams.h"
+#include "Poco/Net/HTTPRequestHandler.h"
+#include "Poco/Net/HTTPRequestHandlerFactory.h"
+#include "Poco/Net/HTTPSClientSession.h"
+#include "Poco/Net/HTTPRequest.h"
+#include "Poco/Net/HTTPServerRequest.h"
+#include "Poco/Net/HTTPResponse.h"
+#include "Poco/Net/HTTPServerResponse.h"
+#include "Poco/Net/SecureServerSocket.h"
+#include "Poco/StreamCopier.h"
+#include
+
+
+using Poco::Net::HTTPServer;
+using Poco::Net::HTTPServerParams;
+using Poco::Net::HTTPRequestHandler;
+using Poco::Net::HTTPRequestHandlerFactory;
+using Poco::Net::HTTPSClientSession;
+using Poco::Net::HTTPRequest;
+using Poco::Net::HTTPServerRequest;
+using Poco::Net::HTTPResponse;
+using Poco::Net::HTTPServerResponse;
+using Poco::Net::HTTPMessage;
+using Poco::Net::SecureServerSocket;
+using Poco::StreamCopier;
+
+
+namespace
+{
+ class EchoBodyRequestHandler: public HTTPRequestHandler
+ {
+ public:
+ void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ if (request.getChunkedTransferEncoding())
+ response.setChunkedTransferEncoding(true);
+ else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
+ response.setContentLength(request.getContentLength());
+
+ response.setContentType(request.getContentType());
+
+ std::istream& istr = request.stream();
+ std::ostream& ostr = response.send();
+ int n = StreamCopier::copyStream(istr, ostr);
+ }
+ };
+
+ class EchoHeaderRequestHandler: public HTTPRequestHandler
+ {
+ public:
+ void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ std::ostringstream osstr;
+ request.write(osstr);
+ int n = (int) osstr.str().length();
+ response.setContentLength(n);
+ std::ostream& ostr = response.send();
+ if (request.getMethod() != HTTPRequest::HTTP_HEAD)
+ request.write(ostr);
+ }
+ };
+
+ class RedirectRequestHandler: public HTTPRequestHandler
+ {
+ public:
+ void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ response.redirect("http://www.appinf.com/");
+ }
+ };
+
+ class AuthRequestHandler: public HTTPRequestHandler
+ {
+ public:
+ void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
+ {
+ response.requireAuthentication("/auth");
+ response.send();
+ }
+ };
+
+ class RequestHandlerFactory: public HTTPRequestHandlerFactory
+ {
+ public:
+ HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
+ {
+ if (request.getURI() == "/echoBody")
+ return new EchoBodyRequestHandler;
+ else if (request.getURI() == "/echoHeader")
+ return new EchoHeaderRequestHandler;
+ else if (request.getURI() == "/redirect")
+ return new RedirectRequestHandler();
+ else if (request.getURI() == "/auth")
+ return new AuthRequestHandler();
+ else
+ return 0;
+ }
+ };
+}
+
+
+HTTPSServerTest::HTTPSServerTest(const std::string& name): CppUnit::TestCase(name)
+{
+}
+
+
+HTTPSServerTest::~HTTPSServerTest()
+{
+}
+
+
+void HTTPSServerTest::testIdentityRequest()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentLength((int) body.length());
+ request.setContentType("text/plain");
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == body.size());
+ assert (response.getContentType() == "text/plain");
+ assert (rbody == body);
+}
+
+
+void HTTPSServerTest::testChunkedRequest()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentType("text/plain");
+ request.setChunkedTransferEncoding(true);
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ assert (response.getContentType() == "text/plain");
+ assert (response.getChunkedTransferEncoding());
+ assert (rbody == body);
+}
+
+
+void HTTPSServerTest::testClosedRequest()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentType("text/plain");
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ assert (response.getContentType() == "text/plain");
+ assert (!response.getChunkedTransferEncoding());
+ assert (rbody == body);
+}
+
+
+void HTTPSServerTest::testIdentityRequestKeepAlive()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(true);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ cs.setKeepAlive(true);
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentLength((int) body.length());
+ request.setContentType("text/plain");
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == body.size());
+ assert (response.getContentType() == "text/plain");
+ assert (response.getKeepAlive());
+ assert (rbody == body);
+
+ body.assign(1000, 'y');
+ request.setContentLength((int) body.length());
+ cs.setKeepAlive(false);
+ cs.sendRequest(request) << body;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == body.size());
+ assert (response.getContentType() == "text/plain");
+ assert (!response.getKeepAlive());
+ assert (rbody == body);}
+
+
+void HTTPSServerTest::testChunkedRequestKeepAlive()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(true);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ cs.setKeepAlive(true);
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentType("text/plain");
+ request.setChunkedTransferEncoding(true);
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ assert (response.getContentType() == "text/plain");
+ assert (response.getChunkedTransferEncoding());
+ assert (rbody == body);
+
+ body.assign(1000, 'y');
+ cs.setKeepAlive(false);
+ cs.sendRequest(request) << body;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ assert (response.getContentType() == "text/plain");
+ assert (response.getChunkedTransferEncoding());
+ assert (!response.getKeepAlive());
+ assert (rbody == body);
+}
+
+
+void HTTPSServerTest::testClosedRequestKeepAlive()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(true);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentType("text/plain");
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
+ assert (response.getContentType() == "text/plain");
+ assert (!response.getChunkedTransferEncoding());
+ assert (!response.getKeepAlive());
+ assert (rbody == body);
+ int n = (int) rbody.size();
+}
+
+
+void HTTPSServerTest::test100Continue()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ std::string body(5000, 'x');
+ HTTPRequest request("POST", "/echoBody");
+ request.setContentLength((int) body.length());
+ request.setContentType("text/plain");
+ request.set("Expect", "100-Continue");
+ cs.sendRequest(request) << body;
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getContentLength() == body.size());
+ assert (response.getContentType() == "text/plain");
+ assert (rbody == body);
+}
+
+
+void HTTPSServerTest::testRedirect()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ HTTPRequest request("GET", "/redirect");
+ cs.sendRequest(request);
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getStatus() == HTTPResponse::HTTP_FOUND);
+ assert (response.get("Location") == "http://www.appinf.com/");
+ assert (rbody.empty());
+}
+
+
+void HTTPSServerTest::testAuth()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ HTTPRequest request("GET", "/auth");
+ cs.sendRequest(request);
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED);
+ assert (response.get("WWW-Authenticate") == "Basic realm=\"/auth\"");
+ assert (rbody.empty());
+}
+
+
+void HTTPSServerTest::testNotImpl()
+{
+ SecureServerSocket svs(0);
+ HTTPServerParams* pParams = new HTTPServerParams;
+ pParams->setKeepAlive(false);
+ HTTPServer srv(new RequestHandlerFactory, svs, pParams);
+ srv.start();
+
+ HTTPSClientSession cs("localhost", svs.address().port());
+ HTTPRequest request("GET", "/notImpl");
+ cs.sendRequest(request);
+ HTTPResponse response;
+ std::string rbody;
+ cs.receiveResponse(response) >> rbody;
+ assert (response.getStatus() == HTTPResponse::HTTP_NOT_IMPLEMENTED);
+ assert (rbody.empty());
+}
+
+
+void HTTPSServerTest::setUp()
+{
+}
+
+
+void HTTPSServerTest::tearDown()
+{
+}
+
+
+CppUnit::Test* HTTPSServerTest::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPSServerTest");
+
+ CppUnit_addTest(pSuite, HTTPSServerTest, testIdentityRequest);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testChunkedRequest);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testClosedRequest);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testIdentityRequestKeepAlive);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testChunkedRequestKeepAlive);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testClosedRequestKeepAlive);
+ CppUnit_addTest(pSuite, HTTPSServerTest, test100Continue);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testRedirect);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testAuth);
+ CppUnit_addTest(pSuite, HTTPSServerTest, testNotImpl);
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.h b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.h
new file mode 100644
index 000000000..f70caa2ae
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.h
@@ -0,0 +1,69 @@
+//
+// HTTPSServerTest.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSServerTest.h#1 $
+//
+// Definition of the HTTPSServerTest class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef HTTPSServerTest_INCLUDED
+#define HTTPSServerTest_INCLUDED
+
+
+#include "Poco/Net/Net.h"
+#include "CppUnit/TestCase.h"
+
+
+class HTTPSServerTest: public CppUnit::TestCase
+{
+public:
+ HTTPSServerTest(const std::string& name);
+ ~HTTPSServerTest();
+
+ void testIdentityRequest();
+ void testChunkedRequest();
+ void testClosedRequest();
+ void testIdentityRequestKeepAlive();
+ void testChunkedRequestKeepAlive();
+ void testClosedRequestKeepAlive();
+ void test100Continue();
+ void testRedirect();
+ void testAuth();
+ void testNotImpl();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+private:
+};
+
+
+#endif // HTTPSServerTest_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.cpp b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.cpp
new file mode 100644
index 000000000..516695637
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.cpp
@@ -0,0 +1,44 @@
+//
+// HTTPSServerTestSuite.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "HTTPSServerTestSuite.h"
+#include "HTTPSServerTest.h"
+
+
+CppUnit::Test* HTTPSServerTestSuite::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPSServerTestSuite");
+
+ pSuite->addTest(HTTPSServerTest::suite());
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.h b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.h
new file mode 100644
index 000000000..699568c87
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.h
@@ -0,0 +1,49 @@
+//
+// HTTPSServerTestSuite.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSServerTestSuite.h#1 $
+//
+// Definition of the HTTPSServerTestSuite class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef HTTPSServerTestSuite_INCLUDED
+#define HTTPSServerTestSuite_INCLUDED
+
+
+#include "CppUnit/TestSuite.h"
+
+
+class HTTPSServerTestSuite
+{
+public:
+ static CppUnit::Test* suite();
+};
+
+
+#endif // HTTPSServerTestSuite_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.cpp b/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.cpp
new file mode 100644
index 000000000..8a2d5ac9e
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.cpp
@@ -0,0 +1,153 @@
+//
+// HTTPSStreamFactoryTest.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "HTTPSStreamFactoryTest.h"
+#include "CppUnit/TestCaller.h"
+#include "CppUnit/TestSuite.h"
+#include "Poco/Net/HTTPSStreamFactory.h"
+#include "Poco/Net/NetException.h"
+#include "Poco/URI.h"
+#include "Poco/Exception.h"
+#include "Poco/StreamCopier.h"
+#include "HTTPSTestServer.h"
+#include
+#include
+
+
+using Poco::Net::HTTPSStreamFactory;
+using Poco::Net::NetException;
+using Poco::Net::HTTPException;
+using Poco::URI;
+using Poco::StreamCopier;
+
+
+HTTPSStreamFactoryTest::HTTPSStreamFactoryTest(const std::string& name): CppUnit::TestCase(name)
+{
+}
+
+
+HTTPSStreamFactoryTest::~HTTPSStreamFactoryTest()
+{
+}
+
+
+void HTTPSStreamFactoryTest::testNoRedirect()
+{
+ HTTPSTestServer server;
+ HTTPSStreamFactory factory;
+ URI uri("https://localhost/large");
+ uri.setPort(server.port());
+ std::auto_ptr pStr(factory.open(uri));
+ std::ostringstream ostr;
+ StreamCopier::copyStream(*pStr.get(), ostr);
+ assert (ostr.str() == HTTPSTestServer::LARGE_BODY);
+}
+
+
+void HTTPSStreamFactoryTest::testEmptyPath()
+{
+ HTTPSTestServer server;
+ HTTPSStreamFactory factory;
+ URI uri("https://localhost");
+ uri.setPort(server.port());
+ std::auto_ptr pStr(factory.open(uri));
+ std::ostringstream ostr;
+ StreamCopier::copyStream(*pStr.get(), ostr);
+ assert (ostr.str() == HTTPSTestServer::SMALL_BODY);
+}
+
+
+void HTTPSStreamFactoryTest::testRedirect()
+{
+ HTTPSTestServer server;
+ HTTPSStreamFactory factory;
+ URI uri("https://localhost/redirect");
+ uri.setPort(server.port());
+ std::auto_ptr pStr(factory.open(uri));
+ std::ostringstream ostr;
+ StreamCopier::copyStream(*pStr.get(), ostr);
+ assert (ostr.str() == HTTPSTestServer::LARGE_BODY);
+}
+
+
+void HTTPSStreamFactoryTest::testProxy()
+{
+ HTTPSTestServer server;
+ HTTPSStreamFactory factory("proxy.aon.at", 8080);
+ URI uri("https://wwws.appinf.com/");
+ std::auto_ptr pStr(factory.open(uri));
+ std::ostringstream ostr;
+ StreamCopier::copyStream(*pStr.get(), ostr);
+ assert (ostr.str().length() > 0);
+}
+
+
+void HTTPSStreamFactoryTest::testError()
+{
+ HTTPSTestServer server;
+ HTTPSStreamFactory factory;
+ URI uri("https://localhost/notfound");
+ uri.setPort(server.port());
+ try
+ {
+ std::istream* pStr = factory.open(uri);
+ fail("not found - must throw");
+ }
+ catch (HTTPException& exc)
+ {
+ std::string m = exc.displayText();
+ }
+}
+
+
+void HTTPSStreamFactoryTest::setUp()
+{
+}
+
+
+void HTTPSStreamFactoryTest::tearDown()
+{
+}
+
+
+CppUnit::Test* HTTPSStreamFactoryTest::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPSStreamFactoryTest");
+
+ CppUnit_addTest(pSuite, HTTPSStreamFactoryTest, testNoRedirect);
+ CppUnit_addTest(pSuite, HTTPSStreamFactoryTest, testEmptyPath);
+ CppUnit_addTest(pSuite, HTTPSStreamFactoryTest, testRedirect);
+ CppUnit_addTest(pSuite, HTTPSStreamFactoryTest, testProxy);
+ CppUnit_addTest(pSuite, HTTPSStreamFactoryTest, testError);
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.h b/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.h
new file mode 100644
index 000000000..b1f6283e4
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.h
@@ -0,0 +1,64 @@
+//
+// HTTPSStreamFactoryTest.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSStreamFactoryTest.h#1 $
+//
+// Definition of the HTTPSStreamFactoryTest class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef HTTPSStreamFactoryTest_INCLUDED
+#define HTTPSStreamFactoryTest_INCLUDED
+
+
+#include "Poco/Net/Net.h"
+#include "CppUnit/TestCase.h"
+
+
+class HTTPSStreamFactoryTest: public CppUnit::TestCase
+{
+public:
+ HTTPSStreamFactoryTest(const std::string& name);
+ ~HTTPSStreamFactoryTest();
+
+ void testNoRedirect();
+ void testEmptyPath();
+ void testRedirect();
+ void testProxy();
+ void testError();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+private:
+};
+
+
+#endif // HTTPSStreamFactoryTest_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp b/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp
new file mode 100644
index 000000000..11ad00467
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp
@@ -0,0 +1,238 @@
+//
+// HTTPSTestServer.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "HTTPSTestServer.h"
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Net/SocketAddress.h"
+#include "Poco/Timespan.h"
+#include "Poco/NumberFormatter.h"
+#include
+
+
+using Poco::Net::Socket;
+using Poco::Net::StreamSocket;
+using Poco::Net::SecureStreamSocket;
+using Poco::Net::SecureServerSocket;
+using Poco::Net::SocketAddress;
+using Poco::NumberFormatter;
+
+
+const std::string HTTPSTestServer::SMALL_BODY("This is some random text data returned by the server");
+const std::string HTTPSTestServer::LARGE_BODY(4000, 'x');
+
+
+HTTPSTestServer::HTTPSTestServer():
+ _socket(SocketAddress()),
+ _thread("HTTPSTestServer"),
+ _stop(false)
+{
+ _thread.start(*this);
+ _ready.wait();
+ _lastRequest.reserve(4000);
+}
+
+
+HTTPSTestServer::~HTTPSTestServer()
+{
+ _stop = true;
+ _thread.join();
+}
+
+
+Poco::UInt16 HTTPSTestServer::port() const
+{
+ return _socket.address().port();
+}
+
+
+const std::string& HTTPSTestServer::lastRequest() const
+{
+ return _lastRequest;
+}
+
+
+void HTTPSTestServer::run()
+{
+ _ready.set();
+ Poco::Timespan span(250000);
+ while (!_stop)
+ {
+ if (_socket.poll(span, Socket::SELECT_READ))
+ {
+ StreamSocket ss = _socket.acceptConnection();
+ try
+ {
+ _lastRequest.clear();
+ char buffer[256];
+ int n = ss.receiveBytes(buffer, sizeof(buffer));
+ while (n > 0 && !_stop)
+ {
+ _lastRequest.append(buffer, n);
+ if (!requestComplete())
+ n = ss.receiveBytes(buffer, sizeof(buffer));
+ else
+ n = 0;
+ }
+ std::string response = handleRequest();
+ ss.sendBytes(response.data(), (int) response.size());
+ Poco::Thread::sleep(1000);
+ }
+ catch (Poco::Exception& exc)
+ {
+ std::cerr << "HTTPSTestServer: " << exc.displayText() << std::endl;
+ }
+ }
+ }
+}
+
+
+bool HTTPSTestServer::requestComplete() const
+{
+ return ((_lastRequest.substr(0, 3) == "GET" || _lastRequest.substr(0, 4) == "HEAD") &&
+ (_lastRequest.find("\r\n\r\n") != std::string::npos)) ||
+ (_lastRequest.find("\r\n0\r\n") != std::string::npos);
+}
+
+
+std::string HTTPSTestServer::handleRequest() const
+{
+ std::string response;
+ response.reserve(16000);
+ if (_lastRequest.substr(0, 10) == "GET /small" ||
+ _lastRequest.substr(0, 11) == "HEAD /small")
+ {
+ std::string body(SMALL_BODY);
+ response.append("HTTP/1.0 200 OK\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n");
+ response.append("Connection: Close\r\n");
+ response.append("\r\n");
+ if (_lastRequest.substr(0, 3) == "GET")
+ response.append(body);
+ }
+ else if (_lastRequest.substr(0, 10) == "GET /large" ||
+ _lastRequest.substr(0, 11) == "HEAD /large" ||
+ _lastRequest.substr(0, 36) == "GET http://www.somehost.com:80/large")
+ {
+ std::string body(LARGE_BODY);
+ response.append("HTTP/1.0 200 OK\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n");
+ response.append("Connection: Close\r\n");
+ response.append("\r\n");
+ if (_lastRequest.substr(0, 3) == "GET")
+ response.append(body);
+ }
+ else if (_lastRequest.substr(0, 4) == "POST")
+ {
+ std::string::size_type pos = _lastRequest.find("\r\n\r\n");
+ pos += 4;
+ std::string body = _lastRequest.substr(pos);
+ response.append("HTTP/1.0 200 OK\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ if (_lastRequest.find("Content-Length") != std::string::npos)
+ {
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n");
+ }
+ else if (_lastRequest.find("chunked") != std::string::npos)
+ {
+ response.append("Transfer-Encoding: chunked\r\n");
+ }
+ response.append("Connection: Close\r\n");
+ response.append("\r\n");
+ response.append(body);
+ }
+ else if (_lastRequest.substr(0, 15) == "HEAD /keepAlive")
+ {
+ std::string body(SMALL_BODY);
+ response.append("HTTP/1.1 200 OK\r\n");
+ response.append("Connection: keep-alive\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n\r\n");
+ response.append("HTTP/1.1 200 OK\r\n");
+ response.append("Connection: Keep-Alive\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n\r\n");
+ response.append(body);
+ body = LARGE_BODY;
+ response.append("HTTP/1.1 200 OK\r\n");
+ response.append("Connection: keep-alive\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Transfer-Encoding: chunked\r\n\r\n");
+ response.append(NumberFormatter::formatHex((unsigned) body.length()));
+ response.append("\r\n");
+ response.append(body);
+ response.append("\r\n0\r\n");
+ response.append("HTTP/1.1 200 OK\r\n");
+ response.append("Connection: close\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n\r\n");
+ }
+ else if (_lastRequest.substr(0, 13) == "GET /redirect")
+ {
+ response.append("HTTP/1.0 302 Found\r\n");
+ response.append("Location: /large\r\n");
+ response.append("\r\n");
+ }
+ else if (_lastRequest.substr(0, 13) == "GET /notfound")
+ {
+ response.append("HTTP/1.0 404 Not Found\r\n");
+ response.append("\r\n");
+ }
+ else if (_lastRequest.substr(0, 5) == "GET /" ||
+ _lastRequest.substr(0, 6) == "HEAD /")
+ {
+ std::string body(SMALL_BODY);
+ response.append("HTTP/1.0 200 OK\r\n");
+ response.append("Content-Type: text/plain\r\n");
+ response.append("Content-Length: ");
+ response.append(NumberFormatter::format((int) body.size()));
+ response.append("\r\n");
+ response.append("Connection: Close\r\n");
+ response.append("\r\n");
+ if (_lastRequest.substr(0, 3) == "GET")
+ response.append(body);
+ }
+ return response;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.h b/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.h
new file mode 100644
index 000000000..cc985c634
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.h
@@ -0,0 +1,81 @@
+//
+// HTTPSTestServer.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/HTTPSTestServer.h#1 $
+//
+// Definition of the HTTPSTestServer class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef HTTPSTestServer_INCLUDED
+#define HTTPSTestServer_INCLUDED
+
+
+#include "Poco/Net/Net.h"
+#include "Poco/Net/SecureServerSocket.h"
+#include "Poco/Thread.h"
+#include "Poco/Event.h"
+
+
+class HTTPSTestServer: public Poco::Runnable
+ /// A simple sequential echo server.
+{
+public:
+ HTTPSTestServer();
+ /// Creates the HTTPSTestServer.
+
+ ~HTTPSTestServer();
+ /// Destroys the HTTPSTestServer.
+
+ Poco::UInt16 port() const;
+ /// Returns the port the echo server is
+ /// listening on.
+
+ void run();
+ /// Does the work.
+
+ const std::string& lastRequest() const;
+ /// Returns the last request.
+
+ static const std::string SMALL_BODY;
+ static const std::string LARGE_BODY;
+
+protected:
+ bool requestComplete() const;
+ std::string handleRequest() const;
+
+private:
+ Poco::Net::SecureServerSocket _socket;
+ Poco::Thread _thread;
+ Poco::Event _ready;
+ bool _stop;
+ std::string _lastRequest;
+};
+
+
+#endif // HTTPSTestServer_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.cpp b/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.cpp
new file mode 100644
index 000000000..9650a8fba
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.cpp
@@ -0,0 +1,50 @@
+//
+// OpenSSLTestSuite.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "NetSSLTestSuite.h"
+
+#include "HTTPSClientTestSuite.h"
+#include "TCPServerTestSuite.h"
+#include "HTTPSServerTestSuite.h"
+
+
+CppUnit::Test* NetSSLTestSuite::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("OpenSSLTestSuite");
+
+
+ pSuite->addTest(HTTPSClientTestSuite::suite());
+ pSuite->addTest(TCPServerTestSuite::suite());
+ pSuite->addTest(HTTPSServerTestSuite::suite());
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.h b/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.h
new file mode 100644
index 000000000..952bf403b
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.h
@@ -0,0 +1,49 @@
+//
+// NetSSLTestSuite.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/NetSSLTestSuite.h#1 $
+//
+// Definition of the NetSSLTestSuite class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef NetSSLTestSuite_INCLUDED
+#define NetSSLTestSuite_INCLUDED
+
+
+#include "CppUnit/TestSuite.h"
+
+
+class NetSSLTestSuite
+{
+public:
+ static CppUnit::Test* suite();
+};
+
+
+#endif // NetSSLTestSuite_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/TCPServerTest.cpp b/NetSSL_OpenSSL/testsuite/src/TCPServerTest.cpp
new file mode 100644
index 000000000..9a01632f2
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/TCPServerTest.cpp
@@ -0,0 +1,277 @@
+//
+// TCPServerTest.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/TCPServerTest.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "TCPServerTest.h"
+#include "CppUnit/TestCaller.h"
+#include "CppUnit/TestSuite.h"
+#include "Poco/Net/TCPServer.h"
+#include "Poco/Net/TCPServerConnection.h"
+#include "Poco/Net/TCPServerConnectionFactory.h"
+#include "Poco/Net/TCPServerParams.h"
+#include "Poco/Net/SecureStreamSocket.h"
+#include "Poco/Net/SecureServerSocket.h"
+#include "Poco/Thread.h"
+#include
+
+
+using Poco::Net::TCPServer;
+using Poco::Net::TCPServerConnection;
+using Poco::Net::TCPServerConnectionFactory;
+using Poco::Net::TCPServerConnectionFactoryImpl;
+using Poco::Net::TCPServerParams;
+using Poco::Net::StreamSocket;
+using Poco::Net::SecureStreamSocket;
+using Poco::Net::SecureServerSocket;
+using Poco::Net::SocketAddress;
+using Poco::Thread;
+
+
+namespace
+{
+ class EchoConnection: public TCPServerConnection
+ {
+ public:
+ EchoConnection(const StreamSocket& s): TCPServerConnection(s)
+ {
+ }
+
+ void run()
+ {
+ StreamSocket& ss = socket();
+ try
+ {
+ char buffer[256];
+ int n = ss.receiveBytes(buffer, sizeof(buffer));
+ while (n > 0)
+ {
+ ss.sendBytes(buffer, n);
+ n = ss.receiveBytes(buffer, sizeof(buffer));
+ }
+ }
+ catch (Poco::Exception& exc)
+ {
+ std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
+ }
+ }
+ };
+}
+
+
+TCPServerTest::TCPServerTest(const std::string& name): CppUnit::TestCase(name)
+{
+}
+
+
+TCPServerTest::~TCPServerTest()
+{
+}
+
+
+void TCPServerTest::testOneConnection()
+{
+ SecureServerSocket svs(0);
+ TCPServer srv(new TCPServerConnectionFactoryImpl(), svs);
+ srv.start();
+ assert (srv.currentConnections() == 0);
+ assert (srv.currentThreads() == 0);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 0);
+
+ SocketAddress sa("localhost", svs.address().port());
+ SecureStreamSocket ss1(sa);
+ std::string data("hello, world");
+ ss1.sendBytes(data.data(), (int) data.size());
+ char buffer[256];
+ int n = ss1.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+ assert (srv.currentConnections() == 1);
+ assert (srv.currentThreads() == 1);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 1);
+ ss1.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 0);
+}
+
+
+void TCPServerTest::testTwoConnections()
+{
+ SecureServerSocket svs(0);
+ TCPServer srv(new TCPServerConnectionFactoryImpl(), svs);
+ srv.start();
+ assert (srv.currentConnections() == 0);
+ assert (srv.currentThreads() == 0);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 0);
+
+ SocketAddress sa("localhost", svs.address().port());
+ SecureStreamSocket ss1(sa);
+ SecureStreamSocket ss2(sa);
+ std::string data("hello, world");
+ ss1.sendBytes(data.data(), (int) data.size());
+ ss2.sendBytes(data.data(), (int) data.size());
+
+ char buffer[256];
+ int n = ss1.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+
+ n = ss2.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+
+ assert (srv.currentConnections() == 2);
+ assert (srv.currentThreads() == 2);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 2);
+ ss1.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 1);
+ assert (srv.currentThreads() == 1);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 2);
+ ss2.close();
+
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 0);
+}
+
+
+void TCPServerTest::testMultiConnections()
+{
+ SecureServerSocket svs(0);
+ TCPServerParams* pParams = new TCPServerParams;
+ pParams->setMaxThreads(4);
+ pParams->setMaxQueued(4);
+ pParams->setThreadIdleTime(100);
+ TCPServer srv(new TCPServerConnectionFactoryImpl(), svs, pParams);
+ srv.start();
+ assert (srv.currentConnections() == 0);
+ assert (srv.currentThreads() == 0);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 0);
+
+ SocketAddress sa("localhost", svs.address().port());
+ SecureStreamSocket ss1(sa);
+ SecureStreamSocket ss2(sa);
+ SecureStreamSocket ss3(sa);
+ SecureStreamSocket ss4(sa);
+ std::string data("hello, world");
+ ss1.sendBytes(data.data(), (int) data.size());
+ ss2.sendBytes(data.data(), (int) data.size());
+ ss3.sendBytes(data.data(), (int) data.size());
+ ss4.sendBytes(data.data(), (int) data.size());
+
+ char buffer[256];
+ int n = ss1.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+
+ n = ss2.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+
+ n = ss3.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+
+ n = ss4.receiveBytes(buffer, sizeof(buffer));
+ assert (n > 0);
+ assert (std::string(buffer, n) == data);
+
+ assert (srv.currentConnections() == 4);
+ assert (srv.currentThreads() == 4);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 4);
+
+ SecureStreamSocket ss5(sa);
+ Thread::sleep(200);
+ assert (srv.queuedConnections() == 1);
+ SecureStreamSocket ss6(sa);
+ Thread::sleep(200);
+ assert (srv.queuedConnections() == 2);
+
+ ss1.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 4);
+ assert (srv.currentThreads() == 4);
+ assert (srv.queuedConnections() == 1);
+ assert (srv.totalConnections() == 5);
+
+ ss2.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 4);
+ assert (srv.currentThreads() == 4);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 6);
+
+ ss3.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 3);
+ assert (srv.currentThreads() == 3);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 6);
+
+ ss4.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 2);
+ assert (srv.currentThreads() == 2);
+ assert (srv.queuedConnections() == 0);
+ assert (srv.totalConnections() == 6);
+
+ ss5.close();
+ ss6.close();
+ Thread::sleep(300);
+ assert (srv.currentConnections() == 0);}
+
+
+void TCPServerTest::setUp()
+{
+}
+
+
+void TCPServerTest::tearDown()
+{
+}
+
+
+CppUnit::Test* TCPServerTest::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TCPServerTest");
+
+ CppUnit_addTest(pSuite, TCPServerTest, testOneConnection);
+ CppUnit_addTest(pSuite, TCPServerTest, testTwoConnections);
+ CppUnit_addTest(pSuite, TCPServerTest, testMultiConnections);
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/TCPServerTest.h b/NetSSL_OpenSSL/testsuite/src/TCPServerTest.h
new file mode 100644
index 000000000..6904d1226
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/TCPServerTest.h
@@ -0,0 +1,62 @@
+//
+// TCPServerTest.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/TCPServerTest.h#1 $
+//
+// Definition of the TCPServerTest class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef TCPServerTest_INCLUDED
+#define TCPServerTest_INCLUDED
+
+
+#include "Poco/Net/Net.h"
+#include "CppUnit/TestCase.h"
+
+
+class TCPServerTest: public CppUnit::TestCase
+{
+public:
+ TCPServerTest(const std::string& name);
+ ~TCPServerTest();
+
+ void testOneConnection();
+ void testTwoConnections();
+ void testMultiConnections();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+private:
+};
+
+
+#endif // TCPServerTest_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.cpp b/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.cpp
new file mode 100644
index 000000000..4459e2616
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.cpp
@@ -0,0 +1,44 @@
+//
+// TCPServerTestSuite.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.cpp#1 $
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "TCPServerTestSuite.h"
+#include "TCPServerTest.h"
+
+
+CppUnit::Test* TCPServerTestSuite::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TCPServerTestSuite");
+
+ pSuite->addTest(TCPServerTest::suite());
+
+ return pSuite;
+}
diff --git a/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.h b/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.h
new file mode 100644
index 000000000..6af24f91c
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.h
@@ -0,0 +1,49 @@
+//
+// TCPServerTestSuite.h
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/TCPServerTestSuite.h#1 $
+//
+// Definition of the TCPServerTestSuite class.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef TCPServerTestSuite_INCLUDED
+#define TCPServerTestSuite_INCLUDED
+
+
+#include "CppUnit/TestSuite.h"
+
+
+class TCPServerTestSuite
+{
+public:
+ static CppUnit::Test* suite();
+};
+
+
+#endif // TCPServerTestSuite_INCLUDED
diff --git a/NetSSL_OpenSSL/testsuite/src/WinDriver.cpp b/NetSSL_OpenSSL/testsuite/src/WinDriver.cpp
new file mode 100644
index 000000000..445706f88
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/src/WinDriver.cpp
@@ -0,0 +1,86 @@
+//
+// WinDriver.cpp
+//
+// $Id: //poco/1.3/NetSSL_OpenSSL/testsuite/src/WinDriver.cpp#1 $
+//
+// Windows test driver for Poco OpenSSL.
+//
+// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "WinTestRunner/WinTestRunner.h"
+#include "NetSSLTestSuite.h"
+#include "Poco/Util/Application.h"
+#include "Poco/Net/HTTPStreamFactory.h"
+#include "Poco/Net/HTTPSStreamFactory.h"
+
+
+class NetSSLApp: public Poco::Util::Application
+{
+public:
+ NetSSLApp()
+ {
+ }
+
+ ~NetSSLApp()
+ {
+ }
+
+protected:
+ void initialize(Application& self)
+ {
+ loadConfiguration(); // load default configuration files, if present
+ Application::initialize(self);
+ }
+};
+
+
+class TestDriver: public CppUnit::WinTestRunnerApp
+{
+ void TestMain()
+ {
+ CppUnit::WinTestRunner runner;
+ Poco::Net::HTTPStreamFactory::registerFactory();
+ Poco::Net::HTTPSStreamFactory::registerFactory();
+ NetSSLApp app;
+ std::string argv("OpenSSLTest");
+ const char* pArgv = argv.c_str();
+ try
+ {
+ app.init(1, (char**)&pArgv);
+ }
+ catch (Poco::Exception& exc)
+ {
+ app.logger().log(exc);
+ }
+ runner.addTest(NetSSLTestSuite::suite());
+ runner.run();
+ }
+};
+
+
+static TestDriver theDriver;
diff --git a/NetSSL_OpenSSL/testsuite/testrunner.xml b/NetSSL_OpenSSL/testsuite/testrunner.xml
new file mode 100644
index 000000000..ed8b08790
--- /dev/null
+++ b/NetSSL_OpenSSL/testsuite/testrunner.xml
@@ -0,0 +1,42 @@
+
+
+
+ ${application.configDir}any.pem
+ ${application.configDir}rootcert.pem
+ none
+ 9
+ true
+ ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH
+
+ KeyFileHandler
+
+ test
+
+
+
+ AcceptCertificateHandler
+
+
+
+
+
+ ${application.configDir}any.pem
+ ${application.configDir}rootcert.pem
+ relaxed
+ 9
+ true
+ ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH
+
+ KeyFileHandler
+
+ test
+
+
+
+ AcceptCertificateHandler
+
+
+
+
+
+