Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lavabit/magma.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpadkins <jacobpadkins@gmail.com>2017-03-20 20:59:39 +0300
committerjpadkins <jacobpadkins@gmail.com>2017-03-20 20:59:39 +0300
commite2ed8f77db50a37ed50670f67d31e084e8233301 (patch)
treecbbeb3490655ce334e839bb27810bfc5b4f67f3b /check/magma
parentd2273a05020345924f704c9124fa46932c3e1fe2 (diff)
Added SMTP AUTH PlAIN test
Diffstat (limited to 'check/magma')
-rw-r--r--check/magma/servers/smtp/smtp_check.c8
-rw-r--r--check/magma/servers/smtp/smtp_check.h7
-rw-r--r--check/magma/servers/smtp/smtp_check_network.c96
3 files changed, 99 insertions, 12 deletions
diff --git a/check/magma/servers/smtp/smtp_check.c b/check/magma/servers/smtp/smtp_check.c
index 836110ad..8f3baecd 100644
--- a/check/magma/servers/smtp/smtp_check.c
+++ b/check/magma/servers/smtp/smtp_check.c
@@ -90,7 +90,7 @@ START_TEST (check_smtp_checkers_filters_s) {
}
END_TEST
-START_TEST (check_smtp_auth_from_field_s) {
+START_TEST (check_smtp_network_auth_plain_s) {
log_disable();
bool_t outcome = true;
@@ -102,10 +102,10 @@ START_TEST (check_smtp_auth_from_field_s) {
outcome = false;
}
else if (status()) {
- outcome = check_smtp_auth_from_field_sthread(errmsg, server->network.port);
+ outcome = check_smtp_network_auth_plain_sthread(errmsg, server->network.port);
}
- log_test("SMTP / NETWORK / AUTH / FROM FIELD / SINGLE THREADED:", errmsg);
+ log_test("SMTP / NETWORK / AUTH PLAIN / SINGLE THREADED:", errmsg);
ck_assert_msg(outcome, st_char_get(errmsg));
}
END_TEST
@@ -119,7 +119,7 @@ Suite * suite_check_smtp(void) {
suite_check_testcase(s, "SMTP", "SMTP Checkers Filters/S", check_smtp_checkers_filters_s);
suite_check_testcase(s, "SMTP", "SMTP Network Basic/ TCP/S", check_smtp_network_basic_tcp_s);
suite_check_testcase(s, "SMTP", "SMTP Network Basic/ TLS/S", check_smtp_network_basic_tls_s);
- suite_check_testcase(s, "SMTP", "SMTP Network Auth From Field/S", check_smtp_auth_from_field_s);
+ suite_check_testcase(s, "SMTP", "SMTP Network Auth Plain/S", check_smtp_network_auth_plain_s);
return s;
}
diff --git a/check/magma/servers/smtp/smtp_check.h b/check/magma/servers/smtp/smtp_check.h
index e8b6862d..691c39c7 100644
--- a/check/magma/servers/smtp/smtp_check.h
+++ b/check/magma/servers/smtp/smtp_check.h
@@ -16,11 +16,12 @@ bool_t check_smtp_checkers_regex_sthread(stringer_t *errmsg);
bool_t check_smtp_checkers_filters_sthread(stringer_t *errmsg, int_t action, int_t expected);
/// smtp_check_network.c
-bool_t check_smtp_client_read_line_to_end(client_t *client);
+bool_t check_smtp_client_read_end(client_t *client);
+bool_t check_smtp_client_mail_rcpt_data(client_t *client, chr_t *from, chr_t *to, stringer_t *errmsg);
+bool_t check_smtp_client_quit_cleanup(client_t *client, stringer_t *errmsg);
bool_t check_smtp_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t secure);
-bool_t check_smtp_auth_from_field_sthread(stringer_t *errmsg, uint32_t port);
+bool_t check_smtp_network_auth_plain_sthread(stringer_t *errmsg, uint32_t port);
Suite * suite_check_smtp(void);
#endif
-
diff --git a/check/magma/servers/smtp/smtp_check_network.c b/check/magma/servers/smtp/smtp_check_network.c
index 0664ceb4..db72c617 100644
--- a/check/magma/servers/smtp/smtp_check_network.c
+++ b/check/magma/servers/smtp/smtp_check_network.c
@@ -16,7 +16,7 @@
* @return Returns true if client_read_line was successful until the last line was found.
* Otherwise returns false.
*/
-bool_t check_smtp_client_read_line_to_end(client_t *client) {
+bool_t check_smtp_client_read_end(client_t *client) {
while (client_read_line(client) > 0) {
if (pl_char_get(client->line)[3] == ' ') return true;
@@ -24,6 +24,56 @@ bool_t check_smtp_client_read_line_to_end(client_t *client) {
return false;
}
+bool_t check_smtp_client_mail_rcpt_data(client_t *client, chr_t *from, chr_t *to, stringer_t *errmsg) {
+
+ chr_t *line_from = "MAIL FROM: <%s>\r\n", *line_to = "RCPT TO: <%s>\r\n";
+ size_t size_from = strlen(line_from) + strlen(from) -2, size_to = strlen(line_to) + strlen(to) -2;
+
+ // Issue MAIL command.
+ if (client_print(client, line_from, from) != size_from || !check_smtp_client_read_end(client) ||
+ client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+ st_sprint(errmsg, "Failed to return successful status after MAIL.");
+ return false;
+ }
+
+ // Issue RCPT command.
+ else if (client_print(client, line_to, to) != size_to || !check_smtp_client_read_end(client) ||
+ client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+ st_sprint(errmsg, "Failed to return successful status after RCPT.");
+ return false;
+ }
+
+ // Issue DATA command.
+ else if (client_print(client, "DATA\r\n") != 6 || !check_smtp_client_read_end(client) ||
+ client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("354"))) {
+ st_sprint(errmsg, "Failed to return a proceed status code after DATA.");
+ return false;
+ }
+
+ return true;
+}
+
+bool_t check_smtp_client_quit_cleanup(client_t *client, stringer_t *errmsg) {
+
+ // Test the QUIT command.
+ if (client_print(client, "QUIT\r\n") != 6 || client_read_line(client) <= 0 ||
+ client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("221"))) {
+ st_sprint(errmsg, "Failed to return successful status following the QUIT command.");
+ client_close(client);
+ return false;
+ }
+
+ else if (client_read_line(client) > 0) {
+ st_sprint(errmsg, "The server failed to close the connection after issuing a QUIT command.");
+ client_close(client);
+ return false;
+ }
+
+ client_close(client);
+
+ return true;
+}
+
bool_t check_smtp_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t secure) {
size_t location = 0;
@@ -49,7 +99,7 @@ bool_t check_smtp_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_
// Test the EHLO command.
- else if (client_print(client, "EHLO localhost\r\n") != 16 || !check_smtp_client_read_line_to_end(client) ||
+ else if (client_print(client, "EHLO localhost\r\n") != 16 || !check_smtp_client_read_end(client) ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
st_sprint(errmsg, "Failed to return successful status after EHLO.");
client_close(client);
@@ -108,7 +158,7 @@ bool_t check_smtp_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_
return true;
}
-bool_t check_smtp_auth_from_field_sthread(stringer_t *errmsg, uint32_t port) {
+bool_t check_smtp_network_auth_plain_sthread(stringer_t *errmsg, uint32_t port) {
size_t location = 0;
client_t *client = NULL;
@@ -123,13 +173,49 @@ bool_t check_smtp_auth_from_field_sthread(stringer_t *errmsg, uint32_t port) {
return false;
}
// Issue EHLO.
- else if (client_print(client, "EHLO localhost\r\n") != 16 || !check_smtp_client_read_line_to_end(client) ||
+ else if (client_print(client, "EHLO localhost\r\n") != 16 || !check_smtp_client_read_end(client) ||
client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) {
st_sprint(errmsg, "Failed to return successful status after EHLO.");
client_close(client);
return false;
}
+ // Issue AUTH with incorrect credentials.
+ else if (client_print(client, "AUTH PLAIN bWFnbWEAbWFnbWEAaW52YWxpZHBhc3N3b3Jk\r\n") != 49 ||
+ !check_smtp_client_read_end(client) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER("535"))) {
- return true;
+ st_sprint(errmsg, "Failed to return error status after AUTH with incorrect credentials.");
+ client_close(client);
+ return false;
+ }
+ // Issue AUTH with correct credentials.
+ else if (client_print(client, "AUTH PLAIN bWFnbWEAbWFnbWEAcGFzc3dvcmQ=\r\n") != 41 ||
+ !check_smtp_client_read_end(client) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER("235"))) {
+
+ st_sprint(errmsg, "Failed to return successful status after AUTH with correct credentials.");
+ client_close(client);
+ return false;
+ }
+ // Try sending mail from an unauthenticated account (ladar@lavabit.com).
+ else if (!check_smtp_client_mail_rcpt_data(client, "ladar@lavabit.com", "princess@example.com", errmsg) ||
+ client_print(client, ".\r\n") != 3 || !check_smtp_client_read_end(client) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER("550"))) {
+
+ if (!errmsg) st_sprint(errmsg, "Failed to return an error status after sending from an unauthenticated account.");
+ client_close(client);
+ return false;
+ }
+ // Try sending mail from the authenticated account (magma@lavabit.com).
+ else if (!check_smtp_client_mail_rcpt_data(client, "magma@lavabit.com", "princess@example.com", errmsg) ||
+ client_print(client, ".\r\n") != 3 || !check_smtp_client_read_end(client) || client_status(client) != 1 ||
+ st_cmp_cs_starts(&(client->line), NULLER("250"))) {
+
+ if (!errmsg) st_sprint(errmsg, "Failed to return successful status after sending from an authenticated account.");
+ client_close(client);
+ return false;
+ }
+
+ return check_smtp_client_quit_cleanup(client, errmsg);
}