2 * Copyright 2001-2006 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * ClientCertAuthRule.cpp
20 * XML Signature checking SecurityPolicyRule
24 #include "exceptions.h"
25 #include "binding/ClientCertAuthRule.h"
26 #include "saml2/metadata/Metadata.h"
27 #include "saml2/metadata/MetadataProvider.h"
29 #include <xmltooling/security/X509TrustEngine.h>
30 #include <xmltooling/util/ReplayCache.h>
31 #include <log4cpp/Category.hh>
33 using namespace opensaml::saml2md;
34 using namespace opensaml;
35 using namespace xmltooling;
36 using namespace log4cpp;
40 SecurityPolicyRule* SAML_DLLLOCAL ClientCertAuthRuleFactory(const DOMElement* const & e)
42 return new ClientCertAuthRule(e);
46 void ClientCertAuthRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
48 Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.ClientCertAuth");
49 log.debug("evaluating client certificate authentication policy");
52 log.debug("ignoring message, no protocol request available");
55 else if (!policy.getIssuerMetadata()) {
56 log.debug("ignoring message, no issuer metadata supplied");
60 const X509TrustEngine* x509trust;
61 if (!(x509trust=dynamic_cast<const X509TrustEngine*>(policy.getTrustEngine()))) {
62 log.debug("ignoring message, no X509TrustEngine supplied");
66 const std::vector<XSECCryptoX509*>& chain = request->getClientCertificates();
68 log.debug("ignoring message, no client certificates in request");
72 if (!x509trust->validate(chain.front(), chain, *(policy.getIssuerMetadata()), true,
73 policy.getMetadataProvider()->getKeyResolver())) {
74 log.error("unable to verify certificate chain with supplied trust engine");
78 log.debug("client certificate verified against message issuer");