code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def unpack_from( cls, buffer: bytes | bytearray, offset: int, timestamp: float | None = None ) -> tuple[int, DNSMessage]: """Converts the buffer from a given offset into a DNS message and also returns its length.""" ( id, flags, len_questions, ...
Converts the buffer from a given offset into a DNS message and also returns its length.
unpack_from
python
mitmproxy/mitmproxy
mitmproxy/dns.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/dns.py
MIT
def packed(self) -> bytes: """Converts the message into network bytes.""" if self.id < 0 or self.id > 65535: raise ValueError(f"DNS message's id {self.id} is out of bounds.") flags = 0 if not self.query: flags |= 1 << 15 if self.op_code < 0 or self.op_code...
Converts the message into network bytes.
packed
python
mitmproxy/mitmproxy
mitmproxy/dns.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/dns.py
MIT
def modified(self): """ `True` if this file has been modified by a user, `False` otherwise. """ if self._backup: return self._backup != self.get_state() else: return False
`True` if this file has been modified by a user, `False` otherwise.
modified
python
mitmproxy/mitmproxy
mitmproxy/flow.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flow.py
MIT
def backup(self, force=False): """ Save a backup of this flow, which can be restored by calling `Flow.revert()`. """ if not self._backup: self._backup = self.get_state()
Save a backup of this flow, which can be restored by calling `Flow.revert()`.
backup
python
mitmproxy/mitmproxy
mitmproxy/flow.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flow.py
MIT
def revert(self): """ Revert to the last backed up state. """ if self._backup: self.set_state(self._backup) self._backup = None
Revert to the last backed up state.
revert
python
mitmproxy/mitmproxy
mitmproxy/flow.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flow.py
MIT
def kill(self): """ Kill this flow. The current request/response will not be forwarded to its destination. """ if not self.killable: raise exceptions.ControlException("Flow is not killable.") # TODO: The way we currently signal killing is not ideal. One major problem ...
Kill this flow. The current request/response will not be forwarded to its destination.
kill
python
mitmproxy/mitmproxy
mitmproxy/flow.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flow.py
MIT
def intercept(self): """ Intercept this Flow. Processing will stop until resume is called. """ if self.intercepted: return self.intercepted = True if self._resume_event is not None: self._resume_event.clear()
Intercept this Flow. Processing will stop until resume is called.
intercept
python
mitmproxy/mitmproxy
mitmproxy/flow.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flow.py
MIT
async def wait_for_resume(self): """ Wait until this Flow is resumed. """ if not self.intercepted: return if self._resume_event is None: self._resume_event = asyncio.Event() await self._resume_event.wait()
Wait until this Flow is resumed.
wait_for_resume
python
mitmproxy/mitmproxy
mitmproxy/flow.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flow.py
MIT
def parse(s: str) -> TFilter: """ Parse a filter expression and return the compiled filter function. If the filter syntax is invalid, `ValueError` is raised. """ if not s: raise ValueError("Empty filter expression") try: flt = bnf.parseString(s, parseAll=True)[0] flt.patt...
Parse a filter expression and return the compiled filter function. If the filter syntax is invalid, `ValueError` is raised.
parse
python
mitmproxy/mitmproxy
mitmproxy/flowfilter.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flowfilter.py
MIT
def match(flt: str | TFilter, flow: flow.Flow) -> bool: """ Matches a flow against a compiled filter expression. Returns True if matched, False if not. If flt is a string, it will be compiled as a filter expression. If the expression is invalid, ValueError is raised. """ if isinstance(flt, ...
Matches a flow against a compiled filter expression. Returns True if matched, False if not. If flt is a string, it will be compiled as a filter expression. If the expression is invalid, ValueError is raised.
match
python
mitmproxy/mitmproxy
mitmproxy/flowfilter.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/flowfilter.py
MIT
def __init__(self, fields: Iterable[tuple[bytes, bytes]] = (), **headers): """ *Args:* - *fields:* (optional) list of ``(name, value)`` header byte tuples, e.g. ``[(b"Host", b"example.com")]``. All names and values must be bytes. - *\\*\\*headers:* Additional headers to set....
*Args:* - *fields:* (optional) list of ``(name, value)`` header byte tuples, e.g. ``[(b"Host", b"example.com")]``. All names and values must be bytes. - *\*\*headers:* Additional headers to set. Will overwrite existing values from `fields`. For convenience, underscores i...
__init__
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def get_all(self, name: str | bytes) -> list[str]: """ Like `Headers.get`, but does not fold multiple headers into a single one. This is useful for Set-Cookie and Cookie headers, which do not support folding. *See also:* - <https://tools.ietf.org/html/rfc7230#section-3.2.2> ...
Like `Headers.get`, but does not fold multiple headers into a single one. This is useful for Set-Cookie and Cookie headers, which do not support folding. *See also:* - <https://tools.ietf.org/html/rfc7230#section-3.2.2> - <https://datatracker.ietf.org/doc/html/rfc6265#section...
get_all
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def set_all(self, name: str | bytes, values: Iterable[str | bytes]): """ Explicitly set multiple headers for the given key. See `Headers.get_all`. """ name = _always_bytes(name) values = [_always_bytes(x) for x in values] return super().set_all(name, values)
Explicitly set multiple headers for the given key. See `Headers.get_all`.
set_all
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def get_content(self, strict: bool = True) -> bytes | None: """ Similar to `Message.content`, but does not raise if `strict` is `False`. Instead, the compressed message body is returned as-is. """ if self.raw_content is None: return None ce = self.headers.get(...
Similar to `Message.content`, but does not raise if `strict` is `False`. Instead, the compressed message body is returned as-is.
get_content
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def get_text(self, strict: bool = True) -> str | None: """ Similar to `Message.text`, but does not raise if `strict` is `False`. Instead, the message body is returned as surrogate-escaped UTF-8. """ content = self.get_content(strict) if content is None: return...
Similar to `Message.text`, but does not raise if `strict` is `False`. Instead, the message body is returned as surrogate-escaped UTF-8.
get_text
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def decode(self, strict: bool = True) -> None: """ Decodes body based on the current Content-Encoding header, then removes the header. If the message body is missing or empty, no action is taken. *Raises:* - `ValueError`, when the content-encoding is invalid and strict...
Decodes body based on the current Content-Encoding header, then removes the header. If the message body is missing or empty, no action is taken. *Raises:* - `ValueError`, when the content-encoding is invalid and strict is True.
decode
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def encode(self, encoding: str) -> None: """ Encodes body with the given encoding, where e is "gzip", "deflate", "identity", "br", or "zstd". Any existing content-encodings are overwritten, the content is not decoded beforehand. *Raises:* - `ValueError`, when the specified cont...
Encodes body with the given encoding, where e is "gzip", "deflate", "identity", "br", or "zstd". Any existing content-encodings are overwritten, the content is not decoded beforehand. *Raises:* - `ValueError`, when the specified content-encoding is invalid.
encode
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def json(self, **kwargs: Any) -> Any: """ Returns the JSON encoded content of the response, if any. `**kwargs` are optional arguments that will be passed to `json.loads()`. Will raise if the content can not be decoded and then parsed as JSON. *Raises:* - `json....
Returns the JSON encoded content of the response, if any. `**kwargs` are optional arguments that will be passed to `json.loads()`. Will raise if the content can not be decoded and then parsed as JSON. *Raises:* - `json.decoder.JSONDecodeError` if content is not valid ...
json
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def make( cls, method: str, url: str, content: bytes | str = "", headers: ( Headers | dict[str | bytes, str | bytes] | Iterable[tuple[bytes, bytes]] ) = (), ) -> "Request": """ Simplified API for creating request objects. """ ...
Simplified API for creating request objects.
make
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def first_line_format(self) -> str: """ *Read-only:* HTTP request form as defined in [RFC 7230](https://tools.ietf.org/html/rfc7230#section-5.3). origin-form and asterisk-form are subsumed as "relative". """ if self.method == "CONNECT": return "authority" eli...
*Read-only:* HTTP request form as defined in [RFC 7230](https://tools.ietf.org/html/rfc7230#section-5.3). origin-form and asterisk-form are subsumed as "relative".
first_line_format
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def authority(self) -> str: """ HTTP request authority. For HTTP/1, this is the authority portion of the request target (in either absolute-form or authority-form). For origin-form and asterisk-form requests, this property is set to an empty string. For HTTP/2, this is ...
HTTP request authority. For HTTP/1, this is the authority portion of the request target (in either absolute-form or authority-form). For origin-form and asterisk-form requests, this property is set to an empty string. For HTTP/2, this is the :authority pseudo header. ...
authority
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def host_header(self) -> str | None: """ The request's host/authority header. This property maps to either ``request.headers["Host"]`` or ``request.authority``, depending on whether it's HTTP/1.x or HTTP/2.0. *See also:* `Request.authority`,`Request.host`, `Request.pretty_host`...
The request's host/authority header. This property maps to either ``request.headers["Host"]`` or ``request.authority``, depending on whether it's HTTP/1.x or HTTP/2.0. *See also:* `Request.authority`,`Request.host`, `Request.pretty_host`
host_header
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def url(self) -> str: """ The full URL string, constructed from `Request.scheme`, `Request.host`, `Request.port` and `Request.path`. Settings this property updates these attributes as well. """ if self.first_line_format == "authority": return f"{self.host}:{self.port...
The full URL string, constructed from `Request.scheme`, `Request.host`, `Request.port` and `Request.path`. Settings this property updates these attributes as well.
url
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def pretty_host(self) -> str: """ *Read-only:* Like `Request.host`, but using `Request.host_header` header as an additional (preferred) data source. This is useful in transparent mode where `Request.host` is only an IP address. *Warning:* When working in adversarial environments, this m...
*Read-only:* Like `Request.host`, but using `Request.host_header` header as an additional (preferred) data source. This is useful in transparent mode where `Request.host` is only an IP address. *Warning:* When working in adversarial environments, this may not reflect the actual destination ...
pretty_host
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def pretty_url(self) -> str: """ *Read-only:* Like `Request.url`, but using `Request.pretty_host` instead of `Request.host`. """ if self.first_line_format == "authority": return self.authority host_header = self.host_header if not host_header: ret...
*Read-only:* Like `Request.url`, but using `Request.pretty_host` instead of `Request.host`.
pretty_url
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def path_components(self) -> tuple[str, ...]: """ The URL's path components as a tuple of strings. Components are unquoted. """ path = urllib.parse.urlparse(self.url).path # This needs to be a tuple so that it's immutable. # Otherwise, this would fail silently: ...
The URL's path components as a tuple of strings. Components are unquoted.
path_components
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def anticache(self) -> None: """ Modifies this request to remove headers that might produce a cached response. """ delheaders = ( "if-modified-since", "if-none-match", ) for i in delheaders: self.headers.pop(i, None)
Modifies this request to remove headers that might produce a cached response.
anticache
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def _set_urlencoded_form(self, form_data: Sequence[tuple[str, str]]) -> None: """ Sets the body to the URL-encoded form data, and adds the appropriate content-type header. This will overwrite the existing content if there is one. """ self.headers["content-type"] = "application/x-...
Sets the body to the URL-encoded form data, and adds the appropriate content-type header. This will overwrite the existing content if there is one.
_set_urlencoded_form
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def urlencoded_form(self) -> multidict.MultiDictView[str, str]: """ The URL-encoded form data. If the content-type indicates non-form data or the form could not be parsed, this is set to an empty `MultiDictView`. Modifications to the MultiDictView update `Request.content`, and ...
The URL-encoded form data. If the content-type indicates non-form data or the form could not be parsed, this is set to an empty `MultiDictView`. Modifications to the MultiDictView update `Request.content`, and vice versa.
urlencoded_form
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def multipart_form(self) -> multidict.MultiDictView[bytes, bytes]: """ The multipart form data. If the content-type indicates non-form data or the form could not be parsed, this is set to an empty `MultiDictView`. Modifications to the MultiDictView update `Request.content`, and...
The multipart form data. If the content-type indicates non-form data or the form could not be parsed, this is set to an empty `MultiDictView`. Modifications to the MultiDictView update `Request.content`, and vice versa.
multipart_form
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def make( cls, status_code: int = 200, content: bytes | str = b"", headers: ( Headers | Mapping[str, str | bytes] | Iterable[tuple[bytes, bytes]] ) = (), ) -> "Response": """ Simplified API for creating response objects. """ if isin...
Simplified API for creating response objects.
make
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def cookies( self, ) -> multidict.MultiDictView[str, tuple[str, multidict.MultiDict[str, str | None]]]: """ The response cookies. A possibly empty `MultiDictView`, where the keys are cookie name strings, and values are `(cookie value, attributes)` tuples. Within attributes, u...
The response cookies. A possibly empty `MultiDictView`, where the keys are cookie name strings, and values are `(cookie value, attributes)` tuples. Within attributes, unary attributes (e.g. `HTTPOnly`) are indicated by a `None` value. Modifications to the MultiDictView update `Response....
cookies
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def refresh(self, now=None): """ This fairly complex and heuristic function refreshes a server response for replay. - It adjusts date, expires, and last-modified headers. - It adjusts cookie expiration. """ if not now: now = time.time() delt...
This fairly complex and heuristic function refreshes a server response for replay. - It adjusts date, expires, and last-modified headers. - It adjusts cookie expiration.
refresh
python
mitmproxy/mitmproxy
mitmproxy/http.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py
MIT
def alert(self, txt): """ Log with level alert. Alerts have the same urgency as info, but signals to interactive tools that the user's attention should be drawn to the output even if they're not currently looking at the event log. """ warnings.warn( "m...
Log with level alert. Alerts have the same urgency as info, but signals to interactive tools that the user's attention should be drawn to the output even if they're not currently looking at the event log.
alert
python
mitmproxy/mitmproxy
mitmproxy/log.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/log.py
MIT
def subscribe(self, func, opts): """ Subscribe a callable to the .changed signal, but only for a specified list of options. The callable should accept arguments (options, updated), and may raise an OptionsError. The event will automatically be unsubscribed if the callable goes o...
Subscribe a callable to the .changed signal, but only for a specified list of options. The callable should accept arguments (options, updated), and may raise an OptionsError. The event will automatically be unsubscribed if the callable goes out of scope.
subscribe
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def update_known(self, **kwargs): """ Update and set all known options from kwargs. Returns a dictionary of unknown options. """ known, unknown = {}, {} for k, v in kwargs.items(): if k in self._options: known[k] = v else: ...
Update and set all known options from kwargs. Returns a dictionary of unknown options.
update_known
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def setter(self, attr): """ Generate a setter for a given attribute. This returns a callable taking a single argument. """ if attr not in self._options: raise KeyError("No such option: %s" % attr) def setter(x): setattr(self, attr, x) ret...
Generate a setter for a given attribute. This returns a callable taking a single argument.
setter
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def toggler(self, attr): """ Generate a toggler for a boolean attribute. This returns a callable that takes no arguments. """ if attr not in self._options: raise KeyError("No such option: %s" % attr) o = self._options[attr] if o.typespec is not bool: ...
Generate a toggler for a boolean attribute. This returns a callable that takes no arguments.
toggler
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def merge(self, opts): """ Merge a dict of options into this object. Options that have None value are ignored. Lists and tuples are appended to the current option value. """ toset = {} for k, v in opts.items(): if v is not None: if isin...
Merge a dict of options into this object. Options that have None value are ignored. Lists and tuples are appended to the current option value.
merge
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def set(self, *specs: str, defer: bool = False) -> None: """ Takes a list of set specification in standard form (option=value). Options that are known are updated immediately. If defer is true, options that are not known are deferred, and will be set once they are added. ...
Takes a list of set specification in standard form (option=value). Options that are known are updated immediately. If defer is true, options that are not known are deferred, and will be set once they are added. May raise an `OptionsError` if a value is malformed or an option is...
set
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def process_deferred(self) -> None: """ Processes options that were deferred in previous calls to set, and have since been added. """ update: dict[str, Any] = {} for optname, value in self.deferred.items(): if optname in self._options: if isins...
Processes options that were deferred in previous calls to set, and have since been added.
process_deferred
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def _parse_setval(self, o: _Option, values: list[str]) -> Any: """ Convert a string to a value appropriate for the option type. """ if o.typespec == Sequence[str]: return values if len(values) > 1: raise exceptions.OptionsError( f"Received ...
Convert a string to a value appropriate for the option type.
_parse_setval
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def make_parser(self, parser, optname, metavar=None, short=None): """ Auto-Create a command-line parser entry for a named option. If the option does not exist, it is ignored. """ if optname not in self._options: return o = self._options[optname] def ...
Auto-Create a command-line parser entry for a named option. If the option does not exist, it is ignored.
make_parser
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def dump_defaults(opts, out: TextIO): """ Dumps an annotated file with all options. """ # Sort data s = ruamel.yaml.comments.CommentedMap() for k in sorted(opts.keys()): o = opts._options[k] s[k] = o.default txt = o.help.strip() if o.choices: txt += "...
Dumps an annotated file with all options.
dump_defaults
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def dump_dicts(opts, keys: Iterable[str] | None = None) -> dict: """ Dumps the options into a list of dict object. Return: A list like: { "anticache": { type: "bool", default: false, value: true, help: "help text"} } """ options_dict = {} if keys is None: keys = opts.keys() for k in...
Dumps the options into a list of dict object. Return: A list like: { "anticache": { type: "bool", default: false, value: true, help: "help text"} }
dump_dicts
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def load(opts: OptManager, text: str, cwd: Path | str | None = None) -> None: """ Load configuration from text, over-writing options already set in this object. May raise OptionsError if the config file is invalid. """ data = parse(text) scripts = data.get("scripts") if scripts is not None ...
Load configuration from text, over-writing options already set in this object. May raise OptionsError if the config file is invalid.
load
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def load_paths(opts: OptManager, *paths: Path | str) -> None: """ Load paths in order. Each path takes precedence over the previous path. Paths that don't exist are ignored, errors raise an OptionsError. """ for p in paths: p = Path(p).expanduser() if p.exists() and p.is_file(): ...
Load paths in order. Each path takes precedence over the previous path. Paths that don't exist are ignored, errors raise an OptionsError.
load_paths
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def serialize( opts: OptManager, file: TextIO, text: str, defaults: bool = False ) -> None: """ Performs a round-trip serialization. If text is not None, it is treated as a previous serialization that should be modified in-place. - If "defaults" is False, only options with non-default values ar...
Performs a round-trip serialization. If text is not None, it is treated as a previous serialization that should be modified in-place. - If "defaults" is False, only options with non-default values are serialized. Default values in text are preserved. - Unknown options in text are removed. ...
serialize
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def save(opts: OptManager, path: Path | str, defaults: bool = False) -> None: """ Save to path. If the destination file exists, modify it in-place. Raises OptionsError if the existing data is corrupt. """ path = Path(path).expanduser() if path.exists() and path.is_file(): with path.open...
Save to path. If the destination file exists, modify it in-place. Raises OptionsError if the existing data is corrupt.
save
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def relative_path(script_path: Path | str, *, relative_to: Path | str) -> Path: """ Make relative paths found in config files relative to said config file, instead of relative to where the command is ran. """ script_path = Path(script_path) # Edge case when $HOME is not an absolute path if s...
Make relative paths found in config files relative to said config file, instead of relative to where the command is ran.
relative_path
python
mitmproxy/mitmproxy
mitmproxy/optmanager.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/optmanager.py
MIT
def __init__(self, raw_client_hello: bytes, dtls: bool = False): """Create a TLS ClientHello object from raw bytes.""" self._raw_bytes = raw_client_hello if dtls: self._client_hello = dtls_client_hello.DtlsClientHello( KaitaiStream(io.BytesIO(raw_client_hello)) ...
Create a TLS ClientHello object from raw bytes.
__init__
python
mitmproxy/mitmproxy
mitmproxy/tls.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/tls.py
MIT
def raw_bytes(self, wrap_in_record: bool = True) -> bytes: """ The raw ClientHello bytes as seen on the wire. If `wrap_in_record` is True, the ClientHello will be wrapped in a synthetic TLS record (`0x160303 + len(chm) + 0x01 + len(ch)`), which is the format expected by some tools. ...
The raw ClientHello bytes as seen on the wire. If `wrap_in_record` is True, the ClientHello will be wrapped in a synthetic TLS record (`0x160303 + len(chm) + 0x01 + len(ch)`), which is the format expected by some tools. The synthetic record assumes TLS version (`0x0303`), which may be ...
raw_bytes
python
mitmproxy/mitmproxy
mitmproxy/tls.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/tls.py
MIT
def sni(self) -> str | None: """ The [Server Name Indication](https://en.wikipedia.org/wiki/Server_Name_Indication), which indicates which hostname the client wants to connect to. """ if ext := getattr(self._client_hello, "extensions", None): for extension in ext.exte...
The [Server Name Indication](https://en.wikipedia.org/wiki/Server_Name_Indication), which indicates which hostname the client wants to connect to.
sni
python
mitmproxy/mitmproxy
mitmproxy/tls.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/tls.py
MIT
def alpn_protocols(self) -> list[bytes]: """ The application layer protocols offered by the client as part of the [ALPN](https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation) TLS extension. """ if ext := getattr(self._client_hello, "extensions", None): ...
The application layer protocols offered by the client as part of the [ALPN](https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation) TLS extension.
alpn_protocols
python
mitmproxy/mitmproxy
mitmproxy/tls.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/tls.py
MIT
def extensions(self) -> list[tuple[int, bytes]]: """The raw list of extensions in the form of `(extension_type, raw_bytes)` tuples.""" ret = [] if ext := getattr(self._client_hello, "extensions", None): for extension in ext.extensions: body = getattr(extension, "_raw_...
The raw list of extensions in the form of `(extension_type, raw_bytes)` tuples.
extensions
python
mitmproxy/mitmproxy
mitmproxy/tls.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/tls.py
MIT
def get_dev_version() -> str: """ Return a detailed version string, sourced either from VERSION or obtained dynamically using git. """ mitmproxy_version = VERSION here = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) try: # pragma: no cover # Check that we're in the mi...
Return a detailed version string, sourced either from VERSION or obtained dynamically using git.
get_dev_version
python
mitmproxy/mitmproxy
mitmproxy/version.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/version.py
MIT
def text(self) -> str: """ The message content as text. This attribute is only available if `WebSocketMessage.is_text` is `True`. *See also:* `WebSocketMessage.content` """ if self.type != Opcode.TEXT: raise AttributeError( f"{self.type.name....
The message content as text. This attribute is only available if `WebSocketMessage.is_text` is `True`. *See also:* `WebSocketMessage.content`
text
python
mitmproxy/mitmproxy
mitmproxy/websocket.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/websocket.py
MIT
def parse_spec(option: str) -> BlockSpec: """ Parses strings in the following format, enforces number of segments: /flow-filter/status """ sep, rem = option[0], option[1:] parts = rem.split(sep, 2) if len(parts) != 2: raise ValueError("Invalid number of parameters (2 are expec...
Parses strings in the following format, enforces number of segments: /flow-filter/status
parse_spec
python
mitmproxy/mitmproxy
mitmproxy/addons/blocklist.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/blocklist.py
MIT
def launch_chrome(self) -> None: """ Start an isolated instance of Chrome that points to the currently running proxy. """ cmd = find_executable_cmd( "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", # https://stackoverflow.com/questions/40674...
Start an isolated instance of Chrome that points to the currently running proxy.
launch_chrome
python
mitmproxy/mitmproxy
mitmproxy/addons/browser.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/browser.py
MIT
def launch_firefox(self) -> None: """ Start an isolated instance of Firefox that points to the currently running proxy. """ cmd = find_executable_cmd( "/Applications/Firefox.app/Contents/MacOS/firefox", r"C:\Program Files\Mozilla Firefox\firefox.exe", ...
Start an isolated instance of Firefox that points to the currently running proxy.
launch_firefox
python
mitmproxy/mitmproxy
mitmproxy/addons/browser.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/browser.py
MIT
def start_replay(self, flows: Sequence[flow.Flow]) -> None: """ Add flows to the replay queue, skipping flows that can't be replayed. """ updated: list[http.HTTPFlow] = [] for f in flows: err = self.check(f) if err: logger.warning(err) ...
Add flows to the replay queue, skipping flows that can't be replayed.
start_replay
python
mitmproxy/mitmproxy
mitmproxy/addons/clientplayback.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/clientplayback.py
MIT
def load_file(self, path: mitmproxy.types.Path) -> None: """ Load flows from file, and add them to the replay queue. """ try: flows = io.read_flows_from_paths([path]) except exceptions.FlowReadException as e: raise exceptions.CommandError(str(e)) s...
Load flows from file, and add them to the replay queue.
load_file
python
mitmproxy/mitmproxy
mitmproxy/addons/clientplayback.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/clientplayback.py
MIT
def resume(self, flows: Sequence[flow.Flow]) -> None: """ Resume flows if they are intercepted. """ intercepted = [i for i in flows if i.intercepted] for f in intercepted: f.resume() ctx.master.addons.trigger(hooks.UpdateHook(intercepted))
Resume flows if they are intercepted.
resume
python
mitmproxy/mitmproxy
mitmproxy/addons/core.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/core.py
MIT
def flow_set(self, flows: Sequence[flow.Flow], attr: str, value: str) -> None: """ Quickly set a number of common values on flows. """ val: int | str = value if attr == "status_code": try: val = int(val) # type: ignore except ValueError as...
Quickly set a number of common values on flows.
flow_set
python
mitmproxy/mitmproxy
mitmproxy/addons/core.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/core.py
MIT
def encode_toggle(self, flows: Sequence[flow.Flow], part: str) -> None: """ Toggle flow encoding on and off, using deflate for encoding. """ updated = [] for f in flows: p = getattr(f, part, None) if p: f.backup() current_en...
Toggle flow encoding on and off, using deflate for encoding.
encode_toggle
python
mitmproxy/mitmproxy
mitmproxy/addons/core.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/core.py
MIT
def options_reset_one(self, name: str) -> None: """ Reset one option to its default value. """ if name not in ctx.options: raise exceptions.CommandError("No such option: %s" % name) setattr( ctx.options, name, ctx.options.default(na...
Reset one option to its default value.
options_reset_one
python
mitmproxy/mitmproxy
mitmproxy/addons/core.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/core.py
MIT
def cut( self, flows: Sequence[flow.Flow], cuts: mitmproxy.types.CutSpec, ) -> mitmproxy.types.Data: """ Cut data from a set of flows. Cut specifications are attribute paths from the base of the flow object, with a few conveniences - "port" and "host" retrieve...
Cut data from a set of flows. Cut specifications are attribute paths from the base of the flow object, with a few conveniences - "port" and "host" retrieve parts of an address tuple, ".header[key]" retrieves a header value. Return values converted to strings or bytes: SSL certif...
cut
python
mitmproxy/mitmproxy
mitmproxy/addons/cut.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/cut.py
MIT
def save( self, flows: Sequence[flow.Flow], cuts: mitmproxy.types.CutSpec, path: mitmproxy.types.Path, ) -> None: """ Save cuts to file. If there are multiple flows or cuts, the format is UTF-8 encoded CSV. If there is exactly one row and one column, t...
Save cuts to file. If there are multiple flows or cuts, the format is UTF-8 encoded CSV. If there is exactly one row and one column, the data is written to file as-is, with raw bytes preserved. If the path is prefixed with a "+", values are appended if there is an existing file....
save
python
mitmproxy/mitmproxy
mitmproxy/addons/cut.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/cut.py
MIT
def clip( self, flows: Sequence[flow.Flow], cuts: mitmproxy.types.CutSpec, ) -> None: """ Send cuts to the clipboard. If there are multiple flows or cuts, the format is UTF-8 encoded CSV. If there is exactly one row and one column, the data is written to file ...
Send cuts to the clipboard. If there are multiple flows or cuts, the format is UTF-8 encoded CSV. If there is exactly one row and one column, the data is written to file as-is, with raw bytes preserved.
clip
python
mitmproxy/mitmproxy
mitmproxy/addons/cut.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/cut.py
MIT
def name_servers(self) -> list[str]: """ Returns the operating system's name servers unless custom name servers are set. On error, an empty list is returned. """ try: return ( ctx.options.dns_name_servers or mitmproxy_rs.dns.get_system_...
Returns the operating system's name servers unless custom name servers are set. On error, an empty list is returned.
name_servers
python
mitmproxy/mitmproxy
mitmproxy/addons/dns_resolver.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/dns_resolver.py
MIT
def resolver(self) -> Resolver: """ Returns: The DNS resolver to use. Raises: MissingNameServers, if name servers are unknown and `dns_use_hosts_file` is disabled. """ if ns := self.name_servers(): # We always want to use our own resolver if na...
Returns: The DNS resolver to use. Raises: MissingNameServers, if name servers are unknown and `dns_use_hosts_file` is disabled.
resolver
python
mitmproxy/mitmproxy
mitmproxy/addons/dns_resolver.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/dns_resolver.py
MIT
def raw(f: flow.Flow, separator=b"\r\n\r\n") -> bytes: """Return either the request or response if only one exists, otherwise return both""" request_present = ( isinstance(f, http.HTTPFlow) and f.request and f.request.raw_content is not None ) response_present = ( isinstance(f, http.HTTP...
Return either the request or response if only one exists, otherwise return both
raw
python
mitmproxy/mitmproxy
mitmproxy/addons/export.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/export.py
MIT
def clip(self, format: str, f: flow.Flow) -> None: """ Export a flow to the system clipboard. """ content = self.export_str(format, f) try: pyperclip.copy(content) except pyperclip.PyperclipException as e: logging.error(str(e))
Export a flow to the system clipboard.
clip
python
mitmproxy/mitmproxy
mitmproxy/addons/export.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/export.py
MIT
def export_str(self, format: str, f: flow.Flow) -> str: """ Export a flow and return the result. """ if format not in formats: raise exceptions.CommandError("No such export format: %s" % format) content = formats[format](f) # The individual formatters may ret...
Export a flow and return the result.
export_str
python
mitmproxy/mitmproxy
mitmproxy/addons/export.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/export.py
MIT
def _safe_path_join(root: Path, untrusted: str) -> Path: """Join a Path element with an untrusted str. This is a convenience wrapper for werkzeug's safe_join, raising a ValueError if the path is malformed.""" untrusted_parts = Path(untrusted).parts joined = safe_join(root.as_posix(), *untrusted_par...
Join a Path element with an untrusted str. This is a convenience wrapper for werkzeug's safe_join, raising a ValueError if the path is malformed.
_safe_path_join
python
mitmproxy/mitmproxy
mitmproxy/addons/maplocal.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/maplocal.py
MIT
def file_candidates(url: str, spec: MapLocalSpec) -> list[Path]: """ Get all potential file candidates given a URL and a mapping spec ordered by preference. This function already assumes that the spec regex matches the URL. """ m = re.search(spec.regex, url) assert m if m.groups(): s...
Get all potential file candidates given a URL and a mapping spec ordered by preference. This function already assumes that the spec regex matches the URL.
file_candidates
python
mitmproxy/mitmproxy
mitmproxy/addons/maplocal.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/maplocal.py
MIT
def read_replacement(self) -> bytes: """ Process the replacement str. This usually just involves converting it to bytes. However, if it starts with `@`, we interpret the rest as a file path to read from. Raises: - IOError if the file cannot be read. """ if se...
Process the replacement str. This usually just involves converting it to bytes. However, if it starts with `@`, we interpret the rest as a file path to read from. Raises: - IOError if the file cannot be read.
read_replacement
python
mitmproxy/mitmproxy
mitmproxy/addons/modifyheaders.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/modifyheaders.py
MIT
def _ignore_connection( self, context: Context, data_client: bytes, data_server: bytes, ) -> bool | None: """ Returns: True, if the connection should be ignored. False, if it should not be ignored. Raises: NeedsMoreData, if...
Returns: True, if the connection should be ignored. False, if it should not be ignored. Raises: NeedsMoreData, if we need to wait for more input data.
_ignore_connection
python
mitmproxy/mitmproxy
mitmproxy/addons/next_layer.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/next_layer.py
MIT
def _get_host_header( context: Context, data_client: bytes, data_server: bytes, ) -> str | None: """ Try to read a host header from data_client. Returns: The host header value, or None, if no host header was found. Raises: NeedsMoreDa...
Try to read a host header from data_client. Returns: The host header value, or None, if no host header was found. Raises: NeedsMoreData, if the HTTP request is incomplete.
_get_host_header
python
mitmproxy/mitmproxy
mitmproxy/addons/next_layer.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/next_layer.py
MIT
def _get_client_hello(context: Context, data_client: bytes) -> ClientHello | None: """ Try to read a TLS/DTLS/QUIC ClientHello from data_client. Returns: A complete ClientHello, or None, if no ClientHello was found. Raises: NeedsMoreData, if the ClientHello is i...
Try to read a TLS/DTLS/QUIC ClientHello from data_client. Returns: A complete ClientHello, or None, if no ClientHello was found. Raises: NeedsMoreData, if the ClientHello is incomplete.
_get_client_hello
python
mitmproxy/mitmproxy
mitmproxy/addons/next_layer.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/next_layer.py
MIT
def authenticate_http(self, f: http.HTTPFlow) -> bool: """ Authenticate an HTTP request, returns if authentication was successful. If valid credentials are found, the matching authentication header is removed. In no or invalid credentials are found, flow.response is set to an error page...
Authenticate an HTTP request, returns if authentication was successful. If valid credentials are found, the matching authentication header is removed. In no or invalid credentials are found, flow.response is set to an error page.
authenticate_http
python
mitmproxy/mitmproxy
mitmproxy/addons/proxyauth.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/proxyauth.py
MIT
def parse_http_basic_auth(s: str) -> tuple[str, str, str]: """ Parse a basic auth header. Raises a ValueError if the input is invalid. """ scheme, authinfo = s.split() if scheme.lower() != "basic": raise ValueError("Unknown scheme") try: user, password = ( binasci...
Parse a basic auth header. Raises a ValueError if the input is invalid.
parse_http_basic_auth
python
mitmproxy/mitmproxy
mitmproxy/addons/proxyauth.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/proxyauth.py
MIT
async def setup_servers(self) -> bool: """Setup proxy servers. This may take an indefinite amount of time to complete (e.g. on permission prompts).""" return await self.servers.update( [mode_specs.ProxyMode.parse(m) for m in ctx.options.mode] )
Setup proxy servers. This may take an indefinite amount of time to complete (e.g. on permission prompts).
setup_servers
python
mitmproxy/mitmproxy
mitmproxy/addons/proxyserver.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/proxyserver.py
MIT
def _path(path: str) -> str: """Extract the path from a path spec (which may have an extra "+" at the front)""" if path.startswith("+"): path = path[1:] return os.path.expanduser(path)
Extract the path from a path spec (which may have an extra "+" at the front)
_path
python
mitmproxy/mitmproxy
mitmproxy/addons/save.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/save.py
MIT
def _mode(path: str) -> Literal["ab", "wb"]: """Extract the writing mode (overwrite or append) from a path spec""" if path.startswith("+"): return "ab" else: return "wb"
Extract the writing mode (overwrite or append) from a path spec
_mode
python
mitmproxy/mitmproxy
mitmproxy/addons/save.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/save.py
MIT
def save_flow(self, flow: flow.Flow) -> None: """ Write the flow to the stream, but first check if we need to rotate to a new file. """ if not self.stream: return try: self.maybe_rotate_to_new_file() self.stream.add(flow) except OSError...
Write the flow to the stream, but first check if we need to rotate to a new file.
save_flow
python
mitmproxy/mitmproxy
mitmproxy/addons/save.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/save.py
MIT
def save(self, flows: Sequence[flow.Flow], path: mitmproxy.types.Path) -> None: """ Save flows to a file. If the path starts with a +, flows are appended to the file, otherwise it is over-written. """ try: with open(_path(path), _mode(path)) as f: stre...
Save flows to a file. If the path starts with a +, flows are appended to the file, otherwise it is over-written.
save
python
mitmproxy/mitmproxy
mitmproxy/addons/save.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/save.py
MIT
def export_har(self, flows: Sequence[flow.Flow], path: types.Path) -> None: """Export flows to an HAR (HTTP Archive) file.""" har = json.dumps(self.make_har(flows), indent=4).encode() if path.endswith(".zhar"): har = zlib.compress(har, 9) with open(path, "wb") as f: ...
Export flows to an HAR (HTTP Archive) file.
export_har
python
mitmproxy/mitmproxy
mitmproxy/addons/savehar.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/savehar.py
MIT
def format_response_cookies(self, response: http.Response) -> list[dict]: """Formats the response's cookie header to list of cookies""" cookie_list = response.cookies.items(multi=True) rv = [] for name, (value, attrs) in cookie_list: cookie = { "name": name, ...
Formats the response's cookie header to list of cookies
format_response_cookies
python
mitmproxy/mitmproxy
mitmproxy/addons/savehar.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/savehar.py
MIT
def script_run(self, flows: Sequence[flow.Flow], path: mtypes.Path) -> None: """ Run a script on the specified flows. The script is configured with the current options and all lifecycle events for each flow are simulated. Note that the load event is not invoked. """ if no...
Run a script on the specified flows. The script is configured with the current options and all lifecycle events for each flow are simulated. Note that the load event is not invoked.
script_run
python
mitmproxy/mitmproxy
mitmproxy/addons/script.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/script.py
MIT
def add_flows(self, flows: Sequence[flow.Flow]) -> None: """ Add responses from flows to server replay list. """ for f in flows: if isinstance(f, http.HTTPFlow): lst = self.flowmap.setdefault(self._hash(f), []) lst.append(f) ctx.master....
Add responses from flows to server replay list.
add_flows
python
mitmproxy/mitmproxy
mitmproxy/addons/serverplayback.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/serverplayback.py
MIT
def _hash(self, flow: http.HTTPFlow) -> Hashable: """ Calculates a loose hash of the flow request. """ r = flow.request _, _, path, _, query, _ = urllib.parse.urlparse(r.url) queriesArray = urllib.parse.parse_qsl(query, keep_blank_values=True) key: list[Any] = [s...
Calculates a loose hash of the flow request.
_hash
python
mitmproxy/mitmproxy
mitmproxy/addons/serverplayback.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/serverplayback.py
MIT
def next_flow(self, flow: http.HTTPFlow) -> http.HTTPFlow | None: """ Returns the next flow object, or None if no matching flow was found. """ hash = self._hash(flow) if hash in self.flowmap: if ctx.options.server_replay_reuse or ctx.options.server_replay_nopo...
Returns the next flow object, or None if no matching flow was found.
next_flow
python
mitmproxy/mitmproxy
mitmproxy/addons/serverplayback.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/serverplayback.py
MIT
def _default_ciphers( min_tls_version: net_tls.Version, ) -> tuple[str, ...]: """ @SECLEVEL=0 is necessary for TLS 1.1 and below to work, see https://github.com/pyca/cryptography/issues/9523 """ if min_tls_version in net_tls.INSECURE_TLS_MIN_VERSIONS: return _DEFAULT_CIPHERS_WITH_SECLEVE...
@SECLEVEL=0 is necessary for TLS 1.1 and below to work, see https://github.com/pyca/cryptography/issues/9523
_default_ciphers
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT
def tls_start_client(self, tls_start: tls.TlsData) -> None: """Establish TLS or DTLS between client and proxy.""" if tls_start.ssl_conn is not None: return # a user addon has already provided the pyOpenSSL context. assert isinstance(tls_start.conn, connection.Client) clien...
Establish TLS or DTLS between client and proxy.
tls_start_client
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT
def tls_start_server(self, tls_start: tls.TlsData) -> None: """Establish TLS or DTLS between proxy and server.""" if tls_start.ssl_conn is not None: return # a user addon has already provided the pyOpenSSL context. assert isinstance(tls_start.conn, connection.Server) clien...
Establish TLS or DTLS between proxy and server.
tls_start_server
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT
def quic_start_client(self, tls_start: quic.QuicTlsData) -> None: """Establish QUIC between client and proxy.""" if tls_start.settings is not None: return # a user addon has already provided the settings. tls_start.settings = quic.QuicTlsSettings() # keep the following part...
Establish QUIC between client and proxy.
quic_start_client
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT
def quic_start_server(self, tls_start: quic.QuicTlsData) -> None: """Establish QUIC between proxy and server.""" if tls_start.settings is not None: return # a user addon has already provided the settings. tls_start.settings = quic.QuicTlsSettings() # keep the following part...
Establish QUIC between proxy and server.
quic_start_server
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT
def _warn_seclevel_missing(self, side: Literal["client", "server"]) -> None: """ OpenSSL cipher spec need to specify @SECLEVEL for old TLS versions to work, see https://github.com/pyca/cryptography/issues/9523. """ if side == "client": custom_ciphers = ctx.options.cip...
OpenSSL cipher spec need to specify @SECLEVEL for old TLS versions to work, see https://github.com/pyca/cryptography/issues/9523.
_warn_seclevel_missing
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT
def get_cert(self, conn_context: context.Context) -> certs.CertStoreEntry: """ This function determines the Common Name (CN), Subject Alternative Names (SANs) and Organization Name our certificate should have and then fetches a matching cert from the certstore. """ altnames: list...
This function determines the Common Name (CN), Subject Alternative Names (SANs) and Organization Name our certificate should have and then fetches a matching cert from the certstore.
get_cert
python
mitmproxy/mitmproxy
mitmproxy/addons/tlsconfig.py
https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/addons/tlsconfig.py
MIT