summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-05-04 19:52:13 +0200
committerLinus Nordberg <linus@nordberg.se>2014-05-04 19:52:13 +0200
commited8bb6d1e454b9ddc793f74f682bd80b1c728904 (patch)
treeae81a24c1e7bbafd0a169ef94d8fada9d9403408 /src
parent68f6bdf0f88322867b35a6ae35a0c4c3ea641884 (diff)
Get going, first cut.
add-chain looks like it might work properly. Not verified!
Diffstat (limited to 'src')
-rw-r--r--src/.erlang5
-rw-r--r--src/Makefile10
-rw-r--r--src/Makefile.inc6
-rw-r--r--src/https/Makefile5
-rw-r--r--src/https/https_server.erl5
-rw-r--r--src/https_server.erl43
-rw-r--r--src/v1.erl45
7 files changed, 88 insertions, 31 deletions
diff --git a/src/.erlang b/src/.erlang
deleted file mode 100644
index b0147e0..0000000
--- a/src/.erlang
+++ /dev/null
@@ -1,5 +0,0 @@
-%% Erlang init file for ctls (in Emacs -*- erlang -*- mode)
-%%io:format("Inititaing for ctls~n").
-code:add_pathz("https").
-code:add_pathz("merkletree").
-code:add_pathz("x509").
diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644
index 62548f6..0000000
--- a/src/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-## TODO: Consider using 'rebar' instead of Make.
-
-MODULES = ctls
-
-all: subdirs $(MODULES:%=%.beam)
-
-subdirs:
- $(MAKE) -C https
-
-include Makefile.inc
diff --git a/src/Makefile.inc b/src/Makefile.inc
deleted file mode 100644
index 928b06a..0000000
--- a/src/Makefile.inc
+++ /dev/null
@@ -1,6 +0,0 @@
-# -*- makefile -*-
-
-.erl.beam:
- erlc -W $<
-
-.SUFFIXES: .erl .beam
diff --git a/src/https/Makefile b/src/https/Makefile
deleted file mode 100644
index ac3b57b..0000000
--- a/src/https/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-MODULES = https_server
-
-all: $(MODULES:%=%.beam)
-
-include ../Makefile.inc
diff --git a/src/https/https_server.erl b/src/https/https_server.erl
deleted file mode 100644
index a62a02f..0000000
--- a/src/https/https_server.erl
+++ /dev/null
@@ -1,5 +0,0 @@
--module(https_server).
--export([start/0]).
-
-start() ->
- io:format("Starting https server~n").
diff --git a/src/https_server.erl b/src/https_server.erl
new file mode 100644
index 0000000..a0b81b4
--- /dev/null
+++ b/src/https_server.erl
@@ -0,0 +1,43 @@
+-module(https_server).
+-export([start/0, stop/1]).
+
+start() ->
+ io:format("Starting https server~n"),
+ %% TODO: put this in httpd_props.conf and use that at erlang
+ %% start. inets:start(httpd, {proplist_file, "httpd_props.conf"}).
+ ServerRoot = "/home/linus/usr/src/ct/ctls/webroot",
+ {ok, Pid} =
+ inets:start(httpd,
+ [{port, 8080},
+ %%{bind_address, {127,0,0,1}},
+ {bind_address, {192, 168, 122, 119}},
+ {server_name, "flimsy.ct.nordu.net"},
+ {server_root, ServerRoot},
+ {document_root, ServerRoot ++ "/docroot"},
+ {modules, [mod_alias,
+ mod_auth,
+ mod_esi,
+ mod_get,
+ mod_head,
+ mod_log,
+ mod_disk_log]},
+ %%{re_write, {"^/ct/v1/(.*)$", "/ct/v1/https_server/\\1"}},
+ {re_write, {"^/ct/v1/(.*)_(.*)$", "/ct/v1/\\1-\\2"}},
+ {erl_script_alias, {"/ct", [v1]}},
+ {erl_script_nocache, true},
+ {error_log, "log/error"},
+ {security_log, "log/security"},
+ {transfer_log, "log/transfer"},
+ %% See ssl(3erl) for SSL options.
+ {socket_type, {essl, [
+ {certfile, ServerRoot ++ "/certs/webcert.pem"},
+ {keyfile, ServerRoot ++ "/keys/webkey.pem"},
+ %%{cacertfile, ServerRoot ++ "/certs/cacert.pem"},
+ {ciphers, ssl:cipher_suites()},
+ {verify, verify_none}
+ ]}}
+ ]),
+ Pid.
+
+stop(Pid) ->
+ inets:stop(httpd, Pid).
diff --git a/src/v1.erl b/src/v1.erl
new file mode 100644
index 0000000..99cf55b
--- /dev/null
+++ b/src/v1.erl
@@ -0,0 +1,45 @@
+-module(v1).
+-export([add_chain/3]).
+-export([hello/3]).
+-include("/home/linus/usr/src/ct/plop/include/plop.hrl").
+-define(PROTOCOL_VERSION, 1).
+
+%% Public functions.
+add_chain(SessionID, _Env, Input) ->
+ Res = case (catch jiffy:decode(Input)) of
+ {error, E} -> html("add-chain: bad input; see RFC 6962", E);
+ {[{<<"chain">>, Chain}]} ->
+ Entry = #plop_entry{type = x509,
+ data = list_to_binary(Chain)},
+ SPT = plop:add(#timestamped_entry{entry = Entry}),
+ Timestamp = SPT#spt_on_wire.timestamp,
+ R = [{sct_version, ?PROTOCOL_VERSION},
+ {id, base64:encode(plop:get_logid())},
+ {timestamp, Timestamp},
+ {extensions, []},
+ {signature, base64:encode(list_to_binary(plop:serialise(SPT)))}],
+ binary_to_list(jiffy:encode({R}));
+ _ -> html("add-chain: missing input: chain; see RFC 6962", Input)
+ end,
+ mod_esi:deliver(SessionID, Res).
+
+%% For testing. FIXME: Remove.
+hello(SessionID, Env, Input) ->
+ Query = httpd:parse_query(Input),
+ mod_esi:deliver(SessionID, io_lib:format(
+ "Content-Type: text/html\r\n\r\n" ++
+ "<html><body>hello again, erlang world" ++
+ "<p>SessionID: ~p~n" ++
+ "<p>Env: ~p~n" ++
+ "<p>Input, raw: ~p~n" ++
+ "<p>Input, parsed: ~p~n" ++
+ "</body></html>", [SessionID, Env, Input, Query])).
+
+%% Private functions.
+html(Text, Input) ->
+ io_lib:format(
+ "Content-Type: text/html\r\n\r\n" ++
+ "<html><body><p>~n" ++
+ "~s~n" ++
+ "~p~n" ++
+ "</body></html>~n", [Text, Input]).