From a84e39caa065a850880467b8eeaf2061bccfbf6d Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Thu, 4 May 2006 18:13:54 +0000 Subject: [PATCH] Tighten up validator namespace checking, rework registration. --- xmltooling/Makefile.am | 1 + xmltooling/XMLToolingConfig.cpp | 60 +------ xmltooling/base.h | 51 ++++++ xmltooling/io/AbstractXMLObjectUnmarshaller.cpp | 5 + xmltooling/io/AbstractXMLObjectUnmarshaller.h | 4 +- xmltooling/signature/KeyInfo.h | 80 +-------- .../signature/impl/KeyInfoSchemaValidators.cpp | 180 +++++++++++++++++++++ xmltooling/xmltooling.vcproj | 4 + 8 files changed, 249 insertions(+), 136 deletions(-) create mode 100644 xmltooling/signature/impl/KeyInfoSchemaValidators.cpp diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index b76066d..17b0d43 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -91,6 +91,7 @@ libxmltooling_la_SOURCES = \ io/AbstractXMLObjectMarshaller.cpp \ io/AbstractXMLObjectUnmarshaller.cpp \ signature/impl/KeyInfoImpl.cpp \ + signature/impl/KeyInfoSchemaValidators.cpp \ util/NDC.cpp \ util/ParserPool.cpp \ util/XMLConstants.cpp \ diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index e5b1768..7b9d378 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -20,8 +20,6 @@ * Library configuration */ -#define XMLTOOLING_DECLARE_VALIDATORS - #include "internal.h" #include "exceptions.h" #include "XMLToolingConfig.h" @@ -51,17 +49,6 @@ using namespace xmltooling; using namespace log4cpp; using namespace std; -#define REGISTER_ELEMENT(namespaceURI,cname) \ - q=QName(namespaceURI,cname::LOCAL_NAME); \ - XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \ - Validator::registerValidator(q,new cname##SchemaValidator()) - -#define REGISTER_TYPE(namespaceURI,cname) \ - q=QName(namespaceURI,cname::TYPE_NAME); \ - XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \ - Validator::registerValidator(q,new cname##SchemaValidator()) - - DECL_EXCEPTION_FACTORY(XMLParserException,xmltooling); DECL_EXCEPTION_FACTORY(XMLObjectException,xmltooling); DECL_EXCEPTION_FACTORY(MarshallingException,xmltooling); @@ -172,52 +159,9 @@ bool XMLToolingInternalConfig::init() // default registrations XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder()); - - QName q; - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyInfo); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyName); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyValue); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,MgmtData); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,DSAKeyValue); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,RSAKeyValue); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Exponent); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Modulus); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,P); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Q); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,G); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Y); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,J); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Seed); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PgenCounter); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,XPath); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Transform); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Transforms); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,RetrievalMethod); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509IssuerSerial); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509IssuerName); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509SerialNumber); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509SKI); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509SubjectName); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509Certificate); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509CRL); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509Data); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,SPKISexp); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,SPKIData); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PGPKeyID); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PGPKeyPacket); - REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PGPData); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyInfo); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyValue); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,DSAKeyValue); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,RSAKeyValue); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,Transform); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,Transforms); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,RetrievalMethod); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,X509IssuerSerial); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,X509Data); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,SPKIData); - REGISTER_TYPE(XMLConstants::XMLSIG_NS,PGPData); + registerKeyInfoClasses(); + REGISTER_EXCEPTION_FACTORY(XMLParserException,xmltooling); REGISTER_EXCEPTION_FACTORY(XMLObjectException,xmltooling); REGISTER_EXCEPTION_FACTORY(MarshallingException,xmltooling); diff --git a/xmltooling/base.h b/xmltooling/base.h index 9f222a5..f9e81db 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -154,9 +154,60 @@ {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, chNull} +#define UNICODE_LITERAL_27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \ + chLatin_##aa, chNull} +#define UNICODE_LITERAL_28(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \ + chLatin_##aa, chLatin_##bb, chNull} +#define UNICODE_LITERAL_29(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \ + chLatin_##aa, chLatin_##bb, chLatin_##cc, chNull} +#define UNICODE_LITERAL_30(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \ + chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chNull} +#define UNICODE_LITERAL_31(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \ + chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chLatin_##ee, chNull} +#define UNICODE_LITERAL_32(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \ + chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chLatin_##ee, chLatin_##ff, chNull} #endif /* DOXYGEN_SKIP */ /** + * Begins the declaration of an XMLObject specialization for an abstract element/type. + * Basic boilerplate includes a protected constructor, empty virtual destructor, + * and Unicode constants for the default associated element's name and prefix. + * + * @param linkage linkage specifier for the class + * @param cname the name of the class to declare + * @param base the base class to derive from using public virtual inheritance + * @param desc documentation comment for class + */ +#define DECL_XMLOBJECT_ABSTRACT(linkage,cname,base,desc) \ + XMLTOOLING_DOXYGEN(desc) \ + class linkage cname : public virtual base { \ + protected: \ + cname() {} \ + public: \ + virtual ~cname() {} \ + XMLTOOLING_DOXYGEN(Element local name) \ + static const XMLCh LOCAL_NAME[]; \ + } + +/** * Begins the declaration of an XMLObject specialization. * Basic boilerplate includes a protected constructor, empty virtual destructor, * and Unicode constants for the default associated element's name and prefix. diff --git a/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp b/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp index fd4c9f5..3afab8c 100644 --- a/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp +++ b/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp @@ -174,3 +174,8 @@ void AbstractXMLObjectUnmarshaller::unmarshallChildElements(const DOMElement* do } } } + +void AbstractXMLObjectUnmarshaller::processChildElement(XMLObject* child, const DOMElement* childRoot) +{ + throw UnmarshallingException("Child elements are not permitted on this object."); +} diff --git a/xmltooling/io/AbstractXMLObjectUnmarshaller.h b/xmltooling/io/AbstractXMLObjectUnmarshaller.h index be4e116..7d75827 100644 --- a/xmltooling/io/AbstractXMLObjectUnmarshaller.h +++ b/xmltooling/io/AbstractXMLObjectUnmarshaller.h @@ -20,7 +20,7 @@ * A thread-safe abstract unmarshaller. */ -#if !defined(__xmltooling_xmlunmarshaller_h__) +#ifndef __xmltooling_xmlunmarshaller_h__ #define __xmltooling_xmlunmarshaller_h__ #include @@ -75,7 +75,7 @@ namespace xmltooling { * * @throws UnmarshallingException thrown if there is a problem adding the child to the parent */ - virtual void processChildElement(XMLObject* child, const DOMElement* childRoot) {} + virtual void processChildElement(XMLObject* child, const DOMElement* childRoot); /** * Called after an attribute has been unmarshalled so that it can be added to the XMLObject. diff --git a/xmltooling/signature/KeyInfo.h b/xmltooling/signature/KeyInfo.h index 40b3722..00cc9d6 100644 --- a/xmltooling/signature/KeyInfo.h +++ b/xmltooling/signature/KeyInfo.h @@ -31,8 +31,6 @@ #include #include -#include - #define DECL_XMLSIGOBJECTBUILDER(cname) \ DECL_XMLOBJECTBUILDER(XMLTOOL_API,cname,xmltooling::XMLConstants::XMLSIG_NS,xmltooling::XMLConstants::XMLSIG_PREFIX) @@ -192,80 +190,10 @@ namespace xmlsignature { DECL_XMLSIGOBJECTBUILDER(KeyValue); DECL_XMLSIGOBJECTBUILDER(KeyInfo); -#ifdef XMLTOOLING_DECLARE_VALIDATORS - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,KeyName); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,MgmtData); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Modulus); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Exponent); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Seed); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,PgenCounter); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,P); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Q); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,G); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Y); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,J); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,XPath); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509IssuerName); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509SerialNumber); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509SKI); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509SubjectName); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509Certificate); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509CRL); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,SPKISexp); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,PGPKeyID); - XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,PGPKeyPacket); - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,RSAKeyValue); - XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Modulus); - XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Exponent); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,DSAKeyValue); - XMLOBJECTVALIDATOR_REQUIRE(DSAKeyValue,Y); - XMLOBJECTVALIDATOR_NONEORBOTH(DSKeyValue,P,Q); - XMLOBJECTVALIDATOR_NONEORBOTH(DSKeyValue,Seed,PgenCounter); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyValue); - XMLOBJECTVALIDATOR_ONEOF3(KeyValue,DSAKeyValue,RSAKeyValue,XMLObject); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transform); - XMLOBJECTVALIDATOR_REQUIRE(Transform,Algorithm); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transforms); - XMLOBJECTVALIDATOR_NONEMPTY(Transforms,Transform); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,RetrievalMethod); - XMLOBJECTVALIDATOR_REQUIRE(RetrievalMethod,URI); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,X509IssuerSerial); - XMLOBJECTVALIDATOR_REQUIRE(X509IssuerSerial,X509IssuerName); - XMLOBJECTVALIDATOR_REQUIRE(X509IssuerSerial,X509SerialNumber); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,X509Data); - if (!ptr->hasChildren()) - throw xmltooling::ValidationException("X509Data must have at least one child element."); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,SPKIData); - XMLOBJECTVALIDATOR_NONEMPTY(SPKIData,SPKISexp); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,PGPData); - XMLOBJECTVALIDATOR_ONEOF(PGPData,PGPKeyID,PGPKeyPacket); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyInfo); - if (!ptr->hasChildren()) - throw xmltooling::ValidationException("KeyInfo must have at least one child element."); - END_XMLOBJECTVALIDATOR; -#endif /* XMLTOOLING_DECLARE_VALIDATORS */ - + /** + * Registers builders and validators for KeyInfo classes into the runtime. + */ + void XMLTOOL_API registerKeyInfoClasses(); }; #endif /* __xmltooling_keyinfo_h__ */ diff --git a/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp b/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp new file mode 100644 index 0000000..e2dc57d --- /dev/null +++ b/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp @@ -0,0 +1,180 @@ +/* +* Copyright 2001-2006 Internet2 + * +* Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * KeyInfoSchemaValidators.cpp + * + * Schema validators for KeyInfo schema + */ + +#include "internal.h" +#include "exceptions.h" +#include "signature/KeyInfo.h" + +using namespace xmlsignature; +using namespace xmltooling; +using namespace std; + +namespace xmlsignature { + + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,KeyName); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,MgmtData); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Modulus); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Exponent); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Seed); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,PgenCounter); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,P); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Q); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,G); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,Y); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,J); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,XPath); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509IssuerName); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509SerialNumber); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509SKI); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509SubjectName); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509Certificate); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,X509CRL); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,SPKISexp); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,PGPKeyID); + XMLOBJECTVALIDATOR_SIMPLE(XMLTOOL_DLLLOCAL,PGPKeyPacket); + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,RSAKeyValue); + XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Modulus); + XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Exponent); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,DSAKeyValue); + XMLOBJECTVALIDATOR_REQUIRE(DSAKeyValue,Y); + XMLOBJECTVALIDATOR_NONEORBOTH(DSKeyValue,P,Q); + XMLOBJECTVALIDATOR_NONEORBOTH(DSKeyValue,Seed,PgenCounter); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyValue); + XMLOBJECTVALIDATOR_ONEOF3(KeyValue,DSAKeyValue,RSAKeyValue,XMLObject); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transform); + XMLOBJECTVALIDATOR_REQUIRE(Transform,Algorithm); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Transforms); + XMLOBJECTVALIDATOR_NONEMPTY(Transforms,Transform); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,RetrievalMethod); + XMLOBJECTVALIDATOR_REQUIRE(RetrievalMethod,URI); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,X509IssuerSerial); + XMLOBJECTVALIDATOR_REQUIRE(X509IssuerSerial,X509IssuerName); + XMLOBJECTVALIDATOR_REQUIRE(X509IssuerSerial,X509SerialNumber); + END_XMLOBJECTVALIDATOR; + + class XMLTOOL_DLLLOCAL checkWildcardNS { + public: + void operator()(const XMLObject* xmlObject) const { + const XMLCh* ns=xmlObject->getElementQName().getNamespaceURI(); + if (XMLString::equals(ns,XMLConstants::XMLSIG_NS) || !ns || !*ns) { + throw ValidationException( + "X509Data contains an illegal extension element ($1).", + params(1,xmlObject->getElementQName().toString().c_str()) + ); + } + } + }; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,X509Data); + if (!ptr->hasChildren()) + throw ValidationException("X509Data must have at least one child element."); + vector anys=ptr->getXMLObjects(); + for_each(anys.begin(),anys.end(),checkWildcardNS()); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,SPKIData); + XMLOBJECTVALIDATOR_NONEMPTY(SPKIData,SPKISexp); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,PGPData); + XMLOBJECTVALIDATOR_ONEOF(PGPData,PGPKeyID,PGPKeyPacket); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyInfo); + if (!ptr->hasChildren()) + throw ValidationException("KeyInfo must have at least one child element."); + vector anys=ptr->getXMLObjects(); + for_each(anys.begin(),anys.end(),checkWildcardNS()); + END_XMLOBJECTVALIDATOR; + +}; + +#define REGISTER_ELEMENT(namespaceURI,cname) \ + q=QName(namespaceURI,cname::LOCAL_NAME); \ + XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \ + Validator::registerValidator(q,new cname##SchemaValidator()) + +#define REGISTER_TYPE(namespaceURI,cname) \ + q=QName(namespaceURI,cname::TYPE_NAME); \ + XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \ + Validator::registerValidator(q,new cname##SchemaValidator()) + +void xmlsignature::registerKeyInfoClasses() +{ + QName q; + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyInfo); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyName); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyValue); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,MgmtData); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,DSAKeyValue); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,RSAKeyValue); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Exponent); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Modulus); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,P); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Q); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,G); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Y); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,J); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Seed); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PgenCounter); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,XPath); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Transform); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Transforms); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,RetrievalMethod); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509IssuerSerial); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509IssuerName); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509SerialNumber); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509SKI); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509SubjectName); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509Certificate); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509CRL); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,X509Data); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,SPKISexp); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,SPKIData); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PGPKeyID); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PGPKeyPacket); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,PGPData); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyInfo); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyValue); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,DSAKeyValue); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,RSAKeyValue); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,Transform); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,Transforms); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,RetrievalMethod); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,X509IssuerSerial); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,X509Data); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,SPKIData); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,PGPData); +} diff --git a/xmltooling/xmltooling.vcproj b/xmltooling/xmltooling.vcproj index f6dc10a..3b729cc 100644 --- a/xmltooling/xmltooling.vcproj +++ b/xmltooling/xmltooling.vcproj @@ -292,6 +292,10 @@ > + + -- 2.1.4