Add EC key support to helpers and KeyInfo resolution.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / InlineKeyResolver.cpp
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * InlineKeyResolver.cpp
19  * 
20  * Resolves key information directly from recognized KeyInfo structures.
21  */
22
23 #include "internal.h"
24 #include "logging.h"
25 #include "security/BasicX509Credential.h"
26 #include "security/KeyInfoCredentialContext.h"
27 #include "security/KeyInfoResolver.h"
28 #include "security/SecurityHelper.h"
29 #include "security/XSECCryptoX509CRL.h"
30 #include "signature/KeyInfo.h"
31 #include "signature/Signature.h"
32 #include "util/NDC.h"
33 #include "util/Threads.h"
34 #include "util/XMLConstants.h"
35 #include "validation/ValidatorSuite.h"
36
37 #include <xercesc/util/XMLUniDefs.hpp>
38 #include <xsec/dsig/DSIGKeyInfoX509.hpp>
39 #include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
40 #include <xsec/enc/XSECCryptoX509.hpp>
41 #include <xsec/enc/XSECCryptoKeyRSA.hpp>
42 #include <xsec/enc/XSECCryptoKeyDSA.hpp>
43 #include <xsec/enc/XSECCryptoKeyEC.hpp>
44 #include <xsec/enc/XSECCryptoException.hpp>
45 #include <xsec/framework/XSECException.hpp>
46
47 using namespace xmlsignature;
48 using namespace xmltooling::logging;
49 using namespace xmltooling;
50 using namespace xercesc;
51 using namespace std;
52
53 namespace xmltooling {
54
55     class XMLTOOL_DLLLOCAL InlineCredential : public BasicX509Credential
56     {
57     public:
58         InlineCredential(const KeyInfo* keyInfo=nullptr) : BasicX509Credential(keyInfo!=nullptr), m_credctx(new KeyInfoCredentialContext(keyInfo)) {
59         }
60         InlineCredential(DSIGKeyInfoList* keyInfo) : BasicX509Credential(false), m_credctx(new KeyInfoCredentialContext(keyInfo)) {
61         }
62         InlineCredential(KeyInfoCredentialContext* context) : BasicX509Credential(context->getKeyInfo()!=nullptr), m_credctx(nullptr) {
63         }
64         virtual ~InlineCredential() {
65             delete m_credctx;
66         }
67
68         XSECCryptoKey* getPrivateKey() const {
69             return nullptr;
70         }
71
72         KeyInfo* getKeyInfo(bool compact=false) const {
73             KeyInfo* ret = m_credctx->getKeyInfo() ? m_credctx->getKeyInfo()->cloneKeyInfo() : nullptr;
74             if (ret) {
75                 ret->setId(nullptr);
76                 ret->getRetrievalMethods().clear();
77                 ret->getKeyInfoReferences().clear();
78                 if (compact) {
79                     ret->getKeyValues().clear();
80                     ret->getDEREncodedKeyValues().clear();
81                     ret->getSPKIDatas().clear();
82                     ret->getPGPDatas().clear();
83                     ret->getUnknownXMLObjects().clear();
84                     VectorOf(X509Data) x509Datas=ret->getX509Datas();
85                     for (VectorOf(X509Data)::size_type pos = 0; pos < x509Datas.size();) {
86                         x509Datas[pos]->getX509Certificates().clear();
87                         x509Datas[pos]->getX509CRLs().clear();
88                         x509Datas[pos]->getOCSPResponses().clear();
89                         x509Datas[pos]->getUnknownXMLObjects().clear();
90                         if (x509Datas[pos]->hasChildren())
91                             ++pos;
92                         else
93                             x509Datas.erase(x509Datas.begin() + pos);
94                     }
95                 }
96             }
97             if (!ret->hasChildren()) {
98                 delete ret;
99                 ret = nullptr;
100             }
101             return ret;
102         }
103         
104         const CredentialContext* getCredentalContext() const {
105             return m_credctx;
106         }
107
108         void setCredentialContext(KeyInfoCredentialContext* context) {
109             m_credctx = context;
110         }
111
112         void resolve(const KeyInfo* keyInfo, int types=0, bool followRefs=false);
113         void resolve(DSIGKeyInfoList* keyInfo, int types=0, bool followRefs=false);
114
115     private:
116         bool resolveCerts(const KeyInfo* keyInfo, bool followRefs=false);
117         bool resolveKey(const KeyInfo* keyInfo, bool followRefs=false);
118         bool resolveCRLs(const KeyInfo* keyInfo, bool followRefs=false);
119
120         KeyInfoCredentialContext* m_credctx;
121     };
122
123     static const XMLCh keyInfoReferences[] = UNICODE_LITERAL_17(k,e,y,I,n,f,o,R,e,f,e,r,e,n,c,e,s);
124
125     class XMLTOOL_DLLLOCAL InlineKeyResolver : public KeyInfoResolver
126     {
127     public:
128         InlineKeyResolver(const DOMElement* e)
129             : m_followRefs(XMLHelper::getNodeValueAsBool(e ? e->getAttributeNodeNS(nullptr, keyInfoReferences) : nullptr, false)) {
130         }
131
132         virtual ~InlineKeyResolver() {}
133
134         Credential* resolve(const KeyInfo* keyInfo, int types=0) const {
135             if (!keyInfo)
136                 return nullptr;
137             if (types == 0)
138                 types = Credential::RESOLVE_KEYS|X509Credential::RESOLVE_CERTS|X509Credential::RESOLVE_CRLS;
139             auto_ptr<InlineCredential> credential(new InlineCredential(keyInfo));
140             credential->resolve(keyInfo, types, m_followRefs);
141             return credential.release();
142         }
143         Credential* resolve(DSIGKeyInfoList* keyInfo, int types=0) const {
144             if (!keyInfo)
145                 return nullptr;
146             if (types == 0)
147                 types = Credential::RESOLVE_KEYS|X509Credential::RESOLVE_CERTS|X509Credential::RESOLVE_CRLS;
148             auto_ptr<InlineCredential> credential(new InlineCredential(keyInfo));
149             credential->resolve(keyInfo, types, m_followRefs);
150             return credential.release();
151         }
152         Credential* resolve(KeyInfoCredentialContext* context, int types=0) const {
153             if (!context)
154                 return nullptr;
155             if (types == 0)
156                 types = Credential::RESOLVE_KEYS|X509Credential::RESOLVE_CERTS|X509Credential::RESOLVE_CRLS;
157             auto_ptr<InlineCredential> credential(new InlineCredential(context));
158             if (context->getKeyInfo())
159                 credential->resolve(context->getKeyInfo(), types, m_followRefs);
160             else if (context->getNativeKeyInfo())
161                 credential->resolve(context->getNativeKeyInfo(), types, m_followRefs);
162             credential->setCredentialContext(context);
163             return credential.release();
164         }
165
166     private:
167         bool m_followRefs;
168     };
169
170     KeyInfoResolver* XMLTOOL_DLLLOCAL InlineKeyInfoResolverFactory(const DOMElement* const & e)
171     {
172         return new InlineKeyResolver(e);
173     }
174 };
175
176 void InlineCredential::resolve(const KeyInfo* keyInfo, int types, bool followRefs)
177 {
178 #ifdef _DEBUG
179     NDC ndc("resolve");
180 #endif
181
182     if (types & X509Credential::RESOLVE_CERTS)
183         resolveCerts(keyInfo, followRefs);
184     
185     if (types & Credential::RESOLVE_KEYS) {
186         if (types & X509Credential::RESOLVE_CERTS) {
187             // If we have a cert, just use it.
188             if (!m_xseccerts.empty())
189                 m_key = m_xseccerts.front()->clonePublicKey();
190             else
191                 resolveKey(keyInfo, followRefs);
192         }
193         // Otherwise try directly for a key and then go for certs if none is found.
194         else if (!resolveKey(keyInfo, followRefs) && resolveCerts(keyInfo, followRefs)) {
195             m_key = m_xseccerts.front()->clonePublicKey();
196         }
197     }
198
199     if (types & X509Credential::RESOLVE_CRLS)
200         resolveCRLs(keyInfo, followRefs);
201
202     const XMLCh* n;
203     char* kn;
204     const vector<KeyName*>& knames=keyInfo->getKeyNames();
205     for (vector<KeyName*>::const_iterator kn_i=knames.begin(); kn_i!=knames.end(); ++kn_i) {
206         n=(*kn_i)->getName();
207         if (n && *n) {
208             kn=toUTF8(n);
209             m_keyNames.insert(kn);
210             delete[] kn;
211         }
212     }
213     const vector<X509Data*> datas=keyInfo->getX509Datas();
214     for (vector<X509Data*>::const_iterator x_i=datas.begin(); x_i!=datas.end(); ++x_i) {
215         const vector<X509SubjectName*> snames = const_cast<const X509Data*>(*x_i)->getX509SubjectNames();
216         for (vector<X509SubjectName*>::const_iterator sn_i = snames.begin(); sn_i!=snames.end(); ++sn_i) {
217             n = (*sn_i)->getName();
218             if (n && *n) {
219                 kn=toUTF8(n);
220                 m_keyNames.insert(kn);
221                 m_subjectName = kn;
222                 delete[] kn;
223             }
224         }
225
226         const vector<X509IssuerSerial*> inames = const_cast<const X509Data*>(*x_i)->getX509IssuerSerials();
227         if (!inames.empty()) {
228             const X509IssuerName* iname = inames.front()->getX509IssuerName();
229             if (iname) {
230                 kn = toUTF8(iname->getName());
231                 if (kn)
232                     m_issuerName = kn;
233                 delete[] kn;
234             }
235
236             const X509SerialNumber* ser = inames.front()->getX509SerialNumber();
237             if (ser) {
238                 auto_ptr_char sn(ser->getSerialNumber());
239                 m_serial = sn.get();
240             }
241         }
242     }
243 }
244
245 bool InlineCredential::resolveKey(const KeyInfo* keyInfo, bool followRefs)
246 {
247     Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
248
249     // Check for ds:KeyValue
250     const vector<KeyValue*>& keyValues = keyInfo->getKeyValues();
251     for (vector<KeyValue*>::const_iterator i = keyValues.begin(); i != keyValues.end(); ++i) {
252         try {
253             SchemaValidators.validate(*i);    // see if it's a "valid" key
254             RSAKeyValue* rsakv = (*i)->getRSAKeyValue();
255             if (rsakv) {
256                 log.debug("resolving ds:RSAKeyValue");
257                 auto_ptr_char mod(rsakv->getModulus()->getValue());
258                 auto_ptr_char exp(rsakv->getExponent()->getValue());
259                 auto_ptr<XSECCryptoKeyRSA> rsa(XSECPlatformUtils::g_cryptoProvider->keyRSA());
260                 rsa->loadPublicModulusBase64BigNums(mod.get(), strlen(mod.get()));
261                 rsa->loadPublicExponentBase64BigNums(exp.get(), strlen(exp.get()));
262                 m_key = rsa.release();
263                 return true;
264             }
265             DSAKeyValue* dsakv = (*i)->getDSAKeyValue();
266             if (dsakv) {
267                 log.debug("resolving ds:DSAKeyValue");
268                 auto_ptr<XSECCryptoKeyDSA> dsa(XSECPlatformUtils::g_cryptoProvider->keyDSA());
269                 auto_ptr_char y(dsakv->getY()->getValue());
270                 dsa->loadYBase64BigNums(y.get(), strlen(y.get()));
271                 if (dsakv->getP()) {
272                     auto_ptr_char p(dsakv->getP()->getValue());
273                     dsa->loadPBase64BigNums(p.get(), strlen(p.get()));
274                 }
275                 if (dsakv->getQ()) {
276                     auto_ptr_char q(dsakv->getQ()->getValue());
277                     dsa->loadQBase64BigNums(q.get(), strlen(q.get()));
278                 }
279                 if (dsakv->getG()) {
280                     auto_ptr_char g(dsakv->getG()->getValue());
281                     dsa->loadGBase64BigNums(g.get(), strlen(g.get()));
282                 }
283                 m_key = dsa.release();
284                 return true;
285             }
286 #ifdef XMLTOOLING_XMLSEC_ECC
287             ECKeyValue* eckv = (*i)->getECKeyValue();
288             if (eckv && eckv->getNamedCurve() && eckv->getPublicKey()) {
289                 log.warn("resolving ds11:ECKeyValue");
290                 auto_ptr<XSECCryptoKeyEC> ec(XSECPlatformUtils::g_cryptoProvider->keyEC());
291                 auto_ptr_char uri(eckv->getNamedCurve()->getURI());
292                 auto_ptr_char val(eckv->getPublicKey()->getValue());
293                 if (uri.get() && val.get()) {
294                     ec->loadPublicKeyBase64(uri.get(), val.get(), XMLString::stringLen(val.get()));
295                     m_key = ec.release();
296                     return true;
297                 }
298             }
299 #endif
300         }
301         catch (ValidationException& ex) {
302             log.warn("skipping invalid ds:KeyValue (%s)", ex.what());
303         }
304         catch(XSECException& e) {
305             auto_ptr_char temp(e.getMsg());
306             log.error("caught XML-Security exception loading key: %s", temp.get());
307         }
308         catch(XSECCryptoException& e) {
309             log.error("caught XML-Security exception loading key: %s", e.getMsg());
310         }
311     }
312
313     // Check for ds11:DEREncodedKeyValue
314     const vector<DEREncodedKeyValue*>& derValues = keyInfo->getDEREncodedKeyValues();
315     for (vector<DEREncodedKeyValue*>::const_iterator j = derValues.begin(); j != derValues.end(); ++j) {
316         log.debug("resolving ds11:DEREncodedKeyValue");
317         m_key = SecurityHelper::fromDEREncoding((*j)->getValue());
318         if (m_key)
319             return true;
320         log.warn("failed to resolve ds11:DEREncodedKeyValue");
321     }
322
323
324     if (followRefs) {
325         // Check for KeyInfoReference.
326         const XMLCh* fragID=NULL;
327         const XMLObject* treeRoot=NULL;
328         const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
329         for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
330             fragID = (*ref)->getURI();
331             if (!fragID || *fragID != chPound || !*(fragID+1)) {
332                 log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
333                 continue;
334             }
335             if (!treeRoot) {
336                 treeRoot = keyInfo;
337                 while (treeRoot->getParent())
338                     treeRoot = treeRoot->getParent();
339             }
340             keyInfo = dynamic_cast<const KeyInfo*>(XMLHelper::getXMLObjectById(*treeRoot, fragID+1));
341             if (!keyInfo) {
342                 log.warn("skipping ds11:KeyInfoReference, local reference did not resolve to a ds:KeyInfo");
343                 continue;
344             }
345             if (resolveKey(keyInfo, false))
346                 return true;
347         }
348     }
349
350     return false;
351 }
352
353 bool InlineCredential::resolveCerts(const KeyInfo* keyInfo, bool followRefs)
354 {
355     Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
356
357     // Check for ds:X509Data
358     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
359     for (vector<X509Data*>::const_iterator j=x509Datas.begin(); m_xseccerts.empty() && j!=x509Datas.end(); ++j) {
360         const vector<X509Certificate*> x509Certs=const_cast<const X509Data*>(*j)->getX509Certificates();
361         for (vector<X509Certificate*>::const_iterator k=x509Certs.begin(); k!=x509Certs.end(); ++k) {
362             try {
363                 auto_ptr_char x((*k)->getValue());
364                 if (!x.get()) {
365                     log.warn("skipping empty ds:X509Certificate");
366                 }
367                 else {
368                     log.debug("resolving ds:X509Certificate");
369                     auto_ptr<XSECCryptoX509> x509(XSECPlatformUtils::g_cryptoProvider->X509());
370                     x509->loadX509Base64Bin(x.get(), strlen(x.get()));
371                     m_xseccerts.push_back(x509.release());
372                 }
373             }
374             catch(XSECException& e) {
375                 auto_ptr_char temp(e.getMsg());
376                 log.error("caught XML-Security exception loading certificate: %s", temp.get());
377             }
378             catch(XSECCryptoException& e) {
379                 log.error("caught XML-Security exception loading certificate: %s", e.getMsg());
380             }
381         }
382     }
383
384     if (followRefs && m_xseccerts.empty()) {
385         // Check for KeyInfoReference.
386         const XMLCh* fragID=NULL;
387         const XMLObject* treeRoot=NULL;
388         const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
389         for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
390             fragID = (*ref)->getURI();
391             if (!fragID || *fragID != chPound || !*(fragID+1)) {
392                 log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
393                 continue;
394             }
395             if (!treeRoot) {
396                 treeRoot = keyInfo;
397                 while (treeRoot->getParent())
398                     treeRoot = treeRoot->getParent();
399             }
400             keyInfo = dynamic_cast<const KeyInfo*>(XMLHelper::getXMLObjectById(*treeRoot, fragID+1));
401             if (!keyInfo) {
402                 log.warn("skipping ds11:KeyInfoReference, local reference did not resolve to a ds:KeyInfo");
403                 continue;
404             }
405             if (resolveCerts(keyInfo, false))
406                 return true;
407         }
408         return false;
409     }
410     
411     log.debug("resolved %d certificate(s)", m_xseccerts.size());
412     return !m_xseccerts.empty();
413 }
414
415 bool InlineCredential::resolveCRLs(const KeyInfo* keyInfo, bool followRefs)
416 {
417     Category& log = Category::getInstance(XMLTOOLING_LOGCAT".KeyInfoResolver."INLINE_KEYINFO_RESOLVER);
418
419     // Check for ds:X509Data
420     const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
421     for (vector<X509Data*>::const_iterator j=x509Datas.begin(); j!=x509Datas.end(); ++j) {
422         const vector<X509CRL*> x509CRLs=const_cast<const X509Data*>(*j)->getX509CRLs();
423         for (vector<X509CRL*>::const_iterator k=x509CRLs.begin(); k!=x509CRLs.end(); ++k) {
424             try {
425                 auto_ptr_char x((*k)->getValue());
426                 if (!x.get()) {
427                     log.warn("skipping empty ds:X509CRL");
428                 }
429                 else {
430                     log.debug("resolving ds:X509CRL");
431                     auto_ptr<XSECCryptoX509CRL> crl(XMLToolingConfig::getConfig().X509CRL());
432                     crl->loadX509CRLBase64Bin(x.get(), strlen(x.get()));
433                     m_crls.push_back(crl.release());
434                 }
435             }
436             catch(XSECException& e) {
437                 auto_ptr_char temp(e.getMsg());
438                 log.error("caught XML-Security exception loading CRL: %s", temp.get());
439             }
440             catch(XSECCryptoException& e) {
441                 log.error("caught XML-Security exception loading CRL: %s", e.getMsg());
442             }
443         }
444     }
445
446     if (followRefs && m_crls.empty()) {
447         // Check for KeyInfoReference.
448         const XMLCh* fragID=NULL;
449         const XMLObject* treeRoot=NULL;
450         const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
451         for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
452             fragID = (*ref)->getURI();
453             if (!fragID || *fragID != chPound || !*(fragID+1)) {
454                 log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
455                 continue;
456             }
457             if (!treeRoot) {
458                 treeRoot = keyInfo;
459                 while (treeRoot->getParent())
460                     treeRoot = treeRoot->getParent();
461             }
462             keyInfo = dynamic_cast<const KeyInfo*>(XMLHelper::getXMLObjectById(*treeRoot, fragID+1));
463             if (!keyInfo) {
464                 log.warn("skipping ds11:KeyInfoReference, local reference did not resolve to a ds:KeyInfo");
465                 continue;
466             }
467             if (resolveCRLs(keyInfo, false))
468                 return true;
469         }
470         return false;
471     }
472
473     log.debug("resolved %d CRL(s)", m_crls.size());
474     return !m_crls.empty();
475 }
476
477 void InlineCredential::resolve(DSIGKeyInfoList* keyInfo, int types, bool followRefs)
478 {
479 #ifdef _DEBUG
480     NDC ndc("resolve");
481 #endif
482
483     if (types & Credential::RESOLVE_KEYS) {
484         // Default resolver handles RSA/DSAKeyValue and X509Certificate elements.
485         try {
486             XSECKeyInfoResolverDefault def;
487             m_key = def.resolveKey(keyInfo);
488         }
489         catch(XSECException& e) {
490             auto_ptr_char temp(e.getMsg());
491             Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", temp.get());
492         }
493         catch(XSECCryptoException& e) {
494             Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading certificate: %s", e.getMsg());
495         }
496     }
497
498         DSIGKeyInfoList::size_type sz = keyInfo->getSize();
499
500     if (types & X509Credential::RESOLVE_CERTS) {
501         for (DSIGKeyInfoList::size_type i=0; i<sz; ++i) {
502             if (keyInfo->item(i)->getKeyInfoType()==DSIGKeyInfo::KEYINFO_X509) {
503                 DSIGKeyInfoX509* x509 = static_cast<DSIGKeyInfoX509*>(keyInfo->item(i));
504                 int count = x509->getCertificateListSize();
505                 if (count) {
506                     for (int j=0; j<count; ++j)
507                         m_xseccerts.push_back(x509->getCertificateCryptoItem(j));
508                     break;
509                 }
510             }
511         }
512     }
513
514     if (types & X509Credential::RESOLVE_CRLS) {
515         for (DSIGKeyInfoList::size_type i=0; i<sz; ++i) {
516             if (keyInfo->item(i)->getKeyInfoType()==DSIGKeyInfo::KEYINFO_X509) {
517 #ifdef XMLTOOLING_XMLSEC_MULTIPLECRL
518                 DSIGKeyInfoX509* x509 = static_cast<DSIGKeyInfoX509*>(keyInfo->item(i));
519                 int count = x509->getX509CRLListSize();
520                 for (int j=0; j<count; ++j) {
521                     auto_ptr_char buf(x509->getX509CRLItem(j));
522                     if (buf.get()) {
523                         try {
524                             auto_ptr<XSECCryptoX509CRL> crlobj(XMLToolingConfig::getConfig().X509CRL());
525                             crlobj->loadX509CRLBase64Bin(buf.get(), strlen(buf.get()));
526                             m_crls.push_back(crlobj.release());
527                         }
528                         catch(XSECException& e) {
529                             auto_ptr_char temp(e.getMsg());
530                             Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", temp.get());
531                         }
532                         catch(XSECCryptoException& e) {
533                             Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", e.getMsg());
534                         }
535                     }
536                 }
537 #else
538                 // The current xmlsec API is limited to one CRL per KeyInfo.
539                 // For now, I'm going to process the DOM directly.
540                 DOMNode* x509Node = keyInfo->item(i)->getKeyInfoDOMNode();
541                 DOMElement* crlElement = x509Node ? XMLHelper::getFirstChildElement(x509Node, xmlconstants::XMLSIG_NS, X509CRL::LOCAL_NAME) : nullptr;
542                 while (crlElement) {
543                     if (crlElement->hasChildNodes()) {
544                         auto_ptr_char buf(crlElement->getFirstChild()->getNodeValue());
545                         if (buf.get()) {
546                             try {
547                                 auto_ptr<XSECCryptoX509CRL> crlobj(XMLToolingConfig::getConfig().X509CRL());
548                                 crlobj->loadX509CRLBase64Bin(buf.get(), strlen(buf.get()));
549                                 m_crls.push_back(crlobj.release());
550                             }
551                             catch(XSECException& e) {
552                                 auto_ptr_char temp(e.getMsg());
553                                 Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", temp.get());
554                             }
555                             catch(XSECCryptoException& e) {
556                                 Category::getInstance(XMLTOOLING_LOGCAT".KeyResolver."INLINE_KEYINFO_RESOLVER).error("caught XML-Security exception loading CRL: %s", e.getMsg());
557                             }
558                         }
559                     }
560                     crlElement = XMLHelper::getNextSiblingElement(crlElement, xmlconstants::XMLSIG_NS, X509CRL::LOCAL_NAME);
561                 }
562 #endif
563             }
564         }
565     }
566
567     char* kn;
568     const XMLCh* n;
569
570     for (size_t s=0; s<keyInfo->getSize(); s++) {
571         DSIGKeyInfo* dki = keyInfo->item(s);
572         n=dki->getKeyName();
573         if (n && *n) {
574             kn=toUTF8(n);
575             m_keyNames.insert(kn);
576             if (dki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_X509)
577                 m_subjectName = kn;
578             delete[] kn;
579         }
580
581         if (dki->getKeyInfoType() == DSIGKeyInfo::KEYINFO_X509) {
582             DSIGKeyInfoX509* kix = static_cast<DSIGKeyInfoX509*>(dki);
583             n = kix->getX509IssuerName();
584             if (n && *n) {
585                 kn=toUTF8(n);
586                 m_issuerName = kn;
587                 delete[] kn;
588             }
589             n = kix->getX509IssuerSerialNumber();
590             if (n && *n) {
591                 auto_ptr_char sn(n);
592                 m_serial = sn.get();
593             }
594         }
595     }
596 }