Simplifying non-signed contentobject creation

Change-Id: Ib78e4dcbee7e2ef1939f1ebb54fdd4f26beeb922
diff --git a/ccnx/ccnx-wrapper.cpp b/ccnx/ccnx-wrapper.cpp
index 91148de..af64b87 100644
--- a/ccnx/ccnx-wrapper.cpp
+++ b/ccnx/ccnx-wrapper.cpp
@@ -43,58 +43,43 @@
 
 namespace Ccnx {
 
+// hack to enable fake signatures
+// min length for signature field is 16, as defined in ccn_buf_decoder.c:728
+const int DEFAULT_SIGNATURE_SIZE = 16;
+
+// Although ccn_buf_decoder.c:745 defines minimum length 16, something else is checking and only 32-byte fake value is accepted by ccnd
+const int PUBLISHER_KEY_SIZE = 32;
+
 static int
-ccn_encode_Signature(struct ccn_charbuf *buf,
-                     const char *digest_algorithm,
-                     const void *witness,
-                     size_t witness_size,
-                     const struct ccn_signature *signature,
-                     size_t signature_size)
+ccn_encode_garbage_Signature(struct ccn_charbuf *buf)
 {
     int res = 0;
 
-    if (signature == NULL)
-        return(-1);
-
     res |= ccn_charbuf_append_tt(buf, CCN_DTAG_Signature, CCN_DTAG);
 
-    if (digest_algorithm != NULL) {
-        res |= ccn_charbuf_append_tt(buf, CCN_DTAG_DigestAlgorithm, CCN_DTAG);
-        res |= ccn_charbuf_append_tt(buf, strlen(digest_algorithm), CCN_UDATA);
-        res |= ccn_charbuf_append_string(buf, digest_algorithm);
-        res |= ccn_charbuf_append_closer(buf);
-    }
+    // Let's cheat more.  Default signing algorithm in ccnd is SHA256, so we just need add 32 bytes of garbage
+    static char garbage [DEFAULT_SIGNATURE_SIZE];
 
-    if (witness != NULL) {
-        res |= ccn_charbuf_append_tt(buf, CCN_DTAG_Witness, CCN_DTAG);
-        res |= ccn_charbuf_append_tt(buf, witness_size, CCN_BLOB);
-        res |= ccn_charbuf_append(buf, witness, witness_size);
-        res |= ccn_charbuf_append_closer(buf);
-    }
+    // digest and witness fields are optional, so use default ones
 
     res |= ccn_charbuf_append_tt(buf, CCN_DTAG_SignatureBits, CCN_DTAG);
-    res |= ccn_charbuf_append_tt(buf, signature_size, CCN_BLOB);
-    res |= ccn_charbuf_append(buf, signature, signature_size);
+    res |= ccn_charbuf_append_tt(buf, DEFAULT_SIGNATURE_SIZE, CCN_BLOB);
+    res |= ccn_charbuf_append(buf, garbage, DEFAULT_SIGNATURE_SIZE);
     res |= ccn_charbuf_append_closer(buf);
-    
+
     res |= ccn_charbuf_append_closer(buf);
 
     return(res == 0 ? 0 : -1);
 }
 
 static int
-ccn_pack_ContentObject(struct ccn_charbuf *buf,
-                         const struct ccn_charbuf *Name,
-                         const struct ccn_charbuf *SignedInfo,
-                         const void *data,
-                         size_t size,
-                         const char *digest_algorithm,
-                         const struct ccn_pkey *private_key
-                         )
+ccn_pack_unsigned_ContentObject(struct ccn_charbuf *buf,
+                                const struct ccn_charbuf *Name,
+                                const struct ccn_charbuf *SignedInfo,
+                                const void *data,
+                                size_t size)
 {
     int res = 0;
-    struct ccn_sigc *sig_ctx;
-    struct ccn_signature *signature;
     struct ccn_charbuf *content_header;
     size_t closer_start;
 
@@ -106,19 +91,16 @@
     res |= ccn_charbuf_append_closer(content_header);
     if (res < 0)
         return(-1);
-    sig_ctx = ccn_sigc_create();
-    size_t sig_size = ccn_sigc_signature_max_size(sig_ctx, private_key);
-    signature = (ccn_signature *)calloc(1, sig_size);
-    ccn_sigc_destroy(&sig_ctx);
+
     res |= ccn_charbuf_append_tt(buf, CCN_DTAG_ContentObject, CCN_DTAG);
 
-    res |= ccn_encode_Signature(buf, digest_algorithm,
-                                NULL, 0, signature, sig_size);
+    res |= ccn_encode_garbage_Signature(buf);
+
     res |= ccn_charbuf_append_charbuf(buf, Name);
     res |= ccn_charbuf_append_charbuf(buf, SignedInfo);
     res |= ccnb_append_tagged_blob(buf, CCN_DTAG_Content, data, size);
     res |= ccn_charbuf_append_closer(buf);
-    free(signature);
+
     ccn_charbuf_destroy(&content_header);
     return(res == 0 ? 0 : -1);
 }
@@ -128,7 +110,6 @@
   , m_running (true)
   , m_connected (false)
   , m_executor (new Executor(1))
-  , m_keystore(NULL)
 {
   start ();
 }
@@ -162,10 +143,6 @@
 CcnxWrapper::~CcnxWrapper()
 {
   shutdown ();
-  if (m_keystore != NULL)
-  {
-    ccn_keystore_destroy(&m_keystore);
-  }
 }
 
 void
@@ -379,25 +356,17 @@
   ccn_charbuf *content = ccn_charbuf_create();
   ccn_charbuf *signed_info = ccn_charbuf_create();
 
-  if (m_keystore == NULL)
-  {
-    m_keystore = ccn_keystore_create ();
-    string keystoreFile = string(getenv("HOME")) + string("/.ccnx/.ccnx_keystore");
-    if (ccn_keystore_init (m_keystore, (char *)keystoreFile.c_str(), (char*)"Th1s1sn0t8g00dp8ssw0rd.") < 0)
-      BOOST_THROW_EXCEPTION(CcnxOperationException() << errmsg_info_str(keystoreFile.c_str()));
-  }
+  static char fakeKey[PUBLISHER_KEY_SIZE];
 
   int res = ccn_signed_info_create(signed_info,
-                         ccn_keystore_public_key_digest(m_keystore),
-                         ccn_keystore_public_key_digest_length(m_keystore),
-                         NULL,
-                         CCN_CONTENT_DATA,
-                         freshness,
-                         NULL,
-                         NULL
-                         );
-
-  ccn_pack_ContentObject(content, pname, signed_info, buf, len, NULL,  ccn_keystore_private_key (m_keystore));
+                                   fakeKey, PUBLISHER_KEY_SIZE,
+                                   NULL,
+                                   CCN_CONTENT_DATA,
+                                   freshness,
+                                   NULL,
+                                   NULL  // ccnd is happy with absent key locator and key itself... ha ha
+                                   );
+  ccn_pack_unsigned_ContentObject(content, pname, signed_info, buf, len);
 
   Bytes bytes;
   readRaw(bytes, content->buf, content->length);
diff --git a/ccnx/ccnx-wrapper.h b/ccnx/ccnx-wrapper.h
index 1bf6f4c..8ad6e34 100644
--- a/ccnx/ccnx-wrapper.h
+++ b/ccnx/ccnx-wrapper.h
@@ -117,7 +117,6 @@
   bool m_connected;
   std::map<Name, InterestCallback> m_registeredInterests;
   ExecutorPtr m_executor;
-  ccn_keystore *m_keystore;
 };
 
 typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;