Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

DSIGSignature.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * DSIGSignature := Class for checking and setting up signature nodes in a DSIG signature
00021  *
00022  * Author(s): Berin Lautenbach
00023  *
00024  * $Id: DSIGSignature.hpp,v 1.26 2005/06/04 11:30:25 blautenb Exp $
00025  *
00026  */
00027 
00028 #ifndef DSIGSIGNATURE_INCLUDE
00029 #define DSIGSIGNATURE_INCLUDE
00030 
00031 // XSEC Includes
00032 #include <xsec/utils/XSECSafeBufferFormatter.hpp>
00033 #include <xsec/dsig/DSIGTransform.hpp>
00034 #include <xsec/dsig/DSIGKeyInfoList.hpp>
00035 #include <xsec/dsig/DSIGConstants.hpp>
00036 #include <xsec/dsig/DSIGSignedInfo.hpp>
00037 
00038 // Xerces Includes
00039 
00040 #include <xercesc/dom/DOM.hpp>
00041 
00042 class XSECEnv;
00043 class XSECBinTXFMInputStream;
00044 class XSECURIResolver;
00045 class XSECKeyInfoResolver;
00046 class DSIGKeyInfoValue;
00047 class DSIGKeyInfoX509;
00048 class DSIGKeyInfoName;
00049 class DSIGKeyInfoPGPData;
00050 class DSIGKeyInfoSPKIData;
00051 class DSIGKeyInfoMgmtData;
00052 class DSIGObject;
00053 
00057 /*\@{*/
00058 
00068 class DSIG_EXPORT DSIGSignature {
00069 
00070 protected:
00071 
00074     
00091     DSIGSignature(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, 
00092                   XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *sigNode);
00093 
00094     ~DSIGSignature();
00096     
00097 public:
00098 
00101 
00111     void load(void);
00112 
00126     void setSigningKey(XSECCryptoKey *k);
00127 
00129 
00132 
00157     bool verify(void);
00158 
00169     bool verifySignatureOnly(void);
00170 
00196     void sign(void);
00198 
00201     
00222     void setDSIGNSPrefix(const XMLCh * prefix);
00223 
00240     void setECNSPrefix(const XMLCh * prefix);
00241 
00258     void setXPFNSPrefix(const XMLCh * prefix);
00259 
00271     void setPrettyPrint(bool flag);
00272 
00279     bool getPrettyPrint(void);
00280 
00304     XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *createBlankSignature(
00305         XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc,
00306         canonicalizationMethod cm = CANON_C14N_NOC,
00307         signatureMethod sm = SIGNATURE_DSA,
00308         hashMethod hm = HASH_SHA1
00309     );
00310 
00331     DSIGReference * createReference(
00332         const XMLCh * URI,
00333         hashMethod hm = HASH_SHA1, 
00334         char * type = NULL
00335     );
00336 
00338 
00341 
00355     unsigned int calculateSignedInfoAndReferenceHash(unsigned char * hashBuf, 
00356                                                     unsigned int hashBufLen);
00357 
00371     unsigned int calculateSignedInfoHash(unsigned char * hashBuf, 
00372                                         unsigned int hashBufLen);
00373 
00383     DSIGReferenceList * getReferenceList(void);
00384 
00398     XSECBinTXFMInputStream * makeBinInputStream(void) const;
00399 
00400 
00414     const XMLCh * getErrMsgs(void);
00415 
00424     const XMLCh * getDSIGNSPrefix();
00425 
00433     const XMLCh * getECNSPrefix();
00434 
00442     const XMLCh * getXPFNSPrefix();
00443 
00454     XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * getParentDocument() 
00455         {return mp_doc;}
00456 
00466     canonicalizationMethod getCanonicalizationMethod(void) 
00467     {return (mp_signedInfo != NULL ? 
00468              mp_signedInfo->getCanonicalizationMethod() : CANON_NONE);}
00469 
00470 
00480     hashMethod getHashMethod(void)
00481     {return (mp_signedInfo != NULL ? 
00482              mp_signedInfo->getHashMethod() : HASH_NONE);}
00483 
00493     signatureMethod getSignatureMethod(void)
00494     {return (mp_signedInfo != NULL ? 
00495              mp_signedInfo->getSignatureMethod() : SIGNATURE_NONE);}
00496 
00505     const XMLCh * getSignatureValue(void) const;
00506          
00514     XSECSafeBufferFormatter * getSBFormatter(void) {return mp_formatter;}
00515 
00517 
00520 
00529     void setURIResolver(XSECURIResolver * resolver);
00530 
00537     XSECURIResolver * getURIResolver(void);
00538 
00547     void setKeyInfoResolver(XSECKeyInfoResolver * resolver);
00548 
00555     XSECKeyInfoResolver * getKeyInfoResolver(void);
00556 
00558 
00562 
00578     DSIGKeyInfoList * getKeyInfoList() {return &m_keyInfoList;}
00579 
00588     void clearKeyInfo(void);
00589 
00602     DSIGKeyInfoValue * appendDSAKeyValue(const XMLCh * P, 
00603                            const XMLCh * Q, 
00604                            const XMLCh * G, 
00605                            const XMLCh * Y);
00606 
00617     DSIGKeyInfoValue * appendRSAKeyValue(const XMLCh * modulus, 
00618                            const XMLCh * exponent);
00619 
00631     DSIGKeyInfoX509 * appendX509Data(void);
00632 
00643     DSIGKeyInfoName * appendKeyName(const XMLCh * name, bool isDName = false);
00644 
00656     DSIGKeyInfoPGPData * appendPGPData(const XMLCh * id, const XMLCh * packet);
00657 
00667     DSIGKeyInfoSPKIData * appendSPKIData(const XMLCh * sexp);
00668 
00678     DSIGKeyInfoMgmtData * appendMgmtData(const XMLCh * data);
00679 
00681 
00684 
00695     DSIGObject * appendObject(void);
00696 
00703     int getObjectLength(void);
00704 
00712     DSIGObject * getObjectItem(int i);
00713 
00715 
00719 
00744     void setIdByAttributeName(bool flag);
00745 
00755     bool getIdByAttributeName(void);
00756 
00769     void registerIdAttributeName(const XMLCh * name);
00770 
00781     bool deregisterIdAttributeName(const XMLCh * name);
00782 
00797     void registerIdAttributeNameNS(const XMLCh * ns, const XMLCh * name);
00798 
00810     bool deregisterIdAttributeNameNS(const XMLCh * ns, const XMLCh * name);
00811 
00813 
00814     friend class XSECProvider;
00815 
00816 private:
00817 
00818     // For holding DSIGObject nodes
00819 #if defined(XSEC_NO_NAMESPACES)
00820     typedef vector<DSIGObject *>            ObjectVectorType;
00821 #else
00822     typedef std::vector<DSIGObject *>       ObjectVectorType;
00823 #endif
00824 
00825 
00826     // Internal functions
00827     void createKeyInfoElement(void);
00828     bool verifySignatureOnlyInternal(void);
00829 
00830     XSECSafeBufferFormatter     * mp_formatter;
00831     bool                        m_loaded;               // Have we already loaded?
00832     XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument                  
00833                                 * mp_doc;
00834     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode                      
00835                                 * mp_sigNode;
00836     DSIGSignedInfo              * mp_signedInfo;
00837     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode                      
00838                                 * mp_signatureValueNode;
00839     safeBuffer                  m_signatureValueSB;
00840     DSIGKeyInfoList             m_keyInfoList;
00841     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode                      
00842                                 * mp_KeyInfoNode;
00843     safeBuffer                  m_errStr;
00844 
00845     // Environment
00846     XSECEnv                     * mp_env;
00847     
00848     // The signing/verifying key
00849     XSECCryptoKey               * mp_signingKey;
00850 
00851     // Resolvers
00852     XSECKeyInfoResolver         * mp_KeyInfoResolver;
00853 
00854     // Objects
00855 
00856     ObjectVectorType            m_objects;
00857 
00858     // Not implemented constructors
00859 
00860     DSIGSignature();
00861 
00862     /*\@}*/
00863 };
00864 
00865 #endif /* DSIGSIGNATURE_INCLUDE */

Generated on Sun Jul 3 17:37:25 2005 for XML-Security-C by  doxygen 1.4.2