2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * SignatureProfileValidator.cpp
24 * SAML-specific signature verification.
28 #include "exceptions.h"
29 #include "signature/SignableObject.h"
30 #include "signature/SignatureProfileValidator.h"
32 #include <xmltooling/signature/Signature.h>
34 #include <xercesc/util/XMLUniDefs.hpp>
35 #include <xsec/dsig/DSIGReference.hpp>
36 #include <xsec/dsig/DSIGSignature.hpp>
37 #include <xsec/dsig/DSIGTransformList.hpp>
39 using namespace opensaml;
40 using namespace xmlsignature;
41 using namespace xmltooling;
44 SignatureProfileValidator::SignatureProfileValidator()
48 SignatureProfileValidator::~SignatureProfileValidator()
52 void SignatureProfileValidator::validate(const XMLObject* xmlObject) const
54 const Signature* sigObj=dynamic_cast<const Signature*>(xmlObject);
56 throw ValidationException("Validator only applies to Signature objects.");
57 validateSignature(*sigObj);
60 void SignatureProfileValidator::validateSignature(const Signature& sigObj) const
62 DSIGSignature* sig=sigObj.getXMLSignature();
64 throw ValidationException("Signature does not exist yet.");
66 const SignableObject* signableObj=dynamic_cast<const SignableObject*>(sigObj.getParent());
68 throw ValidationException("Signature is not a child of a signable SAML object.");
71 DSIGReferenceList* refs=sig->getReferenceList();
72 if (refs && refs->getSize()==1) {
73 DSIGReference* ref=refs->item(0);
75 const XMLCh* URI=ref->getURI();
76 const XMLCh* ID=signableObj->getXMLID();
77 if (URI==nullptr || *URI==0 || (*URI==chPound && ID && !XMLString::compareString(URI+1,ID))) {
78 DSIGTransformList* tlist=ref->getTransforms();
79 if (tlist->getSize() <= 2) {
80 for (unsigned int i=0; tlist && i<tlist->getSize(); i++) {
81 if (tlist->item(i)->getTransformType()==TRANSFORM_ENVELOPED_SIGNATURE)
83 else if (tlist->item(i)->getTransformType()!=TRANSFORM_EXC_C14N &&
84 tlist->item(i)->getTransformType()!=TRANSFORM_C14N) {
95 throw ValidationException("Invalid signature profile for SAML object.");