X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsignature%2FContentReference.cpp;h=320daac0cd7886758e1488524871b700352360d5;hb=f1208cd2f514700244816377443c4951dc22c848;hp=3f2674f344b0deaab830e3cf4a0bde96b44c4a12;hpb=d1ad8c104a2641c55e0377417b793055efcc69e1;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/signature/ContentReference.cpp b/saml/signature/ContentReference.cpp index 3f2674f..320daac 100644 --- a/saml/signature/ContentReference.cpp +++ b/saml/signature/ContentReference.cpp @@ -1,23 +1,27 @@ -/* - * Copyright 2001-2009 Internet2 - * - * 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 +/** + * 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. + * + * 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. */ /** * ContentReference.cpp * - * SAML-specific signature reference profile + * SAML-specific signature reference profile. */ #include "internal.h" @@ -34,8 +38,27 @@ using namespace opensaml; using namespace xmltooling; using namespace std; +void SignableObject::declareNonVisibleNamespaces() const +{ + ContentReference* cr = getSignature() ? dynamic_cast(getSignature()->getContentReference()) : nullptr; + + // Compute inclusive prefix set. + map decls; + XMLHelper::getNonVisiblyUsedPrefixes(*this, decls); + + for (map::const_iterator decl = decls.begin(); decl != decls.end(); ++decl) { + + // Pin it to the object root. An existing copy of the prefix on the root will take precedence. + addNamespace(Namespace(decl->second.c_str(), decl->first.c_str(), true, Namespace::NonVisiblyUsed)); + + // Add to content reference, if any. + if (cr) + cr->addInclusivePrefix(decl->first.c_str()); + } +} + ContentReference::ContentReference(const SignableObject& signableObject) - : m_signableObject(signableObject), m_digest(NULL), m_c14n(NULL) + : m_signableObject(signableObject), m_digest(nullptr), m_c14n(nullptr) { } @@ -45,7 +68,7 @@ ContentReference::~ContentReference() void ContentReference::createReferences(DSIGSignature* sig) { - DSIGReference* ref=NULL; + DSIGReference* ref = nullptr; const XMLCh* id=m_signableObject.getXMLID(); if (!id || !*id) ref=sig->createReference(&chNull, m_digest ? m_digest : DSIGConstants::s_unicodeStrURISHA1); // whole doc reference @@ -66,40 +89,25 @@ void ContentReference::createReferences(DSIGSignature* sig) ref->appendEnvelopedSignatureTransform(); DSIGTransformC14n* c14n=ref->appendCanonicalizationTransform(m_c14n ? m_c14n : DSIGConstants::s_unicodeStrURIEXC_C14N_NOC); + if (!m_c14n || m_c14n == DSIGConstants::s_unicodeStrURIEXC_C14N_NOC || m_c14n == DSIGConstants::s_unicodeStrURIEXC_C14N_COM) { - addPrefixes(m_signableObject); -#ifdef HAVE_GOOD_STL + // Build up the string of prefixes. xstring prefixes; - for (set::const_iterator p = m_prefixes.begin(); p!=m_prefixes.end(); ++p) - prefixes += *p + chSpace; + static const XMLCh _default[] = { chPound, chLatin_d, chLatin_e, chLatin_f, chLatin_a, chLatin_u, chLatin_l, chLatin_t, chNull }; + for (set::const_iterator p = m_prefixes.begin(); p != m_prefixes.end(); ++p) { + prefixes += (p->empty() ? _default : p->c_str()); + prefixes += chSpace; + } if (!prefixes.empty()) { prefixes.erase(prefixes.begin() + prefixes.size() - 1); - c14n->setInclusiveNamespaces(XMLString::replicate(prefixes.c_str())); + c14n->setInclusiveNamespaces(const_cast(prefixes.c_str())); } -#else - for (set::const_iterator p = m_prefixes.begin(); p!=m_prefixes.end(); ++p) - c14n->addInclusiveNamespace(p->c_str()); -#endif } } void ContentReference::addInclusivePrefix(const XMLCh* prefix) { - static const XMLCh _default[] = { chPound, chLatin_d, chLatin_e, chLatin_f, chLatin_a, chLatin_u, chLatin_l, chLatin_t, chNull }; - -#ifdef HAVE_GOOD_STL - if (prefix && *prefix) - m_prefixes.insert(prefix); - else - m_prefixes.insert(_default); -#else - if (prefix && *prefix) { - auto_ptr_char p(prefix); - m_prefixes.insert(p.get()); - } - else - m_prefixes.insert("#default"); -#endif + m_prefixes.insert(prefix ? prefix : &chNull); } void ContentReference::setDigestAlgorithm(const XMLCh* digest) @@ -111,22 +119,3 @@ void ContentReference::setCanonicalizationMethod(const XMLCh* c14n) { m_c14n = c14n; } - -void ContentReference::addPrefixes(const std::set& namespaces) -{ - for (set::const_iterator n = namespaces.begin(); n!=namespaces.end(); ++n) { - // Check for xmlns:xml. - if (!XMLString::equals(n->getNamespacePrefix(), xmlconstants::XML_PREFIX) || !XMLString::equals(n->getNamespaceURI(), xmlconstants::XML_NS)) - addInclusivePrefix(n->getNamespacePrefix()); - } -} - -void ContentReference::addPrefixes(const XMLObject& xmlObject) -{ - addPrefixes(xmlObject.getNamespaces()); - const list& children = xmlObject.getOrderedChildren(); - for (list::const_iterator child = children.begin(); child!=children.end(); ++child) { - if (*child) - addPrefixes(*(*child)); - } -}