Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ Options are:
Using this extension may miss some supported cipher suites, if the
server does not support EC-based suites without the client extension.

- `-st protocol`

Negotiate TLS on ports that do not have always-on TLS. The supported
protocols at this time ar `FTP` and `SMTP`.

- `-text fname`

Produce a text report (readable by humans) into the designated
Expand Down
48 changes: 46 additions & 2 deletions Src/FullTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ internal int ConnectionWait {
}
}

internal string StartTls {
get {
return startTls;
}
set {
startTls = value;
}
}

bool verbose;
TextWriter debugLog;
int minVersion;
Expand All @@ -210,6 +219,7 @@ internal int ConnectionWait {
bool proxSSL;
int readTimeout;
int connectionWait;
string startTls;

Report rp;
SSLTestBuilder tb;
Expand Down Expand Up @@ -601,6 +611,40 @@ internal Report Run()
return rp;
}

Stream PrepareStream(Stream stream)
{
if (startTls != null) {
StreamReader r = new StreamReader(stream);
StreamWriter w = new StreamWriter(stream);
switch (startTls) {
case "FTP":
w.AutoFlush = true;
r.ReadLine();
w.WriteLine("AUTH TLS");
r.ReadLine();
break;
case "SMTP":
w.AutoFlush = true;
string response;
do {response = r.ReadLine();} while (response[3] == '-');
w.WriteLine("EHLO TestSSLServer");
bool TlsEnabled = false;
do {
response = r.ReadLine();
TlsEnabled |= response.EndsWith("STARTTLS");
} while (response[3] == '-');
if (TlsEnabled)
{
w.WriteLine("STARTTLS");
do { response = r.ReadLine(); } while (response[3] == '-');
}
else throw new InvalidOperationException("TLS not supported");
break;
}
}
return stream;
}

Stream OpenConnection()
{
if (connectionWait > 0) {
Expand All @@ -609,7 +653,7 @@ Stream OpenConnection()

if (proxName == null) {
TcpClient tc = new TcpClient(serverName, serverPort);
return tc.GetStream();
return PrepareStream(tc.GetStream());
}

Stream ns = null;
Expand All @@ -624,7 +668,7 @@ Stream OpenConnection()
HTTPProx hp = new HTTPProx();
Stream ns2 = hp.DoProxy(ns, serverName, serverPort);
ns = null;
return ns2;
return PrepareStream(ns2);
} finally {
if (ns != null) {
try {
Expand Down
9 changes: 9 additions & 0 deletions Src/TestSSLServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static void Usage()
Console.WriteLine(
" -noec try connecting without a 'supported curves' extension");
Console.WriteLine(
" -st protocol negotiate TLS connection (FTP, SMTP)");
Console.WriteLine(
" -text fname write text report in file 'fname' ('-' = stdout)");
Console.WriteLine(
" -json fname write JSON report in file 'fname' ('-' = stdout)");
Expand Down Expand Up @@ -187,6 +189,13 @@ static void Process(string[] args)
}
logName = args[i];
break;
case "-st":
case "--start-tls":
if (++ i >= args.Length) {
Usage();
}
ft.StartTls = args[i].ToUpperInvariant();
break;
default:
if (a.Length > 0 && a[0] == '-') {
Usage();
Expand Down