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

Crypro Error "not enough data" #212

Closed
Apollon77 opened this issue Jul 17, 2023 · 6 comments · Fixed by #255
Closed

Crypro Error "not enough data" #212

Apollon77 opened this issue Jul 17, 2023 · 6 comments · Fixed by #255

Comments

@Apollon77
Copy link
Collaborator

Here and there this error happens:

Error: error:0D06B08E:asn1 encoding routines:asn1_d2i_read_bio:not enough data
    at Sign.sign (node:internal/crypto/sig:131:29)
    at CryptoNode.signPkcs8 (/Users/ingof/Dev/GitHub/matter.js/packages/matter-node.js/dist/crypto/CryptoNode.js:115:44)
    at Function.Crypto.signPkcs8 (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/crypto/Crypto.js:46:68)
    at Function.daCertToAsn1 (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/certificate/CertificateManager.js:211:75)
    at AttestationCertificateManager.generateDaCert (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/certificate/AttestationCertificateManager.js:143:59)
    at AttestationCertificateManager.getDACert (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/certificate/AttestationCertificateManager.js:48:23)
    at new CommissioningServer (/Users/ingof/Dev/GitHub/matter.js/packages/matter.js/dist/cjs/CommissioningServer.js:100:54)
    at Device.<anonymous> (/Users/ingof/Dev/GitHub/matter.js/packages/matter-node.js-examples/dist/examples/DeviceNode.js:112:41)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/ingof/Dev/GitHub/matter.js/packages/matter-node.js-examples/dist/examples/DeviceNode.js:11:58) {
  library: 'asn1 encoding routines',
  function: 'asn1_d2i_read_bio',
  reason: 'not enough data',
  code: 'ERR_OSSL_ASN1_NOT_ENOUGH_DATA'
}

We should find out how to work areound that or at least catch-and-retry

@Apollon77
Copy link
Collaborator Author

Another place ...

2023-07-24 13:29:07.581 ERROR Controller error:0680008E:asn1 encoding routines::not enough data
    at Sign.sign (node:internal/crypto/sig:131:29)
    at CryptoNode.signPkcs8 (/home/ingof/matter.js/packages/matter-node.js/dist/crypto/CryptoNode.js:115:44)
    at Crypto.signPkcs8 (/home/ingof/matter.js/packages/matter.js/dist/cjs/crypto/Crypto.js:46:68)
    at Fabric.sign (/home/ingof/matter.js/packages/matter.js/dist/cjs/fabric/Fabric.js:78:35)
    at CaseClient.<anonymous> (/home/ingof/matter.js/packages/matter.js/dist/cjs/session/case/CaseClient.js:80:42)
    at Generator.next (<anonymous>)
    at fulfilled (/home/ingof/matter.js/packages/matter.js/dist/cjs/session/case/CaseClient.js:10:58)

@Apollon77
Copy link
Collaborator Author

Question: Is the the incoming data (eg keys or such) that have insufficient data/quality or is it the sign process that has an issue ...

@lauckhart
Copy link
Collaborator

IIRC we're creating a pkcs8 envelope by concatenating a static asn.1 prefix and a raw key. The actual matter payload doesn't actually use pkcs8... So asn.1 errors may be an issue with the input not matching the (very rigid) format described by the header.

I'd need to look at the code to refresh my memory but I think I may have discarded the pkcs8 stuff and just used JSON web key to convey keys to node. LMK if you want me to check that.

@Apollon77
Copy link
Collaborator Author

For now it happens here and there and no idea why and when (maybe we create a key by changce with a leading "0x00" or such ... but in order to check that we need to add more logging ... or change it completely (but this is later Crypto reafactoring). for now I would add a catch and log all params in order to maybe get an idea

@Apollon77
Copy link
Collaborator Author

I added logging in the PR #251

@Apollon77
Copy link
Collaborator Author

Ok logging will be removed before merge. Reason is that the private key as Buffer sometimes has 31 instead of 32 bytes ... whyever. We wil add a hack workaround for now in extra PR and proper solve it later in Cryptro refactor.

lauckhart added a commit to lauckhart/matter.js that referenced this issue Aug 6, 2023
Replace key handling with a JS implementation that converts keys to standard
JWK Key format.  Streamlines the Crypto.ts API and removes the various formats
and hacks we previously used to pass keys to Node's OpenSSL wrapper.

fixes project-chip#212
could be considered phase 1 of project-chip#122
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

Successfully merging a pull request may close this issue.

2 participants