Skip to content

Conversation

@Benouare
Copy link
Contributor

@Benouare Benouare commented Jan 10, 2020

Hi,

When using locally proxy.py, I saw that, with FF, everything looks good, but with Brave/Chrome that was not the case.
Thx of the console of chrome, it says that there is currently two issues on our certificates :

  • that was in sha1, not enought for chrome -> it needs sha256,
  • the certificate must have SAN information (subectAltName)

This PR, should solved this issue.
Regarding the code, the main problem was to generate on the fly certs with the SAN information.
I tried billions of time & differents solutions, but I was not able to make it on the fly.
Currently, I am generating and consuming a file, before to remove it. I think, it will make a lot of I/O access, and should be powerless...
So, I am waiting your comment to find the best solution.

Ressources :
https://www.fomfus.com/articles/how-to-generate-self-signed-certificates-with-san-subject-alternative-name

Edit :
The 'solution' was to put something like that in the signing process to add the SAN on the fly, but that's not working with python (but working well in direct shell)

'-extfile','<(printf "[SAN]\nsubjectAltName=DNS:CurrentTld")'

But that doesnt work at all

Edit 2 : the base branch is the one for the #258, hope that's not a problem for you.

Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 10, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from d1fe602 to 29c1560 Compare January 10, 2020 08:47
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 10, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 29c1560 to d3280ca Compare January 10, 2020 09:13
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 10, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from d3280ca to 144afdd Compare January 10, 2020 09:40
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 10, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 144afdd to 3f39714 Compare January 10, 2020 09:45
@abhinavsingh
Copy link
Owner

@Benouare I think we must start to use pki.py utilities within the interception code for generating and signing CSR requests. See test_pki.py for some usage information.

While pki.py was updated to comply with latest SSL cert requirements, I think hardcoded openssl usages within interception code might still be complying with cert requirements (specially the extensions part of cert).

@Benouare
Copy link
Contributor Author

@Benouare I think we must start to use pki.py utilities within the interception code for generating and signing CSR requests. See test_pki.py for some usage information.

While pki.py was updated to comply with latest SSL cert requirements, I think hardcoded openssl usages within interception code might still be complying with cert requirements (specially the extensions part of cert).

I agree, I will make the corrections.

Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 11, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 3f39714 to 88f3225 Compare January 11, 2020 23:21
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 11, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 88f3225 to e938b20 Compare January 11, 2020 23:27
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 11, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from e938b20 to feda6fa Compare January 11, 2020 23:30
@Benouare
Copy link
Contributor Author

So, I have made some changes.
I push the branch but it's not the final 'release' version of it : we need to talk about it, and i would like your feedback.
I have to delete some part of the code to generate the certificates 'in the good way'.
I tried to use the existants pki methods to generate certs, but that doesnt work, so I do that.
About the test, I add some, but there is one that is not working anymore. Dont get why...
Let me know what you think about it.

@abhinavsingh
Copy link
Owner

abhinavsingh commented Jan 11, 2020 via email

@abhinavsingh
Copy link
Owner

Hi @Benouare ,

I am wondering why do we need new gen_web_csr and gen_web_cert methods, doesn't existing methods in pki.py already suffice? We already used them previously to update our Makefile.

I am thinking of putting those 4 loc that you added under gen_web to replace current openssl commands run directly during interception. Wdyt?

Also, let's separate out your PR's. Send out a separate one for UUID updates, we should be able to check that in sooner. Then let's continue on this PR for cert generation fixes.

@Benouare
Copy link
Contributor Author

I am wondering why do we need new gen_web_csr and gen_web_cert methods, doesn't existing methods in pki.py already suffice? We already used them previously to update our Makefile.

I did'nt succeed to use the methods in the pki, to generate certs that can be used by ff/chrome & others. It's for that reason that I have put some new methods.

I am thinking of putting those 4 loc that you added under gen_web to replace current openssl commands run directly during interception. Wdyt?

I don't get what you mean. The gen_web is currently used to replace the 'old' way to generate the certificate during the interception.

Also, let's separate out your PR's. Send out a separate one for UUID updates, we should be able to check that in sooner. Then let's continue on this PR for cert generation fixes.

Get it.

Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 12, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from feda6fa to 38adf1c Compare January 12, 2020 14:51
@abhinavsingh
Copy link
Owner

I am wondering why do we need new gen_web_csr and gen_web_cert methods, doesn't existing methods in pki.py already suffice? We already used them previously to update our Makefile.

I did'nt succeed to use the methods in the pki, to generate certs that can be used by ff/chrome & others. It's for that reason that I have put some new methods.

I am trying to understand why can't we modify existing pki.py methods to make them compatible with FF/Chrome. As of today, pki.py is not used by anyone except Makefile, so it is OK to make changes directly into pki.py gen_priv_key and gen_public_key methods.

IIUC, only different is in terms of a few flags right?

@Benouare
Copy link
Contributor Author

Benouare commented Jan 15, 2020

I am trying to understand why can't we modify existing pki.py methods to make them compatible with FF/Chrome.

I didnt touch the existing methods to don't brake the app, but clearly, if we can modify methods and not creating new one, it's the best.

As of today, pki.py is not used by anyone except Makefile, so it is OK to make changes directly into pki.py gen_priv_key and gen_public_key methods.

Get it, I will do that.

IIUC, only different is in terms of a few flags right?

Exactly. The main thing is to sha256, and to add the SAN flag/propertie.

Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 15, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 38adf1c to 8c18410 Compare January 15, 2020 16:08
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Jan 15, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 8c18410 to e9fb473 Compare January 15, 2020 16:44
temp_cert = os.path.join(tempfile.gettempdir(), uuid.uuid4().hex)
gen_web_public_key(temp_cert, signing_key_path,
f'/C=/ST=/L=/O=/OU=/CN={tld}')
sign_csr(csr_path, key_path, crt_path, temp_cert, serial, [tld])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, if i add a

os.remove(temp_cert)

The e2e test will fail : it looks like the temp_cert is already deleted, but I dont know by who.
It looks like the OS is cleaning the temp dir automatically, so I propose to dont put the os.remove.
I let u think about to drop it in other part of the code and let the OS manage those temp files.

Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 3, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 283b596 to 0bc3cd9 Compare February 3, 2020 15:21
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 3, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 0bc3cd9 to 60c3bc3 Compare February 3, 2020 15:24
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 3, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 60c3bc3 to 1119bb9 Compare February 3, 2020 16:02
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 3, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 1119bb9 to b95fc84 Compare February 3, 2020 16:20
private_key_path: str,
private_key_password: str,
subject: str,
alt_subj_names: Optional[List[str]] = None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. SAN is just needed during certificate signing, so my suggestion is to only change that part of the code. So there are 2 steps happening during interception:

  1. Generate a CSR for domain
  2. Sign CSR with CA

To generate a CSR we also need domain private key. This is what current code does, it generate an interim key (never saved on disk), pipes the output into CSR signing command.

We'll have to add a similar method where CSR can be generated without having to persist private key (e.g. gen_priv_key, then remove_passphrase, then gen_csr). You can also remove the need of remove_passphrase by not encrypting the private key in first place (i.e. don't use a password while generating one, this will require changes to gen_priv_key flags as it by default only generated encrypted private key). Note that, CSR generation is a one time step and valid till 365 days (current default sign validity).

Also, utilities in pki.py are not in anyway tied with its user. Idea is to simply have all PKI utilities at a central place for re-use. So, I think terms like "web_cert" shouldn't land in pki.py, just continue using standard terminology like private / public keys and signed certificates (for method names).

Hence we must also preserve DEFAULT_CONFIG for use when needed. We can make ways to take input custom config (e.g. SAN during signing), overriding default config.

I hope this background helps you refactor better :)

Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 4, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from b95fc84 to 1238ec3 Compare February 4, 2020 01:19
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 4, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 1238ec3 to 4146f35 Compare February 4, 2020 02:15
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 4, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 4146f35 to fc7c851 Compare February 4, 2020 10:08
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 4, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from fc7c851 to 37e8c37 Compare February 4, 2020 10:19
Benouare pushed a commit to Benouare/proxy.py that referenced this pull request Feb 4, 2020
@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from 37e8c37 to 3104b45 Compare February 4, 2020 13:13
@Benouare Benouare requested a review from abhinavsingh February 4, 2020 13:32
@abhinavsingh
Copy link
Owner

@Benouare Thanks for your patience. These have been tough times specially with all the travel involved. Good news, I am back at a stable place and will soon jump into pending PR. Really appreciate it. I hope you are safe and sound in these hard times. Thank you!!!

@Benouare Benouare force-pushed the fix/certs-generation-chrome-issue branch from b513c0c to 104dac2 Compare March 25, 2020 11:23
@abhinavsingh
Copy link
Owner

This should be resolved with #362 . Apologies for having to close this. I think approach in #362 is simpler (a single method added to server.py) and if it works let's persist with it. Do check it out, thank you for all the help and investigation done on this subject.

s-medvedev referenced this pull request in neonevm/proxy-model.py Oct 28, 2021
* Use keccak_256 instead of shake_256 (261-restrict-write-instruction)

* Use WriteHolder (15=0x0F) instead of Write (0) (261-restrict-write-instruction)

* WriteHolder index: 15 => 16 (261-restrict-write-instruction)

* WriteHolder index: 16 => 17 (261-restrict-write-instruction)

* WriteHolder index: 17 => 18 (261-restrict-write-instruction)

* WriteHolder instruction creates bigger trx due to seed (261-restrict-write-instruction)

* WriteHolder instruction creates bigger trx due to seed (261-restrict-write-instruction)

* Comment unneeded logging (261-restrict-write-instruction)

* bugfix (261-restrict-write-instruction)

* Refactor WriteHolder from seed to nonce (261-restrict-write-instruction)

* Exclude signer pubkey from seed generation (261-restrict-write-instruction)

* Remove dead code (261-restrict-write-instruction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix A PR sent for a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants