| 121 | """ |
| 122 | |
| 123 | def __init__(self, |
| 124 | connection_end="server", |
| 125 | read_or_write="read", |
| 126 | seq_num=0, |
| 127 | compression_alg=Comp_NULL, |
| 128 | ciphersuite=None, |
| 129 | tls_version=0x0303): |
| 130 | |
| 131 | self.tls_version = tls_version |
| 132 | |
| 133 | # It is the user's responsibility to keep the record seq_num |
| 134 | # under 2**64-1. If this value gets maxed out, the TLS class in |
| 135 | # record.py will crash when trying to encode it with struct.pack(). |
| 136 | self.seq_num = seq_num |
| 137 | |
| 138 | self.connection_end = connection_end |
| 139 | self.row = read_or_write |
| 140 | |
| 141 | if ciphersuite is None: |
| 142 | from scapy.layers.tls.crypto.suites import TLS_NULL_WITH_NULL_NULL |
| 143 | ciphersuite = TLS_NULL_WITH_NULL_NULL |
| 144 | self.ciphersuite = ciphersuite(tls_version=tls_version) |
| 145 | |
| 146 | if not self.ciphersuite.usable: |
| 147 | warning("TLS cipher suite not usable. " |
| 148 | "Is the cryptography Python module installed?") |
| 149 | return |
| 150 | |
| 151 | self.compression = compression_alg() |
| 152 | self.key_exchange = ciphersuite.kx_alg() |
| 153 | self.cipher = ciphersuite.cipher_alg() |
| 154 | self.hash = ciphersuite.hash_alg() |
| 155 | |
| 156 | if tls_version > 0x0200: |
| 157 | if ciphersuite.cipher_alg.type == "aead": |
| 158 | self.hmac = None |
| 159 | self.mac_len = self.cipher.tag_len |
| 160 | else: |
| 161 | self.hmac = ciphersuite.hmac_alg() |
| 162 | self.mac_len = self.hmac.hmac_len |
| 163 | else: |
| 164 | self.hmac = ciphersuite.hmac_alg() # should be Hmac_NULL |
| 165 | self.mac_len = self.hash.hash_len |
| 166 | |
| 167 | if tls_version >= 0x0304: |
| 168 | self.hkdf = TLS13_HKDF(self.hash.name.lower()) |
| 169 | else: |
| 170 | self.prf = PRF(ciphersuite.hash_alg.name, tls_version) |
| 171 | |
| 172 | def debug_repr(self, name, secret): |
| 173 | if conf.debug_tls and secret: |