2

我正在尝试使用 opensaml 解密 java 中的 xbox saml2 令牌。以下是我尝试遵循的步骤 1. 将 saml2 令牌 xml 转换为 saml2 对象 2. 验证签名 3. 解密对象

我在解组 saml2 xml 期间遇到异常。代码无法找到解组器。

令牌示例 saml2 xml。

 <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#aes256-cbc" /> 
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
</e:EncryptionMethod>
<KeyInfo>
<o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<X509Data>
<X509IssuerSerial>
<X509IssuerName>CN=LVISPXBOX01.istreamplanet.isp</X509IssuerName> 
<X509SerialNumber>26119146566321683660382502106101553957</X509SerialNumber> 
</X509IssuerSerial>
</X509Data>
</o:SecurityTokenReference>
</KeyInfo>
<e:CipherData>
<e:CipherValue></e:CipherValue> 
</e:CipherData>
</e:EncryptedKey>
</KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>token value</xenc:CipherValue> 
</xenc:CipherData>
</xenc:EncryptedData>

用于解组的代码

private String decryptSAML(String filePath){


        try {

            DefaultBootstrap.bootstrap();
            InputStream in = getClass().getResourceAsStream(filePath);
         // Get parser pool manager
            BasicParserPool ppMgr = new BasicParserPool();
            ppMgr.setNamespaceAware(true);
            Document inCommonMDDoc = ppMgr.parse(in);
            Element metadataRoot = inCommonMDDoc.getDocumentElement();

            System.out.println("First element of InCommon data was not expected EntitiesDescriptor"+metadataRoot.toString());

         // Get apropriate unmarshaller
         UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory();
         Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);
         System.out.println("unmarshaller" +unmarshaller);
         EncryptedAssertion encryptedAssertion = (EncryptedAssertion)unmarshaller.unmarshall(metadataRoot);


           List<EncryptedKey> encList=encryptedAssertion.getEncryptedKeys();


    System.out.println("encList "+encList.isEmpty());
     System.out.println("encList "+encList.size());
    for(EncryptedKey encryptedKey:encList){
        System.out.println(encryptedKey);
    }
        } catch (XMLParserException xe) {
            System.err.println("Unable to parse XML file: " + xe);
        } catch (UnmarshallingException ue) {
            System.err.println("Unable to unmarshall XML: " + ue);
        }



        return null;

    }

我无法从中提取任何加密密钥。我究竟做错了什么

unmarshallerFactory 无法找到编组器。它返回为空。

如果有人可以帮助我,我将不胜感激。这方面的文档似乎很少。

4

0 回答 0