Message passing with cookies (app_tag, gssweb_bg_tag, etc.)
[gssweb.git] / json_gssapi / src / commands / GSSUnwrap.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  *
4  * For license details, see the LICENSE file in the root of this project.
5  *
6  */
7
8 #include "GSSUnwrap.h"
9 #include <cache/GSSContextCache.h>
10
11 GSSUnwrap::GSSUnwrap ( JSONObject* params, gss_unwrap_type fn )
12 {
13   function = fn;
14   loadParameters(params);
15 }
16
17 bool GSSUnwrap::loadParameters(JSONObject *params)
18 {
19   /* Variables */
20   std::string sInputMessage;
21   
22   /* Error checking */
23   /* Setup */
24   // Should I zeroOut?
25   
26   /* Main processing */
27   
28   /*****************
29    * input_message *
30    *****************/
31   if ( ! params->get("input_message").isNull() )
32   {
33     sInputMessage = params->get("input_message").string();
34     this->inputMessage.setValue(sInputMessage);
35   }
36   
37   /******************
38    * context_handle *
39    ******************/
40   if ( ! params->get("context_handle").isNull() )
41   {
42     sInputMessage = params->get("context_handle").string();
43     GSSContext ctx = GSSContextCache::instance()->retrieve(sInputMessage);
44     this->context = ctx.getContext();
45   }
46   
47   /* Cleanup */
48   /* Return */
49   return true;
50 }
51
52
53 void GSSUnwrap::execute()
54 {
55   /* Variables */
56   gss_buffer_desc output_buf;
57   
58   retVal = function(
59     &(this->minor_status),
60     this->context,
61     this->inputMessage.toGss(),
62     &output_buf,
63     &(this->conf_state),
64     &(this->qop_state)
65   );
66   
67   this->outputMessage.setValue( (char *)output_buf.value, output_buf.length );
68 }
69
70 JSONObject* GSSUnwrap::toJSON()
71 {
72   /* Variables */
73   const char *conf_state;
74   JSONObject *values = new JSONObject();
75   
76   /* Error checking */
77   
78   /* Setup */
79   
80   /* Main */
81   // Return Values
82   // Easy stuff
83   values->set("major_status", this->retVal);
84   values->set("minor_status", this->minor_status);
85   
86   values->set("qop_state", this->qop_state);
87   
88   conf_state = (this->conf_state) ? "TRUE" : "FALSE";
89   values->set("conf_state", conf_state);
90   
91   values->set(
92     "output_message",
93     this->outputMessage.toString().c_str()
94   );
95   
96   /* Cleanup */
97   
98   /* Return */
99   return(values);
100 }