This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ct_mail_alert.erl
69 lines (63 loc) · 2.65 KB
/
ct_mail_alert.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-module(ct_mail_alert).
-export([send_alert/3]).
-record(credentials, {hostname, username, password}).
%% Issues an email alert.
-spec send_alert([{string(), string()}]|[], [tuple()], {serial, string()}) ->
{'ok', pid()}|ok.
send_alert([], _Certificate, {serial, _Serial}) ->
ok;
send_alert([{Domain, User}|Tail], Certificate, {serial, Serial}) ->
lager:notice("We have an alert for ~p, ~p with cert ~p~n",
[Domain, User, Certificate]),
{ok, Config} = file:consult("priv/credentials.rr"),
Creds = proplists:get_value(smtp, Config),
{ok, Pid} = gen_smtp_client:send({"ctadvisor@lolware.net", [User],
"Subject: SSL Has been issued for monitored domain\r\n"
"From: ctadvisor@lolware.net\r\nTo: " ++ User ++ "\r\n\r\n"
"ct_advisor has detected the issuance of an SSL certificate for domain "
++ Domain ++ " for which you are registered. If this was not you, you"
" may wish to investigate. You can obtain further information "
"by reviewing the issued certificate here: https://crt.sh/?serial="
++ Serial ++ "\r\nIf you would like to unsubscribe from this service "
"please visit this link: "
"https://ctadvisor.lolware.net/registrations/unsubscribe"},
[{relay, Creds#credentials.hostname},
{username, Creds#credentials.username},
{password, Creds#credentials.password}, {port, 587} ]),
send_alert(Tail, Certificate, {serial, Serial}),
{ok, Pid}.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
send_bouncemail_test() ->
% AWS SES will still accept a bounce - but should generate an alert to SNS
{T, Pid} = send_alert([{"lolwaretest.net",
"bounce@simulator.amazonses.com"}],
[{dNSName, "www.lolwaretest.net"}, {dNSName, "lolwaretest.net"}],
{serial, "19F169D2A081E71A79CE2219220D0B582D6"}),
?assertEqual(ok, T),
unlink(Pid),
Monitor = erlang:monitor(process, Pid),
Response = receive
{'DOWN', Monitor, process, Pid, Error} ->
Error
after 5000 ->
nomessage
end,
?assertEqual(normal, Response).
send_mail_test() ->
{T, Pid} = send_alert([{"lolware.net",
"success@simulator.amazonses.com"},
{"www.lolware.net", "success@simulator.amazonses.com"}],
[{dNSName, "www.lolwaretest.net"}, {dNSName, "lolwaretest.net"}],
{serial, "19F169D2A081E71A79CE2219220D0B582D6"}),
?assertEqual(ok, T),
unlink(Pid),
Monitor = erlang:monitor(process, Pid),
Response = receive
{'DOWN', Monitor, process, Pid, Error} ->
Error
after 5000 ->
nomessage
end,
?assertEqual(normal, Response).
-endif.