【问题标题】:passport-saml lib doesn't correctly decrypt saml EncryptedAssertion with a private decryption keypassport-saml lib 没有正确解密 saml EncryptedAssertion 与私有解密密钥
【发布时间】:2017-04-19 05:49:38
【问题描述】:

我有一个需要解密的加密 SAML 2.0 响应/断言。格式如下:

<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
    <xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
      <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <xenc:EncryptedKey>
          <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
          <xenc:CipherData>
            <xenc:CipherValue>{some ciphers}</xenc:CipherValue>
          </xenc:CipherData>
        </xenc:EncryptedKey>
      </ds:KeyInfo>
      <xenc:CipherData>
        <xenc:CipherValue>{assertion body}</xenc:CipherValue>
    </xenc:CipherData>
    </xenc:EncryptedData>
</saml:EncryptedAssertion>

我还有一个私有解密密钥,格式如下:

-----BEGIN RSA PRIVATE KEY-----
{mumbo jumbos}
-----END RSA PRIVATE KEY-----

我在这里尝试使用 OneLogin 的 saml 解密工具来解密加密的 SAML 断言(复制+粘贴到该输入框),它就像一个魅力。 https://www.samltool.com/decrypt.php

但是,当我尝试使用 nodejs、passport-saml 导入私钥文件并尝试解密响应时,如果我省略 ("-----BEGIN-- --" 或 "---END---" 横幅),或者它收到“无效的 RSAES-OAEP 填充”错误。

这是我的代码 sn-p:

const fs = require('fs');
const Promise = require('bluebird');
const path = require('path');
const forge = require('node-forge');
let pkey = fs.readFileSync(path.join(__dirname,'./myTestKey.pem'), 'utf8');
//let testKey = new Buffer(pkey).toString('base64');
let SAML = require('passport-saml/lib/passport-saml/saml.js');
let saml = new SAML({...,decryptionPvk: pkey });
let validatePostResponseAsync = Promise.promisify(saml.validatePostResponse);

validatePostResponseAsync(myResponse, pkey)
.then(response=>{
})
.catch(error=>{
 // it always throw error of the 2 mentioned above. 
})

任何解决方法将不胜感激。

【问题讨论】:

  • @dlongley 如果我的私钥是 ASCII/UTF8 格式的纯字符串会发生什么

标签: node.js encryption onelogin passport-saml


【解决方案1】:

我想我明白了。对于那些遇到类似问题的人,您必须包括---BEGIN RSA PRIVATE KEY------END RSA PRIVATE KEY---。如果不包含横幅,则 passport-saml 库所依赖的 node-forge 库将引发错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    相关资源
    最近更新 更多