You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2010/10/25 18:58:42 UTC

svn commit: r1027194 - in /santuario/trunk/c/xsec/dsig: DSIGKeyInfoX509.cpp DSIGKeyInfoX509.hpp

Author: scantor
Date: Mon Oct 25 16:58:41 2010
New Revision: 1027194

URL: http://svn.apache.org/viewvc?rev=1027194&view=rev
Log:
Add X509Digest.

Modified:
    santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.cpp
    santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.hpp

Modified: santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.cpp
URL: http://svn.apache.org/viewvc/santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.cpp?rev=1027194&r1=1027193&r2=1027194&view=diff
==============================================================================
--- santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.cpp (original)
+++ santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.cpp Mon Oct 25 16:58:41 2010
@@ -50,7 +50,8 @@ mp_rawRetrievalURI(NULL),
 mp_X509SubjectNameTextNode(0),
 mp_X509IssuerNameTextNode(0),
 mp_X509SerialNumberTextNode(0),
-mp_X509SKITextNode(0) {
+mp_X509SKITextNode(0),
+mp_X509DigestTextNode(0) {
 
 	mp_keyInfoDOMNode = X509Data;
 	m_X509List.clear();
@@ -67,7 +68,8 @@ mp_rawRetrievalURI(NULL),
 mp_X509SubjectNameTextNode(0),
 mp_X509IssuerNameTextNode(0),
 mp_X509SerialNumberTextNode(0),
-mp_X509SKITextNode(0) {
+mp_X509SKITextNode(0),
+mp_X509DigestTextNode(0){
 
 	mp_keyInfoDOMNode = 0;
 	m_X509List.clear();
@@ -267,6 +269,20 @@ void DSIGKeyInfoX509::load(void) {
 				mp_X509SKI = child->getNodeValue();
 
 			}
+            else if (strEquals(getDSIG11LocalName(tmpElt), "X509Digest")) {
+
+                child = findFirstChildOfType(tmpElt, DOMNode::TEXT_NODE);
+
+                if (child == NULL) {
+
+                    throw XSECException(XSECException::ExpectedDSIGChildNotFound,
+                        "Expected TEXT_NODE child of <X509Digest>");
+
+                }
+
+                mp_X509DigestTextNode = child;
+
+            }
 		}
 
 		// Go to next data element to load if we understand
@@ -292,12 +308,32 @@ const XMLCh * DSIGKeyInfoX509::getX509Su
 
 }
 
+const XMLCh * DSIGKeyInfoX509::getX509DigestAlgorithm(void) const {
+
+    return mp_X509DigestTextNode ?
+        static_cast<DOMElement*>(mp_X509DigestTextNode->getParentNode())->getAttributeNS(NULL, DSIGConstants::s_unicodeStrAlgorithm) :
+            NULL;
+
+}
+
+const XMLCh * DSIGKeyInfoX509::getX509DigestValue(void) const {
+
+    return mp_X509DigestTextNode ? mp_X509DigestTextNode->getNodeValue() : NULL;
+
+}
+
 const XMLCh * DSIGKeyInfoX509::getX509IssuerName(void) const {
 
 	return mp_X509IssuerName;
 
 }
 
+const XMLCh * DSIGKeyInfoX509::getX509IssuerSerialNumber(void) const {
+
+    return mp_X509SerialNumber;
+
+}
+
 const XMLCh * DSIGKeyInfoX509::getX509CRL(void) const {
 
 	return m_X509CRLList.empty() ? NULL : m_X509CRLList.front();
@@ -326,12 +362,6 @@ const XMLCh * DSIGKeyInfoX509::getX509SK
 
 }
 
-const XMLCh * DSIGKeyInfoX509::getX509IssuerSerialNumber(void) const {
-
-	return mp_X509SerialNumber;
-
-}
-
 int DSIGKeyInfoX509::getCertificateListSize(void) const {
 
 	return (int) m_X509List.size();
@@ -542,6 +572,44 @@ void DSIGKeyInfoX509::setX509IssuerSeria
 	XSEC_RELEASE_XMLCH(encodedName);
 }
 
+void DSIGKeyInfoX509::setX509Digest(const XMLCh * algorithm, const XMLCh * value) {
+
+    if (mp_X509DigestTextNode == 0) {
+
+        // Does not yet exist in the DOM
+
+        safeBuffer str;
+        DOMDocument *doc = mp_env->getParentDocument();
+        const XMLCh * prefix = mp_env->getDSIG11NSPrefix();
+
+        makeQName(str, prefix, "X509Digest");
+
+        DOMElement * s = doc->createElementNS(DSIGConstants::s_unicodeStrURIDSIG11, str.rawXMLChBuffer());
+        s->setAttributeNS(NULL, DSIGConstants::s_unicodeStrAlgorithm, algorithm);
+
+        // Create the text node with the contents
+
+        mp_X509DigestTextNode = doc->createTextNode(value);
+        s->appendChild(mp_X509DigestTextNode);
+
+        mp_env->doPrettyPrint(s);
+
+        // Add to the over-arching X509Data
+
+        mp_keyInfoDOMNode->appendChild(s);
+        mp_env->doPrettyPrint(mp_keyInfoDOMNode);
+
+    }
+
+    else {
+
+        mp_X509DigestTextNode->setNodeValue(value);
+        static_cast<DOMElement*>(mp_X509DigestTextNode->getParentNode())->setAttributeNS(NULL, DSIGConstants::s_unicodeStrAlgorithm, algorithm);
+
+    }
+
+}
+
 void DSIGKeyInfoX509::setRawRetrievalURI(const XMLCh * uri) {
 
 	if (mp_rawRetrievalURI != NULL)

Modified: santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.hpp
URL: http://svn.apache.org/viewvc/santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.hpp?rev=1027194&r1=1027193&r2=1027194&view=diff
==============================================================================
--- santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.hpp (original)
+++ santuario/trunk/c/xsec/dsig/DSIGKeyInfoX509.hpp Mon Oct 25 16:58:41 2010
@@ -145,14 +145,36 @@ public:
 
 	const XMLCh * getKeyName(void) const;
 	
-	/**
-	 * \brief Get the IssuerSerialName
-	 *
-	 * Get the name of the Issuer (stored in the X509IssuerSerial element).
-	 *
-	 * @returns A pointer to the buffer containing the issuer name.
-	 * (0 if not set.)
-	 */
+    /**
+     * \brief Get the X509Digest Algorithm
+     *
+     * Get the Algorithm for the X509Digest.
+     *
+     * @returns A pointer to the buffer containing the algorithm
+     * (0 if not set.)
+     */
+
+	const XMLCh* getX509DigestAlgorithm(void) const;
+
+    /**
+     * \brief Get the X509Digest value
+     *
+     * Get the value for the X509Digest.
+     *
+     * @returns A pointer to the buffer containing the digest
+     * (0 if not set.)
+     */
+
+	const XMLCh* getX509DigestValue(void) const;
+
+    /**
+     * \brief Get the IssuerSerialName
+     *
+     * Get the name of the Issuer (stored in the X509IssuerSerial element).
+     *
+     * @returns A pointer to the buffer containing the issuer name.
+     * (0 if not set.)
+     */
 
 	const XMLCh * getX509IssuerName(void) const;
 
@@ -323,6 +345,18 @@ public:
 
 	void setX509IssuerSerial(const XMLCh * name, const XMLCh * serial);
 
+    /**
+     * \brief Set the dsig11:X509Digest element
+     *
+     * If a dsig11:X509Digest exists, replace the values with those provided,
+     * otherwise create a new element and set the values appropriately.
+     *
+     * @param algorithm The algorithm type
+     * @param value The digest value
+     */
+
+    void setX509Digest(const XMLCh * algorithm, const XMLCh * value);
+
 	/**
      * \brief Add a CRL.
 	 *
@@ -406,6 +440,7 @@ private:
 	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode	* mp_X509IssuerNameTextNode;
 	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode	* mp_X509SerialNumberTextNode;
 	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode	* mp_X509SKITextNode;
+	XERCES_CPP_NAMESPACE_QUALIFIER DOMNode  * mp_X509DigestTextNode;
 
 };