A Java library for parsing TLS cipher suite and protocol variant names and filtering them using simple builder syntax or OpenSSL like filter expressions.
- Parsing of SSL and TLS cipher suite names and protocol version names on all Java platforms
- Smart parsing handles current and future cipher suite names, including non-standard names on IBM Java VMs
- Criteria based filtering of cipher suites and protocol versions using a fluent builder syntax
- OpenSSL like filter syntax, allowing configuration of filters in applications
- Filter syntax is compatible with lists of cipher suite names, allowing drop-in enhancement of existing applications
- Filtering excludes unsafe cipher suites (including export cipher suites) by default, avoiding mistakes
- Interactive tester application to determine JRE and JSSE capabilities, and test filters
- Packaged as an OSGi bundle
Copyright 2013 Tim Whittington Licensed under the The Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
...
By default GrokTLS excludes unsafe cipher suites and protocol variants, and unless you explicitly include them they aren't matched by filter rules, with the exception of filter rules explicitly noted as matching unsafe filters (such as SUPPORTED
).
The exception to this rule is that unsafe items that have already been matched in a filter will be matched by subsequent safe filters.
Unsafe cipher suites are those that have:
NULL
encryptionNULL
key exchangeNULL
oranon
authenticationNULL
mac/digestEXPORT
grade key exchange or encryption
Unsafe protocol variants are SSLv2
and below.
CipherSuite cs = new GrokTLS().createCipherSuiteParser().parse("TLS_DHE_DSS_WITH_RC4_128_SHA");
ProtocolVariant pv = new GrokTLS().createProtocolVariantParser().parse("TLSv1.2");
import static org.archie.groktls.protocol.CipherSuiteFilters.*;
...
ItemFilterBuilder<CipherSuite> csBuilder = new GrokTLS().createCipherSuiteFilterBuilder();
ItemFilter<CipherSuite> csFilter = csBuilder.add(fips()).sort(byEncryptionStrength()).build();
SSLContext context = SSLContext.getInstance("TLS");
context.init(...);
String[] ciphers = csFilter.filterServer(sslContext).getIncludedNames();
ItemFilterBuilder<ProtocolVariant> pvBuilder = new GrokTLS().createProtocolVariantFilterBuilder();
ItemFilter<ProtocolVariant> pvFilter = pvBuilder.add(minimumVersion("TLSv1")).build();
SSLContext context = SSLContext.getInstance("TLS");
context.init(...);
String[] protocols = pvFilter.filter(sslContext).getIncludedNames();
ItemFilterSpecParser<CipherSuite> parser = new GrokTLS().createCipherSuiteFilterSpecParser();
ItemFilter<CipherSuite> csFilter = parser.parse("FIPS:@STRENGTH");
SSLContext context = SSLContext.getInstance("TLS");
context.init(...);
String[] ciphers = csFilter.filterServer(sslContext).getIncludedNames();
ItemFilterSpecParser<CipherSuite> parser = new GrokTLS().createProtocolVariantFilterSpecParser();
ItemFilter<ProtocolVariant> pvFilter = parser.parse(">=TLSv1");
SSLContext context = SSLContext.getInstance("TLS");
context.init(...);
String[] protocols = pvFilter.filter(sslContext).getIncludedNames();
The GrokTLS distribution is an executable jar, providing an interactive tool to analyse the TLS support and JSSE implementation of the JVM invoking it, and to test filter expressions.
-e
- process all commands on the command line immediately, and then exit.bare
/full
- switch between bare and full output. Bare output is intended for copy-paste into config: cipher suite names are listed one per line, and on a single line comma separated.client
- switch to use client TLS defaults (e.g. what anSSLSocket
would use).server
- switch to use server TLS defaults (e.g. what anSSLServerSocket
would use).engine <Name>
- switch the TLS engine to the specified engine/protocol.provider <Name>
- switch to a specific JSSE provider (must also specifyengine
explicitly).cipher
orcs
- switch to cipher suite filtering mode.proto
orpv
- switch to protocol variant filtering mode.consistent
- analyse all JSSE APIs and display a report explaining which APIs are consistent with each other.FILTERSPEC
- any other command is matched as a filter spec (see below for syntax) and the results of the filter are displayed.
java -jar -e groktls.jar consistent
java -jar -e groktls.jar server "engine TLSv1.2" cipher DEFAULT
java -jar groktls.jar
> eAES+kDHE
8 matches, 0 excluded, 0 blacklisted.
Cipher Kx Au Enc Mode Key Str Mac Size Unsafe
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 DHE RSA AES CBC 256 (256) SHA256 256
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 DHE DSS AES CBC 256 (256) SHA256 256
TLS_DHE_RSA_WITH_AES_256_CBC_SHA DHE RSA AES CBC 256 (256) SHA 160
TLS_DHE_DSS_WITH_AES_256_CBC_SHA DHE DSS AES CBC 256 (256) SHA 160
TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 DHE RSA AES CBC 128 (128) SHA256 256
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 DHE DSS AES CBC 128 (128) SHA256 256
TLS_DHE_RSA_WITH_AES_128_CBC_SHA DHE RSA AES CBC 128 (128) SHA 160
TLS_DHE_DSS_WITH_AES_128_CBC_SHA DHE DSS AES CBC 128 (128) SHA 160
Filters consist of one or more parts, separated by a :
or ,
.
Each part is either a single filter expression, or a concatenation of multiple filter expressions (a logical and operation) using a +
.
Parts are of the following types, distinguished by a prefix character:
- (no prefix) - add matched items. Items already matched remain in the place they were matched, new items are added to the end.
+
- add matched items. Items already matched are removed from the order and added again at the end.-
- remove matched items. Items may be re-added by subsequent filter parts.!
- remove matched items and blacklist them. Items will not be re-added, even if matched by subsequent filter parts.
e.g.:
EXPR1:EXPR2
- all items matchingEXPR1
, followed by items matchingEXPR2
EXPR1+EXPR2
- all items matchingEXPR1
andEXPR2
EXPR1:+EXPR2
- all items matchingEXPR1
, with any items matchingEXPR2
moved to the end of the listEXPR1:-EXPR2
- all items matchingEXPR1
, except the items matchingEXPR2
EXPR1:!EXPR2:EXPR3
- all items matchingEXPR1
, except the items matchingEXPR2
, followed by items matchingEXPR3
that are not matched byEXPR2
These filters can be applied to cipher suites or protocol variants.
SUPPORTED
- matches all supported items, including those classified as unsafeALL
- matches all safe supported itemsCOMPLEMENTOFALL
/UNSAFE
- matches all supported items not matched byALL
DEFAULT
- matches all safe default itemsCOMPLEMENTOFDEFAULT
- matches all safe supported items (e.g.ALL
) not matched byDEFAULT
FIPS
orFIPS140
- matches cipher suites using only approved (or generally accepted) for use in FIP 140-2:DH
,DHE
,RSA
,ECDH
andECDHE
key exchangeDSS
,RSA
,ECDSA
authenticationAES
and3DES
encryptionCBC
,CCM
andGCM
encryption modesSHA
,SHA256
andSHA384
mac/digest
SCSV
- matches any signalling cipher suite values (e.g.TLS_EMPTY_RENEGOTIATION_INFO_SCSV
)HIGH
- matches cipher suites with strong encryption - currentlyAES
>= 128 bit encryption and any other algorithm with key length > 128 bitsMEDIUM
- matches cipher suites using medium strength encryption - currently any 128 bit encryption algorithm other thanAES
LOW
- matches cipher suites using low strength encryption - currently any encryption algorithm with < 128 bit key lengthEXPORT
orEXP
- matches cipher suites with export weakened key exchange or encryption. Will not match anything unlessUNSAFE
is also used.SUITEB128
- matches cipher suites using algorithms approved for use in TLS by NSA Suite B with a 128 bit minimum securitySUITEB192
- matches cipher suites using algorithms approved for use in TLS by NSA Suite B with a 192 bit minimum securityCIPHER_SUITE_NAME
- e.g.TLS_DHE_DSS_WITH_RC4_128_SHA
- matches a specific cipher suitekALGO
- e.g.kECDHE
- matches cipher suites using the specified key exchange algorithmFS
- matches cipher suites using key exchange with forward secrecy (e.g.DHE
orECDHE
key exchange).aALGO
- e.g.aDSS
- matches cipher suites using the specified authentication algorithmmALGO
- e.g.mSHA
- matches cipher suites using the specified digest/mac algorithmAEAD
/BLOCK
/STREAM
- matches cipher suites using ciphers in AEAD/BLOCK/STREAM mode.eALGO
- e.g.eAES
- matches cipher suites using the specified encryption algorithmeALGO_LEN
- e.g.eAES_128
- matches cipher suites using the specified encryption algorithm with at least the specified key lengtheALGO_LEN_MODE
- e.g.eAES_128_GCM
- matches cipher suites using the specified encryption algorithm and mode with at least the specified key lengthe_LEN
- e.g.e_128
- matches cipher suites using the any encryption algorithm with at least the specified key lengthe_MODE
- e.g.e_GCM
- matches cipher suites using the specified encryption modee_LEN_MODE
- e.g.e_128_GCM
- matches cipher suites using the any encryption algorithm in the specified mode with at least the specified key length
All filter expressions that take an algorithm accept the value NULL
to match cipher suites with NULL
or anon
values.
@STRENGTH
- orders matched cipher suites by the effective key length (taking into account known vulnerabilities)@KEYLENGTH
- orders matched cipher suites by the key length
fFAMILY
- e.g.fTLS
- matches any protocol variant in the specified family>=PROTOCOL
- e.g.>=TLSv1.1
- matches any protocol variant >= the specified variantPSEUDO
- matches any pseudo protocols (e.g.SSLv2Hello
)
Filter Syntax
new GrokTLS().createProtocolVariantFilterSpecParser().parse(">=TLSv1");
Builder Syntax
new GrokTLS().createProtocolVariantFilterBuilder().add(minimumVersion("TLSv1")).build();
Filter Syntax
new GrokTLS().createCipherSuiteFilterSpecParser().parse("FIPS:@STRENGTH");
Builder Syntax
new GrokTLS().createCipherSuiteFilterBuilder().add(fips()).sort(byEncryptionStrength()).build();
Filter Syntax
new GrokTLS().createCipherSuiteFilterSpecParser().parse("eRC4");
Builder Syntax
new GrokTLS().createCipherSuiteFilterBuilder().add(encryption("RC4")).build();
Filter Syntax
new GrokTLS().createCipherSuiteFilterSpecParser().parse("eAES:+aRSA");
Builder Syntax
new GrokTLS().createCipherSuiteFilterBuilder().add(encryption("AES")).end(authentication("RSA")).build();
Filter Syntax
new GrokTLS().createCipherSuiteFilterSpecParser().parse("UNSAFE+SSL_RSA_EXPORT_WITH_RC4_40_MD5");
Builder Syntax
new GrokTLS().createCipherSuiteFilterBuilder()
.add(and(
supportedIncludingUnsafe(),
cipherSuite("kRSA:UNSAFE+SSL_RSA_EXPORT_WITH_RC4_40_MD5")))
.build();