Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] allow client certificate selection and settings from Python #485

Closed
mesa123123 opened this issue Feb 6, 2021 · 3 comments
Closed

Comments

@mesa123123
Copy link

mesa123123 commented Feb 6, 2021

microsoft/playwright#1799

Basically theres a workaround you can use in JS that works with the agent options settings in the node request library that allows you to dynamically inject ca bundles straight to the context.route.EventHandler

I've tried to find out if this can work using urllib request but I can't seem to find a plausible way to do it

Could you guys please advise?

Heres the work around from the JS version

const fs = require('fs');
const request = require('request');
const browser = await chromium.launch();
const ctx = await browser.newContext();
await ctx.route('**/*', (route, req) => {
    const options = {
      uri: req.url(),
      method: req.method(),
      headers: req.headers(),
      body: req.postDataBuffer(),
      timeout: 10000,
      followRedirect: false,
      agentOptions: {
        ca: fs.readFileSync('./certs/ca.pem'),
        pfx: fs.readFileSync('./certs/user_cert.p12'),
        passphrase: fs.readFileSync('./certs/user_cert.p12.pwd'),
      },
    };
    let firstTry = true;
    const handler = function handler(err, resp, data) {
      if (err) {
        /* Strange random connection error on first request, do one re-try */
        if (firstTry) {
          firstTry = false;
          return request(options, handler);
        }
        console.error(`Unable to call ${options.uri}`, err.code, err);
        return route.abort();
      } else {
        return route.fulfill({
          status: resp.statusCode,
          headers: resp.headers,
          body: data,
        });
      }
    };
    return request(options, handler);
  });
@mxschmitt
Copy link
Member

mxschmitt commented Apr 20, 2021

Closing as duplicate of microsoft/playwright#1799
Please upvote it there.

(The features are tracked upstream and then get implemented in the specific languages)

@medina325
Copy link

Except it's not a duplicate, he's asking for the implementation in Python of the code. Which I also seem to have no idea on how to do it :)

@dchronos
Copy link

yeap, same problem here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants