Custom KeyInfo support in signature creation.
authorScott Cantor <cantor.2@osu.edu>
Sun, 14 May 2006 03:33:10 +0000 (03:33 +0000)
committerScott Cantor <cantor.2@osu.edu>
Sun, 14 May 2006 03:33:10 +0000 (03:33 +0000)
xmltooling/signature/SigningContext.h
xmltooling/signature/impl/XMLSecSignatureImpl.cpp
xmltoolingtest/SignatureTest.h

index af2e7f4..520e2d3 100644 (file)
@@ -23,6 +23,8 @@
 #if !defined(__xmltooling_signctx_h__) && !defined(XMLTOOLING_NO_XMLSEC)\r
 #define __xmltooling_signctx_h__\r
 \r
+#include <xmltooling/signature/KeyInfo.h>\r
+\r
 #include <vector>\r
 #include <xsec/dsig/DSIGSignature.hpp>\r
 \r
@@ -61,8 +63,18 @@ namespace xmlsignature {
          * \r
          * @return  an immutable collection of certificates to embed\r
          */\r
-        virtual const std::vector<XSECCryptoX509*>& getX509Certificates() const=0;\r
-        \r
+        virtual const std::vector<XSECCryptoX509*>* getX509Certificates() const=0;\r
+\r
+        /**\r
+         * Gets a KeyInfo structure to embed.\r
+         * Ownership of the object MUST be transferred to the caller.\r
+         * This method will only be called if no certificates are returned from\r
+         * the getX509Certificates() method.\r
+         * \r
+         * @return  pointer to a KeyInfo structure, will be freed by caller\r
+         */\r
+        virtual KeyInfo* getKeyInfo() const=0;\r
+\r
         /**\r
          * Gets the signing key to use.\r
          * Must be compatible with the intended signature algorithm. Ownership of the key\r
index 4bd7653..2d97b94 100644 (file)
@@ -148,10 +148,17 @@ void XMLSecSignatureImpl::sign(const SigningContext& ctx)
     try {\r
         log.debug("creating signature content");\r
         ctx.createSignature(m_signature);\r
-        const std::vector<XSECCryptoX509*>& certs=ctx.getX509Certificates();\r
-        if (!certs.empty()) {\r
+        const std::vector<XSECCryptoX509*>* certs=ctx.getX509Certificates();\r
+        if (certs && !certs->empty()) {\r
             DSIGKeyInfoX509* x509Data=m_signature->appendX509Data();\r
-            for_each(certs.begin(),certs.end(),bind1st(_addcert(),x509Data));\r
+            for_each(certs->begin(),certs->end(),bind1st(_addcert(),x509Data));\r
+        }\r
+        else {\r
+            auto_ptr<KeyInfo> keyInfo(ctx.getKeyInfo());\r
+            if (keyInfo.get()) {\r
+                DOMElement* domElement=keyInfo->marshall(m_signature->getParentDocument());\r
+                getDOM()->appendChild(domElement);\r
+            }\r
         }\r
         \r
         log.debug("computing signature");\r
index 01262bd..62009ed 100644 (file)
@@ -79,7 +79,8 @@ public:
         sig->verify();\r
     }\r
     \r
-    const std::vector<XSECCryptoX509*>& getX509Certificates() const { return m_certs; }\r
+    const std::vector<XSECCryptoX509*>* getX509Certificates() const { return &m_certs; }\r
+    KeyInfo* getKeyInfo() const { return NULL; }\r
     XSECCryptoKey* getSigningKey() const { return m_key->clone(); }\r
 };\r
 \r