checkin for GSS import name
authorMark Donnelly <mark@painless-security.com>
Mon, 28 Apr 2014 18:15:07 +0000 (14:15 -0400)
committerMark Donnelly <mark@painless-security.com>
Mon, 28 Apr 2014 18:15:07 +0000 (14:15 -0400)
25 files changed:
.gitignore
json_gssapi/CMakeLists.txt
json_gssapi/main.cpp [new file with mode: 0644]
json_gssapi/src/CMakeLists.txt
json_gssapi/src/GSSCommand.h
json_gssapi/src/GSSCreateSecContextCommand.cpp
json_gssapi/src/GSSCreateSecContextCommand.h
json_gssapi/src/GSSImportName.cpp [new file with mode: 0644]
json_gssapi/src/GSSImportName.h [new file with mode: 0644]
json_gssapi/src/datamodel/CMakeLists.txt [new file with mode: 0644]
json_gssapi/src/datamodel/GSSBuffer.cpp [new file with mode: 0644]
json_gssapi/src/datamodel/GSSBuffer.h [new file with mode: 0644]
json_gssapi/src/datamodel/GSSName.cpp [new file with mode: 0644]
json_gssapi/src/datamodel/GSSName.h [new file with mode: 0644]
json_gssapi/src/datamodel/GSSOID.cpp [new file with mode: 0644]
json_gssapi/src/datamodel/GSSOID.h [new file with mode: 0644]
json_gssapi/src/util_json.cpp
json_gssapi/test/CMakeLists.txt
json_gssapi/test/GSSImportNameTest.cpp [new file with mode: 0644]
json_gssapi/test/GSSImportNameTest.h [new file with mode: 0644]
json_gssapi/test/MockImportName.cpp [new file with mode: 0644]
json_gssapi/test/MockImportName.h [new file with mode: 0644]
json_gssapi/test/datamodel/CMakeLists.txt [new file with mode: 0644]
json_gssapi/test/datamodel/GSSBufferTest.cpp [new file with mode: 0644]
json_gssapi/test/datamodel/GSSBufferTest.h [new file with mode: 0644]

index d368523..a0028da 100644 (file)
@@ -73,3 +73,12 @@ Doxyfile
 .*kate-swp
 #build
 #build/
+
+
+#
+# Files specific to gssweb
+############################
+json_gssapi/build
+json_gssapi/debug
+json_gssapi/manual
+test/
\ No newline at end of file
index 059a6b6..c99987d 100644 (file)
@@ -2,7 +2,12 @@ cmake_minimum_required(VERSION 2.8)
 
 project(json_gssapi)
 
-add_executable(json_gssapi src/GSSException.cpp src/GSSCreateSecContextCommand.cpp src/GSSCommand.cpp src/util_json.cpp main.cpp)
+add_executable(json_gssapi src/datamodel/GSSName.cpp src/datamodel/GSSOID.cpp src/datamodel/GSSBuffer.cpp src/GSSException.cpp 
+                           src/GSSCreateSecContextCommand.cpp
+                           src/GSSCommand.cpp 
+                           src/GSSImportName.cpp
+                           src/util_json.cpp 
+                           main.cpp)
 target_link_libraries(json_gssapi gssapi_krb5 jansson)
 
 
diff --git a/json_gssapi/main.cpp b/json_gssapi/main.cpp
new file mode 100644 (file)
index 0000000..8bb47f1
--- /dev/null
@@ -0,0 +1,6 @@
+#include <iostream>
+
+int main(int argc, char **argv) {
+    std::cout << "Hello, world!" << std::endl;
+    return 0;
+}
index e69de29..c97eb6f 100644 (file)
@@ -0,0 +1,2 @@
+
+add_subdirectory(datamodel)
\ No newline at end of file
index 261b3aa..6665c5b 100644 (file)
@@ -15,15 +15,13 @@ class GSSCommand
 {
 public:
   GSSCommand() {};
-  GSSCommand(void *fn) : function(fn) {};
-  GSSCommand(JSONObject params, void *fn) : function(fn) { };
+  GSSCommand(JSONObject params) : parameters(params) { };
   
-  void *getGSSFunction() { return function; };
   virtual void execute() { std::cout << "\ninside GSSCommand::invoke()\n"; };  
   virtual JSONObject *toJSON() { return new JSONObject(); }
   
 protected:
-  void *function;
+  JSONObject parameters;
 };
 
 #endif // GSSCOMMAND_H
index 7e35b45..6104046 100644 (file)
@@ -288,14 +288,16 @@ JSONObject *GSSCreateSecContextCommand::toJSON()
 
 GSSCreateSecContextCommand::GSSCreateSecContextCommand(
   JSONObject *params, 
-  void *fn) : GSSCommand(params, fn)
+  void *fn) : GSSCommand(params)
 {
   zeroOut(false);
   loadParameters(params);
+  function = fn;
 }
 
-GSSCreateSecContextCommand::GSSCreateSecContextCommand(void *fn) : GSSCommand(fn)
+GSSCreateSecContextCommand::GSSCreateSecContextCommand(void *fn)
 {
   zeroOut(false);
+  function = fn;
 }
 
index 915084d..52dcdd2 100644 (file)
@@ -42,6 +42,7 @@ public:
     OM_uint32 getReqFlags() { return req_flags; }
     OM_uint32 getTimeReq() { return time_req; }
     gss_ctx_id_t getContextHandle() { return context_handle; }
+    void *getGSSFunction() { return function; }
     
     // complex accessors
     const char * getTargetDisplayName();
@@ -49,6 +50,7 @@ public:
     const char * getActualMechType();
     
 private:
+    void *function;
     const char * oidToStr(gss_OID oid);
 };
 
diff --git a/json_gssapi/src/GSSImportName.cpp b/json_gssapi/src/GSSImportName.cpp
new file mode 100644 (file)
index 0000000..84e512d
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#include "GSSImportName.h"
+
+void GSSImportName::execute()
+{
+
+}
+
+JSONObject *GSSImportName::toJSON()
+{
+  return new JSONObject();
+}
+
+GSSImportName::GSSImportName(JSONObject *params, gss_imp_name_type fn) : GSSCommand(params)
+{
+  /* Variables */
+  /* Error checking */
+  /* Setup */
+  /* Main */
+  loadParameters(params);
+  function = fn;
+  /* Cleanup */
+  /* Return */
+  
+}
+
+bool GSSImportName::loadParameters(JSONObject *params)
+{
+  /* Variables */
+  /* Error checking */
+  /* Setup */
+  // Should I zeroOut?
+  
+  /* Main processing */
+  // Easy stuff(*params)
+  std::string input_name = (*params)["arguments"]["input_name"].string();
+  std::string input_name_type = (*params)["arguments"]["input_name_type"].string();
+  
+  this->inputName.setValue( (*params)["arguments"]["input_name"].string() );
+  this->inputNameType.setValue( (*params)["arguments"]["input_name_type"].string() );
+  
+  /* Cleanup */
+  /* Return */
+  return true;
+}
+
+
+/* Variables */
+/* Error checking */
+/* Setup */
+/* Main */
+/* Cleanup */
+/* Return */
diff --git a/json_gssapi/src/GSSImportName.h b/json_gssapi/src/GSSImportName.h
new file mode 100644 (file)
index 0000000..26d671f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#ifndef GSSIMPORTNAME_H
+#define GSSIMPORTNAME_H
+
+#include "GSSCommand.h"
+#include "datamodel/GSSBuffer.h"
+#include "datamodel/GSSName.h"
+
+#include <gssapi.h>
+
+class GSSImportName : public GSSCommand
+{
+public:
+  GSSImportName(gss_imp_name_type fn = &gss_import_name) : function(fn) {};
+  GSSImportName(JSONObject *params, gss_imp_name_type fn = &gss_import_name);
+  
+  void execute();
+  JSONObject* toJSON();
+  
+  GSSBuffer getInputName() { return GSSBuffer(inputName); }
+  GSSBuffer getInputNameType() { return GSSBuffer(inputNameType); }
+  
+  gss_imp_name_type getGSSFunction() { return function; }
+  
+private:
+  gss_imp_name_type function;
+  bool loadParameters(JSONObject *params);
+  GSSBuffer inputName;
+  GSSBuffer inputNameType;
+
+};
+
+#endif // GSSIMPORTNAME_H
diff --git a/json_gssapi/src/datamodel/CMakeLists.txt b/json_gssapi/src/datamodel/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/json_gssapi/src/datamodel/GSSBuffer.cpp b/json_gssapi/src/datamodel/GSSBuffer.cpp
new file mode 100644 (file)
index 0000000..e00c650
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#include <stdexcept>
+#include <cstring>
+#include "GSSBuffer.h"
+#include "../GSSException.h"
+
+
+/* Constructor pattern:
+ * 1) Set gssInternal to false, so that setting values is permitted.
+ * 2) Allocate memory for a new gss_buffer_desc
+ * 3) Set the buffer length to 0, so that setting values doesn't try
+ *    to free memory.
+ * 4) Set the value of the buffer.
+ * 5) Set the value of gssInternal correctly
+ */
+GSSBuffer::GSSBuffer ( const GSSBuffer &other )
+{
+  gss_buffer_t otherBuf = other.buf;
+  initEmpty();
+  setValue( (char *)(otherBuf->value), otherBuf->length);
+  this->gssInternal = false;
+}
+
+GSSBuffer::GSSBuffer(std::string str, bool gssInternal)
+{
+  initEmpty();
+  setValue(str);
+  this->gssInternal = gssInternal;
+}
+
+GSSBuffer::GSSBuffer(char *str, bool gssInternal)
+{
+  initEmpty();
+  setValue(str);
+  this->gssInternal = gssInternal;
+}
+
+GSSBuffer::GSSBuffer(char *str, int len, bool gssInternal)
+{
+  initEmpty();
+  setValue(str, len);
+  this->gssInternal = gssInternal;
+}
+
+GSSBuffer::GSSBuffer(gss_buffer_t gssbuf, bool gssInternal)
+{
+  initEmpty();
+  setValue(gssbuf);
+  this->gssInternal = gssInternal;
+}
+
+GSSBuffer::~GSSBuffer(void)
+{
+  OM_uint32 major, minor;
+
+  if (this->gssInternal) 
+  {
+    major = gss_release_buffer(&minor, buf);
+    if (GSS_ERROR(major))
+    {
+      throw GSSException("Error in releasing a buffer allocated by GSS", major, minor);
+    }
+  } else {
+    freeBufValue();
+  }
+}
+
+
+void GSSBuffer::initEmpty()
+{
+  this->gssInternal = false;
+  this->buf = new gss_buffer_desc;
+  this->buf->length = 0;
+  this->buf->value = NULL;
+}
+
+void GSSBuffer::freeBufValue()
+{
+  if (this->buf->length == 0 && this->buf->value != NULL)
+    delete[] ( (char *)(this->buf->value) );
+  this->buf->length = 0;
+  this->buf->value = NULL;
+}
+
+
+/* setValue pattern:
+ * 1) Throw an exception when attempting to mutate a buffer supplied by 
+ *    GSS itself. 
+ * 2) Free the GSS buffer value, if needed.
+ * 3) Set the buffer value as needed.
+ */
+void GSSBuffer::setValue(std::string str)
+{
+  setValue((char *)str.c_str(), str.size());
+}
+
+void GSSBuffer::setValue(char *str)
+{
+  setValue(str, std::strlen(str));
+}
+
+void GSSBuffer::setValue(char *str, int len)
+{
+  /* Variables */
+  /* Error checking */
+  if (this->gssInternal)
+    throw std::logic_error("Attempting to modify an immutable GSSBuffer");
+  
+  /* Setup */
+  freeBufValue();
+  
+  /* Main */
+  this->buf->value = new char[len];
+  std::memcpy( (void *)(this->buf->value), (void *)str, len);
+  this->buf->length = len;
+  
+  /* Cleanup */
+  /* Return */
+}
+
+void GSSBuffer::setValue(gss_buffer_t gssbuf)
+{
+  if (this->gssInternal)
+    throw std::logic_error("Attempting to modify an immutable GSSBuffer");
+  freeBufValue();
+  delete buf;
+  this->buf = gssbuf;
+}
diff --git a/json_gssapi/src/datamodel/GSSBuffer.h b/json_gssapi/src/datamodel/GSSBuffer.h
new file mode 100644 (file)
index 0000000..2174431
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#ifndef GSSBUFFER_H
+#define GSSBUFFER_H
+
+#include <string>
+#include "gssapi.h"
+#include <iostream>
+
+class GSSBuffer {
+public:
+  GSSBuffer(std::string str = "", bool gssInternal = false);
+  GSSBuffer(char *str, bool gssInternal = false);
+  GSSBuffer(char *str, int len, bool gssInternal = false);
+  GSSBuffer(gss_buffer_t gssbuf, bool gssInternal = false);
+  GSSBuffer(const GSSBuffer &other);
+  ~GSSBuffer(void);
+  
+  std::string toString() { return(std::string((char *)buf->value, buf->length)); }
+  gss_buffer_t toGss() { return( buf ); }
+  int length() { return(buf->length); }
+  
+  void setValue(std::string str);
+  void setValue(char *str);
+  void setValue(char *str, int len);
+  void setValue(gss_buffer_t gssbuf);
+  
+  bool operator==(GSSBuffer B) { return(this->toString() == B.toString()); }
+
+private:
+  gss_buffer_t buf;
+  bool         gssInternal;
+  
+  void freeBufValue();
+  void initEmpty();
+};
+
+
+
+
+#endif // GSSBUFFER_H
diff --git a/json_gssapi/src/datamodel/GSSName.cpp b/json_gssapi/src/datamodel/GSSName.cpp
new file mode 100644 (file)
index 0000000..eb55aff
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#include "GSSName.h"
+#include "../GSSException.h" 
+
+void GSSName::init(GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn)
+{
+  /* Variables */
+  OM_uint32 major, minor;
+  /* Error checking */
+  /* Setup */
+  /* Main */ 
+  major = gss_import_name(&minor, namestr.toGss(), name_type.toGss(), &name);
+  if ( GSS_ERROR(major) )
+  {
+    std::string errMsg;
+    errMsg += "Cannot import name: ";
+    errMsg += namestr.toString();
+    throw GSSException(errMsg.c_str(), major, minor, name_type.toGss());
+  }
+  this->function = fn;
+  
+  /* Cleanup */
+  /* Return */
+}
+
+
+
+GSSName::GSSName(std::string namestr, GSSOID name_type, gss_imp_name_type fn)
+{
+  init(namestr, name_type, fn);
+}
+
+GSSName::GSSName(char *namestr,       GSSOID name_type, gss_imp_name_type fn)
+{
+  init(GSSBuffer(namestr), name_type, fn); 
+}
+
+GSSName::GSSName(GSSBuffer namestr,   GSSOID name_type, gss_imp_name_type fn)
+{
+  init(GSSBuffer(namestr), name_type, fn); 
+}
+
+GSSName::GSSName(std::string namestr, gss_OID name_type, gss_imp_name_type fn)
+{
+  init(GSSBuffer(namestr), GSSOID(name_type), fn); 
+}
+
+GSSName::GSSName(char *namestr,       gss_OID name_type, gss_imp_name_type fn)
+{
+  init(GSSBuffer(namestr), GSSOID(name_type), fn); 
+}
+
+GSSName::GSSName(GSSBuffer namestr,   gss_OID name_type, gss_imp_name_type fn)
+{
+  init(namestr, GSSOID(name_type), fn); 
+}
+
+GSSName::GSSName(std::string namestr, std::string name_type, gss_imp_name_type fn)
+{
+  init(GSSBuffer(namestr), GSSOID(name_type), fn); 
+}
+
+GSSName::GSSName(char *namestr,       std::string name_type, gss_imp_name_type fn)
+{
+  init(GSSBuffer(namestr), GSSOID(name_type), fn); 
+}
+
+GSSName::GSSName(GSSBuffer namestr,   std::string name_type, gss_imp_name_type fn)
+{
+  init(namestr, GSSOID(name_type), fn); 
+}
+
+
+GSSName::~GSSName()
+{
+  /* Variables */
+  OM_uint32 major, minor;
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */ 
+  major = gss_release_name(&minor, &name);
+  if ( GSS_ERROR(major) && !( major & GSS_S_BAD_NAME ) )
+  {
+    throw GSSException("Cannot free memory for a GSS name.", major, minor);
+  }
+
+  /* Cleanup */
+  /* Return */
+}  
+
+
+std::string GSSName::toString()
+{
+  /* Variables */
+  OM_uint32 major, minor;
+  gss_OID oid;
+  GSSBuffer buf;
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */ 
+  major = gss_display_name(&minor, (this->name), buf.toGss(), &oid);
+  if ( GSS_ERROR(major) )
+  {
+    throw GSSException("Cannot convert a GSS name to a string.", major, minor);
+  }
+  
+  /* Cleanup */
+  /* Return */
+  return buf.toString();
+}
diff --git a/json_gssapi/src/datamodel/GSSName.h b/json_gssapi/src/datamodel/GSSName.h
new file mode 100644 (file)
index 0000000..839c24e
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#include <string>
+#include "GSSBuffer.h"
+#include "GSSOID.h"
+
+#ifndef GSSNAME_H
+#define GSSNAME_H
+
+
+typedef OM_uint32 (*gss_imp_name_type)(
+    OM_uint32 *,        /* minor_status */
+    gss_buffer_t,       /* input_name_buffer */
+    gss_OID,            /* input_name_type(used to be const) */
+    gss_name_t *);      /* output_name */
+
+
+class GSSName {
+public:
+  GSSName(std::string nameStr, 
+          GSSOID name_type = GSSOID( (gss_OID)GSS_C_NO_OID ), 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+  GSSName(char *namestr,       
+          GSSOID name_type = GSSOID( (gss_OID)GSS_C_NO_OID ), 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+  GSSName(GSSBuffer namestr,   
+          GSSOID name_type = GSSOID( (gss_OID)GSS_C_NO_OID ), 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+
+  GSSName(std::string nameStr, 
+          gss_OID name_type, 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+  GSSName(char *namestr,       
+          gss_OID name_type, 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+  GSSName(GSSBuffer namestr,   
+          gss_OID name_type, 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+
+  GSSName(std::string nameStr, 
+          std::string name_type, 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+  GSSName(char *namestr,       
+          std::string name_type, 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+  GSSName(GSSBuffer namestr,   
+          std::string name_type, 
+          gss_imp_name_type fn = (gss_imp_name_type)&gss_import_name);
+
+  ~GSSName();
+  
+  
+  gss_name_t toGSS() { return(name); }
+  std::string toString();
+  
+private:
+  gss_name_t name;
+  void init(GSSBuffer namestr, GSSOID name_type, gss_imp_name_type fn);
+  gss_imp_name_type function;
+};
+
+
+#endif // GSSNAME_H
diff --git a/json_gssapi/src/datamodel/GSSOID.cpp b/json_gssapi/src/datamodel/GSSOID.cpp
new file mode 100644 (file)
index 0000000..c8b545c
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#include "GSSOID.h"
+#include "../GSSException.h"
+
+GSSOID::GSSOID(std::string oid_str)
+{
+  init( GSSBuffer(oid_str) );
+}
+
+GSSOID::GSSOID(char *oid_str)
+{
+  init( GSSBuffer(oid_str) );
+}
+  
+GSSOID::GSSOID(GSSBuffer oid_str)
+{
+  init(oid_str);
+}
+
+GSSOID::GSSOID(gss_OID gssoid)
+{
+  oid = gssoid;
+  this->gssInternal = true;
+}
+
+GSSOID::~GSSOID()
+{
+  OM_uint32 major, minor;
+  if (! this->gssInternal)
+  {
+    major = gss_release_oid(&minor, &(this->oid));
+    if (GSS_ERROR(major))
+    {
+      throw GSSException("Error in releasing a GSS OID", major, minor);
+    }
+  }
+}
+  
+void GSSOID::init(GSSBuffer oid_str)
+{
+  /* Variables */
+  OM_uint32 major, minor;
+  
+  /* Error checking */
+  /* Setup */
+  
+  /* Main */
+  major = gss_str_to_oid(&minor, oid_str.toGss(), &(this->oid));
+  if (GSS_ERROR(major))
+  {
+    throw GSSException("Error creating GSS OID", major, minor);
+  }
+  this->gssInternal = false;
+  
+  /* Cleanup */
+  /* Return */
+}
+
+std::string GSSOID::toString()
+{
+  /* Variables */
+  OM_uint32 major, minor;
+  gss_buffer_desc buf;
+  std::string ret;
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */ 
+  major = gss_oid_to_str(&minor, this->oid, &buf);
+  if (GSS_ERROR(major))
+  {
+    throw GSSException("Error in creating a string representation of a GSS OID", 
+                      major, minor);
+  }
+  ret = std::string((char *)buf.value);
+  
+  /* Cleanup */
+  major = gss_release_buffer(&minor, &buf);
+  if (GSS_ERROR(major))
+  {
+    throw GSSException("Error releasing a gss_buffer", 
+                      major, minor);
+  }
+  
+  /* Return */ 
+  return(ret);
+}
diff --git a/json_gssapi/src/datamodel/GSSOID.h b/json_gssapi/src/datamodel/GSSOID.h
new file mode 100644 (file)
index 0000000..636c1a8
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#include <string>
+#include "gssapi.h"
+
+#include "GSSBuffer.h"
+
+#ifndef GSSOID_H
+#define GSSOID_H
+
+class GSSOID { 
+public:
+  GSSOID(char *oid_str);
+  GSSOID(std::string oid_str);
+  GSSOID(GSSBuffer oid_str);
+  GSSOID(gss_OID gssoid);
+  ~GSSOID();
+  
+  gss_OID toGss() { return(oid); };
+  std::string toString();
+
+private:
+  gss_OID oid;
+  bool gssInternal;
+  
+  void init(GSSBuffer oid_str);
+};
+
+
+#endif // GSSOID_H
index dbd453e..f0c7863 100644 (file)
@@ -354,7 +354,7 @@ bool JSONObject::isBoolean(void) const
 
 bool JSONObject::isNull(void) const
 {
-    return json_is_null(m_obj);
+   return json_is_null(m_obj);
 }
 
 JSONIterator::JSONIterator(const JSONObject &obj)
index 8717060..a9d673e 100644 (file)
@@ -1,10 +1,21 @@
 include_directories(${CMAKE_SOURCE_DIR}/src)
 
-add_executable(test GSSExceptionTest.cpp InitSecContextMock.cpp 
-                    GSSCreateSecContextTest.cpp test_run.cpp 
+add_executable(test GSSExceptionTest.cpp 
+                    InitSecContextMock.cpp 
+                    GSSCreateSecContextTest.cpp 
+                    GSSImportNameTest.cpp
+                    MockImportName.cpp
+                    test_run.cpp 
                     ../src/GSSCreateSecContextCommand.cpp 
-                    ../src/util_json.cpp ../src/GSSException.cpp)
+                    ../src/util_json.cpp 
+                    ../src/GSSImportName.cpp
+                    ../src/GSSException.cpp
+                    ../src/datamodel/GSSBuffer.cpp
+                    datamodel/GSSBufferTest.cpp
+  )
 
 target_link_libraries(test cppunit gssapi_krb5 jansson)
 
 # install(TARGETS test RUNTIME DESTINATION bin)
+
+add_subdirectory(datamodel)
\ No newline at end of file
diff --git a/json_gssapi/test/GSSImportNameTest.cpp b/json_gssapi/test/GSSImportNameTest.cpp
new file mode 100644 (file)
index 0000000..5c915fa
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2014 Painless Security LLC
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ * GSSImportNameTest.h - Test the GSSImportName object.
+ * Tests include:
+ *   testConstructor - 
+ *       Testing basic object creation
+ *   testConstructorWithJSONObject - 
+ *       Test object creation with a set of arguments
+ *   testEmptyCall - 
+ *       Basic test of the system, with an empty call to
+ *       a mocked out gss_import_name function, to test
+ *       whether the object passes and records arguments
+ *       correctly
+ *   testJSONMarshal - 
+ *       test the JSON serialization of the object
+ */
+
+#include "GSSImportNameTest.h"
+#include "GSSImportName.h"
+#include "MockImportName.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( GSSImportNameTest );
+
+
+/* 
+ * a mock of the gss_import_name call
+ * 
+ * Basically, just copy the arguments over to/from the
+ * MockImportName global object
+ */
+static OM_uint32 KRB5_CALLCONV
+mock_import_name(
+    OM_uint32     *minor_status,
+    gss_buffer_t   input_name_buffer, 
+    gss_OID        input_name_type,
+    gss_name_t    *output_name)
+{
+  /* Error checking */
+  /* Variables */
+  /* Setup */
+  /* Main */
+  // Copy our input from the appropriate parameters to MockImportName
+  MockImportName::input_name_buffer = input_name_buffer;
+  MockImportName::input_name_type = input_name_type;
+  
+  // copy our output to the appropriate parameters
+  *minor_status = MockImportName::minor_status;
+  *output_name = MockImportName::output_name;
+  
+  
+  /* Cleanup */
+  /* return */
+  return MockImportName::retVal;
+}
+
+void GSSImportNameTest::setUp()
+{
+  CppUnit::TestFixture::setUp();
+  MockImportName::reset();
+}
+
+void GSSImportNameTest::tearDown()
+{
+    CppUnit::TestFixture::tearDown();
+}
+
+void GSSImportNameTest::testConstructor()
+{
+  /* Variables */
+  GSSImportName cmd = GSSImportName();
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "The GSSImportName object has the wrong GSS function",
+    (void *)&gss_import_name,
+    (void *)cmd.getGSSFunction()
+  );
+  
+  /* Cleanup */
+  /* Return */
+}
+void GSSImportNameTest::testEmptyCall()
+{
+  /* Variables */
+  GSSImportName cmd = GSSImportName();
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */
+  
+  /* Cleanup */
+  /* Return */
+}
+void GSSImportNameTest::testConstructorWithJSONObject()
+{
+  /* Variables */
+  const char* input = "{\"method\": \"gss_import_name\", \
+    \"arguments\": {\"input_name\": \"http@localhost\", \
+    \"input_name_type\": \"{ 1 2 840 113554 1 2 1 4 }\"}}";
+  json_error_t jsonErr;
+  JSONObject json = JSONObject::load(input, 0, &jsonErr);
+  
+  GSSImportName cmd = GSSImportName(&json, &mock_import_name);
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */
+  
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "GSSImportName did not parse the input_name argument correctly",
+    std::string("http@localhost"),
+    cmd.getInputName().toString()
+  );
+  
+  CPPUNIT_ASSERT_EQUAL_MESSAGE(
+    "GSSImportName did not parse the input_name_type argument correctly",
+    std::string("{ 1 2 840 113554 1 2 1 4 }"),
+    cmd.getInputNameType().toString()
+  );
+  
+  /* Cleanup */
+  /* Return */
+}
+void GSSImportNameTest::testJSONMarshal()
+{
+  /* Variables */
+  GSSImportName cmd = GSSImportName();
+  
+  /* Error checking */
+  /* Setup */
+  /* Main */
+  
+  /* Cleanup */
+  /* Return */
+}
+
diff --git a/json_gssapi/test/GSSImportNameTest.h b/json_gssapi/test/GSSImportNameTest.h
new file mode 100644 (file)
index 0000000..8c12252
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 Painless Security LLC
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ * GSSImportNameTest.h - Test the GSSImportName object.
+ * Tests include:
+ *   testConstructor - 
+ *       Testing basic object creation
+ *   testConstructorWithJSONObject - 
+ *       Test object creation with a set of arguments
+ *   testEmptyCall - 
+ *       Basic test of the system, with an empty call to
+ *       a mocked out gss_import_name function, to test
+ *       whether the object passes and records arguments
+ *       correctly
+ *   testJSONMarshal - 
+ *       test the JSON serialization of the object
+ */
+
+#ifndef GSSIMPORTNAMETEST_H
+#define GSSIMPORTNAMETEST_H
+
+// #include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <gssapi.h>
+#include "GSSCreateSecContextCommand.h"
+
+#include <stdlib.h>
+
+class GSSImportNameTest :  public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( GSSImportNameTest );
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testConstructorWithJSONObject );
+  CPPUNIT_TEST( testEmptyCall );
+  CPPUNIT_TEST( testJSONMarshal );
+  CPPUNIT_TEST_SUITE_END();
+  
+  
+  
+public:
+  void setUp();
+  void tearDown();
+
+  
+  void testConstructor();
+  void testConstructorWithJSONObject();
+  void testEmptyCall();
+  void testJSONMarshal();
+};
+
+#endif // GSSIMPORTNAMETEST_H
diff --git a/json_gssapi/test/MockImportName.cpp b/json_gssapi/test/MockImportName.cpp
new file mode 100644 (file)
index 0000000..f8a9aeb
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2014 Painless Security, LLC.
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ * MockImportName - Mock out the parameters for calling the
+ * GSSImportName object's function
+ * 
+ */
+
+#include "MockImportName.h"
+#include <string>
+
+/*
+class MockImportName
+{
+public:
+  static OM_uint32              retVal;
+  static OM_uint32              minor_status;
+  static gss_buffer_t           input_name_buffer;
+  static gss_OID                input_name_type;
+  static gss_name_t             output_name;
+  
+  static bool                   visited;
+  
+  static void reset();
+};
+
+*/
+
+OM_uint32 MockImportName::retVal = 0;
+OM_uint32 MockImportName::minor_status = 0;
+GSSBuffer MockImportName::input_name_buffer = GSSBuffer(std::string(""));
+gss_OID MockImportName::input_name_type = NULL;
+gss_name_t MockImportName::output_name = NULL;
+
+
+
+void MockImportName::reset()
+{
+  retVal = 0;
+  minor_status = 0;
+  input_name_buffer.setValue(std::string());
+}
diff --git a/json_gssapi/test/MockImportName.h b/json_gssapi/test/MockImportName.h
new file mode 100644 (file)
index 0000000..98437ac
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ * 
+ * For license details, see the LICENSE file in the root of this project.
+ * 
+ */
+
+#ifndef MOCKIMPORTNAME_H
+#define MOCKIMPORTNAME_H
+
+#include <gssapi.h>
+
+#include "datamodel/GSSBuffer.h"
+
+class MockImportName
+{
+public:
+  static OM_uint32      retVal;
+  static OM_uint32      minor_status;
+  static GSSBuffer      input_name_buffer;
+  static gss_OID        input_name_type;
+  static gss_name_t     output_name;
+  
+  static bool           visited;
+  
+  static void reset();
+};
+
+#endif // MOCKIMPORTNAME_H
diff --git a/json_gssapi/test/datamodel/CMakeLists.txt b/json_gssapi/test/datamodel/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/json_gssapi/test/datamodel/GSSBufferTest.cpp b/json_gssapi/test/datamodel/GSSBufferTest.cpp
new file mode 100644 (file)
index 0000000..9c65af0
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#include "GSSBufferTest.h"
+#include <datamodel/GSSBuffer.h>
+#include <cstring>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( GSSBufferTest );
+
+void
+GSSBufferTest::setUp()
+{
+
+}
+
+void
+GSSBufferTest::tearDown()
+{
+
+}
+
+void GSSBufferTest::testStringConstructor()
+{
+    /* Variables */
+    std::string str("test string");
+    GSSBuffer buf(str);
+    gss_buffer_t gssBuf = buf.toGss();
+    
+    /* Error checking */
+    /* Setup */
+    
+    /* Main */
+    CPPUNIT_ASSERT_MESSAGE(
+        "The string was not copied in :(", 
+        (std::strncmp( (char *)str.c_str(), (char *)gssBuf->value, gssBuf->length ) == 0)
+    );
+    
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(
+        "The string was not output correctly",
+       str,
+       buf.toString()
+    );
+    
+    /* Cleanup */
+    /* Return */
+}
diff --git a/json_gssapi/test/datamodel/GSSBufferTest.h b/json_gssapi/test/datamodel/GSSBufferTest.h
new file mode 100644 (file)
index 0000000..0d73b18
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014 <copyright holder> <email>
+ *
+ * For license details, see the LICENSE file in the root of this project.
+ *
+ */
+
+#ifndef GSSBUFFERTEST_H
+#define GSSBUFFERTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class GSSBufferTest : public CppUnit::TestFixture
+{
+  
+  CPPUNIT_TEST_SUITE( GSSBufferTest );
+  CPPUNIT_TEST( testStringConstructor );
+  CPPUNIT_TEST_SUITE_END();
+
+  
+public:
+    virtual void setUp();
+    virtual void tearDown();
+    
+    virtual void testStringConstructor();
+};
+
+#endif // GSSBUFFERTEST_H