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

BREAKING CHANGE: disallow indefinite length, check length #122

Open
vasco-santos opened this issue Jun 18, 2020 · 7 comments
Open

BREAKING CHANGE: disallow indefinite length, check length #122

vasco-santos opened this issue Jun 18, 2020 · 7 comments

Comments

@vasco-santos
Copy link

Hello,

libp2p/js-libp2p-crypto is using dannycoates/pem-jwk, which is using this module.

With the latest release, we got everything broken in libp2p. Can you revert the release and release as a breaking change, if you really want to go with this? I am not entirely sure about the change yet, but this is breaking all the projects now.

@indutny
Copy link
Owner

indutny commented Jun 18, 2020

Sure thing. I've published 5.4.1 without it.

This is a breaking change, but it is a security bugfix. Ideally it should not become a major release of the library and stay as a minor or even a patch release. Would you mind sharing a test case that reproduces the problem?

FWIW, the crux is that DER encoding disallows certain inputs and asn1.js was very lenient about it before which leads to malleability. I suppose that one way this issue could surface at other libraries is that they were actually passing BER encoded data to the DER decoder. Is it something that happens in libp2p?

@vasco-santos
Copy link
Author

vasco-santos commented Jun 18, 2020

Thanks very much @indutny

I was getting this error, if it helps:

image

I am not sure where it comes from so far

@indutny
Copy link
Owner

indutny commented Jun 18, 2020

How can I reproduce it?

@vasco-santos
Copy link
Author

vasco-santos commented Jun 18, 2020

The easiest way is to install peer-id https://github.com/libp2p/js-peer-id#createopts and do:

const PeerId = require('peer-id')
await PeerId.create()

(with the commit mentioned)

It will create a key using libp2p/js-libp2p-crypto

EDIT: If you use libp2p-crypto directly, you can do:

const crypto = require(libp2p-crypto)
await crypto.keys.generateKeyPair('RSA', 512)

FWIW, the crux is that DER encoding disallows certain inputs and asn1.js was very lenient about it before which leads to malleability. I suppose that one way this issue could surface at other libraries is that they were actually passing BER encoded data to the DER decoder. Is it something that happens in libp2p?

I need to check it out, I am not entirely familiar with libp2p/js-libp2p-crypto, where that should be implemented

@vasco-santos
Copy link
Author

I believe the problem is in pem-jwk, which is the dependency that we use, more precisely on: https://github.com/dannycoates/pem-jwk/blob/master/index.js#L150-L159

@indutny
Copy link
Owner

indutny commented Jun 18, 2020

Oh. I think it is OpenSSL that produces such PEM/DER in PEM_write_bio_RSAPrivateKey, and it is indirectly called through ursa. I'll have to investigate it in better detail.

@panva
Copy link

panva commented Jun 19, 2020

@indutny FWIW the RFC submodule test suites also fail for me when trying out this change.

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

No branches or pull requests

3 participants