在java中使用opensaml解密xbox saml令牌的问题

时间:2012-08-24 10:07:39

标签: java saml xbox unmarshalling opensaml

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

在解组saml2 xml时遇到异常。代码无法找到unmarshaller。

令牌样本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无法找到编组人员。它返回为null。

如果有人能帮助我,我真的很感激。文档似乎很少见。

0 个答案:

没有答案