2 // Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "gnashconfig.h"
24 //#include <netinet/in.h>
26 #include <sys/types.h>
29 #include <sys/types.h>
35 #include "as_object.h"
39 #include "openssl/ssl.h"
40 #include "sslclient.h"
45 #include "arg_parser.h"
46 #include "sslclient.h"
47 #include "sslserver.h"
50 using namespace gnash
;
53 static void usage (void);
55 static TestState runtest
;
59 static void test_client();
60 static void test_server();
62 static SSLClient client
;
66 LogFile
& dbglogfile
= LogFile::getDefaultInstance();
69 main(int argc
, char *argv
[])
71 const Arg_parser::Option opts
[] =
73 { 'h', "help", Arg_parser::no
},
74 { 'v', "verbose", Arg_parser::no
},
75 { 's', "hostname", Arg_parser::yes
},
76 { 'o', "port", Arg_parser::yes
},
77 { 'c', "cert", Arg_parser::yes
},
78 { 'p', "pem", Arg_parser::yes
},
79 { 'k', "keyfile", Arg_parser::yes
},
80 { 'w', "password", Arg_parser::yes
},
81 { 'a', "calist", Arg_parser::yes
},
82 { 'r', "rootpath", Arg_parser::yes
},
83 { 'n', "netdebug", Arg_parser::no
},
84 { 'e', "dsemon", Arg_parser::no
},
87 Arg_parser
parser(argc
, argv
, opts
);
88 if( ! parser
.error().empty() ) {
89 cout
<< parser
.error() << endl
;
94 bool servermode
= false;
96 for( int i
= 0; i
< parser
.arguments(); ++i
) {
97 const int code
= parser
.code(i
);
104 dbglogfile
.setVerbosity();
105 log_debug(_("Verbose output turned on"));
108 client
.setHostname(parser
.argument(i
));
109 log_debug(_("Hostname for SSL connection is: %s"),
110 client
.getHostname());
113 net
.setPort(parser
.argument
<short>(i
));
114 log_debug(_("Port for SSL connections is: %hd"),
118 client
.setCert(parser
.argument(i
));
119 log_debug(_("Cert file for SSL connection is: %s"),
123 client
.setPem(parser
.argument(i
));
124 log_debug(_("Pem file for SSL connection is: %s"),
128 client
.setKeyfile(parser
.argument(i
));
129 log_debug(_("Keyfile file for SSL connection is: %s"),
130 client
.getKeyfile());
133 client
.setCAlist(parser
.argument(i
));
134 log_debug(_("CA List file for SSL connection is: %s"),
138 client
.setRootPath(parser
.argument(i
));
139 server
.setRootPath(parser
.argument(i
));
140 log_debug(_("Root path for SSL pem files is: %s"),
141 client
.getRootPath());
144 client
.setPassword(parser
.argument(i
));
145 log_debug(_("Password for SSL pem files is: %s"),
146 client
.getPassword());
149 net
.toggleDebug(true);
153 log_debug(_("Enabling SSL server mode"));
156 infile
= parser
.argument(i
);
157 log_debug(_("Input file for testing the SSL connection is: %s"), infile
);
162 catch (Arg_parser::ArgParserException
&e
) {
163 cerr
<< _("Error parsing command line options: ") << e
.what() << endl
;
164 cerr
<< _("This is a Gnash bug.") << endl
;
178 static void test_client()
184 // Make a tcp/ip connect to the server
185 if (net
.createClient(client
.getHostname()) == false) {
186 log_error("Can't connect to server %s", client
.getHostname());
190 if (client
.sslConnect(net
.getFileFd(), client
.getHostname(), net
.getPort())) {
191 runtest
.pass("Connected to SSL server");
193 runtest
.fail("Couldn't connect to SSL server");
197 // I haven't seen a password with the first character set to
198 // zero ever. so we assume it got set correctly by the callback.
199 if (client
.getPassword()[0] != 0) {
200 runtest
.pass("Password was set for SSL connection");
203 runtest
.unresolved("Password wasn't set for SSL connection");
205 runtest
.fail("Password wasn't set for SSL connection");
210 runtest
.unresolved("Cert didn't match hostfor SSL connection");
212 if (client
.checkCert()) {
213 runtest
.pass("Cert matched host for SSL connection");
215 runtest
.fail("Cert didn't match host for SSL connection");
222 runtest
.unresolved("Couldn't write to SSL connection");
224 amf::Buffer
&request
= http
.formatRequest("/crossdomain.xml", HTTP::HTTP_GET
);
226 if ((ret
= client
.sslWrite(request
)) == request
.allocated()) {
227 runtest
.pass("Wrote bytes to SSL connection");
229 runtest
.fail("Couldn't write to SSL connection.");
234 // This blocks forever unless data is received.
236 runtest
.unresolved("Couldn't read bytes from SSL connection");
239 if ((ret
= client
.sslRead(buf
)) > 0) {
240 runtest
.pass("Read bytes from SSL connection");
242 runtest
.fail("Couldn't read bytes to SSL connection.");
248 runtest
.unresolved("Couldn't shutdown SSL connection");
250 if (client
.sslShutdown()) {
251 runtest
.pass("Shutdown SSL connection");
253 runtest
.fail("Couldn't shutdown SSL connection");
259 static void test_server()
261 log_debug("Starting SSL Server");
263 // The por is set by the command line arguments
268 server
.sslAccept(net
.getFileFd());
276 cerr
<< "This program tests SSL support in the libnet library." << endl
;
277 cerr
<< "Usage: test_ssl [hvsocpkwar]" << endl
;
278 cerr
<< "-h\tHelp" << endl
;
279 cerr
<< "-v\tVerbose" << endl
;
280 cerr
<< "-s\thostname" << endl
;
281 cerr
<< "-o\tPort" << endl
;
282 cerr
<< "-c\tCert File" << endl
;
283 cerr
<< "-p\tPem file" << endl
;
284 cerr
<< "-k\tKeyfile file" << endl
;
285 cerr
<< "-w\tPassword" << endl
;
286 cerr
<< "-a\tCA List" << endl
;
287 cerr
<< "-r\tRoot path" << endl
;
288 cerr
<< "-e\tServer mode" << endl
;
295 main(int /*argc*/, char /* *argv[]*/)
298 cerr
<< "This program needs to have DejaGnu installed!" << endl
;