[cpp-sp COMMIT] in /branches/REL_2/shibsp: attribute/NameIDAttribute.cpp attribute/NameIDAttribute.h attribute/NameID...

noreply at shibboleth.net noreply at shibboleth.net
Mon May 14 18:57:18 BST 2012


Author: scantor
Date: Mon May 14 18:57:18 2012
New Revision: 3660

URL: http://svn.shibboleth.net/view/cpp-sp?rev=3660&view=rev
Log:
https://issues.shibboleth.net/jira/browse/SSPCPP-376

Modified:
    branches/REL_2/shibsp/attribute/NameIDAttribute.cpp
    branches/REL_2/shibsp/attribute/NameIDAttribute.h
    branches/REL_2/shibsp/attribute/NameIDAttributeDecoder.cpp
    branches/REL_2/shibsp/attribute/NameIDFromScopedAttributeDecoder.cpp
    branches/REL_2/shibsp/remoting/impl/ListenerService.cpp

Modified: branches/REL_2/shibsp/attribute/NameIDAttribute.cpp
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/shibsp/attribute/NameIDAttribute.cpp?rev=3660&r1=3659&r2=3660&view=diff
==============================================================================
--- branches/REL_2/shibsp/attribute/NameIDAttribute.cpp (original)
+++ branches/REL_2/shibsp/attribute/NameIDAttribute.cpp Mon May 14 18:57:18 2012
@@ -25,11 +25,15 @@
  */
 
 #include "internal.h"
+#include "ServiceProvider.h"
 #include "attribute/NameIDAttribute.h"
+#include "remoting/ListenerService.h"
 
 #include <xmltooling/exceptions.h>
+#include <xmltooling/security/SecurityHelper.h>
 
 using namespace shibsp;
+using namespace xmltooling::logging;
 using namespace xmltooling;
 using namespace std;
 
@@ -39,17 +43,21 @@
     }
 };
 
-NameIDAttribute::NameIDAttribute(const vector<string>& ids, const char* formatter) : Attribute(ids), m_formatter(formatter)
+NameIDAttribute::NameIDAttribute(const vector<string>& ids, const char* formatter, const char* hashAlg)
+    : Attribute(ids), m_formatter(formatter), m_hashAlg(hashAlg ? hashAlg : "")
 {
 }
 
 NameIDAttribute::NameIDAttribute(DDF& in) : Attribute(in)
 {
     DDF val = in["_formatter"];
-    if (val.isstring())
+    if (val.isstring() && val.string())
         m_formatter = val.string();
     else
         m_formatter = DEFAULT_NAMEID_FORMATTER;
+    val = in["_hashalg"];
+    if (val.isstring() && val.string())
+        m_hashAlg = val.string();
     const char* pch;
     val = in.first().first();
     while (val.name()) {
@@ -116,7 +124,7 @@
 const vector<string>& NameIDAttribute::getSerializedValues() const
 {
     if (m_serialized.empty()) {
-        for (vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
+        for (vector<Value>::const_iterator i = m_values.begin(); i != m_values.end(); ++i) {
             // This is kind of a hack, but it's a good way to reuse some code.
             XMLToolingException e(
                 m_formatter,
@@ -129,7 +137,27 @@
                     "SPProvidedID", i->m_SPProvidedID.c_str()
                     )
                 );
-            m_serialized.push_back(e.what());
+            if (m_hashAlg.empty()) {
+                m_serialized.push_back(e.what());
+            }
+            else {
+#ifndef SHIBSP_LITE
+                m_serialized.push_back(SecurityHelper::doHash(m_hashAlg.c_str(), e.what(), strlen(e.what())));
+#else
+                try {
+                    DDF out, in("hash");
+                    DDFJanitor jin(in), jout(out);
+                    in.addmember("alg").string(m_hashAlg.c_str());
+                    in.addmember("data").unsafe_string(e.what());
+                    out = SPConfig::getConfig().getServiceProvider()->getListenerService()->send(in);
+                    if (out.isstring() && out.string())
+                        m_serialized.push_back(out.string());
+                }
+                catch (exception& ex) {
+                    Category::getInstance(SHIBSP_LOGCAT".Attribute.NameID").error("exception remoting hash operation: %s", ex.what());
+                }
+#endif
+            }
         }
     }
     return Attribute::getSerializedValues();
@@ -140,6 +168,8 @@
     DDF ddf = Attribute::marshall();
     ddf.name("NameID");
     ddf.addmember("_formatter").string(m_formatter.c_str());
+    if (!m_hashAlg.empty())
+        ddf.addmember("_hashalg").string(m_hashAlg.c_str());
     DDF vlist = ddf.first();
     for (vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
         DDF val = DDF(i->m_Name.c_str()).structure();

Modified: branches/REL_2/shibsp/attribute/NameIDAttribute.h
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/shibsp/attribute/NameIDAttribute.h?rev=3660&r1=3659&r2=3660&view=diff
==============================================================================
--- branches/REL_2/shibsp/attribute/NameIDAttribute.h (original)
+++ branches/REL_2/shibsp/attribute/NameIDAttribute.h Mon May 14 18:57:18 2012
@@ -50,8 +50,9 @@
          * 
          * @param ids       array with primary identifier in first position, followed by any aliases
          * @param formatter template for serialization of tuple
+         * @param hashAlg   hash algorithm to apply in producing serialized values
          */
-        NameIDAttribute(const std::vector<std::string>& ids, const char* formatter=DEFAULT_NAMEID_FORMATTER);
+        NameIDAttribute(const std::vector<std::string>& ids, const char* formatter=DEFAULT_NAMEID_FORMATTER, const char* hashAlg=nullptr);
 

[... 112 lines stripped ...]


More information about the commits mailing list