2 * Copyright (c) 2014, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "GSSPseudoRandom.h"
38 #include <cache/GSSContextCache.h>
39 #include <datamodel/GSSContext.h>
41 GSSPseudoRandom::GSSPseudoRandom(JSONObject *params,
42 gss_pseudo_random_type fn)
48 loadParameters(params);
58 * "context_handle": "########",
60 * "prf_in": "la la la input message",
61 * "desired_output_len": ####
65 bool GSSPseudoRandom::loadParameters ( JSONObject* params )
68 std::string sInputMessage;
77 if ( ! params->get("prf_key").isNull() )
79 if (params->get("prf_key").isInteger())
80 this->key = (int )params->get("prf_key").integer();
82 throw std::invalid_argument( "Unrecognized argument type for prf_key." );
86 /**********************
87 * desired_output_len *
88 **********************/
89 if ( ! params->get("desired_output_len").isNull() )
91 if (params->get("desired_output_len").isInteger())
92 this->desiredOutputLength = (int )params->get("desired_output_len").integer();
94 throw std::invalid_argument( "Unrecognized argument type for desired_output_len." );
101 if ( ! params->get("prf_in").isNull() )
103 if (params->get("prf_in").isString())
105 sInputMessage = params->get("prf_in").string();
106 this->inputMessage.setValue(sInputMessage);
114 if ( ! params->get("context_handle").isNull() )
116 if (params->get("context_handle").isString())
118 std::string contextKey = params->get("context_handle").string();
119 GSSContext ctx = GSSContextCache::instance()->retrieve(contextKey);
120 this->context = ctx.getContext();
130 void GSSPseudoRandom::execute()
133 gss_buffer_desc output_buf;
140 this->inputMessage.toGss(),
141 this->desiredOutputLength,
145 this->minor_status = minor;
146 this->outputMessage.setValue( (char *)output_buf.value, output_buf.length );
149 /* Desired JSON output:
152 * "command": "gss_pseudo_random",
157 * "random_bytes": "asdf"
161 JSONObject* GSSPseudoRandom::toJSON()
164 JSONObject *values = new JSONObject();
173 values->set("major_status", this->retVal);
174 values->set("minor_status", this->minor_status);
178 this->outputMessage.toString().c_str()