Convenience methods to resolve embedded KeyInfo.
authorScott Cantor <cantor.2@osu.edu>
Thu, 24 Aug 2006 03:48:14 +0000 (03:48 +0000)
committerScott Cantor <cantor.2@osu.edu>
Thu, 24 Aug 2006 03:48:14 +0000 (03:48 +0000)
xmltooling/signature/KeyResolver.h
xmltooling/signature/impl/KeyResolver.cpp

index b874bff..424382c 100644 (file)
@@ -34,6 +34,7 @@
 #include <vector>\r
 \r
 namespace xmlsignature {\r
+    class XMLTOOL_API Signature;\r
 \r
     /**\r
      * An API for resolving keys. The default/simple implementation\r
@@ -79,6 +80,15 @@ namespace xmlsignature {
         }\r
 \r
         /**\r
+         * Returns a key based on the supplied KeyInfo information.\r
+         * The caller must delete the key when done with it.\r
+         * \r
+         * @param sig   signature containing the key information\r
+         * @return  the resolved key\r
+         */\r
+        XSECCryptoKey* resolveKey(const Signature* sig) const;\r
+\r
+        /**\r
          * A wrapper that handles disposal of certificates when required.\r
          */\r
         class XMLTOOL_API ResolvedCertificates {\r
@@ -123,6 +133,18 @@ namespace xmlsignature {
             ) const;\r
 \r
         /**\r
+         * Returns a set of certificates based on the supplied KeyInfo information.\r
+         * The certificates must be cloned if kept beyond the lifetime of the KeyInfo source.\r
+         * \r
+         * @param sig   signature containing the key information\r
+         * @param certs     reference to object to hold certificates\r
+         * @return  number of certificates returned\r
+         */\r
+        std::vector<XSECCryptoX509*>::size_type resolveCertificates(\r
+            const Signature* sig, ResolvedCertificates& certs\r
+            ) const;\r
+\r
+        /**\r
          * Returns a CRL based on the supplied KeyInfo information.\r
          * The caller must delete the CRL when done with it.\r
          * \r
@@ -140,6 +162,15 @@ namespace xmlsignature {
          */\r
         virtual xmltooling::XSECCryptoX509CRL* resolveCRL(DSIGKeyInfoList* keyInfo) const;\r
 \r
+        /**\r
+         * Returns a CRL based on the supplied KeyInfo information.\r
+         * The caller must delete the CRL when done with it.\r
+         * \r
+         * @param sig   signature containing the key information\r
+         * @return  the resolved CRL\r
+         */\r
+        xmltooling::XSECCryptoX509CRL* resolveCRL(const Signature* sig) const;\r
+\r
     protected:\r
         XSECCryptoKey* m_key;\r
 \r
index 971c9fd..d5d5d15 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "internal.h"
 #include "signature/KeyResolver.h"
+#include "signature/Signature.h"
 
 using namespace xmlsignature;
 using namespace xmltooling;
@@ -39,6 +40,20 @@ void XMLTOOL_API xmlsignature::registerKeyResolvers()
     conf.KeyResolverManager.registerFactory(INLINE_KEY_RESOLVER, InlineKeyResolverFactory);
 }
 
+XSECCryptoKey* KeyResolver::resolveKey(const Signature* sig) const
+{
+    const KeyInfo* keyInfo = sig->getKeyInfo();
+    if (keyInfo)
+        return resolveKey(keyInfo);
+    DSIGSignature* native = sig->getXMLSignature();
+    if (native) {
+        DSIGKeyInfoList* nativeK = native->getKeyInfoList();
+        if (nativeK)
+            return resolveKey(nativeK);
+    }
+    return NULL;
+}
+
 vector<XSECCryptoX509*>::size_type KeyResolver::resolveCertificates(
     const KeyInfo* keyInfo, ResolvedCertificates& certs
     ) const
@@ -53,6 +68,22 @@ vector<XSECCryptoX509*>::size_type KeyResolver::resolveCertificates(
     return 0;
 }
 
+vector<XSECCryptoX509*>::size_type KeyResolver::resolveCertificates(
+    const Signature* sig, ResolvedCertificates& certs
+    ) const
+{
+    const KeyInfo* keyInfo = sig->getKeyInfo();
+    if (keyInfo)
+        return resolveCertificates(keyInfo, certs);
+    DSIGSignature* native = sig->getXMLSignature();
+    if (native) {
+        DSIGKeyInfoList* nativeK = native->getKeyInfoList();
+        if (nativeK)
+            return resolveCertificates(nativeK, certs);
+    }
+    return NULL;
+}
+
 XSECCryptoX509CRL* KeyResolver::resolveCRL(const KeyInfo* keyInfo) const
 {
     return NULL;
@@ -62,3 +93,17 @@ XSECCryptoX509CRL* KeyResolver::resolveCRL(DSIGKeyInfoList* keyInfo) const
 {
     return NULL;
 }
+
+XSECCryptoX509CRL* KeyResolver::resolveCRL(const Signature* sig) const
+{
+    const KeyInfo* keyInfo = sig->getKeyInfo();
+    if (keyInfo)
+        return resolveCRL(keyInfo);
+    DSIGSignature* native = sig->getXMLSignature();
+    if (native) {
+        DSIGKeyInfoList* nativeK = native->getKeyInfoList();
+        if (nativeK)
+            return resolveCRL(nativeK);
+    }
+    return NULL;
+}