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

Error: error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag #808

Closed
da201501245 opened this issue Nov 10, 2022 · 3 comments
Closed
Labels

Comments

@da201501245
Copy link

da201501245 commented Nov 10, 2022

Receiving error on encrypted SAML Response.

Error: error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag
at Object.privateDecrypt (node:internal/crypto/cipher:79:12)
at decryptKeyInfoWithScheme (/home/myloft/app/node_modules/xml-encryption/lib/xmlenc.js:258:26)
at decryptKeyInfo (/home/myloft/app/node_modules/xml-encryption/lib/xmlenc.js:246:14)
at Object.decrypt (/home/myloft/app/node_modules/xml-encryption/lib/xmlenc.js:187:24)
at node:internal/util:361:7
at new Promise ()
at Object.decrypt (node:internal/util:347:12)
at decryptXml (/home/myloft/app/node_modules/passport-saml/lib/node-saml/xml.js:39:93)
at SAML.validatePostResponseAsync (/home/myloft/app/node_modules/passport-saml/lib/node-saml/saml.js:591:65)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)

after upgrading node version from 12.20.0 to 16.13.2 and passport-saml to 3.2.4

I have decryptionPvk is the same as the previous version with the format start line and end line -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY-----

earlier this was working fine after upgrading to the latest version it stopped working.

To Reproduce

  • pass encrypted SAML Response in passport.authenticate()

Expected behaviour

  • it should decrypt SAML Response have working on earlier version.

Environment

  • Node.js version:
  • 16.13.2
  • passport-saml version:
  • 3.2.4
@srd90
Copy link

srd90 commented Nov 10, 2022

...
after upgrading node version from 12.20.0 to 16.13.2 and passport-saml to 3.2.4
...
earlier this was working fine after upgrading to the latest version it stopped working.
...
Environment

  • Node.js version:
  • 16.13.2
  • passport-saml version:
  • 3.2.4

Care to share your earlier passport-saml version?

@srd90
Copy link

srd90 commented Nov 10, 2022

tl;dr; at the moment it seems that this issue is caused by user error in configurations.


Lets try some guessing what might be wrong but first lets check whether v3.2.4's test pass in your current env:

node -v
v16.13.2
npm -v
8.1.2

git checkout v3.2.4

rm -rf node_modules
git clean -qfdx

npm install
npm run test
205 passing (3s)

All tests passed including e.g.

  1. https://github.com/node-saml/passport-saml/blob/v3.2.4/test/passport-saml/capturedSamlResponses.spec.ts#L37-L51
  2. https://github.com/node-saml/passport-saml/blob/v3.2.4/test/passport-saml/capturedSamlResponses.spec.ts#L82-L94
  3. and all of these https://github.com/node-saml/passport-saml/blob/v3.2.4/test/node-saml/xml.spec.ts

Now guessing part:

You mentioned that your old node.js version was 12.20.0 which implicates that maybe rest of the stack was also quite old (i.e. maybe passport-saml was 2.x or maybe even 1.x or earlier).

In the context of your issue report this means that maybe you had previously used privateCert configuration option to configure privateKey.
That option was deprecated in 2.x and removed in 3.x leaving privateKey as only way to configure private key (see change log of 3.x and especially change introduced to 3.0.0 #569 ).

So during the passport-saml update debugging (after you got some error due privateCert not working anymore) you might have copy pasted certs & keys all over the place and it could be possible that content of decryptionPvk was also affected somehow. With incorrect content or with typo.

After few trials of obvious typos it turned out that with this change to test material

diff --git a/test/static/testshib encryption pvk.pem b/test/static/testshib encryption pvk.pem
index eebdaa1..add5b49 100644
--- a/test/static/testshib encryption pvk.pem   
+++ b/test/static/testshib encryption pvk.pem   
@@ -1,4 +1,4 @@
------BEGIN RSA PRIVATE KEY-----
+-----BEGIN PRIVATE KEY-----
 MIIJKgIBAAKCAgEA5hqjaroJpB+aR8FME7hQ9nMV0h7MpKtmgFLcK3vwP67feAK+
 xdt17i8RyUhxil9FCFR5K08Wjwo3NiHZqHqEKitw+IJSndjLSsoNgKEIaiFSug2e
 V1oYElz06DBXTxc8iq/LazndqTUom51Ode9yI9AGa88cDM5iOqq9mhuGuvwuLtoy
@@ -48,4 +48,4 @@ d8HD6ARQhav0TorWKo3IjpWjIqbGJGmEKy5Vq/CFGHbNv6SNi/MUkY81/SkyhkwZ
 Dw54gyjiNALCKYfbzUf6L4Ptm05aCK+iZPBKgOwh+bbTrDjkHJB5Ln4I2NdSoThZ
 KotlP13Scdq0vxFHqCTKwEJgJJ1Jgh66NwaoXsATOP3WrupwXp8CDob0ECc+RZMb
 S/KF7YZXCQa+ggtrMuEV3I0q6S84RD9d3N9j0j9JaMVjA+F1BmoROinAec08Uw==
------END RSA PRIVATE KEY-----
+-----END PRIVATE KEY-----

all of the aforementioned tests started to fail with:

error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag

Another way to get exactly same error code is to copy paste e.g. base64 encoded public certificate between decryptionPvk's BEGIN/END RSA PRIVATE KEY lines.

E.g. with base64 content of test/static/testshib encryption pub.pem placed to test/static/testshib_encryption_pvk.pem all aforementioned tests started to fail with

error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag

error code. I.e. error code was replicated with this change:

diff --git a/test/static/testshib encryption pvk.pem b/test/static/testshib encryption pvk.pem
index eebdaa1..54c5153 100644
--- a/test/static/testshib encryption pvk.pem	
+++ b/test/static/testshib encryption pvk.pem	
@@ -1,51 +1,14 @@
 -----BEGIN RSA PRIVATE KEY-----
-MIIJKgIBAAKCAgEA5hqjaroJpB+aR8FME7hQ9nMV0h7MpKtmgFLcK3vwP67feAK+
-xdt17i8RyUhxil9FCFR5K08Wjwo3NiHZqHqEKitw+IJSndjLSsoNgKEIaiFSug2e
-V1oYElz06DBXTxc8iq/LazndqTUom51Ode9yI9AGa88cDM5iOqq9mhuGuvwuLtoy
-U78Ld+s1Ea6Mgf7L8M7fZVO7Ncu+FgIzI6Gt035ohYCLBmOoM7o0uj7DcMEvKOMF
-ziwF40wYmyp3hCLlq3qwkM9pTVJltuz0Bt1vqDdrq3kTheA9JHMayRz3I/BZxAV3
-iRd4hzLKTkegD8ToTGU10Gme+ZAr1w/erc5hVrM0/XBmHQlnI5d31GU/mfIkm0XP
-TGRSpPy7E+dUvj9djvm/VqDdojf3uuwirGeLMRlO9P/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m0XPTGRSpPy7E+dUvj9djvm/VqDdojf3uuwirGeL
+MRlO9P/lCerTktW3g27SV8gn3ETm2Mm7rkNqf24KJpDv0tKDosgbdaHr2IEYD4Rp
+qySp8kd25BhzushqKRkS8Xu5t7HAlVSHwiFhuLqrr4dUfkB8kZeM/ycfZLCn7oNU
+DFdgjGYSVMpakL97sC9slAW4/8UtXXZxLqcyq/YxdpCysPYP1hsAp+VgPC7GI6Cy
+iNojKPOptMqLZRYnViKxlOiWBJBzUBRUVuac8LXrMiDw8btWGa1Gh5vThuFUKsvm
+Roeuk7eyXEN9J7j6+fTYjnsCAwEAAQ==
 -----END RSA PRIVATE KEY-----

So at the moment it seems that this issue is caused by user error in configurations.

@cjbarth
Copy link
Collaborator

cjbarth commented Nov 12, 2022

@srd90, that is some good detective work, thanks. I'll close this pending more information from the end user.

@cjbarth cjbarth closed this as completed Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants