| 115 | |
| 116 | |
| 117 | class MaybeTls: |
| 118 | strategy: TlsStrategy |
| 119 | |
| 120 | def load(self, l): |
| 121 | l.add_option( |
| 122 | "tls_strategy", int, 0, |
| 123 | "TLS passthrough strategy. If set to 0, connections will be passed through after the first unsuccessful " |
| 124 | "handshake. If set to 0 < p <= 100, connections with be passed through with probability p.", |
| 125 | ) |
| 126 | |
| 127 | def configure(self, updated): |
| 128 | if "tls_strategy" not in updated: |
| 129 | return |
| 130 | if ctx.options.tls_strategy > 0: |
| 131 | self.strategy = ProbabilisticStrategy(ctx.options.tls_strategy / 100) |
| 132 | else: |
| 133 | self.strategy = ConservativeStrategy() |
| 134 | |
| 135 | def tls_clienthello(self, data: tls.ClientHelloData): |
| 136 | server_address = data.context.server.peername |
| 137 | if not self.strategy.should_intercept(server_address): |
| 138 | ctx.log(f"TLS passthrough: {human.format_address(server_address)}.") |
| 139 | data.ignore_connection = True |
| 140 | self.strategy.record_skipped(server_address) |
| 141 | |
| 142 | def tls_established_client(self, data: tls.TlsData): |
| 143 | server_address = data.context.server.peername |
| 144 | ctx.log(f"TLS handshake successful: {human.format_address(server_address)}") |
| 145 | self.strategy.record_success(server_address) |
| 146 | |
| 147 | def tls_failed_client(self, data: tls.TlsData): |
| 148 | server_address = data.context.server.peername |
| 149 | ctx.log(f"TLS handshake failed: {human.format_address(server_address)}") |
| 150 | self.strategy.record_failure(server_address) |
| 151 | |
| 152 | addons = [ |
| 153 | MlgmXyysd_Animation_Company_Proxy(), |