2
0
mirror of https://github.com/mozilla/cipherscan.git synced 2025-04-21 01:03:39 +02:00
Commit Graph

174 Commits

Author SHA1 Message Date
Richard Soderberg
b91b153bbd Replace instances of string-ish [[ -lt ]] with arithmetic (( < )). 2015-09-18 11:34:25 -07:00
Richard Soderberg
34ae0ccab9 Replace instances of string-ish [[ -ne ]] with arithmetic (( != )). 2015-09-18 11:34:25 -07:00
Richard Soderberg
3d3789828b Replace instances of string-ish [[ -gt ]] with arithmetic (( > )). 2015-09-18 11:34:25 -07:00
Richard Soderberg
9c63841e46 Replace instances of string-ish [[ -eq ]] with arithmetic (( == )). 2015-09-18 11:34:25 -07:00
Richard Soderberg
90ac19cfe8 Replace an instance of string-ish [[ $? -gt 0 ]] with arithmetic (( $? != 0 )).
This more accurately reflects that "non-zero exit status indicates
failure"; while > 0 will no doubt work as well, != 0 avoids the question
of whether $? is signed or unsigned in bash and more accurately
represents the documentation ("non-zero", != 0).
2015-09-18 11:34:25 -07:00
Richard Soderberg
871ad92ae2 Simplify signature algorithm extraction to use a capturing regex and string substitution. 2015-09-18 11:34:25 -07:00
Richard Soderberg
2764a16693 Replace OLDIFS/IFS joins with join_array_by_char(), avoiding $(...) subshell slowdown. 2015-09-18 11:34:25 -07:00
Richard Soderberg
487f7cb6a4 Replace an echo | awk printf with builtin printf. 2015-09-18 11:34:25 -07:00
Richard Soderberg
a342ff7579 Assign r=pass/fail once only, rather than twice for fail->pass. 2015-09-18 11:34:25 -07:00
Richard Soderberg
9e3154389e Replace unnecessary test of command; if $? with if command. 2015-09-18 11:34:25 -07:00
Richard Soderberg
fc71ed7204 Replace |sort|uniq with more efficient |sort -u. 2015-09-18 11:34:25 -07:00
Richard Soderberg
644c1aa83a Replace numeric ALLCIPHERS comparison with simpler -n test. 2015-09-18 11:34:24 -07:00
Julien Vehent
3dd0f58f4c When in JSON mode, run curve and tolerance tests 2015-09-18 13:05:49 -04:00
Julien Vehent
55918f3afb Add OK/KO flags in terminal output 2015-09-18 13:05:49 -04:00
Julien Vehent
249b3be23d Rephrase TLS tolerance output in terminal 2015-09-18 12:35:17 -04:00
Julien Vehent
0de6abab61 Merge pull request #81 from floatingatoll/argparse_fixes
Argparse fixes
2015-09-18 09:35:42 -04:00
Julien Vehent
5e2b12d940 Merge pull request #80 from floatingatoll/cacerts_logic
Replace CACERTS env logic with --cafile parameter.
2015-09-18 09:35:06 -04:00
Julien Vehent
b951fd5588 Merge pull request #79 from floatingatoll/autodetection-perf
separate darwin and non-darwin OS autodetection, add NOAUTODETECT support for top1m performance
2015-09-18 09:32:33 -04:00
Julien Vehent
9dace07f4d Merge pull request #76 from floatingatoll/curves-by-default
enable curves by default
2015-09-18 09:29:18 -04:00
Richard Soderberg
4b87301eb4 separate darwin and non-darwin OS autodetection, add NOAUTODETECT support for top1m performance
This patch implements two structural changes.

First, OS-level detection routines are broken out into a case statement.

Darwin doesn't need to test for readlink/timeout nor Busybox, so this
noticeably improves performance over multiple runs on Darwin.

Linux suffers no additional penalty, since we already ran if $(uname)
every time anyways, and continues to use the more complex
timeout/gtimeout/busybox logic at the (preexisting, unaffected) cost to
performance over multiple runs.

Second, if NOAUTODETECT is set, then the script assumes (and verifies)
that you're providing TIMEOUTBIN and OPENSSLBIN values. If both of those
values are executable files, then the script will proceed, else it will
abort. In this scenario, readlink is unnecessary and is thus unused.

The combination of these two changes will improve performance over
multiple runs both on Darwin and when NOAUTODETECT is set for top1m.
2015-09-05 05:04:37 -07:00
Richard Soderberg
12ede64882 bash4 version check failure should go to STDERR. 2015-09-05 05:04:04 -07:00
Richard Soderberg
6adda69af5 Revise CACERTS autodetection logic, ensure that CACERTS/CAPATH is readable/directory, add undocumented CAPATH env override.
This takes advantage of the new --cafile logic to avoid running CACERTS
autodetection when a file is provided on the command line.

It then ensures the readability of that file, whether provided or
autodetected.

This also adds an undocumented CAPATH environment variable alternative
to --capath, to go along with the existing undocumented CACERTS
environment variable alternative to --cafile, to provide legacy support
for preexisting users.
2015-09-05 04:59:17 -07:00
Richard Soderberg
5dc692566a Refuse to accept both --cafile and --capath.
Prior to this commit, the code accepts both the --cafile and the
--capath options, as that's how it's always behaved. This patch corrects
that, refusing to proceed if the options are provided.

Technically, openssl permits the use of both the -CAfile and -CApath
options. However, cipherscan itself can only make use of one of the two
options, and does not currently support "one or both" scenarios.

So this patch ensures that users are not caught unaware when they
specify --capath and --cafile and the script refuses to honor the
latter.
2015-09-05 04:45:28 -07:00
Richard Soderberg
097bd0c43b Rewrite HOST[:PORT] extraction routine (less sed, more validation).
The HOST[:PORT] extraction routine was written using several calls to
sed and a bunch of regex post-processing of the bash $@ array.

This replaces that with bash-native array commands, copying $@ into
a $PARAMS array, removing the last element into $TARGET, and then
passing the remainder to openssl s_client.

This adds validation of the TARGET to ensure that it matches what we
expect for a HOST[:PORT]; if a ':' is present, it must be preceded by a
hostname and followed by a port number, otherwise :443 is appended.

The check to ensure that HOST is not an -option is merged into this as
well, since we already test for : at the beginning of the HOST
(indicating that only a port was provided).

Additionally, this now defends against an empty string "" being passed
as the final option, which could occur if a script calling cipherscan
goes awry and starts passing empty values as the target.

top1m may see a slight speed improvement from this commit, as 4 calls to
sed are replaced with native bash functions.

Fixes one "SC2086: Double quote to prevent globbing and word splitting.":

In cipherscan line 1402:
SCLIENTARGS=$(sed -e s,${TEMPTARGET},,<<<"${@}")
                       ^-- SC2086: Double quote to prevent globbing and
                       word splitting.
2015-09-05 02:10:50 -07:00
Richard Soderberg
d81ee1c801 Refuse to proceed if no HOST[:PORT] is provided after the options.
Prior to this patch, if the user fails to provide a host:port after
specifying cipherscan options, the script runs sed on an empty variable
(failing with a syntax error) and then asttempts to cipherscan the
target ':443'.

This adds a simple test to ensure that a target was actually provided.
2015-09-05 01:35:47 -07:00
Richard Soderberg
28555b03f0 Refuse to proceed if the final argument starts with a hyphen.
This detects and prevents a specific category of user error, where an
incomplete cipherscan command line ending in an OpenSSL -option results
in cipherscan attempting to scan the target '-option:443'.
2015-09-05 01:01:19 -07:00
Richard Soderberg
e35a6155bc Add --cafile <filename.crt>, alongside --capath <dirpath/>.
For unknown reasons, while we previously supported --capath we did not
support --cafile. This forces the --cafile autodetection logic to run
every time, unnecessarily, when we have a specific file in mind to use.

This patch relocates the -CAfile autodetection logic to run *only if*
the --cafile parameter is not provided. If it is not provided, the
autodetection logic occurs precisely as before.

This patch declines to address what happens if both --capath and
--cafile are passed. The previous logic already ensured that the CA file
was *always* set, and then only sometimes was the CA path set. The new
logic maintains that behavior precisely, reserving logic flow changes
for a separate commit.
2015-09-05 00:22:40 -07:00
Richard Soderberg
0728751208 move bash4 detection as early as possible in the script to permit logic later on 2015-09-05 00:06:31 -07:00
Richard Soderberg
22adaf188a verify that the openssl binary is emitting a valid s_client -help.
This catches instances where the wrong openssl binary is selected (for
instance, if uname -s is neither Darwin nor Linux) and serves as a
simple up-front test to make sure that openssl is working before we
proceed further into the script.
2015-09-03 07:02:40 -07:00
Richard Soderberg
9a0e055628 remove crude_grep in favor of a simple =~ substring match.
The crude_grep function served only to perform a simple substring check
against the output of openssl -help. So, instead of running the command
each time, iterating its output line by line, and checking for the
substring within it, this simply caches the -help output at startup and
uses $help =~ substring to produce the same result in a single pass.
2015-09-03 06:58:05 -07:00
Richard Soderberg
f0142c323a remove one unnecessary assignment when on Darwin. 2015-09-03 06:47:47 -07:00
Richard Soderberg
5ec3184a37 call dirname $0 three fewer times by caching the unmodified value prior to readlink modifications 2015-09-03 06:40:48 -07:00
Richard Soderberg
f002b3573a fixes for "SC2004: $/${} is unnecessary on arithmetic variables."
In cipherscan line 451:
        for ((i=0; i<$certificate_count; i=i+1 )); do
                     ^-- SC2004: $/${} is unnecessary on arithmetic variables.

In cipherscan line 603:
    cipherbenchms="$((t/1000/$BENCHMARKITER))"
                             ^-- SC2004: $/${} is unnecessary on arithmetic variables.
2015-09-03 06:37:09 -07:00
Richard Soderberg
21871b5bd7 fixes for "SC2046: Quote this to prevent word splitting." and "SC2086: Double quote to prevent globbing and word splitting."
In cipherscan line 13:
REALPATH=$(dirname $0)
                   ^-- SC2086: Double quote to prevent globbing and word splitting.

In cipherscan line 15:
readlink -f $0 &>/dev/null && REALPATH=$(dirname $(readlink -f $0))
            ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                 ^-- SC2046: Quote this to prevent word splitting.
                                                               ^-- SC2086: Double quote to prevent globbing and word splitting.

In cipherscan line 46:
if [[ -e $(dirname $0)/openssl.cnf ]]; then
                   ^-- SC2086: Double quote to prevent globbing and word splitting.

In cipherscan line 47:
    export OPENSSL_CONF="$(dirname $0)/openssl.cnf"
           ^-- SC2155: Declare and assign separately to avoid masking return values.
                                   ^-- SC2086: Double quote to prevent globbing and word splitting.

In cipherscan line 60:
    CACERTS="$(dirname $0)/ca-bundle.crt"
                       ^-- SC2086: Double quote to prevent globbing and word splitting.
2015-09-03 06:26:36 -07:00
Richard Soderberg
4405d3fdce remove unused variable "fallback_available" 2015-09-03 06:17:15 -07:00
Richard Soderberg
3664b1a199 fixes for "SC2145: Argument mixes string and array. Use * or separate argument."
In cipherscan line 941:
    verbose "Server supported curves: ${tmp_curves[@]}"
                                      ^-- SC2145: Argument mixes string and array. Use * or separate argument.

In cipherscan line 968:
            verbose "ephem_data: ${ephem_data[@]}"
                                 ^-- SC2145: Argument mixes string and array. Use * or separate argument.
2015-09-03 06:14:28 -07:00
Richard Soderberg
bbb3496627 trim dead trailing ; 2015-09-03 06:02:15 -07:00
Richard Soderberg
1c15af1ce3 verify the results of pushd rather than trusting it 2015-09-03 06:02:12 -07:00
Richard Soderberg
81481cd016 requote, reindent ciphers and curves to the same format 2015-09-03 06:00:38 -07:00
Richard Soderberg
10057f93dc revise whitespace layout of cipher, curve arrays to improve future diffs 2015-09-03 06:00:31 -07:00
Richard Soderberg
9e563782e2 fix syntax error in busybox check - $(( is not the same as $( (, and a subshell is unnecessary here in any case 2015-09-03 06:00:23 -07:00
Richard Soderberg
6efb1a4afb replace if [ ... ] with if [[ ... ]]
Bash implements a backwards-compatible sh syntax for [ .. ], which
handles undef variables poorly. Use [[ .. ]] instead, to take full
advantage of the Bash improvements to the comparison brackets.
2015-09-03 05:51:57 -07:00
Richard Soderberg
5fa972c534 enable curves by default 2015-09-02 21:11:25 -07:00
Hubert Kario
5c98fe2107 do a scan with -no_tlsext openssl if possible 2015-07-16 16:15:39 +02:00
Hubert Kario
a71bfe5ebd detect some TLS intolerancies
buggy servers may choke on large ClientHello's, TLSv1.2 ClientHello's,
etc. try to detect such failures and report them

among tried connections are TLS1.2, TLS1.1, TLS1.0 and SSLv3 with
ability to downgrade to lower protocol versions as well as a size
limited client hello, both TLS1.2 and TLS1.0 version
2015-07-16 16:15:39 +02:00
Julien Vehent
0ab0575274 Merge pull request #58 from tomato42/fallback-scan
Fallback scan
2015-07-15 10:21:47 -04:00
Hubert Kario
8ea6b57f9d cipherscan - capture whole Signature Algorithm line
the GOST certificates have a signature algorithm name with spaces
2015-05-30 14:58:23 +02:00
Hubert Kario
596692a18e add support for GOST cipher scanning 2015-05-30 14:58:23 +02:00
Hubert Kario
8bde9c4d03 do fallback scan in case of problems
It's unlikely that there are SSLv2 only servers on the 'net, all
that were detected as such and I've checked actually are intolerant
to low placement of RC4 in cipher order or intolerant to large client
hello in general. In case we detect issues with the server, switch to
reduced cipher set and run the test again that should give better results
for about 3% of hosts
2015-05-29 23:50:07 +02:00
Julien Vehent
1a26e09c7b Merge pull request #54 from jvehent/jvehent-rework-tomato42-curves-tolerance-5
Jvehent rework tomato42 curves tolerance 5, closes #46
2015-04-02 09:50:46 -04:00
Julien Vehent
a966574edc Fix curve fallback detection 2015-04-01 14:51:01 -04:00
Julien Vehent
4d7e1cb05a Re-add curve fallback detection 2015-04-01 12:50:01 -04:00
Julien Vehent
c90e5c59d7 Improve output of curves 2015-04-01 11:18:31 -04:00
Julien Vehent
cc014f085d test curve for each ECDH cipher, change PFS output to use curve name 2015-03-27 19:03:27 -04:00
Hubert Kario
224227cc5e force at least TLSv1.0 in curves tolerance test
because to advertise curves to server we need extensions and
extensions are only available in TLSv1.0 or later, we need to force
OpenSSL not to send SSLv2 compatible hello if it thinks it's ok to
do (when there are SSLv2 ciphers present in cipherstring it will try to)
2015-03-27 10:04:15 -04:00
Hubert Kario
c52e008347 add support for testing supported curves
since early versions of 1.0.2 openssl supports -curves command line
option, it allows us to set the curves advertised as supported

use the same approach to testing: advertise all, check what server
accepts, remove the accepted from list, repeat. When server aborts
connection or selects non ECC cipher, we know that we've tested all.
2015-03-27 10:04:15 -04:00
Samuel Kleiner
6db82374b4 Fix for busybox timeout binary 2015-03-13 11:58:23 +00:00
Christian Stadelmann
9ecc3f7164 New bash version info test using $BASH_VERSINFO 2015-01-12 16:46:18 +01:00
Christian Stadelmann
54ec2aca99 fix: ignore case in bash version string
Currently on some systems `bash --version` reports `GNU bash, Version 4[…]` which will fail the test.
2015-01-02 22:47:28 +01:00
Julien Vehent
904e311124 Fix OSX: require bash4, add openssl-darwin64 binary 2014-12-25 13:25:29 -05:00
Julien Vehent
4e74308c37 Merge pull request #41 from MikeDawg/master
Added usage print and exit if no options are given
2014-12-25 12:27:35 -05:00
Julien Vehent
008bd6af2b Merge pull request #38 from PeterMosmans/changeorder
Bugfix: correct flow when number of ciphers are loaded
2014-12-25 12:15:11 -05:00
Mike
c019ecd493 Added usage print and exit if no options are given 2014-12-17 13:06:06 -07:00
Peter Mosmans
81c1809463 corrected flow when number of ciphers was shown
First make sure that ${OPENSSLBIN} is correctly set
2014-11-22 18:36:24 +10:00
Peter Mosmans
558bf7c9e2 Make sure that custom openssl gets selected
Symlinks are now resolved (when readlink -f is available)
2014-11-14 10:49:16 +11:00
Hubert Kario
c4a8495a54 limit number of forks needed to speed up execution
bash has a built in regular expression processor, we can match
lines using =~

moreover, stuff that will match while being inside parentheses is
later available in the BASH_REMATCH array

the IFS (Internal Field Separator) by default includes space, tab and
new line, as such we can use it to split longer lines to separate
words, just as awk '{print $1}' can, just need to put the value to
an array for that

we also don't have to use $(echo $var) when assigning variables, $var
is enough

bash has also built in substitution engine, so we can do ${var/,/ & }
to switch all commas to ampersands when using the variable
2014-11-05 18:14:30 +01:00
Hubert Kario
9f06829486 make handling of self signed certs more robust
openssl sometimes will print the filename, then the error, and finish
with OK, matching the colon and space prevents from considering such
certs to be valid
2014-11-05 18:13:39 +01:00
Hubert Kario
4c22d50f0c few less forks in the script
again, we can use arrays and a bit advanced awk syntax to reduce
the number of forks necessary to run the script
2014-11-05 18:13:39 +01:00
Hubert Kario
0f576c1fbc don't calculate sha sums for the certificates over and over
we can use cksum to calculate simple checksum much faster than
with using openssl, so we can compute sums only once
2014-11-05 18:13:39 +01:00
Hubert Kario
d9b718be12 clean up the extracted certificate
the certificate extracted in the above way will contain some junk
from openssl s_client output we don't want like verification status
we can remove it ro reduce disk usage for saved certificates
2014-11-05 18:13:39 +01:00
Hubert Kario
3e37517c96 add ability to also save leaf certificates and untrusted ones 2014-11-05 18:13:39 +01:00
Hubert Kario
826f7b5541 add caching of intermediate CA certificates 2014-11-05 18:13:39 +01:00
Hubert Kario
3b14cd914f no need to grep the input when we're using awk (v2)
awk has an inbuilt version of grep, also truncate processing as soon
as we find what we're looking for

This version uses slightly different syntax that is compatible with old
awk
2014-11-05 18:13:39 +01:00
Hubert Kario
11ce6187de small fixes for delay
firstly, test_cipher_on_target() will try at least 4 connections before
incurring the sleep, for aggressive rate limiter on server side it may be
too much, so sleep before every connection

secondly, because running external commands like sleep incurs a fork
penalty, we first check if it is necessary
2014-10-28 16:44:43 +01:00
Hubert Kario
71ba3c88b0 increase timeout
when some servers notice a scan (because of frequent connections) they
delay further connections, increase the timeout to properly scan them
2014-10-28 13:17:20 +01:00
Julien Vehent
5b32afaa1f Add target to text output 2014-10-17 10:48:59 -04:00
Julien Vehent
37f04054f8 fix json date to use UTC 2014-10-10 18:16:22 -04:00
Julien Vehent
b80b5cdd35 hide errors when json format is used 2014-10-10 17:27:58 -04:00
Julien Vehent
278dab4800 Fix json date argument to be compatible on macos 2014-10-10 17:27:29 -04:00
Julien Vehent
f6f4fe8b86 Find timeout binary on linux and mac 2014-10-10 17:19:44 -04:00
Julien Vehent
c7c91ff5f8 updated authors 2014-10-10 16:56:06 -04:00
Julien Vehent
d5685da796 check that provided openssl is executable, fall back to system one if not 2014-10-10 16:56:00 -04:00
Julien Vehent
26aa8f9408 cleanups 2014-10-10 16:55:34 -04:00
Julien Vehent
7d2c8b4cad Use local ca bundle if none is found on the system, fixes issues with MacOS 2014-10-10 16:55:09 -04:00
Julien Vehent
2858ef8116 Revert "no need to grep the input when we're using awk"
This reverts commit 4c05897be2.
2014-10-08 21:53:22 -04:00
Hubert Kario
ca0ef2fc5c fixes for the pull request #18
there were few small issues with the pull #18 even though jvehent merged
it, this fixes them
2014-10-06 13:26:53 -04:00
Hubert Kario
4c05897be2 no need to grep the input when we're using awk
awk has an inbuilt version of grep, also truncate processing as soon
as we find what we're looking for
2014-10-06 13:24:39 -04:00
Hubert Kario
fb02ae87ac add some comments, group related code 2014-10-06 13:22:29 -04:00
Hubert Kario
77671137df add support for CApath
capath for relatively small cert sets (~300) makes scanning about 5%
faster

also do a little clean up of the command-to-run generation code
2014-10-06 13:22:15 -04:00
Hubert Kario
189460da9e report if server uses client side or server side cipher ordering 2014-10-06 13:21:40 -04:00
Hubert Kario
a7ae42b08e openssl in -ssl2 mode doesn't tolerate -servername option
when openssl is run in -ssl2 mode, it doesn't accept -servername
option and just aborts operation, it doesn't consider -status
to be special though.

Remove this option when running the SSLv2 portion of the test.
2014-10-06 13:21:16 -04:00
Hubert Kario
3a4a5f938d add missing ocsp_staple header 2014-10-06 13:20:49 -04:00
Julien Vehent
ded65c40df Merge pull request #22 from simondeziel/sdeziel
Use Debian's system-wide trust anchors when possible
2014-08-28 16:02:36 -04:00
Julien Vehent
ecd77f94fc Merge pull request #18 from tomato42/wip
Hodgepodge of fixes
2014-08-28 16:02:19 -04:00
Simon Deziel
7dee967dd7 Attempt to use /etc/ssl/certs/ca-certificates.crt if no CACERTS
are available. On Debian, this is the default location for
system-wide trust anchors.
2014-07-25 10:01:31 -04:00
Aaron Zauner
efd84cdb24 add real execution tracing to debug 2014-07-17 18:08:29 +02:00
Phil Cohen
5ae2132f23 minor typo fix 2014-06-25 16:28:48 -07:00
Hubert Kario
ee81927200 fix cipherscan human-readable output - pfs_keysize option 2014-05-30 11:49:44 +02:00
Hubert Kario
4e94d95bd8 ask for OCSP stapling by default
for now, no option to disable
2014-05-16 17:31:44 +02:00
Hubert Kario
0777682aa6 collect TLS ticket lifetime hints 2014-05-16 16:55:19 +02:00