using namespace xmlencryption;
using namespace xmlsignature;
using namespace xmltooling;
+using namespace xercesc;
using namespace std;
EncryptedKeyResolver::EncryptedKeyResolver()
if (!encryptedData.getKeyInfo())
return nullptr;
- const vector<XMLObject*>& others=const_cast<const KeyInfo*>(encryptedData.getKeyInfo())->getUnknownXMLObjects();
- for (vector<XMLObject*>::const_iterator i=others.begin(); i!=others.end(); i++) {
- EncryptedKey* encKey=dynamic_cast<EncryptedKey*>(*i);
- if (encKey && (!recipient || !encKey->getRecipient() || XMLString::equals(recipient,encKey->getRecipient())))
- return encKey;
+ const vector<XMLObject*>& others = const_cast<const KeyInfo*>(encryptedData.getKeyInfo())->getUnknownXMLObjects();
+ for (vector<XMLObject*>::const_iterator i = others.begin(); i != others.end(); i++) {
+ EncryptedKey* encKey = dynamic_cast<EncryptedKey*>(*i);
+ if (encKey) {
+ if (!recipient || !encKey->getRecipient() || XMLString::equals(recipient,encKey->getRecipient()))
+ return encKey;
+ }
+ }
+
+ static const XMLCh rmtype[] = { // http://www.w3.org/2001/04/xmlenc#EncryptedKey
+ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
+ chDigit_2, chDigit_0, chDigit_0, chDigit_1, chForwardSlash, chDigit_0, chDigit_4, chForwardSlash,
+ chLatin_x, chLatin_m, chLatin_l, chLatin_e, chLatin_n, chLatin_c, chPound,
+ chLatin_E, chLatin_n, chLatin_c, chLatin_r, chLatin_y, chLatin_p, chLatin_t, chLatin_e, chLatin_d, chLatin_K, chLatin_e, chLatin_y, chNull
+ };
+
+ const XMLObject* treeRoot = nullptr;
+ const vector<RetrievalMethod*>& methods = const_cast<const KeyInfo*>(encryptedData.getKeyInfo())->getRetrievalMethods();
+ for (vector<RetrievalMethod*>::const_iterator m = methods.begin(); m != methods.end(); ++m) {
+ if (XMLString::equals((*m)->getType(), rmtype)) {
+ const XMLCh* ref = (*m)->getURI();
+ if (ref && *ref == chPound) {
+ if (!treeRoot) {
+ treeRoot = &encryptedData;
+ while (treeRoot->getParent())
+ treeRoot = treeRoot->getParent();
+ }
+ const EncryptedKey* encKey = dynamic_cast<const EncryptedKey*>(XMLHelper::getXMLObjectById(*treeRoot, ref+1));
+ if (encKey)
+ return encKey;
+ }
+ }
}
return nullptr;