2 * Copyright (c) 2014 <copyright holder> <email>
4 * For license details, see the LICENSE file in the root of this project.
9 #include <cache/GSSContextCache.h>
12 #include <mit-krb5/gssapi/gssapi.h>
14 GSSGetMic::GSSGetMic ( JSONObject* params, gss_get_mic_type fn )
17 loadParameters(params);
21 * {"method": "gss_get_mic",
24 * "context_handle": "#######",
25 * "qop_req": "GSS_C_QOP_DEFAULT",
26 * "input_message": "mary had a little lamb"
31 bool GSSGetMic::loadParameters ( JSONObject* params )
33 std::string sQopReq, sConfReq, sInputMessage;
44 if ( ! params->get("arguments").get("qop_req").isNull() )
46 if (params->get("arguments").get("qop_req").isString())
48 sQopReq = params->get("arguments").get("qop_req").string();
49 if (sQopReq == "GSS_C_QOP_DEFAULT")
50 this->qop_req = GSS_C_QOP_DEFAULT;
52 throw std::invalid_argument( std::string("Invalid QOP type given: ") + sQopReq );
53 } else if (params->get("arguments").get("qop_req").isInteger())
54 this->qop_req = (gss_cred_usage_t)( params->get("arguments").get("qop_req").integer() );
56 throw std::invalid_argument( "Unrecognized argument type for qop_req." );
62 if ( ! params->get("arguments").get("input_message").isNull() )
64 sInputMessage = params->get("arguments").get("input_message").string();
65 this->inputMessage.setValue(sInputMessage);
71 if ( ! params->get("arguments").get("context_handle").isNull() )
73 sInputMessage = params->get("arguments").get("context_handle").string();
74 GSSContext ctx = GSSContextCache::instance()->retrieve(sInputMessage);
75 this->context = ctx.getContext();
83 void GSSGetMic::execute()
85 gss_buffer_desc output;
87 this->retVal = this->function(
88 &(this->minor_status),
91 this->inputMessage.toGss(),
95 this->outputToken.setValue( (char *)(output.value), output.length );
98 JSONObject* GSSGetMic::toJSON()
101 JSONObject *ret = new JSONObject();
102 JSONObject *values = new JSONObject();
111 values->set("major_status", this->retVal);
112 values->set("minor_status", this->minor_status);
116 this->outputToken.toString().c_str()
119 // Put it all together.
120 ret->set("command", "gss_get_mic");
121 ret->set("return_values", *values);