def1f98f1859ae0238f629cc705552270d4d6230
[shibboleth/cpp-opensaml.git] / saml / signature / VerifyingContext.cpp
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * VerifyingContext.cpp\r
19  * \r
20  * SAML-specific signature verification \r
21  */\r
22  \r
23 #include "internal.h"\r
24 #include "signature/VerifyingContext.h"\r
25 \r
26 #include <xmltooling/signature/Signature.h>\r
27 \r
28 #include <xercesc/util/XMLUniDefs.hpp>\r
29 #include <xsec/dsig/DSIGReference.hpp>\r
30 #include <xsec/dsig/DSIGTransformC14n.hpp>\r
31 #include <xsec/dsig/DSIGTransformList.hpp>\r
32 \r
33 using namespace opensaml;\r
34 using namespace std;\r
35 \r
36 void VerifyingContext::verifySignature(DSIGSignature* sig) const\r
37 {\r
38     bool valid=false;\r
39 \r
40     DSIGReferenceList* refs=sig->getReferenceList();\r
41     if (refs && refs->getSize()==1) {\r
42         DSIGReference* ref=refs->item(0);\r
43         if (ref) {\r
44             const XMLCh* URI=ref->getURI();\r
45             if (URI==NULL || *URI==0 || (*URI==chPound && !XMLString::compareString(URI+1,m_id))) {\r
46                 DSIGTransformList* tlist=ref->getTransforms();\r
47                 for (unsigned int i=0; tlist && i<tlist->getSize(); i++) {\r
48                     if (tlist->item(i)->getTransformType()==TRANSFORM_ENVELOPED_SIGNATURE)\r
49                         valid=true;\r
50                     else if (tlist->item(i)->getTransformType()!=TRANSFORM_EXC_C14N &&\r
51                              tlist->item(i)->getTransformType()!=TRANSFORM_C14N) {\r
52                         valid=false;\r
53                         break;\r
54                     }\r
55                 }\r
56             }\r
57         }\r
58     }\r
59     \r
60     if (!valid)\r
61         throw xmlsignature::SignatureException("Invalid signature profile for SAML object.");\r
62 }\r