|
| 1 | +/** |
| 2 | + * TLS-Scanner - A TLS configuration and analysis tool based on TLS-Attacker. |
| 3 | + * |
| 4 | + * Copyright 2017-2019 Ruhr University Bochum / Hackmanit GmbH |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + */ |
| 9 | +package de.rub.nds.tlsscanner.probe; |
| 10 | + |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.LinkedList; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +import de.rub.nds.tlsattacker.core.config.Config; |
| 16 | +import de.rub.nds.tlsattacker.core.constants.CipherSuite; |
| 17 | +import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType; |
| 18 | +import de.rub.nds.tlsattacker.core.constants.NamedGroup; |
| 19 | +import de.rub.nds.tlsattacker.core.constants.ProtocolVersion; |
| 20 | +import de.rub.nds.tlsattacker.core.constants.RunningModeType; |
| 21 | +import de.rub.nds.tlsattacker.core.constants.SignatureAndHashAlgorithm; |
| 22 | +import de.rub.nds.tlsattacker.core.state.State; |
| 23 | +import de.rub.nds.tlsattacker.core.state.TlsContext; |
| 24 | +import de.rub.nds.tlsattacker.core.workflow.ParallelExecutor; |
| 25 | +import de.rub.nds.tlsattacker.core.workflow.WorkflowTrace; |
| 26 | +import de.rub.nds.tlsattacker.core.workflow.WorkflowTraceUtil; |
| 27 | +import de.rub.nds.tlsattacker.core.workflow.factory.WorkflowConfigurationFactory; |
| 28 | +import de.rub.nds.tlsattacker.core.workflow.factory.WorkflowTraceType; |
| 29 | +import de.rub.nds.tlsscanner.serverscanner.report.result.EsniResult; |
| 30 | +import de.rub.nds.tlsscanner.serverscanner.config.ScannerConfig; |
| 31 | +import de.rub.nds.tlsscanner.serverscanner.constants.ProbeType; |
| 32 | +import de.rub.nds.tlsscanner.serverscanner.probe.TlsProbe; |
| 33 | +import de.rub.nds.tlsscanner.serverscanner.rating.TestResult; |
| 34 | +import de.rub.nds.tlsscanner.serverscanner.report.SiteReport; |
| 35 | +import de.rub.nds.tlsscanner.serverscanner.report.result.ProbeResult; |
| 36 | +import de.rub.nds.tlsscanner.serverscanner.report.result.SniResult; |
| 37 | + |
| 38 | +public class EsniProbe extends TlsProbe { |
| 39 | + |
| 40 | + public EsniProbe(ScannerConfig scannerConfig, ParallelExecutor parallelExecutor) { |
| 41 | + super(parallelExecutor, ProbeType.ESNI, scannerConfig); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public ProbeResult executeTest() { |
| 46 | + Config tlsConfig = getScannerConfig().createConfig(); |
| 47 | + tlsConfig.setHighestProtocolVersion(ProtocolVersion.TLS13); |
| 48 | + tlsConfig.setSupportedVersions(ProtocolVersion.TLS13); |
| 49 | + tlsConfig.setUseFreshRandom(true); |
| 50 | + tlsConfig.setQuickReceive(true); |
| 51 | + tlsConfig.setDefaultClientSupportedCiphersuites(this.getClientSupportedCiphersuites()); |
| 52 | + tlsConfig.setSupportedSignatureAndHashAlgorithms(this.getTls13SignatureAndHashAlgorithms()); |
| 53 | + tlsConfig.setEnforceSettings(false); |
| 54 | + tlsConfig.setEarlyStop(true); |
| 55 | + tlsConfig.setStopReceivingAfterFatal(true); |
| 56 | + tlsConfig.setStopActionsAfterFatal(true); |
| 57 | + |
| 58 | + tlsConfig.setDefaultClientNamedGroups(NamedGroup.ECDH_X25519); |
| 59 | + tlsConfig.setDefaultSelectedNamedGroup(NamedGroup.ECDH_X25519); |
| 60 | + tlsConfig.setAddECPointFormatExtension(false); |
| 61 | + tlsConfig.setAddEllipticCurveExtension(true); |
| 62 | + tlsConfig.setAddSignatureAndHashAlgorithmsExtension(true); |
| 63 | + tlsConfig.setAddSupportedVersionsExtension(true); |
| 64 | + tlsConfig.setAddKeyShareExtension(true); |
| 65 | + tlsConfig.setClientSupportedEsniCiphersuites(this.getClientSupportedCiphersuites()); |
| 66 | + tlsConfig.getClientSupportedEsniNamedGroups().addAll(this.getImplementedGroups()); |
| 67 | + tlsConfig.setAddServerNameIndicationExtension(false); |
| 68 | + tlsConfig.setAddEncryptedServerNameIndicationExtension(true); |
| 69 | + |
| 70 | + WorkflowTrace trace = new WorkflowConfigurationFactory(tlsConfig).createWorkflowTrace(WorkflowTraceType.HELLO, |
| 71 | + RunningModeType.CLIENT); |
| 72 | + State state = new State(tlsConfig, trace); |
| 73 | + executeState(state); |
| 74 | + |
| 75 | + TlsContext context = state.getTlsContext(); |
| 76 | + boolean isDnsKeyRecordAvailable = context.getEsniRecordBytes() != null; |
| 77 | + boolean isReceivedCorrectNonce = context.getEsniServerNonce() != null |
| 78 | + && Arrays.equals(context.getEsniServerNonce(), context.getEsniClientNonce()); |
| 79 | + if (!WorkflowTraceUtil.didReceiveMessage(HandshakeMessageType.SERVER_HELLO, trace)) { |
| 80 | + return new SniResult(TestResult.ERROR_DURING_TEST); |
| 81 | + } else if (isDnsKeyRecordAvailable && isReceivedCorrectNonce) { |
| 82 | + return (new EsniResult(TestResult.TRUE)); |
| 83 | + } else { |
| 84 | + return (new EsniResult(TestResult.FALSE)); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public boolean canBeExecuted(SiteReport report) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public void adjustConfig(SiteReport report) { |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public ProbeResult getCouldNotExecuteResult() { |
| 99 | + return new SniResult(TestResult.COULD_NOT_TEST); |
| 100 | + } |
| 101 | + |
| 102 | + private List<CipherSuite> getClientSupportedCiphersuites() { |
| 103 | + List<CipherSuite> cipherSuites = new LinkedList<>(); |
| 104 | + cipherSuites.add(CipherSuite.TLS_AES_128_GCM_SHA256); |
| 105 | + cipherSuites.add(CipherSuite.TLS_AES_256_GCM_SHA384); |
| 106 | + return cipherSuites; |
| 107 | + } |
| 108 | + |
| 109 | + private List<SignatureAndHashAlgorithm> getTls13SignatureAndHashAlgorithms() { |
| 110 | + List<SignatureAndHashAlgorithm> algos = new LinkedList<>(); |
| 111 | + algos.add(SignatureAndHashAlgorithm.RSA_SHA256); |
| 112 | + algos.add(SignatureAndHashAlgorithm.RSA_SHA384); |
| 113 | + algos.add(SignatureAndHashAlgorithm.RSA_SHA512); |
| 114 | + algos.add(SignatureAndHashAlgorithm.ECDSA_SHA256); |
| 115 | + algos.add(SignatureAndHashAlgorithm.ECDSA_SHA384); |
| 116 | + algos.add(SignatureAndHashAlgorithm.ECDSA_SHA512); |
| 117 | + algos.add(SignatureAndHashAlgorithm.RSA_PSS_PSS_SHA256); |
| 118 | + algos.add(SignatureAndHashAlgorithm.RSA_PSS_PSS_SHA384); |
| 119 | + algos.add(SignatureAndHashAlgorithm.RSA_PSS_PSS_SHA512); |
| 120 | + algos.add(SignatureAndHashAlgorithm.RSA_PSS_RSAE_SHA256); |
| 121 | + algos.add(SignatureAndHashAlgorithm.RSA_PSS_RSAE_SHA384); |
| 122 | + algos.add(SignatureAndHashAlgorithm.RSA_PSS_RSAE_SHA512); |
| 123 | + return algos; |
| 124 | + } |
| 125 | + |
| 126 | + private List<NamedGroup> getImplementedGroups() { |
| 127 | + List<NamedGroup> list = new LinkedList(); |
| 128 | + list.add(NamedGroup.ECDH_X25519); |
| 129 | + list.add(NamedGroup.ECDH_X448); |
| 130 | + list.add(NamedGroup.SECP160K1); |
| 131 | + list.add(NamedGroup.SECP160R1); |
| 132 | + list.add(NamedGroup.SECP160R2); |
| 133 | + list.add(NamedGroup.SECP192K1); |
| 134 | + list.add(NamedGroup.SECP192R1); |
| 135 | + list.add(NamedGroup.SECP224K1); |
| 136 | + list.add(NamedGroup.SECP224R1); |
| 137 | + list.add(NamedGroup.SECP256K1); |
| 138 | + list.add(NamedGroup.SECP256R1); |
| 139 | + list.add(NamedGroup.SECP384R1); |
| 140 | + list.add(NamedGroup.SECP521R1); |
| 141 | + list.add(NamedGroup.SECT163K1); |
| 142 | + list.add(NamedGroup.SECT163R1); |
| 143 | + list.add(NamedGroup.SECT163R2); |
| 144 | + list.add(NamedGroup.SECT193R1); |
| 145 | + list.add(NamedGroup.SECT193R2); |
| 146 | + list.add(NamedGroup.SECT233K1); |
| 147 | + list.add(NamedGroup.SECT233R1); |
| 148 | + list.add(NamedGroup.SECT239K1); |
| 149 | + list.add(NamedGroup.SECT283K1); |
| 150 | + list.add(NamedGroup.SECT283R1); |
| 151 | + list.add(NamedGroup.SECT409K1); |
| 152 | + list.add(NamedGroup.SECT409R1); |
| 153 | + list.add(NamedGroup.SECT571K1); |
| 154 | + list.add(NamedGroup.SECT571R1); |
| 155 | + return list; |
| 156 | + } |
| 157 | + |
| 158 | +} |
0 commit comments