mitmproxy/web
Matthew Hughes d9cac6fbcd
Make Cert.not{before,after} timezone aware (#4805)
I noticed when running tests the output of
`web/src/js/__tests__/ducks/_tflow.ts` would change depending on how I
set my timezone, e.g.

    $ TZ=America/Los_Angeles pytest --quiet \
        test/mitmproxy/tools/web/test_app.py >/dev/null \
        && grep --extended-regexp 'not(after|before)' web/src/js/__tests__/ducks/_tflow.ts
                "notafter": 2235132207,
                "notbefore": 1604415807,
    $ TZ=Asia/Tokyo pytest --quiet \
        test/mitmproxy/tools/web/test_app.py >/dev/null \
        && grep --extended-regexp 'not(after|before)'  web/src/js/__tests__/ducks/_tflow.ts
                "notafter": 2235074607,
                "notbefore": 1604354607

It looks like this is because the `cert_to_json` function simply calls
`timestamp` the `datetime` object from
`x509.Certificate.not_valid_before`, however, this `datetime` object is
not timestamp aware, from the docs [1]:

> A naïve datetime representing the beginning of the validity period for
the certificate in UTC

So when serializing to JSON, first convert the `datetime` to UTC then
call `timestamp`.

A test was added by inspecting one of the test certs with:

    $ openssl x509 -in test/mitmproxy/net/data/text_cert_2 -text

Extracting the date and asserting on that.

The corresponding test has also been re-run so that `_tflow.ts` was
regenerated with it's correct value. Snapshots were also updated via:

    $(npm bin)/jest --updateSnapshot

[1] https://cryptography.io/en/latest/x509/reference/#cryptography.x509.Certificate.not_valid_after
2021-09-16 10:53:36 +02:00
..
src Make Cert.not{before,after} timezone aware (#4805) 2021-09-16 10:53:36 +02:00
.editorconfig [web] editor config for line endings 2016-06-17 06:26:46 +08:00
gulpfile.js Merge pull request #4779 from mhils/mitmweb-tcp 2021-08-25 13:35:37 +02:00
jest.config.js web: test coverage++, adjust commandbar 2021-08-20 18:38:22 +02:00
package-lock.json web: update dependencies 2021-08-20 18:47:34 +02:00
package.json web: update dependencies 2021-08-20 18:47:34 +02:00
README.md web: major upgrades 2021-06-21 17:51:47 +02:00
tsconfig.json major mitmweb upgrades 2021-08-18 17:38:22 +02:00

Quick Start

  • Install mitmproxy as described in ../CONTRIBUTING.md
  • Run node --version to make sure that you have at least Node.js 14 or above. If you are on Ubuntu <= 20.04, you need to upgrade.
  • Run npm install to install dependencies
  • Run npm start to start live-compilation
  • Run mitmweb after activating your Python virtualenv (see ../CONTRIBUTING.md).

Testing

  • Run npm test to run the test suite.

Architecture

There are two components:

Contributing

We very much appreciate any (small) improvements to mitmweb. Please do not include the compiled assets in mitmproxy/tools/web/static in your pull request. Refreshing them on every commit would massively increase repository size. We will update these files before every release.

Developer Tools