X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsignature%2FContentReference.cpp;h=eb7416261b2efd829bd192cfce017de2aec84023;hb=e9554c255ad3c91c7c4976e7a1a54905903e66a2;hp=452ee09fb145b09eea70b60d80ba9986ea1a9d1b;hpb=f3a43f14f9dd53428f9e879bb489d6a4cf2674a8;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/signature/ContentReference.cpp b/saml/signature/ContentReference.cpp index 452ee09..eb74162 100644 --- a/saml/signature/ContentReference.cpp +++ b/saml/signature/ContentReference.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * ContentReference.cpp * - * SAML-specific signature reference profile + * SAML-specific signature reference profile. */ #include "internal.h" @@ -27,18 +27,28 @@ #include #include #include +#include #include using namespace opensaml; using namespace xmltooling; using namespace std; +ContentReference::ContentReference(const SignableObject& signableObject) + : m_signableObject(signableObject), m_digest(nullptr), m_c14n(nullptr) +{ +} + +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); // whole doc reference + ref=sig->createReference(&chNull, m_digest ? m_digest : DSIGConstants::s_unicodeStrURISHA1); // whole doc reference else { XMLCh* buf=new XMLCh[XMLString::stringLen(id) + 2]; buf[0]=chPound; @@ -56,54 +66,38 @@ 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 + // Compute inclusive prefix set. + set prefix_set; + XMLHelper::getNonVisiblyUsedPrefixes(m_signableObject, prefix_set); + prefix_set.insert(m_prefixes.begin(), m_prefixes.end()); + + // 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 = prefix_set.begin(); p != prefix_set.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())); } -#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::addPrefixes(const std::set& namespaces) +void ContentReference::setDigestAlgorithm(const XMLCh* digest) { - for (set::const_iterator n = namespaces.begin(); n!=namespaces.end(); ++n) - addInclusivePrefix(n->getNamespacePrefix()); + m_digest = digest; } -void ContentReference::addPrefixes(const XMLObject& xmlObject) +void ContentReference::setCanonicalizationMethod(const XMLCh* c14n) { - addPrefixes(xmlObject.getNamespaces()); - const list& children = xmlObject.getOrderedChildren(); - for (list::const_iterator child = children.begin(); child!=children.end(); ++child) { - if (*child) - addPrefixes(*(*child)); - } + m_c14n = c14n; }