blautenb    2003/05/28 03:56:48

  Modified:    c/Projects/VC6.0/xsec/xsec_lib xsec_lib.dsp
               c/src/dsig DSIGKeyInfoList.cpp DSIGSignature.cpp
                        DSIGSignature.hpp
               c/src/tools/xtest xtest.cpp
  Added:       c/src/dsig DSIGKeyInfoMgmtData.cpp DSIGKeyInfoMgmtData.hpp
  Log:
  MgmtData KeyInfo element implemented
  
  Revision  Changes    Path
  1.15      +8 -0      xml-security/c/Projects/VC6.0/xsec/xsec_lib/xsec_lib.dsp
  
  Index: xsec_lib.dsp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/Projects/VC6.0/xsec/xsec_lib/xsec_lib.dsp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- xsec_lib.dsp      27 May 2003 12:06:07 -0000      1.14
  +++ xsec_lib.dsp      28 May 2003 10:56:48 -0000      1.15
  @@ -190,6 +190,14 @@
   # End Source File
   # Begin Source File
   
  +SOURCE=..\..\..\..\src\dsig\DSIGKeyInfoMgmtData.cpp
  +# End Source File
  +# Begin Source File
  +
  +SOURCE=..\..\..\..\src\dsig\DSIGKeyInfoMgmtData.hpp
  +# End Source File
  +# Begin Source File
  +
   SOURCE=..\..\..\..\src\dsig\DSIGKeyInfoName.cpp
   # End Source File
   # Begin Source File
  
  
  
  1.7       +8 -1      xml-security/c/src/dsig/DSIGKeyInfoList.cpp
  
  Index: DSIGKeyInfoList.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGKeyInfoList.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DSIGKeyInfoList.cpp       27 May 2003 12:06:07 -0000      1.6
  +++ DSIGKeyInfoList.cpp       28 May 2003 10:56:48 -0000      1.7
  @@ -75,6 +75,7 @@
   #include <xsec/dsig/DSIGKeyInfoValue.hpp>
   #include <xsec/dsig/DSIGKeyInfoPGPData.hpp>
   #include <xsec/dsig/DSIGKeyInfoSPKIData.hpp>
  +#include <xsec/dsig/DSIGKeyInfoMgmtData.hpp>
   #include <xsec/framework/XSECError.hpp>
   #include <xsec/utils/XSECDOMUtils.hpp>
   #include <xsec/dsig/DSIGSignature.hpp>
  @@ -177,6 +178,12 @@
        else if (strEquals(getDSIGLocalName(ki), "SPKIData")) {
   
                XSECnew(k, DSIGKeyInfoSPKIData(mp_parentSignature, ki));
  +             
  +     }
  +
  +     else if (strEquals(getDSIGLocalName(ki), "MgmtData")) {
  +
  +             XSECnew(k, DSIGKeyInfoMgmtData(mp_parentSignature, ki));
                
        }
   
  
  
  
  1.17      +19 -1     xml-security/c/src/dsig/DSIGSignature.cpp
  
  Index: DSIGSignature.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGSignature.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DSIGSignature.cpp 27 May 2003 12:06:07 -0000      1.16
  +++ DSIGSignature.cpp 28 May 2003 10:56:48 -0000      1.17
  @@ -92,6 +92,7 @@
   #include <xsec/dsig/DSIGKeyInfoName.hpp>
   #include <xsec/dsig/DSIGKeyInfoPGPData.hpp>
   #include <xsec/dsig/DSIGKeyInfoSPKIData.hpp>
  +#include <xsec/dsig/DSIGKeyInfoMgmtData.hpp>
   
   // Xerces includes
   
  @@ -732,6 +733,23 @@
        m_keyInfoList.addKeyInfo(s);
   
        return s;
  +
  +}
  +
  +DSIGKeyInfoMgmtData * DSIGSignature::appendMgmtData(const XMLCh * data) {
  +
  +     createKeyInfoElement();
  +
  +     DSIGKeyInfoMgmtData * m;
  +
  +     XSECnew(m, DSIGKeyInfoMgmtData(this));
  +
  +     mp_KeyInfoNode->appendChild(m->createBlankMgmtData(data));
  +     
mp_KeyInfoNode->appendChild(mp_doc->createTextNode(DSIGConstants::s_unicodeStrNL));
  +
  +     m_keyInfoList.addKeyInfo(m);
  +
  +     return m;
   
   }
   
  
  
  
  1.12      +13 -1     xml-security/c/src/dsig/DSIGSignature.hpp
  
  Index: DSIGSignature.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGSignature.hpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DSIGSignature.hpp 27 May 2003 12:06:07 -0000      1.11
  +++ DSIGSignature.hpp 28 May 2003 10:56:48 -0000      1.12
  @@ -90,6 +90,7 @@
   class DSIGKeyInfoName;
   class DSIGKeyInfoPGPData;
   class DSIGKeyInfoSPKIData;
  +class DSIGKeyInfoMgmtData;
   
   /**
    * @ingroup pubsig
  @@ -650,6 +651,17 @@
         */
   
        DSIGKeyInfoSPKIData * appendSPKIData(const XMLCh * sexp);
  +
  +     /**
  +      * \brief Append a MgmtData element
  +      *
  +      * Add a new KeyInfo element for Management Data
  +      *
  +      * @param data The string to set in the MgmtData element
  +      * @returns A pointer to the created object
  +      */
  +
  +     DSIGKeyInfoMgmtData * appendMgmtData(const XMLCh * data);
   
        //@}
   
  
  
  
  1.1                  xml-security/c/src/dsig/DSIGKeyInfoMgmtData.cpp
  
  Index: DSIGKeyInfoMgmtData.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "<WebSig>" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Institute for
   * Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
   * The development of this software was partly funded by the European 
   * Commission in the <WebSig> project in the ISIS Programme. 
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * XSEC
   *
   * DSIGKeyInfoMgmtData := Inband key information
   *
   * Author(s): Berin Lautenbach
   *
   * $Id: DSIGKeyInfoMgmtData.cpp,v 1.1 2003/05/28 10:56:48 blautenb Exp $
   *
   */
  
  #include <xsec/dsig/DSIGKeyInfoMgmtData.hpp>
  #include <xsec/framework/XSECError.hpp>
  #include <xsec/utils/XSECDOMUtils.hpp>
  #include <xsec/dsig/DSIGSignature.hpp>
  
  #include <xercesc/util/Janitor.hpp>
  
  XSEC_USING_XERCES(ArrayJanitor);
  
  // 
--------------------------------------------------------------------------------
  //           Constructors and Destructors
  // 
--------------------------------------------------------------------------------
  
  
  DSIGKeyInfoMgmtData::DSIGKeyInfoMgmtData(DSIGSignature *sig, DOMNode 
*nameNode) : 
  DSIGKeyInfo(sig),
  mp_data(NULL),
  mp_dataTextNode(0) {
  
        mp_keyInfoDOMNode = nameNode;
  
  }
  
  
  DSIGKeyInfoMgmtData::DSIGKeyInfoMgmtData(DSIGSignature *sig) : 
  DSIGKeyInfo(sig),
  mp_data(NULL),
  mp_dataTextNode(0) {
  
        mp_keyInfoDOMNode = 0;
  
  }
  
  
  DSIGKeyInfoMgmtData::~DSIGKeyInfoMgmtData() {
  
  
  };
  
  // 
--------------------------------------------------------------------------------
  //           Load and Get functions
  // 
--------------------------------------------------------------------------------
  
  
  void DSIGKeyInfoMgmtData::load(void) {
  
        // Assuming we have a valid DOM_Node to start with, load the signing 
key so that it can
        // be used later on
  
        if (mp_keyInfoDOMNode == NULL) {
  
                // Attempt to load an empty signature element
                throw XSECException(XSECException::KeyInfoError,
                        "DSIGKeyInfoMgmtData::load - called on empty DOM");
  
        }
  
        if (!strEquals(getDSIGLocalName(mp_keyInfoDOMNode), "MgmtData")) {
  
                throw XSECException(XSECException::KeyInfoError,
                        "DSIGKeyInfoMgmtData::load - called on non <MgmtData> 
node");
  
        }
  
        // Now find the text node containing the name
  
        DOMNode *tmpElt = findFirstChildOfType(mp_keyInfoDOMNode, 
DOMNode::TEXT_NODE);
  
        if (tmpElt != 0) {
  
                mp_dataTextNode = tmpElt;
                mp_data = tmpElt->getNodeValue();
  
        }
  
        else {
  
                throw XSECException(XSECException::ExpectedDSIGChildNotFound,
                        "DSIGKeyInfoMgmtData::load - Expected TEXT node as 
child to <MgmtData> element");
  
        }
  
  }
  
  // 
--------------------------------------------------------------------------------
  //           Create and Set functions
  // 
--------------------------------------------------------------------------------
  
  DOMElement * DSIGKeyInfoMgmtData::createBlankMgmtData(const XMLCh * data) {
  
        // Create the DOM Structure
  
        safeBuffer str;
        DOMDocument *doc = mp_parentSignature->getParentDocument();
        const XMLCh * prefix = mp_parentSignature->getDSIGNSPrefix();
  
        makeQName(str, prefix, "MgmtData");
  
        DOMElement *ret = 
doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
        mp_keyInfoDOMNode = ret;
  
        // Check whether to encode prior to adding
        mp_dataTextNode = doc->createTextNode(data);
  
        ret->appendChild(mp_dataTextNode);
  
        mp_data = mp_dataTextNode->getNodeValue();
  
        return ret;
  
  }
  
  void DSIGKeyInfoMgmtData::setData(const XMLCh * data) {
  
        if (mp_dataTextNode == 0) {
  
                // Attempt to set an empty element
                throw XSECException(XSECException::KeyInfoError,
                        "KeyInfoMgmtData::setData() called prior to load() or 
createBlank()");
  
        }
  
        mp_dataTextNode->setNodeValue(data);
        mp_data = mp_dataTextNode->getNodeValue();
  
  }
  
  
  
  
  1.1                  xml-security/c/src/dsig/DSIGKeyInfoMgmtData.hpp
  
  Index: DSIGKeyInfoMgmtData.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "<WebSig>" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Institute for
   * Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
   * The development of this software was partly funded by the European 
   * Commission in the <WebSig> project in the ISIS Programme. 
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * XSEC
   *
   * DSIGKeyInfoMgmtData := MgmtData - used for conveying in-band key data
   *
   * Author(s): Berin Lautenbach
   *
   * $Id: DSIGKeyInfoMgmtData.hpp,v 1.1 2003/05/28 10:56:48 blautenb Exp $
   *
   */
  
  #ifndef DSIGKEYINFOMGMTDATA_INCLUDE
  #define DSIGKEYINFOMGMTDATA_INCLUDE
  
  #include <xsec/dsig/DSIGKeyInfo.hpp>
  #include <xsec/utils/XSECPlatformUtils.hpp>
  
  XSEC_DECLARE_XERCES_CLASS(DOMElement);
  
  /**
   * @ingroup pubsig
   * @{
   */
  
  /**
   * @brief The class for <MgmtData> nodes in a KeyInfo list.
   *
   * Class for holding in band key information.
   * @note Use of this class is <em>NOT RECOMMEDED</em> within
   * the DSIG standard.
   *
   */
  
  
  
  class DSIG_EXPORT DSIGKeyInfoMgmtData : public DSIGKeyInfo {
  
  public:
  
        /** @name Constructors and Destructors */
        //@{
  
        /**
         * \brief Constructor used when XML exists.
         *
         * This constructor is used by DSIGSignature objects to load
         * an existing DOM structure into the Name element.
         *
         * @param sig Calling signature object.
         * @param nameNode DOMNode to load information from
         */
  
        DSIGKeyInfoMgmtData(DSIGSignature * sig, DOMNode *nameNode);
  
        /**
         * \brief Constructor used when XML needs to be created.
         *
         * This constructor is used by DSIGSignature objects to
         * create a DSIGKeyInfoName object that can then be used
         * to create the required XML.
         *
         * @param sig Calling signature object.
         */
  
        DSIGKeyInfoMgmtData(DSIGSignature * sig);
  
        /**
         * \brief Destructor
         */
  
        virtual ~DSIGKeyInfoMgmtData();
  
        //@}
  
        /** @name Load and Get functions */
        //@{
  
        /**
         * \brief Load an existing XML structure into this object.
         */
  
        virtual void load(void);
  
        /**
         * \Get key name - unimplemented for MgmtData
         */
  
        virtual const XMLCh * getKeyName(void) {return NULL;}
  
        /**
         * \brief Get the MgmtData string
         *
         * Returns a pointer to the buffer containing the data string.
         *
         * @returns A pointer to the XMLCh buffer containing the data
         */
  
        virtual const XMLCh * getData(void) {return mp_data;};
  
        //@}
  
        /[EMAIL PROTECTED] Create and set functions */
        //@{
        
        /**
         * \brief Create a new MgmtData element in the current document.
         *
         * Creates a new MgmtData element and sets the data with the string
         * passed in.
         *
         * @param data Value to set the MgmtData to
         * @returns The newly created DOMElement with the structure underneath.
         */
  
        DOMElement * createBlankMgmtData(const XMLCh * data);
  
        /**
         * \brief Set the value of the MgmtData to a new string.
         *
         * Uses the passed in string to set a new value in the DOM structure.
         *
         * @param data Value to set in MgmtData
         */
  
        void setData(const XMLCh * data);
  
        //@}
  
        /** @name Information Functions */
        //@{
        
        /**
         * \brief Return type of this KeyInfo element
         */
        
        virtual keyInfoType getKeyInfoType(void) {return 
DSIGKeyInfo::KEYINFO_MGMTDATA;}
  
        //@}
  
  private:
  
        DSIGKeyInfoMgmtData();                                          // 
Non-implemented constructor
  
        const XMLCh                     * mp_data;                              
// The Data stored in the XML file
        DOMNode                         * mp_dataTextNode;              // Text 
node containing the name
  
  };
  
  
  
  #endif /* #define DSIGKEYINFOMGMTDATA_INCLUDE */
  
  
  
  
  1.13      +27 -1     xml-security/c/src/tools/xtest/xtest.cpp
  
  Index: xtest.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/tools/xtest/xtest.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- xtest.cpp 27 May 2003 12:06:07 -0000      1.12
  +++ xtest.cpp 28 May 2003 10:56:48 -0000      1.13
  @@ -121,6 +121,7 @@
   #include <xsec/dsig/DSIGKeyInfoName.hpp>
   #include <xsec/dsig/DSIGKeyInfoPGPData.hpp>
   #include <xsec/dsig/DSIGKeyInfoSPKIData.hpp>
  +#include <xsec/dsig/DSIGKeyInfoMgmtData.hpp>
   
   #if defined (HAVE_OPENSSL)
   #    include <xsec/enc/OpenSSL/OpenSSLCryptoKeyHMAC.hpp>
  @@ -225,6 +226,14 @@
        chLatin_S, chLatin_e, chLatin_x, chLatin_p, chDigit_2, chNull
   };
   
  +XMLCh s_tstMgmtData[] = {
  +
  +     chLatin_D, chLatin_u, chLatin_m, chLatin_m, chLatin_y, chSpace,
  +     chLatin_M, chLatin_g, chLatin_m, chLatin_t, chSpace,
  +     chLatin_D, chLatin_a, chLatin_t, chLatin_a, chNull
  +
  +};
  +
   // 
--------------------------------------------------------------------------------
   //           Create a key
   // 
--------------------------------------------------------------------------------
  @@ -436,6 +445,9 @@
                DSIGKeyInfoSPKIData * spki = sig->appendSPKIData(s_tstSexp1);
                spki->appendSexp(s_tstSexp2);
   
  +             // Append a MgmtData element
  +             sig->appendMgmtData(s_tstMgmtData);
  +
                sig->setSigningKey(createHMACKey((unsigned char *) "secret"));
                sig->sign();
   
  @@ -629,6 +641,20 @@
   
                                if (!(strEquals(s->getSexp(0), s_tstSexp1) &&
                                        strEquals(s->getSexp(1), s_tstSexp2))) {
  +
  +                                     cerr << "no!";
  +                                     exit(1);
  +                             }
  +
  +                             cerr << "yes\n";
  +                     }
  +                     if (kil->item(i)->getKeyInfoType() == 
DSIGKeyInfo::KEYINFO_MGMTDATA) {
  +                             
  +                             cerr << "Validating MgmtData read back OK ... ";
  +
  +                             DSIGKeyInfoMgmtData * m = (DSIGKeyInfoMgmtData 
*)kil->item(i);
  +
  +                             if (!strEquals(m->getData(), s_tstMgmtData)) {
   
                                        cerr << "no!";
                                        exit(1);
  
  
  

Reply via email to