Giter Site home page Giter Site logo

browserify-sign's Issues

The Elliptic package 6.5.2 for Node.js allows ECDSA signature malleability via variations in encoding, leading '\0' bytes, or integer overflows.

Hi

Issue:

The Elliptic package 6.5.2 for Node.js allows ECDSA signature malleability via variations in encoding, 
leading '\0' bytes, or integer overflows. 
This could conceivably have a security-relevant impact if an application relied on a  
single canonical signature. I'm using Elliptic 6.5.3 version but still I'm facing this issue in my project.

Could you please let me know what could be the reason for this?

I tried npm install [email protected]
and
npm audit fix
and I played around lot of other ways but still issue persists.

Thanks

Image reference:

Note: Actually, this issue is throwing by browserify-sign. browserify-sign is internally using few packages and those packages are internally using elliptic.

image

CVE-2020-13822

Elliptic had been caught by the component security scan for our team and it seems like they have a new release version 6.5.3
Could you guys make an update to your dependency graph?

Node incompatibility for "sha256" algorithm

Hello,

there seems to be some differences between this library and Node.js, consider following code:

const bCrypto = require('./browser');
const nCrypto = require('crypto');

const key = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAvvjcmEFSc9CYHZ8gN5phm9xBDxEXbM/8K62Rw5TpAENI3RZr
7Ua570EL3GEJBFM5IfWjn4zlEoXdLIM4Rj4mC9TQdxsmRYr9zGL8r9/jDTwwPTTk
ApGTZWJg5og2IrVaKByXnJHQGtHEkgNS0ay3JnL8TEOUr75WujU8YRPoBCnSnFtN
vhGRgrp+4QOROtP5pW85FmQKTkYK1s0bdlJM4YCDyicFPuqo8d2+pn8uXHcmHq7C
2QJwVEOSESpSEKwwVpZ2jQws7QRb5+ELaRdH2QQQ239FZRhVrEMsNf3AOSXcNULl
W+Mp6rbwY9+xM84g5pKgGJ80i3LDqsPvdvMAcwIDAQABAoIBAB8JvHSkfT2kg+yg
jbBrz3xw9kP4H6oIPbBto9i5TYtE5EVGnSDx00tu83oMbVY+HnWGAmNul1aE2jcf
VpiYBj/7BSyuhXBdEDXVSsNc7H6cryxreblvJpkePaiKL95BQldtmjiQvFV3jW67
yoyYeSXvH1FX1IUhtt/Jwjf278kpKIhfT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;

let p = Buffer.from(key, 'utf8');

let txt = "eyJhbGciOiJSUzI1NiIsInVybCI6Imh0dHBzOi8vYWNtZS1zdGFnaW5nLXYwMi5hcGkubGV0c2VuY3J5cHQub3JnL2FjbWUvbmV3LWFjY3QiLCJub25jZSI6InBuTDIzaDBpR0pPYm9PcWJpdmozOGtPdmdsZTJrbVZWaF9DTXcyeExZSWc4VkMzTzdTRSIsImp3ayI6eyJlIjoiQVFBQiIsImt0eSI6IlJTQSIsIm4iOiJ1VjlEUzB4bnNfOWtYbXZlQUp2VmwxV0M3emduTFlvdnNqcDY5UldQYTJ2UFVCUm1iS1lRWlZOZXQwOTdSaWxjUXNtaEhNMTVpdDA2QUdrQ2ZiNHNZcU1aWVd0QXh0a0N3U2pKUEN1OWN4WmdoU0dYWFFEM3dncm8wYl9vbmN2d1V1cjhaeG10U09pRmJQVElOZWUwUVlMWEg3ak12cVhKN3VzMTcxSU5jNDBhOXU1WDJoa3hGMVFBeWdOYmx2RVJxWHo2V2otNjR3TEhIMnBZNk9QaVFST2Rub0VlQ29DNEhXMjNqNlNDckZXTlNOei1DcUxTZWtYM0Z3TGZUMk55Z3l5N1pEeWFPZHhobFRPa0NxdUlJVGFHMF81Qjl1a1ZHRW9yQ0E5RmhYb20yRk50b1J3c0I3eUFtdkpDQ3B4Q1lUTmFuZ3VWYmVmU3luYS14VWR1ZHcifX0.eyJ0ZXJtc09mU2VydmljZUFncmVlZCI6dHJ1ZSwiY29udGFjdCI6WyJtYWlsdG86ZW1haWxAZXhhbXBsZS5jb20iXX0";

let nData = nCrypto.createSign('sha256WithRSAEncryption').update(txt).sign(p);
console.log('node', nData);
let bData = bCrypto.createSign('sha256WithRSAEncryption').update(txt).sign(p);
console.log('browserify-sign', bData);
console.log('isEqual', nData.toString('hex') === bData.toString('hex'));

nData = nCrypto.createSign('sha256').update(txt).sign(p);
console.log('node', nData);
bData = bCrypto.createSign('sha256').update(txt).sign(p);
console.log('browserify-sign', bData);
console.log('isEqual', nData.toString('hex') === bData.toString('hex'));

For sha256WithRSAEncryption both Node.js and browserify-sign are correctly signing the text using provided private key, but for sha256 only Node.js is able to sign a text, while browserify-sign` throws an error:

Error: wrong private key type
    at sign (/home/ubuntu/Projects/browserify-sign/browser/sign.js:24:63)
    at Sign.signMethod [as sign] (/home/ubuntu/Projects/browserify-sign/browser/index.js:43:13)
    at Object.<anonymous> (/home/ubuntu/Projects/browserify-sign/test-bsign.js:45:50)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

From my initial investigation, its because sha256 algorithm expects only ECDSA key, but we are providing RSA key instead.

Is it expected? Since browserify-sign wants to duplicate node behaviour, I think its a bug.

Expose algorithms

I am finding that the libraries that are attempting to use this are using different algorithm names than are listed in the algorithms.json. The one I am encountering now is sha1 which I was able to get working by duplicating and renaming the existing RSA-SHA1 algorithm.

Ideally it would be great to export a method that allows adding custom algorithm definitions at runtime.

// Very early in code
import { addAlgorithm } from 'broweserify-sign'
addAlgorithm('sha1', "rsa", "sha1", "3021300906052b0e03021a05000414")

window.crypto.subtle.sign()

There is a bunch of new goodies in recent browsers such as window.crypto.subtle.sign() that should be much faster and probably more secure than native javascript implementations. It would be a good idea to detect these methods and automatically use them if present.

Test fixtures

Could all the test fixtures please be moved out of test/ and be put in test/fixtures?

Digest algorithms

Hi guys,

Are you going to add next digest algorithms: sha256, sha384, sha512?

Verify is broken when input is a certificate

specifically it is breaking on the call to parseKeys with the following key

-----BEGIN CERTIFICATE-----
MIIDUDCCAjgCCQD1TryolF9FbDANBgkqhkiG9w0BAQsFADBzMQswCQYDVQQGEwJV
UzEOMAwGA1UECAwFVGV4YXMxDzANBgNVBAcMBkRhbGxhczEWMBQGA1UECgwNUHVi
bGlzaGVyIE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"Failed to match tag: "0" at: ["tbsCertificate"]["version"]",

This issue is causing the following issues auth0/node-jsonwebtoken#464 and auth0/node-jsonwebtoken#568

Incorrect dependency version. Please update

Browserify-sign module uses incorrect dependencies , as in our Vue-Cli project, the bundle ends up containing multiple bn.js files:
https://i.imgur.com/IQuwHHJ.png (webpack-bundle-analyzer shows that).

So, another problem seems that (when you mouseover that bn.js) it is being created called from MyProject/node_modules/browserify-sign/node_modules/bn.js/lib/bn.js while in the project there is already MyProject/node_modules/bn.js/lib/bn.js called once.

So, please correct that, so B.S. module wouldnt inject odd duplicated files into bundle, and used the available bn.js from project.

I doubt that it might be coming from this : https://github.com/crypto-browserify/browserify-rsa (as we use this module in our project too), but the browserify-rsa package.json depend son bn.js : ^4.1 . So, could that be reason? if so, please update bn.js version for browserify-rsa . Moreover, seems somoene had suggested that already - browserify/browserify-rsa#13 but one year passed, no response.

Ignore case in algorithm name

I'm currently running into issues with the casing of the sha256 algorithm name. I'm currently trying to use react-native-crypto which users browserify-sign. When trying to run createSign("SHA256") I get an error, because it's not found in the algorithms.json file.

This seems a little bit odd, as in node the case of the algorithm name does not matter. The following is working without any problems in node:

const crypto = require('crypto');

console.log(crypto.createSign('SHA256'));

breaking changes in 4.2.3

  • crypto-browserify depends on this package transitively
  • this package shipped a breaking change in 4.2.3 by supporting node v1's APIs which modern projects don't support

please ship a major semver release for the 4.2.3 change and push a 4.2.4 that reverts the changes in 4.2.3.

RSA-SHA256 encryption is broken after updates as of 03/22/2016

I'm using this package as a part of crypto-browserify.
So basically it's broken, had to downgrade to 3.0.8 to make it work again.
Code that fails:
crypto.createSign('RSA-SHA256').update(data).sign(pKey, 'base64');
The error: Uncaught Error: fromRed works only with numbers in reduction context.

I debugged this a bit and it fails on sign method, createSign and update work as supposed.

Verify is broken when input is an ECDSA certificate

Here is a simplified version of a script I am running: (The real script uses the ashtuchkin/u2f library)

#!node
var verify = require("browserify-sign/browser/verify");
var cert = `-----BEGIN CERTIFICATE-----
MIICSjCCATKgAwIBAgIEEkpy/jANBgkqhkiG9w0BAQsFADAuMSwwKgYDVQQDEyNZ
dWJpY28gVTJGIFJvb3QgQ0EgU2VyaWFsIDQ1NzIwMDYzMTAgFw0xNDA4MDEwMDAw
MDBaGA8yMDUwMDkwNDAwMDAwMFowLDEqMCgGA1UEAwwhWXViaWNvIFUyRiBFRSBT
ZXJpYWwgMjQ5NDE0OTcyMTU4MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEPYsb
vS/L9ghuEHRxYBRoSEFTwcbTtLaKXoVebkB1fuIrzYmIvzvv183yHLC/XXoVDYRK
/pgQPGxmB9n6rih8AqM7MDkwIgYJKwYBBAGCxAoCBBUxLjMuNi4xLjQuMS40MTQ4
Mi4xLjEwEwYLKwYBBAGC5RwCAQEEBAMCBSAwDQYJKoZIhvcNAQELBQADggEBAKFP
HuoAdva4R2oQor5y5g0CcbtGWy37/Hwb0S01GYmRcDJjHXldCX+jCiajJWNOhXIb
wtAahjA/a8B15ZlzGeEiFIsElu7I0fT5TPQRDeYmwolEPR8PW7sjnKE+gdHVqp31
r442EmR1v8I68GKDFXJSdi/2iHm88O9XjVXWf5UbTzK2PIrqWw+Zxn19gUp/9ab1
Lfg+iUo6XZyLguf4vI2vTIAXX/iXL9p5Mz7EZdgG6syUjxurIgRalVWKSMICJtrA
A9QfvJ4F6iimu14QpJ3gYKCk9qJnajTWjEq+jGGHQ1W5An6CjKngZLAC1i6NjPB0
SSF1PTXjyHxdV3lFPnc=
-----END CERTIFICATE-----`;
verify("fake", "fake", cert, "ecdsa/rsa")

Instead of returning some sort of 'failed verification', the code breaks instead:

TypeError: Cannot read property 'join' of undefined
    at ecVerify (node_modules/browserify-sign/browser/verify.js:48:49)
    at verify (node_modules/browserify-sign/browser/verify.js:12:12)

This is failing because ecVerify is expecting pub.data.algorithm.curve to exist, but the parse-asn1 library does not add this attribute to certificates (see crypto-browserify/parse-asn1/blob/master/index.js#L25)

Signature Forgery Attack In Browserify-Sign

Bug Description:
As I work on developing an Website in React Native, I conducted a vulnerability scan of my application's manifest file using Vulert. During this process, I uncovered an issue associated with your package.

References:
In the course of the vulnerability scan, the following references were identified:

Error: Can't resolve './browser/algorithms'

Looks like 4.0.3 was published today.

localhost > Module not found: Error: Can't resolve './browser/algorithms' in '.../node_modules/browserify-sign'
localhost > @ ./~/browserify-sign/algos.js 1:17-48
localhost > @ ./~/crypto-browserify/index.js
localhost > @ ./~/node-uuid/uuid.js

@calvinmetcalf ?

EDIT: looks like we were missing .json in our extensions: ['.js', '.jsx', '.json'] in our webpack configuration.

signing data with private key generated by new openssh 8.0 not working.

Trying to sign some data with private key which is generated by new openssh 8.0, signature output is always random, Output is always different, when passing same data. I have checked and think that problem comes from var "crt" func related to browserify-rsa. for older keys it works as expected, problem occurs only in case of using new private key. Can someone help me with this ? Thanks in advance.

Error with verifier.verify

Getting TypeError: Cannot read property '2' of null on the following code:

const verifier = crypto.createVerify('RSA-SHA256');
verifier.update(atob(oraclize_doc));
awsSignatureValid = verifier.verify(awsPublicCertificateRSA, atob(awsSignature));

Verifies just fine on node, but throws the aforementioned exception, when trying to verify on the 3rd line.

Tested with Chrome 45 and 47.

process is not defind

My project uses vue2 + webpack 5, and I have configured the fallback in webpack's resolve

resolve: {
    fallback: {
        crypto: require.resolve('crypto-browserify')
    }
}

crypto-browserify dependence browserify-sign

However, after upgrading the version of browserify-sign to 4.2.3, my project throws an error stating "process is not defined."

How can I solve this problem? Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.