Skip to content

Commit

Permalink
Terminate SSL test cases after too many attempts
Browse files Browse the repository at this point in the history
When the handshake fails to complete in a certain number of steps,
terminate it. We set this limit as 40 as it should be significantly
larger than the number of required steps (since the buffer limit is at
2048, we'd expect no more than 10 steps, even with a large certificate
or chain).

Signed-off-by: Alexander Scheel <[email protected]>
  • Loading branch information
cipherboy committed Jul 15, 2019
1 parent 0b6924d commit d634b1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions org/mozilla/jss/tests/TestBufferPRFD.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ int main(int argc, char** argv)
* size, we'll be able to step one of the two sides until something useful
* happens. */
printf("Trying handshake...\n");

int count = 0;
while (!is_finished(c_nspr, s_nspr)) {
printf("Client Handshake:\n");
if (SSL_ForceHandshake(c_nspr) != SECSuccess) {
Expand All @@ -335,6 +337,10 @@ int main(int argc, char** argv)
}

printf("\n\n");
count += 1;
if (count >= 40) {
fprintf(stderr, "error: unable to make progress after %d steps!\n", count);
}
}

/* Send a test message from client -> server to ensure that the connection
Expand Down
7 changes: 7 additions & 0 deletions org/mozilla/jss/tests/TestBufferPRFD.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public static void TestSSLHandshake(String nickname) throws Exception
assert(!IsHandshakeFinished(c_nspr, s_nspr));

/* Try a handshake */
int count = 0;
while(!IsHandshakeFinished(c_nspr, s_nspr)) {
if (SSL.ForceHandshake(c_nspr) != SSL.SECSuccess) {
int error = PR.GetError();
Expand All @@ -157,6 +158,12 @@ public static void TestSSLHandshake(String nickname) throws Exception
System.exit(1);
}
}

count += 1;
if (count >= 40) {
System.err.println("Error: unable to make progress after " + count + " steps!");
System.exit(1);
}
}
System.out.println("Handshake completed successfully!\n");
assert(IsHandshakeFinished(c_nspr, s_nspr));
Expand Down

0 comments on commit d634b1e

Please sign in to comment.