pike.git/lib/modules/SSL.pmod/https.pike:1:
#pike __REAL_VERSION__
/*
- * dummy https server
+ * dummy https server/client
*/
- //! Dummy HTTPS server
+ //! Dummy HTTPS server/client
#define PORT 25678
#ifdef SSL3_DEBUG
#define SSL3_DEBUG_MSG(X ...) werror(X)
#else /*! SSL3_DEBUG */
#define SSL3_DEBUG_MSG(X ...)
#endif /* SSL3_DEBUG */
#if constant(SSL.Cipher.CipherAlgorithm)
import Stdio;
-
+ #ifndef HTTPS_CLIENT
inherit SSL.sslport;
-
+ protected void create()
+ {
+ SSL3_DEBUG_MSG("https->create\n");
+ sslport::create();
+ }
+
+ void my_accept_callback(object f)
+ {
+ werror("Accept!\n");
+ conn(accept());
+ }
+ #endif
+
string my_certificate = MIME.decode_base64(
"MIIBxDCCAW4CAQAwDQYJKoZIhvcNAQEEBQAwbTELMAkGA1UEBhMCREUxEzARBgNV\n"
"BAgTClRodWVyaW5nZW4xEDAOBgNVBAcTB0lsbWVuYXUxEzARBgNVBAoTClRVIEls\n"
"bWVuYXUxDDAKBgNVBAsTA1BNSTEUMBIGA1UEAxMLZGVtbyBzZXJ2ZXIwHhcNOTYw\n"
"NDMwMDUzNjU4WhcNOTYwNTMwMDUzNjU5WjBtMQswCQYDVQQGEwJERTETMBEGA1UE\n"
"CBMKVGh1ZXJpbmdlbjEQMA4GA1UEBxMHSWxtZW5hdTETMBEGA1UEChMKVFUgSWxt\n"
"ZW5hdTEMMAoGA1UECxMDUE1JMRQwEgYDVQQDEwtkZW1vIHNlcnZlcjBcMA0GCSqG\n"
"SIb3DQEBAQUAA0sAMEgCQQDBB6T7bGJhRhRSpDESxk6FKh3iKKrpn4KcDtFM0W6s\n"
"16QSPz6J0Z2a00lDxudwhJfQFkarJ2w44Gdl/8b+de37AgMBAAEwDQYJKoZIhvcN\n"
"AQEEBQADQQB5O9VOLqt28vjLBuSP1De92uAiLURwg41idH8qXxmylD39UE/YtHnf\n"
pike.git/lib/modules/SSL.pmod/https.pike:104: Inside #if constant(SSL.Cipher.CipherAlgorithm)
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
*/
- void my_accept_callback(object f)
+ class client
{
- werror("Accept!\n");
- conn(accept());
+ 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);
}
-
+ 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);
+ }
-
+ protected void create(Stdio.File con)
+ {
+ SSL.context ctx = SSL.context();
+ ctx->random = no_random()->read;
+ 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("127.0.0.1", PORT)) {
+ werror("Failed to connect to server: %s\n", strerror(con->errno()));
+ return 17;
+ }
+ client(con);
+ return -17;
+ #else
SSL3_DEBUG_MSG("Cert: '%s'\n", String.string2hex(my_certificate));
SSL3_DEBUG_MSG("Key: '%s'\n", String.string2hex(my_key));
#if 0
array key = SSL.asn1.ber_decode(my_key)->get_asn1()[1];
SSL3_DEBUG_MSG("Decoded key: %O\n", key);
object n = key[1][1];
object e = key[2][1];
object d = key[3][1];
object p = key[4][1];
object q = key[5][1];
pike.git/lib/modules/SSL.pmod/https.pike:143:
certificates = ({ my_certificate });
random = no_random()->read;
werror("Starting\n");
if (!bind(PORT, my_accept_callback))
{
perror("");
return 17;
}
else
return -17;
+ #endif
}
- protected void create()
- {
- SSL3_DEBUG_MSG("https->create\n");
- sslport::create();
- }
-
+
#else // constant(SSL.Cipher.CipherAlgorithm)
constant this_program_does_not_exist = 1;
#endif