pike.git/
lib/
modules/
Protocols.pmod/
HTTP.pmod/
Server.pmod/
SSLPort.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2014-09-29
2014-09-29 00:08:09 by Martin Nilsson <nilsson@opera.com>
b1fd32c96793952fbbc7f7aa85c2880f8c2de834 (
172
lines) (+
81
/-
91
)
[
Show
|
Annotate
]
Branch:
8.0
Removed one level of indirection and inherit SSL.Port directly into SSLPort.
1:
#pike __REAL_VERSION__
-
#require constant(SSL.
Cipher
)
+
#require constant(SSL.
Port
)
-
+
inherit SSL.Port;
+
import ".";
-
MySSLPort port;
+
int portno;
-
string
|int(0..0)
interface;
+
string interface;
function(Request:void) callback; //! object|function|program request_program=Request;
-
//!
The
simplest
SSL server
possible
. Binds a port and calls
-
//!
a callback with @[request_program] objects.
+
//!
A
very
simple
SSL server. Binds a port and calls a callback with
+
//!
@[request_program] objects.
//! Create a HTTPS (HTTP over SSL) server. //!
-
//! @param
_
callback
+
//! @param callback
//! The function run when a request is received. //! takes one argument of type @[Request].
-
//! @param
_portno
+
//! @param
port
//! The port number to bind to, defaults to 443.
-
//! @param
_
interface
+
//! @param interface
//! The interface address to bind to. //! @param key //! An optional SSL secret key, provided in binary format, such
32:
//! @param share //! If true, the connection will be shared if possible. See //! @[Stdio.Port.bind] for more information
-
void create(function(Request:void)
_
callback,
-
void|int
_portno
,
-
void|string
_
interface,
+
protected
void create(function(Request:void) callback,
+
void|int
port
,
+
void|string interface,
void|string|Crypto.Sign.State key, void|string|array(string) certificate, void|int share) {
-
portno=_portno;
-
if
(
!portno
)
portno=443
;
// default HTTPS port
+
::create
();
-
callback
=_callback;
-
interface=
_
interface;
+
portno
=
port || 443;
+
this
_
program::
callback
=callback
;
+
this_program::
interface=interface;
-
port=MySSLPort();
+
if( key && certificate ) { if( stringp(certificate) ) certificate = ({ certificate });
-
port->
ctx->add_cert( key, certificate, ({"*"}) );
+
ctx->add_cert( key, certificate, ({"*"}) );
} else
-
port->
set_default_keycert();
+
set_default_keycert();
-
if (!
port->
bind(portno,new_connection,
[string]
interface,share))
-
error("
HTTP.Server.SSLPort:
failed
to bind port %s%d: %s\n",
-
interface?interface+":":"",
-
portno,strerror(
port->
errno()));
+
if (!bind(portno,
new_connection,
this_program::
interface,
share))
+
error("
Failed
to bind port %s%d: %s\n",
+
interface?interface+":":"", portno,
strerror(errno()));
}
-
//! Closes the HTTP port.
-
void close()
-
{
-
destruct(port);
-
port=0;
-
}
-
+
void destroy() { close(); } //! The port accept callback protected void new_connection() {
-
SSL.File fd=
port->
accept();
+
SSL.File fd=accept();
Request r=request_program(); r->attach_fd(fd,this,callback); }
-
//!
-
class
MySSLPort
+
protected
void set_default_keycert()
{
-
-
inherit SSL.Port;
-
-
//!
-
void set_default_keycert()
-
{
+
foreach(({ Crypto.RSA(), Crypto.DSA(), #if constant(Crypto.ECC.Curve) Crypto.ECC.SECP_521R1.ECDSA(), #endif
-
}), Crypto.Sign private_key)
{
-
private_key->set_random(Crypto.Random.random_string);
+
}), Crypto.Sign private_key)
+
{
switch(private_key->name()) { case "RSA": private_key->generate_key(4096);
124:
private string tmp_key; private array(string) tmp_cert;
+
__deprecated__ this_program `port()
+
{
+
return this;
+
}
+
//! @deprecated add_cert __deprecated__ void set_key(string skey) {
142:
if( tmp_key && tmp_cert ) ctx->add_cert( tmp_key, tmp_cert ); }
-
}
+
protected string _sprintf(int t) { return t=='O' && sprintf("%O(%O:%d)", this_program, interface, portno); }