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 * SignatureProfileValidator.cpp
20 * SAML-specific signature verification.
24 #include "exceptions.h"
25 #include "signature/SignableObject.h"
26 #include "signature/SignatureProfileValidator.h"
28 #include <xmltooling/signature/Signature.h>
30 #include <xercesc/util/XMLUniDefs.hpp>
31 #include <xsec/dsig/DSIGReference.hpp>
32 #include <xsec/dsig/DSIGSignature.hpp>
33 #include <xsec/dsig/DSIGTransformList.hpp>
35 using namespace opensaml;
36 using namespace xmlsignature;
37 using namespace xmltooling;
40 SignatureProfileValidator::SignatureProfileValidator()
44 SignatureProfileValidator::~SignatureProfileValidator()
48 void SignatureProfileValidator::validate(const XMLObject* xmlObject) const
50 const Signature* sigObj=dynamic_cast<const Signature*>(xmlObject);
52 throw ValidationException("Validator only applies to Signature objects.");
53 validateSignature(*sigObj);
56 void SignatureProfileValidator::validateSignature(const Signature& sigObj) const
58 DSIGSignature* sig=sigObj.getXMLSignature();
60 throw ValidationException("Signature does not exist yet.");
62 const SignableObject* signableObj=dynamic_cast<const SignableObject*>(sigObj.getParent());
64 throw ValidationException("Signature is not a child of a signable SAML object.");
67 DSIGReferenceList* refs=sig->getReferenceList();
68 if (refs && refs->getSize()==1) {
69 DSIGReference* ref=refs->item(0);
71 const XMLCh* URI=ref->getURI();
72 const XMLCh* ID=signableObj->getXMLID();
73 if (URI==nullptr || *URI==0 || (*URI==chPound && ID && !XMLString::compareString(URI+1,ID))) {
74 DSIGTransformList* tlist=ref->getTransforms();
75 if (tlist->getSize() <= 2) {
76 for (unsigned int i=0; tlist && i<tlist->getSize(); i++) {
77 if (tlist->item(i)->getTransformType()==TRANSFORM_ENVELOPED_SIGNATURE)
79 else if (tlist->item(i)->getTransformType()!=TRANSFORM_EXC_C14N &&
80 tlist->item(i)->getTransformType()!=TRANSFORM_C14N) {
91 throw ValidationException("Invalid signature profile for SAML object.");