86903b | 2003-01-23 | Martin Nilsson | |
|
50c4c4 | 2001-08-23 | Martin Nilsson | |
|
153908 | 2005-04-15 | Marc Dirix | |
|
c39ebd | 2000-12-28 | Martin Stjernholm | |
#ifdef SSL3_DEBUG
|
e6ad50 | 2004-05-17 | Martin Nilsson | | # define SSL3_WERR(X ...) werror("SSL3: " X)
|
c39ebd | 2000-12-28 | Martin Stjernholm | | #else
|
e6ad50 | 2004-05-17 | Martin Nilsson | | # define SSL3_WERR(X ...)
|
c39ebd | 2000-12-28 | Martin Stjernholm | | #endif
|
0d0e95 | 2000-11-13 | Per Hedbor | | inherit SSLProtocol;
constant supports_ipless = 0;
constant name = "https";
|
a9fa0d | 2001-07-21 | Martin Stjernholm | | constant prot_name = "https";
|
325025 | 2002-06-14 | Martin Nilsson | | constant requesthandlerfile = "plugins/protocols/http.pike";
|
0d0e95 | 2000-11-13 | Per Hedbor | | constant default_port = 443;
class fallback_redirect_request
{
string in = "";
string out;
string default_prefix;
int port;
Stdio.File f;
void die()
{
|
e6ad50 | 2004-05-17 | Martin Nilsson | | SSL3_WERR("fallback_redirect_request::die()\n");
|
e31781 | 2004-04-03 | Martin Nilsson | | f->set_blocking();
|
0d0e95 | 2000-11-13 | Per Hedbor | | f->close();
}
|
e31781 | 2004-04-03 | Martin Nilsson | | void write_callback()
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
|
e6ad50 | 2004-05-17 | Martin Nilsson | | SSL3_WERR("fallback_redirect_request::write_callback()\n");
|
e31781 | 2004-04-03 | Martin Nilsson | | int written = f->write(out);
|
0d0e95 | 2000-11-13 | Per Hedbor | | if (written <= 0)
die();
|
e31781 | 2004-04-03 | Martin Nilsson | | else {
out = out[written..];
|
f48716 | 2004-06-04 | Stephen R. van den Berg | | if (!sizeof(out))
|
e31781 | 2004-04-03 | Martin Nilsson | | die();
}
|
0d0e95 | 2000-11-13 | Per Hedbor | | }
|
153908 | 2005-04-15 | Marc Dirix | | void timeout()
{
SSL3_WERR("fallback_redirect_request::timeout()");
die();
}
|
e31781 | 2004-04-03 | Martin Nilsson | | void read_callback(mixed ignored, string s)
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
|
e6ad50 | 2004-05-17 | Martin Nilsson | | SSL3_WERR("fallback_redirect_request::read_callback(X, %O)\n", s);
|
0d0e95 | 2000-11-13 | Per Hedbor | | in += s;
string name;
string prefix;
|
153908 | 2005-04-15 | Marc Dirix | | remove_call_out(timeout);
|
6bae6e | 2002-10-22 | Martin Nilsson | | if (has_value(in, "\r\n\r\n"))
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
array(string) lines = in / "\r\n";
array(string) req = replace(lines[0], "\t", " ") / " ";
if (sizeof(req) < 2)
{
out = "HTTP/1.0 400 Bad Request\r\n\r\n";
}
else
{
if (sizeof(req) == 2)
{
name = req[1];
}
else
{
name = req[1..sizeof(req)-2] * " ";
foreach(map(lines[1..], `/, ":"), array header)
{
if ( (sizeof(header) >= 2) &&
(lower_case(header[0]) == "host") )
prefix = "https://" + header[1] - " ";
}
}
if (prefix) {
if (prefix[-1] == '/')
|
d74800 | 2004-06-04 | Stephen R. van den Berg | | prefix = prefix[..sizeof(prefix)-2];
|
0d0e95 | 2000-11-13 | Per Hedbor | | prefix = prefix + ":" + port;
} else {
if (!(prefix = default_prefix)) {
string ip = (f->query_address(1)/" ")[0];
|
153908 | 2005-04-15 | Marc Dirix | |
if (has_value(ip, ":")) {
ip = "[" + ip + "]";
}
|
0d0e95 | 2000-11-13 | Per Hedbor | | prefix = "https://" + ip + ":" + port;
} else if (prefix[..4] == "http:") {
prefix = "https:" + prefix[5..];
}
}
out = sprintf("HTTP/1.0 301 Redirect to secure server\r\n"
"Location: %s%s\r\n\r\n", prefix, name);
}
f->set_read_callback(0);
f->set_write_callback(write_callback);
|
153908 | 2005-04-15 | Marc Dirix | | } else {
if (sizeof(in) > 5) {
string q = replace(upper_case(in[..10]), "\t", " ");
if (!(has_prefix(q, "GET ") ||
has_prefix(q, "HEAD ") ||
has_prefix(q, "OPTIONS ") ||
has_prefix(q, "PUT ") ||
has_prefix(q, "PROPFIND "))) {
SSL3_WERR(sprintf("fallback_redirect_request->read_callback():\n"
"Doesn't look like HTTP (method: %O)\n", q));
die();
return;
}
}
call_out(timeout, 30);
|
0d0e95 | 2000-11-13 | Per Hedbor | | }
}
|
e31781 | 2004-04-03 | Martin Nilsson | | void create(Stdio.File socket, string s, string l, int p)
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
|
e6ad50 | 2004-05-17 | Martin Nilsson | | SSL3_WERR("fallback_redirect_request(X, %O, %O, %O)\n", s, l||"CONFIG PORT", p);
|
0d0e95 | 2000-11-13 | Per Hedbor | | f = socket;
default_prefix = l;
port = p;
f->set_nonblocking(read_callback, 0, die);
read_callback(f, s);
}
|
e31781 | 2004-04-03 | Martin Nilsson | |
string _sprintf(int t) {
return t=='O' && sprintf("fallback_redirect_request(%O)", f);
}
|
0d0e95 | 2000-11-13 | Per Hedbor | | }
class http_fallback
{
|
e31781 | 2004-04-03 | Martin Nilsson | | SSL.sslfile my_fd;
|
0d0e95 | 2000-11-13 | Per Hedbor | |
void ssl_alert_callback(object alert, object|int n, string data)
{
|
e6ad50 | 2004-05-17 | Martin Nilsson | | SSL3_WERR("http_fallback(X, %O, %O)\n", n, data);
|
0d0e95 | 2000-11-13 | Per Hedbor | |
|
153908 | 2005-04-15 | Marc Dirix | | if (((my_fd->current_write_state||
my_fd->query_connection()->current_write_state)->seq_num == 0) &&
has_value(lower_case(data), "http"))
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
|
153908 | 2005-04-15 | Marc Dirix | | Stdio.File raw_fd;
if (my_fd->shutdown) {
raw_fd = my_fd->shutdown();
} else {
raw_fd = my_fd->socket;
my_fd->socket = 0;
}
|
0d0e95 | 2000-11-13 | Per Hedbor | |
|
153908 | 2005-04-15 | Marc Dirix | |
|
0d0e95 | 2000-11-13 | Per Hedbor | | fallback_redirect_request(raw_fd, data,
my_fd->config &&
my_fd->config->query("MyWorldLocation"),
port);
|
153908 | 2005-04-15 | Marc Dirix | | if (!my_fd->shutdown) {
destruct(my_fd);
}
|
0d0e95 | 2000-11-13 | Per Hedbor | | }
}
|
e31781 | 2004-04-03 | Martin Nilsson | | void ssl_accept_callback(mixed ignored)
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
|
e6ad50 | 2004-05-17 | Martin Nilsson | | SSL3_WERR("ssl_accept_callback(X)\n");
|
e31781 | 2004-04-03 | Martin Nilsson | | my_fd->set_alert_callback(0);
my_fd->set_accept_callback(0);
|
0d0e95 | 2000-11-13 | Per Hedbor | | my_fd = 0;
}
|
153908 | 2005-04-15 | Marc Dirix | | void create(SSL.sslfile|Stdio.File fd)
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
my_fd = fd;
fd->set_alert_callback(ssl_alert_callback);
fd->set_accept_callback(ssl_accept_callback);
}
|
e31781 | 2004-04-03 | Martin Nilsson | |
string _sprintf(int t) {
return t=='O' && sprintf("http_fallback(%O)", my_fd);
}
|
0d0e95 | 2000-11-13 | Per Hedbor | | }
|
153908 | 2005-04-15 | Marc Dirix | | Stdio.File accept()
|
0d0e95 | 2000-11-13 | Per Hedbor | | {
|
153908 | 2005-04-15 | Marc Dirix | | object(Stdio.File)|SSL.sslfile q = ::accept();
|
0d0e95 | 2000-11-13 | Per Hedbor | |
if (q) {
http_fallback(q);
}
return q;
}
int set_cookie, set_cookie_only_once;
void fix_cvars( Variable.Variable a )
{
set_cookie = query( "set_cookie" );
set_cookie_only_once = query( "set_cookie_only_once" );
}
void create( mixed ... args )
{
|
f9531d | 2004-04-04 | Martin Nilsson | | core.set_up_http_variables( this );
|
0d0e95 | 2000-11-13 | Per Hedbor | | if( variables[ "set_cookie" ] )
variables[ "set_cookie" ]->set_changed_callback( fix_cvars );
if( variables[ "set_cookie_only_once" ] )
variables[ "set_cookie_only_once" ]->set_changed_callback( fix_cvars );
fix_cvars(0);
::create( @args );
}
|