2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
21 #include "XMLObjectBaseTestCase.h"
24 #include <xmltooling/security/X509Credential.h>
25 #include <xmltooling/security/KeyInfoResolver.h>
26 #include <xmltooling/signature/KeyInfo.h>
27 #include <xsec/enc/XSECCryptoKey.hpp>
29 using namespace xmlsignature;
31 class InlineKeyResolverTest : public CxxTest::TestSuite {
32 KeyInfoResolver* m_resolver;
34 InlineKeyResolverTest() : m_resolver(nullptr) {}
37 string config = data_path + "InlineKeyResolver.xml";
38 ifstream in(config.c_str());
39 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
40 XercesJanitor<DOMDocument> janitor(doc);
41 m_resolver=XMLToolingConfig::getConfig().KeyInfoResolverManager.newPlugin(INLINE_KEYINFO_RESOLVER,doc->getDocumentElement());
50 string path=data_path + "KeyInfo1.xml";
51 ifstream fs(path.c_str());
52 DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);
53 TS_ASSERT(doc!=nullptr);
54 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
55 TS_ASSERT(b!=nullptr);
56 auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
57 TS_ASSERT(kiObject.get()!=nullptr);
59 auto_ptr<X509Credential> cred(dynamic_cast<X509Credential*>(m_resolver->resolve(kiObject.get())));
60 TSM_ASSERT("Unable to resolve KeyInfo into Credential.", cred.get()!=nullptr);
62 TSM_ASSERT("Unable to resolve public key.", cred->getPublicKey()!=nullptr);
63 TSM_ASSERT_EQUALS("Unexpected key type.", cred->getPublicKey()->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
64 TSM_ASSERT_EQUALS("Wrong certificate count.", cred->getEntityCertificateChain().size(), 1);
65 TSM_ASSERT_EQUALS("Wrong CRL count.", cred->getCRLs().size(), 3);
69 string path=data_path + "KeyInfo5.xml";
70 ifstream fs(path.c_str());
71 DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);
72 TS_ASSERT(doc!=nullptr);
73 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
74 TS_ASSERT(b!=nullptr);
75 auto_ptr<KeyInfo> kiObject(dynamic_cast<KeyInfo*>(b->buildFromDocument(doc)));
76 TS_ASSERT(kiObject.get()!=nullptr);
78 auto_ptr<X509Credential> cred(dynamic_cast<X509Credential*>(m_resolver->resolve(kiObject.get())));
79 TSM_ASSERT("Unable to resolve KeyInfo into Credential.", cred.get()!=nullptr);
81 TSM_ASSERT("Unable to resolve public key.", cred->getPublicKey()!=nullptr);
82 TSM_ASSERT_EQUALS("Unexpected key type.", cred->getPublicKey()->getKeyType(), XSECCryptoKey::KEY_RSA_PUBLIC);
83 TSM_ASSERT_EQUALS("Wrong certificate count.", cred->getEntityCertificateChain().size(), 0);
84 TSM_ASSERT_EQUALS("Wrong CRL count.", cred->getCRLs().size(), 0);