2 * Copyright 2001-2005 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * ExplicitKeyTrustEngine.cpp
\r
20 * TrustEngine based on explicit knowledge of peer key information.
\r
23 #include "internal.h"
\r
24 #include "exceptions.h"
\r
25 #include "security/MetadataKeyInfoIterator.h"
\r
26 #include "security/X509TrustEngine.h"
\r
27 #include "signature/SignatureProfileValidator.h"
\r
29 #include <log4cpp/Category.hh>
\r
30 #include <xmltooling/security/X509TrustEngine.h>
\r
31 #include <xmltooling/util/NDC.h>
\r
33 using namespace opensaml::saml2md;
\r
34 using namespace opensaml;
\r
35 using namespace xmlsignature;
\r
36 using namespace log4cpp;
\r
37 using namespace std;
\r
39 namespace opensaml {
\r
40 class SAML_DLLLOCAL ExplicitKeyTrustEngine : public X509TrustEngine
\r
43 ExplicitKeyTrustEngine(const DOMElement* e) : X509TrustEngine(e), m_engine(NULL) {
\r
44 auto_ptr<xmltooling::TrustEngine> engine(
\r
45 xmltooling::XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(EXPLICIT_KEY_TRUSTENGINE, e)
\r
47 if (m_engine=dynamic_cast<xmltooling::X509TrustEngine*>(engine.get()))
\r
50 throw xmltooling::UnknownExtensionException("Embedded trust engine does not support required interface.");
\r
53 virtual ~ExplicitKeyTrustEngine() {
\r
57 virtual bool validate(
\r
59 const RoleDescriptor& role,
\r
60 const KeyResolver* keyResolver=NULL
\r
62 virtual bool validate(
\r
63 XSECCryptoX509* certEE,
\r
64 const vector<XSECCryptoX509*>& certChain,
\r
65 const RoleDescriptor& role,
\r
66 bool checkName=true,
\r
67 const KeyResolver* keyResolver=NULL
\r
71 xmltooling::X509TrustEngine* m_engine;
\r
74 TrustEngine* SAML_DLLLOCAL ExplicitKeyTrustEngineFactory(const DOMElement* const & e)
\r
76 return new ExplicitKeyTrustEngine(e);
\r
80 bool ExplicitKeyTrustEngine::validate(
\r
82 const RoleDescriptor& role,
\r
83 const KeyResolver* keyResolver
\r
87 xmltooling::NDC ndc("validate");
\r
89 Category& log=Category::getInstance(SAML_LOGCAT".TrustEngine");
\r
91 log.debug("attempting to validate signature profile");
\r
92 SignatureProfileValidator sigValidator;
\r
94 sigValidator.validate(&sig);
\r
95 log.debug("signature profile validated");
\r
97 catch (xmltooling::ValidationException& e) {
\r
98 if (log.isDebugEnabled()) {
\r
99 log.debug("signature profile failed to validate: %s", e.what());
\r
104 MetadataKeyInfoIterator keys(role);
\r
105 return static_cast<xmltooling::TrustEngine*>(m_engine)->validate(sig,keys,keyResolver);
\r
108 bool ExplicitKeyTrustEngine::validate(
\r
109 XSECCryptoX509* certEE,
\r
110 const vector<XSECCryptoX509*>& certChain,
\r
111 const RoleDescriptor& role,
\r
113 const KeyResolver* keyResolver
\r
116 MetadataKeyInfoIterator keys(role);
\r
117 return m_engine->validate(certEE,certChain,keys,checkName,keyResolver);
\r