813b392000-08-04Andreas Sigfridsson #! /usr/bin/env pike
d502122002-09-17Johan Sundström #pike __REAL_VERSION__
813b392000-08-04Andreas Sigfridsson  // SSL Client example
2b3fe22004-02-29Martin Nilsson #if constant(SSL.Cipher.CipherAlgorithm)
4f5e1d2003-01-27Martin Nilsson import SSL.Constants;
813b392000-08-04Andreas Sigfridsson  SSL.sslfile sslfile; void write_callback(mixed id) { sslfile->set_write_callback(0);
aa77d52001-04-18Pär Svensson  // sslfile->write("GET / HTTP/1.0\r\n\r\n");
813b392000-08-04Andreas Sigfridsson } void read_callback(mixed id, string s) { write(s); } int main(int argc, array(string) argv) { SSL.context context = SSL.context(); // Allow only strong crypto context->preferred_suites = ({ SSL_rsa_with_idea_cbc_sha, SSL_rsa_with_rc4_128_sha, SSL_rsa_with_rc4_128_md5, SSL_rsa_with_3des_ede_cbc_sha, });
f90e3c2004-02-03Martin Nilsson  context->random = Crypto.Random.random_string;
813b392000-08-04Andreas Sigfridsson  Stdio.File socket = Stdio.File();
d502122002-09-17Johan Sundström  if(!socket->connect("pike.ida.liu.se", 443))
813b392000-08-04Andreas Sigfridsson  { werror("couldn't connect\n"); exit(-1); } socket->set_nonblocking();
aa77d52001-04-18Pär Svensson  sslfile = SSL.sslfile(socket, context, 1,0);
813b392000-08-04Andreas Sigfridsson  sslfile->set_nonblocking(read_callback, write_callback, exit); return -17; }
2b3fe22004-02-29Martin Nilsson  #endif