blautenb    2003/05/22 04:17:41

  Modified:    c/src/dsig DSIGConstants.cpp DSIGKeyInfoName.cpp
                        DSIGKeyInfoName.hpp DSIGKeyInfoValue.hpp
                        DSIGKeyInfoX509.cpp DSIGKeyInfoX509.hpp
                        DSIGSignature.cpp DSIGSignature.hpp
               c/src/framework XSECError.cpp XSECException.hpp
               c/src/utils XSECDOMUtils.cpp XSECDOMUtils.hpp
  Log:
  Added support for encoding and decoding of DNames
  
  Revision  Changes    Path
  1.9       +28 -28    xml-security/c/src/dsig/DSIGConstants.cpp
  
  Index: DSIGConstants.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGConstants.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DSIGConstants.cpp 19 May 2003 12:30:59 -0000      1.8
  +++ DSIGConstants.cpp 22 May 2003 11:17:40 -0000      1.9
  @@ -145,33 +145,33 @@
   void DSIGConstants::destroy() {
   
        // Delete the static strings
  -     delete[] s_unicodeStrEmpty;
  -     delete[] s_unicodeStrNL;
  -     delete[] s_unicodeStrXmlns;
  +     delete[] (XMLCh *) s_unicodeStrEmpty;
  +     delete[] (XMLCh *) s_unicodeStrNL;
  +     delete[] (XMLCh *) s_unicodeStrXmlns;
   
  -     delete[] s_unicodeStrAlgorithm;
  +     delete[] (XMLCh *) s_unicodeStrAlgorithm;
   
  -     delete[] s_unicodeStrURIRawX509;
  -     delete[] s_unicodeStrURIDSIG;
  -     delete[] s_unicodeStrURIEC;
  -     delete[] s_unicodeStrURIXPF;
  -     delete[] s_unicodeStrURISHA1;
  -     delete[] s_unicodeStrURIMD5;
  -     delete[] s_unicodeStrURIBASE64;
  -     delete[] s_unicodeStrURIXPATH;
  -     delete[] s_unicodeStrURIXSLT;
  -     delete[] s_unicodeStrURIENVELOPE;
  -     delete[] s_unicodeStrURIC14N_NOC;
  -     delete[] s_unicodeStrURIC14N_COM;
  -     delete[] s_unicodeStrURIEXC_C14N_NOC;
  -     delete[] s_unicodeStrURIEXC_C14N_COM;
  -     delete[] s_unicodeStrURIDSA_SHA1;
  -     delete[] s_unicodeStrURIRSA_SHA1;
  -     delete[] s_unicodeStrURIHMAC_SHA1;
  -     delete[] s_unicodeStrURIXMLNS;
  -     delete[] s_unicodeStrURIMANIFEST;
  +     delete[] (XMLCh *) s_unicodeStrURIRawX509;
  +     delete[] (XMLCh *) s_unicodeStrURIDSIG;
  +     delete[] (XMLCh *) s_unicodeStrURIEC;
  +     delete[] (XMLCh *) s_unicodeStrURIXPF;
  +     delete[] (XMLCh *) s_unicodeStrURISHA1;
  +     delete[] (XMLCh *) s_unicodeStrURIMD5;
  +     delete[] (XMLCh *) s_unicodeStrURIBASE64;
  +     delete[] (XMLCh *) s_unicodeStrURIXPATH;
  +     delete[] (XMLCh *) s_unicodeStrURIXSLT;
  +     delete[] (XMLCh *) s_unicodeStrURIENVELOPE;
  +     delete[] (XMLCh *) s_unicodeStrURIC14N_NOC;
  +     delete[] (XMLCh *) s_unicodeStrURIC14N_COM;
  +     delete[] (XMLCh *) s_unicodeStrURIEXC_C14N_NOC;
  +     delete[] (XMLCh *) s_unicodeStrURIEXC_C14N_COM;
  +     delete[] (XMLCh *) s_unicodeStrURIDSA_SHA1;
  +     delete[] (XMLCh *) s_unicodeStrURIRSA_SHA1;
  +     delete[] (XMLCh *) s_unicodeStrURIHMAC_SHA1;
  +     delete[] (XMLCh *) s_unicodeStrURIXMLNS;
  +     delete[] (XMLCh *) s_unicodeStrURIMANIFEST;
   
  -     delete[] s_unicodeStrPROVOpenSSL;
  -     delete[] s_unicodeStrPROVWinCAPI;
  +     delete[] (XMLCh *) s_unicodeStrPROVOpenSSL;
  +     delete[] (XMLCh *) s_unicodeStrPROVWinCAPI;
   
   }
  
  
  
  1.3       +67 -7     xml-security/c/src/dsig/DSIGKeyInfoName.cpp
  
  Index: DSIGKeyInfoName.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGKeyInfoName.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DSIGKeyInfoName.cpp       9 Feb 2003 11:13:47 -0000       1.2
  +++ DSIGKeyInfoName.cpp       22 May 2003 11:17:40 -0000      1.3
  @@ -64,9 +64,7 @@
    *
    * Author(s): Berin Lautenbach
    *
  - * $ID$
  - *
  - * $LOG$
  + * $Id$
    *
    */
   
  @@ -76,6 +74,10 @@
   #include <xsec/utils/XSECDOMUtils.hpp>
   #include <xsec/dsig/DSIGSignature.hpp>
   
  +#include <xercesc/util/Janitor.hpp>
  +
  +XSEC_USING_XERCES(ArrayJanitor);
  +
   // 
--------------------------------------------------------------------------------
   //           Constructors and Destructors
   // 
--------------------------------------------------------------------------------
  @@ -84,6 +86,7 @@
   DSIGKeyInfoName::DSIGKeyInfoName(DSIGSignature *sig, DOMNode *nameNode) : 
   DSIGKeyInfo(sig),
   mp_name(NULL),
  +mp_decodedDName(NULL),
   mp_keyNameTextNode(0) {
   
        mp_keyInfoDOMNode = nameNode;
  @@ -94,6 +97,7 @@
   DSIGKeyInfoName::DSIGKeyInfoName(DSIGSignature *sig) : 
   DSIGKeyInfo(sig),
   mp_name(NULL),
  +mp_decodedDName(NULL),
   mp_keyNameTextNode(0) {
   
        mp_keyInfoDOMNode = 0;
  @@ -103,6 +107,9 @@
   
   DSIGKeyInfoName::~DSIGKeyInfoName() {
   
  +     if (mp_decodedDName != NULL)
  +             delete[] mp_decodedDName;
  +
   };
   
   // 
--------------------------------------------------------------------------------
  @@ -151,11 +158,23 @@
   
   }
   
  +const XMLCh * DSIGKeyInfoName::getDecodedKeyName(void) {
  +
  +     if (mp_decodedDName == NULL) {
  +
  +             mp_decodedDName = decodeDName(mp_name);
  +
  +     }
  +
  +     return mp_decodedDName;
  +
  +}
  +
   // 
--------------------------------------------------------------------------------
   //           Create and Set functions
   // 
--------------------------------------------------------------------------------
   
  -DOMElement * DSIGKeyInfoName::createBlankKeyName(const XMLCh * name) {
  +DOMElement * DSIGKeyInfoName::createBlankKeyName(const XMLCh * name, bool 
isDName) {
   
        // Create the DOM Structure
   
  @@ -167,7 +186,23 @@
   
        DOMElement *ret = 
doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
        mp_keyInfoDOMNode = ret;
  -     mp_keyNameTextNode = doc->createTextNode(name);
  +
  +     // Check whether to encode prior to adding
  +     if (isDName == true) {
  +
  +             // Treat as a distinguished name
  +
  +             mp_decodedDName = XMLString::replicate(name);
  +             XMLCh * encodedName = encodeDName(name);
  +             ArrayJanitor<XMLCh> j_encodedName(encodedName);
  +
  +             mp_keyNameTextNode = doc->createTextNode(encodedName);
  +
  +     }
  +
  +     else
  +             mp_keyNameTextNode = doc->createTextNode(name);
  +
        ret->appendChild(mp_keyNameTextNode);
   
        mp_name = mp_keyNameTextNode->getNodeValue();
  @@ -176,7 +211,7 @@
   
   }
   
  -void DSIGKeyInfoName::setKeyName(const XMLCh * name) {
  +void DSIGKeyInfoName::setKeyName(const XMLCh * name, bool isDName) {
   
        if (mp_keyNameTextNode == 0) {
   
  @@ -186,7 +221,32 @@
   
        }
   
  -     mp_keyNameTextNode->setNodeValue(name);
  +     if (mp_decodedDName != NULL) {
  +
  +             delete[] mp_decodedDName;
  +             mp_decodedDName = NULL;
  +
  +     }
  +
  +     if (isDName == true) {
  +
  +             // This name should be treated as a Distinguished Name - so do 
the
  +             // required encoding
  +
  +             mp_decodedDName = XMLString::replicate(name);
  +             XMLCh * encodedName = encodeDName(name);
  +             ArrayJanitor<XMLCh> j_encodedName(encodedName);
  +
  +             mp_keyNameTextNode->setNodeValue(encodedName);
  +
  +     }
  +
  +     else {
  +
  +             mp_keyNameTextNode->setNodeValue(name);
  +
  +     }
  +
        mp_name = mp_keyNameTextNode->getNodeValue();
   
   }
  
  
  
  1.3       +18 -2     xml-security/c/src/dsig/DSIGKeyInfoName.hpp
  
  Index: DSIGKeyInfoName.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGKeyInfoName.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DSIGKeyInfoName.hpp       9 Feb 2003 11:13:47 -0000       1.2
  +++ DSIGKeyInfoName.hpp       22 May 2003 11:17:40 -0000      1.3
  @@ -153,6 +153,17 @@
   
        virtual const XMLCh * getKeyName(void) {return mp_name;};
   
  +     /**
  +      * \brief Get the decoded key name (for distinguished names)
  +      *
  +      * Returns a pointer to the buffer containing the decoded Distinguished
  +      * Name.
  +      *
  +      * @returns A pointer to the char buffer containing the key name
  +      */
  +
  +     virtual const XMLCh * getDecodedKeyName(void);
  +
        //@}
   
        /[EMAIL PROTECTED] Create and set functions */
  @@ -165,10 +176,12 @@
         * passed in.
         *
         * @param name Value to set the KeyName as
  +      * @param isDName If set to true, the name will be encoded as a DName
  +      * prior to be being placed in the DOM document
         * @returns The newly created DOMElement with the structure underneath.
         */
   
  -     DOMElement * createBlankKeyName(const XMLCh * name);
  +     DOMElement * createBlankKeyName(const XMLCh * name, bool isDName = 
false);
   
        /**
         * \brief Set the value of the KeyName to a new string.
  @@ -176,9 +189,11 @@
         * Uses the passed in string to set a new value in the DOM structure.
         *
         * @param name Value to set in KeyName
  +      * @param isDName If set to true, the name will be encoded as a DName
  +      * prior to be being placed in the DOM document
         */
   
  -     void setKeyName(const XMLCh * name);
  +     void setKeyName(const XMLCh * name, bool isDName = false);
   
        //@}
   
  @@ -198,6 +213,7 @@
        DSIGKeyInfoName();                                                      
// Non-implemented constructor
   
        const XMLCh                     * mp_name;                              
// The Data stored in the XML file
  +     XMLCh                           * mp_decodedDName;              // When 
this is a DName that needs decoding
        DOMNode                         * mp_keyNameTextNode;   // Text node 
containing the name
   
   };
  
  
  
  1.3       +13 -3     xml-security/c/src/dsig/DSIGKeyInfoValue.hpp
  
  Index: DSIGKeyInfoValue.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGKeyInfoValue.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DSIGKeyInfoValue.hpp      9 Feb 2003 11:13:47 -0000       1.2
  +++ DSIGKeyInfoValue.hpp      22 May 2003 11:17:40 -0000      1.3
  @@ -64,9 +64,7 @@
    *
    * Author(s): Berin Lautenbach
    *
  - * $ID$
  - *
  - * $LOG$
  + * $Id$
    *
    */
   
  @@ -90,6 +88,18 @@
    * Class for holding information on a KeyValue node as well as setting
    * such a node in a signature.
    *
  + * Two types of Value are understood - RSA and DSA.
  + *
  + * RSA values are fully implemented as per XML-DSig.  They have two 
parameters
  + *
  + * <ul>
  + * <li><em>Modulus</em> - holds the modulus of this public key; and</li>
  + * <li><em>Exponent</em> - holds the exponent.</li>
  + * </ul>
  + *
  + * DSA values have all mandatory parts implemented  - P, Q, G and Y.
  + *
  + * J, Seed and PgenCounter are not currently implemented.
    */
   
   
  
  
  
  1.6       +36 -13    xml-security/c/src/dsig/DSIGKeyInfoX509.cpp
  
  Index: DSIGKeyInfoX509.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGKeyInfoX509.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DSIGKeyInfoX509.cpp       18 May 2003 11:00:02 -0000      1.5
  +++ DSIGKeyInfoX509.cpp       22 May 2003 11:17:40 -0000      1.6
  @@ -75,6 +75,10 @@
   #include <xsec/utils/XSECDOMUtils.hpp>
   #include <xsec/dsig/DSIGSignature.hpp>
   
  +#include <xercesc/util/Janitor.hpp>
  +
  +XSEC_USING_XERCES(ArrayJanitor);
  +
   // 
--------------------------------------------------------------------------------
   //           Constructors and Destructors
   // 
--------------------------------------------------------------------------------
  @@ -121,6 +125,15 @@
   
   DSIGKeyInfoX509::~DSIGKeyInfoX509() {
   
  +     // SubjectName and IssuerName are local (decoded) copies of the
  +     // encoded DName held in the DOM
  +
  +     if (mp_X509IssuerName != NULL)
  +             delete[] mp_X509IssuerName;
  +
  +     if (mp_X509SubjectName != NULL)
  +             delete[] mp_X509SubjectName;
  +
        X509ListType::iterator i;
   
        for (i = m_X509List.begin(); i != m_X509List.end(); ++i) {
  @@ -202,7 +215,7 @@
   
                                }
   
  -                             mp_X509SubjectName = child->getNodeValue();
  +                             mp_X509SubjectName = 
decodeDName(child->getNodeValue());
   
                        }
   
  @@ -231,7 +244,7 @@
   
                                }
   
  -                             mp_X509IssuerName = child->getNodeValue();
  +                             mp_X509IssuerName = 
decodeDName(child->getNodeValue());
   
                                // Now find the serial number
                                child = tmpElt->getFirstChild();
  @@ -447,6 +460,14 @@
   
   void DSIGKeyInfoX509::setX509SubjectName(const XMLCh * name) {
   
  +     if (mp_X509SubjectName != NULL)
  +             delete[] mp_X509SubjectName;
  +
  +     mp_X509SubjectName = XMLString::replicate(name);
  +     
  +     XMLCh * encodedName = encodeDName(name);
  +     ArrayJanitor<XMLCh> j_encodedName(encodedName);
  +
        if (mp_X509SubjectNameTextNode == 0) {
   
                // Does not yet exist in the DOM
  @@ -458,7 +479,7 @@
                makeQName(str, prefix, "X509SubjectName");
   
                DOMElement * s = 
doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG, str.rawXMLChBuffer());
  -             mp_X509SubjectNameTextNode = doc->createTextNode(name);
  +             mp_X509SubjectNameTextNode = doc->createTextNode(encodedName);
                s->appendChild(mp_X509SubjectNameTextNode);
   
                // Add to the over-arching node
  @@ -469,16 +490,21 @@
   
        else {
   
  -             mp_X509SubjectNameTextNode->setNodeValue(name);
  +             mp_X509SubjectNameTextNode->setNodeValue(encodedName);
   
        }
  -
  -     mp_X509SubjectName = mp_X509SubjectNameTextNode->getNodeValue();
  -
   }
   
   void DSIGKeyInfoX509::setX509IssuerSerial(const XMLCh * name, const XMLCh * 
serial) {
   
  +     if (mp_X509IssuerName != NULL)
  +             delete[] mp_X509IssuerName;
  +
  +     mp_X509IssuerName = XMLString::replicate(name);
  +     
  +     XMLCh * encodedName = encodeDName(name);
  +     ArrayJanitor<XMLCh> j_encodedName(encodedName);
  +
        if (mp_X509IssuerNameTextNode == 0) {
   
                // Does not yet exist in the DOM
  @@ -494,7 +520,7 @@
   
                // Create the text nodes with the contents
   
  -             mp_X509IssuerNameTextNode = doc->createTextNode(name);
  +             mp_X509IssuerNameTextNode = doc->createTextNode(encodedName);
                mp_X509SerialNumberTextNode = doc->createTextNode(serial);
        
                // Create the sub elements
  @@ -522,13 +548,10 @@
   
        else {
   
  -             mp_X509IssuerNameTextNode->setNodeValue(name);
  +             mp_X509IssuerNameTextNode->setNodeValue(encodedName);
                mp_X509SerialNumberTextNode->setNodeValue(serial);
   
        }
  -
  -     mp_X509IssuerName = mp_X509IssuerNameTextNode->getNodeValue();
  -     mp_X509SerialNumber = mp_X509SerialNumberTextNode->getNodeValue();
   
   }
   
  
  
  
  1.4       +15 -4     xml-security/c/src/dsig/DSIGKeyInfoX509.hpp
  
  Index: DSIGKeyInfoX509.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/dsig/DSIGKeyInfoX509.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DSIGKeyInfoX509.hpp       18 May 2003 11:00:02 -0000      1.3
  +++ DSIGKeyInfoX509.hpp       22 May 2003 11:17:40 -0000      1.4
  @@ -183,7 +183,9 @@
         * Get the name stored in the X509SubjectName element (if it
         * exists).
         *
  -      * @returns A pointer to the buffer containing the name (or NULL if not 
set)
  +      * @returns A pointer to the buffer containing the name (or NULL if not 
set).
  +      * The decoded string is returned.
  +      * @see setX509SubjectName(void)
         */
   
        const XMLCh * getKeyName(void);
  @@ -206,7 +208,8 @@
         * signing certificate.
         * 
         * @returns A pointer to the string containing the IssuerSerialNumber.
  -      * (0 if not set.)
  +      * (0 if not set.)  This is the decoded string.
  +      * @see setX509IssuerSerial
         */
   
        const XMLCh * getX509IssuerSerialNumber(void);
  @@ -295,6 +298,10 @@
         * If a X509SubjectName element exists, replace the text with the
         * provided text.  Otherwise create the element and set the text.
         *
  +      * @note XMLDSIG requires Distinguished Names be encoded in a defined
  +      * manner (escaping '<' characters etc.).  This method will perform
  +      * this encoding prior to creating the DOM nodes.
  +      *
         * @param name The name to set.
         */
   
  @@ -306,6 +313,10 @@
         * If an X509IssuerSerial exists, replace the values with those 
provided,
         * otherwise create a new element and set the values appropriately.
         *
  +      * @note XMLDSIG requires Distinguished Names be encoded in a defined
  +      * manner (escaping '<' characters etc.).  This method will perform
  +      * this encoding prior to creating the DOM nodes.
  +      *
         * @param name The name of the issuer.
         * @param serial The serial number of the issuer's certificate
         */
  @@ -369,9 +380,9 @@
        DSIGKeyInfoX509();
   
        X509ListType            m_X509List;                             // The 
X509 structures
  -     const XMLCh             * mp_X509IssuerName;    // Parameters from 
KeyInfo (not cert)
  +     XMLCh                           * mp_X509IssuerName;    // Parameters 
from KeyInfo (not cert)
        const XMLCh             * mp_X509SerialNumber;
  -     const XMLCh             * mp_X509SubjectName;
  +     XMLCh                           * mp_X509SubjectName;
        const XMLCh                     * mp_X509CRL;
        const XMLCh                     * mp_X509SKI;
        XMLCh                           * mp_rawRetrievalURI;
  
  
  
  1.14      +3 -3      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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DSIGSignature.cpp 18 May 2003 11:00:02 -0000      1.13
  +++ DSIGSignature.cpp 22 May 2003 11:17:40 -0000      1.14
  @@ -681,7 +681,7 @@
   
   }
   
  -DSIGKeyInfoName * DSIGSignature::appendKeyName(const XMLCh * name) {
  +DSIGKeyInfoName * DSIGSignature::appendKeyName(const XMLCh * name, bool 
isDName) {
   
        createKeyInfoElement();
   
  @@ -689,7 +689,7 @@
   
        XSECnew(n, DSIGKeyInfoName(this));
   
  -     mp_KeyInfoNode->appendChild(n->createBlankKeyName(name));
  +     mp_KeyInfoNode->appendChild(n->createBlankKeyName(name, isDName));
        
mp_KeyInfoNode->appendChild(mp_doc->createTextNode(DSIGConstants::s_unicodeStrNL));
   
        // Add to the list
  
  
  
  1.9       +3 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DSIGSignature.hpp 8 May 2003 12:10:58 -0000       1.8
  +++ DSIGSignature.hpp 22 May 2003 11:17:40 -0000      1.9
  @@ -619,10 +619,11 @@
         * Add a new KeyInfo element for a key name.
         *
         * @param name The name of the key to set in the XML
  +      * @param isDName Treat the name as a Distinguished name and encode 
accordingly
         * @returns A pointer to the created object
         */
   
  -     DSIGKeyInfoName * appendKeyName(const XMLCh * name);
  +     DSIGKeyInfoName * appendKeyName(const XMLCh * name, bool isDName = 
false);
   
        //@}
   
  
  
  
  1.4       +1 -0      xml-security/c/src/framework/XSECError.cpp
  
  Index: XSECError.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/framework/XSECError.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XSECError.cpp     12 Feb 2003 11:21:03 -0000      1.3
  +++ XSECError.cpp     22 May 2003 11:17:41 -0000      1.4
  @@ -115,6 +115,7 @@
        "An error occured in a DSIGTransform holder",
        "An error occured in a safe buffer",
        "An error occurred processing an HTTP request via internal resolver",
  +     "An error occurred decoding a DSIG encoded Distinguished name",
        "Unknown Error type",
   
   };
  
  
  
  1.7       +3 -2      xml-security/c/src/framework/XSECException.hpp
  
  Index: XSECException.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/framework/XSECException.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSECException.hpp 8 May 2003 12:10:58 -0000       1.6
  +++ XSECException.hpp 22 May 2003 11:17:41 -0000      1.7
  @@ -142,7 +142,8 @@
                HTTPURIInputStreamError     = 38,
                LoadEmptyXPathFilter            = 39,
                XPathFilterError                        = 40,
  -             UnknownError                            = 41            // Must 
be last!
  +             DNameDecodeError                        = 41,
  +             UnknownError                            = 42            // Must 
be last!
   
        };
   
  
  
  
  1.7       +243 -0    xml-security/c/src/utils/XSECDOMUtils.cpp
  
  Index: XSECDOMUtils.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSECDOMUtils.cpp  8 May 2003 12:10:59 -0000       1.6
  +++ XSECDOMUtils.cpp  22 May 2003 11:17:41 -0000      1.7
  @@ -73,6 +73,7 @@
   // XSEC
   
   #include <xsec/utils/XSECDOMUtils.hpp>
  +#include <xsec/framework/XSECError.hpp>
   
   // Xerces
   
  @@ -238,3 +239,245 @@
        }
   
   }
  +
  +// 
--------------------------------------------------------------------------------
  +//           String decode/encode
  +// 
--------------------------------------------------------------------------------
  +
  +/*
  + * Distinguished names have a particular encoding that needs to be performed 
prior
  + * to enclusion in the DOM
  + */
  +
  +XMLCh * encodeDName(const XMLCh * toEncode) {
  +
  +     XERCES_CPP_NAMESPACE_USE;
  +
  +     safeBuffer result;
  +
  +     static XMLCh s_strEncodedSpace[] = {
  +             chBackSlash,
  +             chDigit_2,
  +             chDigit_0,
  +             chNull
  +     };
  +
  +     result.sbXMLChIn(DSIGConstants::s_unicodeStrEmpty);
  +
  +     if (toEncode == NULL) {
  +             return NULL;
  +     }
  +
  +     
  +     // Find where the trailing whitespace starts
  +     const XMLCh * ws = &toEncode[XMLString::stringLen(toEncode)];
  +     
  +     *ws--;
  +     while (ws != toEncode && 
  +             (*ws == '\t' || *ws == '\r' || *ws ==' ' || *ws == '\n'))
  +             *ws--;
  +
  +     // Set to first white space character, if we didn't get back to the 
start
  +     if (toEncode != ws)
  +             *ws++;
  +
  +     // Now run through each character and encode if necessary
  +
  +     const XMLCh * i = toEncode;
  +
  +     if (*i == chPound) {
  +             // "#" Characters escaped at the start of a string
  +             result.sbXMLChAppendCh(chBackSlash);
  +     }
  +
  +     while (*i != chNull && i != ws) {
  +
  +             if (*i <= 0x09) {
  +                     result.sbXMLChAppendCh(chBackSlash);
  +                     result.sbXMLChAppendCh(chDigit_0);
  +                     result.sbXMLChAppendCh(chDigit_0 + *i);
  +             }
  +             else if (*i <= 0x0f) {
  +                     result.sbXMLChAppendCh(chBackSlash);
  +                     result.sbXMLChAppendCh(chDigit_0);
  +                     result.sbXMLChAppendCh(chLatin_A + *i);
  +             }
  +             else if (*i <= 0x19) {
  +                     result.sbXMLChAppendCh(chBackSlash);
  +                     result.sbXMLChAppendCh(chDigit_1);
  +                     result.sbXMLChAppendCh(chDigit_0 + *i);
  +             }
  +             else if (*i <= 0x1f) {
  +                     result.sbXMLChAppendCh(chBackSlash);
  +                     result.sbXMLChAppendCh(chDigit_1);
  +                     result.sbXMLChAppendCh(chLatin_A + *i);
  +             }
  +
  +             else if (*i == chComma) {
  +
  +                     // Determine if this is an RDN separator
  +                     const XMLCh *j = i;
  +                     *j++;
  +                     while (*j != chComma && *j != chEqual && *j != chNull)
  +                             *j++;
  +
  +                     if (*j != chEqual)
  +                             result.sbXMLChAppendCh(chBackSlash);
  +
  +                     result.sbXMLChAppendCh(*i);
  +
  +             }
  +
  +             else {
  +                     
  +                     if (*i == chPlus ||
  +                             *i == chDoubleQuote ||
  +                             *i == chBackSlash ||
  +                             *i == chOpenAngle ||
  +                             *i == chCloseAngle ||
  +                             *i == chSemiColon) {
  +
  +                             result.sbXMLChAppendCh(chBackSlash);
  +                     }
  +
  +                     result.sbXMLChAppendCh(*i);
  +
  +             }
  +
  +             *i++;
  +
  +     }
  +
  +     // Now encode trailing white space
  +     while (*i != NULL) {
  +
  +             if (*i == ' ')
  +                     result.sbXMLChCat(s_strEncodedSpace);
  +             else
  +                     result.sbXMLChAppendCh(*i);
  +
  +             *i++;
  +
  +     }
  +
  +     return XMLString::replicate(result.rawXMLChBuffer());
  +
  +}
  +
  +XMLCh * decodeDName(const XMLCh * toDecode) {
  +
  +     // Take an encoded name and decode to a normal XMLCh string
  +
  +     XERCES_CPP_NAMESPACE_USE;
  +
  +     safeBuffer result;
  +
  +     result.sbXMLChIn(DSIGConstants::s_unicodeStrEmpty);
  +
  +     if (toDecode == NULL) {
  +             return NULL;
  +     }
  +
  +     const XMLCh * i = toDecode;
  +
  +     if (*i == chBackSlash && i[1] == chPound) {
  +
  +             result.sbXMLChAppendCh(chPound);
  +             *i++;
  +             *i++;
  +
  +     }
  +
  +     while (*i != chNull) {
  +
  +             if (*i == chBackSlash) {
  +
  +                     *i++;
  +                     
  +                     if (*i == chDigit_0) {
  +
  +                             *i++;
  +
  +                             if (*i >= chDigit_0 && *i <= chDigit_9) {
  +                                     result.sbXMLChAppendCh(*i - chDigit_0);
  +                             }
  +                             else if (*i >= chLatin_A && *i <= chLatin_F) {
  +                                     result.sbXMLChAppendCh(10 + *i - 
chLatin_A);
  +                             }
  +                             else if (*i >= chLatin_a && *i <= chLatin_f) {
  +                                     result.sbXMLChAppendCh(10 + *i - 
chLatin_a);
  +                             }
  +                             else {
  +                                     throw 
XSECException(XSECException::DNameDecodeError,
  +                                             "Unexpected escaped character 
in Distinguished name");
  +                             }
  +                     }
  +
  +                     else if (*i == chDigit_1) {
  +
  +                             *i++;
  +
  +                             if (*i >= chDigit_0 && *i <= chDigit_9) {
  +                                     result.sbXMLChAppendCh(16 + *i - 
chDigit_0);
  +                             }
  +                             else if (*i >= chLatin_A && *i <= chLatin_F) {
  +                                     result.sbXMLChAppendCh(26 + *i - 
chLatin_A);
  +                             }
  +                             else if (*i >= chLatin_a && *i <= chLatin_f) {
  +                                     result.sbXMLChAppendCh(26 + *i - 
chLatin_a);
  +                             }
  +                             else {
  +                                     throw 
XSECException(XSECException::DNameDecodeError,
  +                                             "Unexpected escaped character 
in Distinguished name");
  +                             }
  +                     }
  +
  +                     else if (*i == chDigit_2) {
  +
  +                             *i++;
  +
  +                             if (*i == '0') {
  +                                     result.sbXMLChAppendCh(' ');
  +                             }
  +
  +                             else {
  +                                     throw 
XSECException(XSECException::DNameDecodeError,
  +                                             "Unexpected escaped character 
in Distinguished name");
  +                             }
  +
  +                     }
  +
  +                     else if (*i == chComma ||
  +                                      *i == chPlus ||
  +                                      *i == chDoubleQuote ||
  +                                      *i == chBackSlash ||
  +                                      *i == chOpenAngle ||
  +                                      *i == chCloseAngle ||
  +                                      *i == chSemiColon) {
  +
  +                             result.sbXMLChAppendCh(*i);
  +                     }
  +
  +                     else {
  +
  +                             throw 
XSECException(XSECException::DNameDecodeError,
  +                                     "Unexpected escaped character in 
Distinguished name");
  +
  +                     }
  +
  +                     *i++;
  +
  +             }
  +
  +             else {
  +
  +                     result.sbXMLChAppendCh(*i++);
  +
  +             }
  +
  +     }
  +
  +     return XMLString::replicate(result.rawXMLChBuffer());
  +
  +}
  +
  
  
  
  1.7       +13 -1     xml-security/c/src/utils/XSECDOMUtils.hpp
  
  Index: XSECDOMUtils.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/XSECDOMUtils.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSECDOMUtils.hpp  8 May 2003 12:10:59 -0000       1.6
  +++ XSECDOMUtils.hpp  22 May 2003 11:17:41 -0000      1.7
  @@ -144,6 +144,18 @@
   void DSIG_EXPORT gatherChildrenText(DOMNode * parent, safeBuffer &output);
   
   // 
--------------------------------------------------------------------------------
  +//           String decode/encode
  +// 
--------------------------------------------------------------------------------
  +
  +/*
  + * Distinguished names have a particular encoding that needs to be performed 
prior
  + * to enclusion in the DOM
  + */
  +
  +XMLCh * encodeDName(const XMLCh * toEncode);
  +XMLCh * decodeDName(const XMLCh * toDecode);
  +
  +// 
--------------------------------------------------------------------------------
   //           String Functions 
   // 
--------------------------------------------------------------------------------
   
  
  
  

Reply via email to