2 * Copyright 2001-2010 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 * ContentReference.cpp
20 * SAML-specific signature reference profile.
24 #include "signature/ContentReference.h"
25 #include "signature/SignableObject.h"
27 #include <xmltooling/signature/Signature.h>
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xsec/dsig/DSIGReference.hpp>
30 #include <xsec/dsig/DSIGSignature.hpp>
31 #include <xsec/dsig/DSIGTransformC14n.hpp>
33 using namespace opensaml;
34 using namespace xmltooling;
37 ContentReference::ContentReference(const SignableObject& signableObject)
38 : m_signableObject(signableObject), m_digest(nullptr), m_c14n(nullptr)
42 ContentReference::~ContentReference()
46 void ContentReference::createReferences(DSIGSignature* sig)
48 DSIGReference* ref = nullptr;
49 const XMLCh* id=m_signableObject.getXMLID();
51 ref=sig->createReference(&chNull, m_digest ? m_digest : DSIGConstants::s_unicodeStrURISHA1); // whole doc reference
53 XMLCh* buf=new XMLCh[XMLString::stringLen(id) + 2];
56 XMLString::catString(buf,id);
58 ref=sig->createReference(buf, m_digest ? m_digest : DSIGConstants::s_unicodeStrURISHA1);
67 ref->appendEnvelopedSignatureTransform();
68 DSIGTransformC14n* c14n=ref->appendCanonicalizationTransform(m_c14n ? m_c14n : DSIGConstants::s_unicodeStrURIEXC_C14N_NOC);
70 if (!m_c14n || m_c14n == DSIGConstants::s_unicodeStrURIEXC_C14N_NOC || m_c14n == DSIGConstants::s_unicodeStrURIEXC_C14N_COM) {
71 // Compute inclusive prefix set.
72 set<xstring> prefix_set;
73 XMLHelper::getNonVisiblyUsedPrefixes(m_signableObject, prefix_set);
74 prefix_set.insert(m_prefixes.begin(), m_prefixes.end());
76 // Build up the string of prefixes.
78 static const XMLCh _default[] = { chPound, chLatin_d, chLatin_e, chLatin_f, chLatin_a, chLatin_u, chLatin_l, chLatin_t, chNull };
79 for (set<xstring>::const_iterator p = prefix_set.begin(); p != prefix_set.end(); ++p) {
80 prefixes += (p->empty() ? _default : p->c_str());
83 if (!prefixes.empty()) {
84 prefixes.erase(prefixes.begin() + prefixes.size() - 1);
85 c14n->setInclusiveNamespaces(prefixes.c_str());
90 void ContentReference::addInclusivePrefix(const XMLCh* prefix)
92 m_prefixes.insert(prefix ? prefix : &chNull);
95 void ContentReference::setDigestAlgorithm(const XMLCh* digest)
100 void ContentReference::setCanonicalizationMethod(const XMLCh* c14n)