pike.git / lib / modules / SSL.pmod / https.pike

version» Context lines:

pike.git/lib/modules/SSL.pmod/https.pike:26:   #ifndef HOST   #define HOST "127.0.0.1"   #endif      #ifdef SSL3_DEBUG   #define SSL3_DEBUG_MSG(X ...) werror(X)   #else /*! SSL3_DEBUG */   #define SSL3_DEBUG_MSG(X ...)   #endif /* SSL3_DEBUG */    - import Stdio; -  +    class MyContext   {    inherit SSL.context;       SSL.alert alert_factory(SSL.connection con,    int level, int description,    SSL.Constants.ProtocolVersion version,    string|void message, mixed|void trace)    {    if (message) {
pike.git/lib/modules/SSL.pmod/https.pike:51:    }    return ::alert_factory(con, level, description, version, message, trace);    }   }      #ifndef HTTPS_CLIENT   SSL.sslport port;      void my_accept_callback(object f)   { -  conn(port->accept()); +  Conn(port->accept());   }   #endif    - class conn { -  import Stdio; + class Conn {       object sslfile;       string message =    "HTTP/1.0 200 Ok\r\n"    "Connection: close\r\n"    "Content-Length: 132\r\n"    "Content-Type: text/html; charset=ISO-8859-1\r\n"    "Date: Thu, 01 Jan 1970 00:00:01 GMT\r\n"    "Server: Bare-Bones\r\n"
pike.git/lib/modules/SSL.pmod/https.pike:100:    sslfile->set_write_callback(write_callback);    }       protected void create(object f)    {    sslfile = f;    sslfile->set_nonblocking(read_callback, 0, 0);    }   }    - class no_random { -  object arcfour = Crypto.Arcfour(); -  -  protected void create(string|void secret) + class Client   { -  if (!secret) -  secret = sprintf("%s%4c", random_string(32), time()); -  arcfour->set_encrypt_key(Crypto.SHA256.hash(secret)); -  read(1000); -  } -  -  string read(int size) -  { -  return arcfour->crypt( "\021"*size ); -  } - } -  - /* PKCS#1 Private key structure: -  - RSAPrivateKey ::= SEQUENCE { -  version Version, -  modulus INTEGER, -- n -  publicExponent INTEGER, -- e -  privateExponent INTEGER, -- d -  prime1 INTEGER, -- p -  prime2 INTEGER, -- q -  exponent1 INTEGER, -- d mod (p-1) -  exponent2 INTEGER, -- d mod (q-1) -  coefficient INTEGER -- (inverse of q) mod p } -  - Version ::= INTEGER -  - */ -  - class client - { +     constant request =    "HEAD / HTTP/1.0\r\n"    "Host: localhost:" + PORT + "\r\n"    "\r\n";       SSL.sslfile ssl;    int sent; -  +     void write_cb()    {    int bytes = ssl->write(request[sent..]);    if (bytes > 0) {    sent += bytes;    } else if (sent < 0) { -  werror("Failed to write data: %s\n", strerror(ssl->errno())); -  exit(17); +  exit(17, "Failed to write data: %s\n", strerror(ssl->errno()));    }    if (sent == sizeof(request)) {    ssl->set_write_callback(UNDEFINED);    }    } -  +     void got_data(mixed ignored, string data)    {    werror("Data: %O\n", data);    } -  +     void con_closed()    { -  werror("Connection closed.\n"); -  exit(0); +  exit(0, "Connection closed.\n");    }       protected void create(Stdio.File con)    {    SSL.context ctx = MyContext(); -  ctx->random = no_random()->read; +     // Make sure all cipher suites are available.    ctx->preferred_suites = ctx->get_suites(-1, 2);    werror("Starting\n");    ssl = SSL.sslfile(con, ctx, 1);    ssl->set_nonblocking(got_data, write_cb, con_closed);    }   }      int main()   {   #ifdef HTTPS_CLIENT    Stdio.File con = Stdio.File();    if (!con->connect(HOST, PORT)) {    werror("Failed to connect to server: %s\n", strerror(con->errno()));    return 17;    } -  client(con); +  Client(con);    return -17;   #else    SSL.context ctx = MyContext();       Crypto.Sign key;    string certificate;       string common_name = gethostname();    common_name = (gethostbyname(common_name) || ({ common_name }))[0];   
pike.git/lib/modules/SSL.pmod/https.pike:274:    ctx->add_cert(key, ({ certificate }), ({ "*" }));   #endif       // Make sure all cipher suites are available.    ctx->preferred_suites = ctx->get_suites(CIPHER_BITS, KE_MODE);    SSL3_DEBUG_MSG("Cipher suites:\n%s",    .Constants.fmt_cipher_suites(ctx->preferred_suites));       SSL3_DEBUG_MSG("Certs:\n%O\n", ctx->cert_pairs);    -  ctx->random = no_random()->read; -  +     port = SSL.sslport(ctx);       werror("Starting\n");    if (!port->bind(PORT, my_accept_callback))    { -  perror(""); +  Stdio.perror("");    return 17;    }    else {    werror("Listening on port %d.\n", PORT);    return -17;    }   #endif   }