Pay attention to implementation notes in section 7.4.7.1 of RFC 5246.
| 893 | |
| 894 | |
| 895 | class EncryptedPreMasterSecret(_GenericTLSSessionInheritance): |
| 896 | """ |
| 897 | Pay attention to implementation notes in section 7.4.7.1 of RFC 5246. |
| 898 | """ |
| 899 | name = "RSA Encrypted PreMaster Secret" |
| 900 | fields_desc = [_TLSClientVersionField("client_version", None, |
| 901 | _tls_version), |
| 902 | StrFixedLenField("random", None, 46)] |
| 903 | |
| 904 | @classmethod |
| 905 | def dispatch_hook(cls, _pkt=None, *args, **kargs): |
| 906 | if _pkt and 'tls_session' in kargs: |
| 907 | s = kargs['tls_session'] |
| 908 | if s.server_tmp_rsa_key is None and s.server_rsa_key is None: |
| 909 | return _UnEncryptedPreMasterSecret |
| 910 | return EncryptedPreMasterSecret |
| 911 | |
| 912 | def pre_dissect(self, m): |
| 913 | s = self.tls_session |
| 914 | tbd = m |
| 915 | tls_version = s.tls_version |
| 916 | if tls_version is None: |
| 917 | tls_version = s.advertised_tls_version |
| 918 | if tls_version >= 0x0301: |
| 919 | if len(m) < 2: # Should not happen |
| 920 | return m |
| 921 | tmp_len = struct.unpack("!H", m[:2])[0] |
| 922 | if len(m) != tmp_len + 2: |
| 923 | err = "TLS 1.0+, but RSA Encrypted PMS with no explicit length" |
| 924 | warning(err) |
| 925 | else: |
| 926 | tbd = m[2:] |
| 927 | if s.server_tmp_rsa_key is not None: |
| 928 | # priority is given to the tmp_key, if there is one |
| 929 | decrypted = s.server_tmp_rsa_key.decrypt(tbd) |
| 930 | pms = decrypted[-48:] |
| 931 | elif s.server_rsa_key is not None: |
| 932 | decrypted = s.server_rsa_key.decrypt(tbd) |
| 933 | pms = decrypted[-48:] |
| 934 | else: |
| 935 | # the dispatch_hook is supposed to prevent this case |
| 936 | pms = b"\x00" * 48 |
| 937 | err = "No server RSA key to decrypt Pre Master Secret. Skipping." |
| 938 | warning(err) |
| 939 | |
| 940 | s.pre_master_secret = pms |
| 941 | if not s.extms: |
| 942 | s.compute_ms_and_derive_keys() |
| 943 | |
| 944 | return pms |
| 945 | |
| 946 | def post_build(self, pkt, pay): |
| 947 | """ |
| 948 | We encrypt the premaster secret (the 48 bytes) with either the server |
| 949 | certificate or the temporary RSA key provided in a server key exchange |
| 950 | message. After that step, we add the 2 bytes to provide the length, as |
| 951 | described in implementation notes at the end of section 7.4.7.1. |
| 952 | """ |
nothing calls this directly
no test coverage detected
searching dependent graphs…