Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / impl / SignatureMetadataFilter.cpp
index 2e6bbd6..6b4e82b 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
@@ -102,36 +106,37 @@ static const XMLCh verifyRoles[] =          UNICODE_LITERAL_11(v,e,r,i,f,y,R,o,l
 static const XMLCh verifyName[] =           UNICODE_LITERAL_10(v,e,r,i,f,y,N,a,m,e);
 
 SignatureMetadataFilter::SignatureMetadataFilter(const DOMElement* e)
-    : m_verifyRoles(false), m_verifyName(true), m_credResolver(nullptr), m_trust(nullptr), m_log(Category::getInstance(SAML_LOGCAT".MetadataFilter.Signature"))
+    : m_verifyRoles(XMLHelper::getAttrBool(e, false, verifyRoles)),
+        m_verifyName(XMLHelper::getAttrBool(e, true, verifyName)),
+        m_credResolver(nullptr), m_trust(nullptr),
+        m_log(Category::getInstance(SAML_LOGCAT".MetadataFilter.Signature"))
 {
-    const XMLCh* flag = e ? e->getAttributeNS(nullptr,verifyRoles) : nullptr;
-    m_verifyRoles = (flag && (*flag == chLatin_t || *flag == chDigit_1));
-
-    flag = e ? e->getAttributeNS(nullptr,verifyName) : nullptr;
-    m_verifyName = !(flag && (*flag == chLatin_f || *flag == chDigit_0));
-
     if (e && e->hasAttributeNS(nullptr,certificate)) {
         // Use a file-based credential resolver rooted here.
-        m_credResolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(FILESYSTEM_CREDENTIAL_RESOLVER,e);
+        m_credResolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(FILESYSTEM_CREDENTIAL_RESOLVER, e);
         return;
     }
 
-    DOMElement* sub = e ? XMLHelper::getFirstChildElement(e, _CredentialResolver) : nullptr;
-    auto_ptr_char t(sub ? sub->getAttributeNS(nullptr,type) : nullptr);
-    if (t.get()) {
-        m_credResolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(t.get(),sub);
-        return;
+    DOMElement* sub = XMLHelper::getFirstChildElement(e, _CredentialResolver);
+    if (sub) {
+        string t = XMLHelper::getAttrString(sub, nullptr, type);
+        if (!t.empty()) {
+            m_credResolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(t.c_str(), sub);
+            return;
+        }
     }
 
-    sub = e ? XMLHelper::getFirstChildElement(e, _TrustEngine) : nullptr;
-    auto_ptr_char t2(sub ? sub->getAttributeNS(nullptr,type) : nullptr);
-    if (t2.get()) {
-        TrustEngine* trust = XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(t2.get(),sub);
-        if (!(m_trust = dynamic_cast<SignatureTrustEngine*>(trust))) {
-            delete trust;
-            throw MetadataFilterException("TrustEngine-based SignatureMetadataFilter requires a SignatureTrustEngine plugin.");
+    sub = XMLHelper::getFirstChildElement(e, _TrustEngine);
+    if (sub) {
+        string t = XMLHelper::getAttrString(sub, nullptr, type);
+        if (!t.empty()) {
+            TrustEngine* trust = XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(t.c_str(), sub);
+            if (!(m_trust = dynamic_cast<SignatureTrustEngine*>(trust))) {
+                delete trust;
+                throw MetadataFilterException("TrustEngine-based SignatureMetadataFilter requires a SignatureTrustEngine plugin.");
+            }
+            return;
         }
-        return;
     }
 
     throw MetadataFilterException("SignatureMetadataFilter configuration requires <CredentialResolver> or <TrustEngine> element.");
@@ -392,10 +397,10 @@ void SignatureMetadataFilter::verifySignature(Signature* sig, const XMLCh* peerN
                 catch (exception&) {
                 }
             }
-            throw MetadataFilterException("CredentialResolver did not supply a successful verification key.");
+            throw MetadataFilterException("Unable to verify signature with supplied key(s).");
         }
         else {
-            throw MetadataFilterException("CredentialResolver did not supply a successful verification key.");
+            throw MetadataFilterException("CredentialResolver did not supply any candidate keys.");
         }
     }
     else if (m_trust) {