Merge branch '1.x' of ssh://authdev.it.ohio-state.edu/~scantor/git/cpp-xmltooling...
[shibboleth/cpp-xmltooling.git] / xmltooling / security / impl / TrustEngine.cpp
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * TrustEngine.cpp
23  * 
24  * Registration of factories for built-in engines.
25  */
26
27 #include "internal.h"
28 #include "security/KeyInfoResolver.h"
29 #include "security/SignatureTrustEngine.h"
30 #include "security/OpenSSLTrustEngine.h"
31 #include "util/XMLHelper.h"
32
33 #include <xercesc/util/XMLUniDefs.hpp>
34
35 using namespace xmltooling;
36 using namespace std;
37
38 using xercesc::DOMElement;
39
40 namespace xmltooling {
41     XMLTOOL_DLLLOCAL PluginManager<TrustEngine,string,const DOMElement*>::Factory ExplicitKeyTrustEngineFactory;
42     XMLTOOL_DLLLOCAL PluginManager<TrustEngine,string,const DOMElement*>::Factory StaticPKIXTrustEngineFactory;
43     XMLTOOL_DLLLOCAL PluginManager<TrustEngine,string,const DOMElement*>::Factory ChainingTrustEngineFactory;
44 };
45
46 void XMLTOOL_API xmltooling::registerTrustEngines()
47 {
48     XMLToolingConfig& conf=XMLToolingConfig::getConfig();
49     conf.TrustEngineManager.registerFactory(EXPLICIT_KEY_TRUSTENGINE, ExplicitKeyTrustEngineFactory);
50     conf.TrustEngineManager.registerFactory(STATIC_PKIX_TRUSTENGINE, StaticPKIXTrustEngineFactory);
51     conf.TrustEngineManager.registerFactory(CHAINING_TRUSTENGINE, ChainingTrustEngineFactory);
52 }
53
54 static const XMLCh _KeyInfoResolver[] = UNICODE_LITERAL_15(K,e,y,I,n,f,o,R,e,s,o,l,v,e,r);
55 static const XMLCh type[] =             UNICODE_LITERAL_4(t,y,p,e);
56
57 TrustEngine::TrustEngine(const DOMElement* e) : m_keyInfoResolver(nullptr)
58 {
59     DOMElement* child = e ? XMLHelper::getFirstChildElement(e, _KeyInfoResolver) : nullptr;
60     if (child) {
61         string t = XMLHelper::getAttrString(child, nullptr, type);
62         if (!t.empty())
63             m_keyInfoResolver = XMLToolingConfig::getConfig().KeyInfoResolverManager.newPlugin(t.c_str(), child);
64         else
65             throw UnknownExtensionException("<KeyInfoResolver> element found with no type attribute");
66     }
67 }
68
69 TrustEngine::~TrustEngine()
70 {
71     delete m_keyInfoResolver;
72 }
73
74 SignatureTrustEngine::SignatureTrustEngine(const DOMElement* e) : TrustEngine(e)
75 {
76 }
77
78 SignatureTrustEngine::~SignatureTrustEngine()
79 {
80 }
81
82 X509TrustEngine::X509TrustEngine(const DOMElement* e) : TrustEngine(e)
83 {
84 }
85
86 X509TrustEngine::~X509TrustEngine()
87 {
88 }
89
90 OpenSSLTrustEngine::OpenSSLTrustEngine(const DOMElement* e) : X509TrustEngine(e)
91 {
92 }
93
94 OpenSSLTrustEngine::~OpenSSLTrustEngine()
95 {
96 }