def _load_http_server_conn(o: http_pb2.ServerConnection) -> ServerConnection: d: dict = {} _move_attrs(o, d, ['id', 'tls_established', 'sni', 'alpn_proto_negotiated', 'tls_version', 'timestamp_start', 'timestamp_tcp_setup', 'timestamp_tls_setup', 'timestamp_end']) for addr in ['address', 'ip_address', 'source_address']: if hasattr(o, addr): d[addr] = (getattr(o, addr).host, getattr(o, addr).port) if o.cert: c = Cert.from_pem(o.cert) d['cert'] = c if o.HasField('via'): d['via'] = _load_http_server_conn(o.via) sc = ServerConnection(tuple()) for k, v in d.items(): setattr(sc, k, v) return sc
def _load_http_client_conn(o: http_pb2.ClientConnection) -> ClientConnection: d: dict = {} _move_attrs(o, d, ['id', 'tls_established', 'sni', 'cipher_name', 'alpn_proto_negotiated', 'tls_version', 'timestamp_start', 'timestamp_tcp_setup', 'timestamp_tls_setup', 'timestamp_end']) for cert in ['clientcert', 'mitmcert']: if hasattr(o, cert) and getattr(o, cert): d[cert] = Cert.from_pem(getattr(o, cert)) if o.tls_extensions: d['tls_extensions'] = [] for extension in o.tls_extensions: d['tls_extensions'].append((extension.int, extension.bytes)) if o.address: d['address'] = (o.address.host, o.address.port) cc = ClientConnection(None, tuple(), None) for k, v in d.items(): setattr(cc, k, v) return cc