Browse Source

add security_token to HTML & JavaScript

refactor-result-recursion
Lars Rohwedder 6 years ago
parent
commit
fa9d95e9e6
5 changed files with 20 additions and 5 deletions
  1. +10
    -0
      html/index.html
  2. +4
    -1
      html/interactive.js
  3. +1
    -1
      server/json_rpc.cc
  4. +2
    -0
      server/mt-server.cc
  5. +3
    -3
      server/security-token.cc

+ 10
- 0
html/index.html View File

@ -33,6 +33,11 @@
<td>
<div id="sessions"><i>(none, yet)</i></div>
</td></tr>
<tr><td>Security token:</td>
<td>
<input type="text" id="security_token" size="50" maxlength="80" placeholder="see /tmp/pEp-json-token-*">
</td>
</tr>
<tr><td>Function name:</td><td>
<select name="fn_name" id="fn_name" size="1" onChange="on_select_change()">
<option>–––––</option>
@ -46,6 +51,11 @@
</form>
<form id="frm_2" name="frm_2">
<textarea placeholder="Just a scratchboard for text copy & paste :-)" rows="20" columns="66">
</textarea>
</form>
<script type="text/javascript">
init_pep_functions();
on_select_change();


+ 4
- 1
html/interactive.js View File

@ -18,7 +18,9 @@ function genInput(id, size, direction, value, onchange)
function addString(nr)
{
document.getElementById('debug').innerHTML += ' * addString(' + nr + ')<\nfunc_params = ' + JSON.stringify(func_params) + '\n';
var pp = {direction:"In", type:"StringList"};
func_params[nr].push("");
genStringList(nr, pp);
document.getElementById('li_' + nr ).innerHTML = Param2Form.StringList(nr, pp, func_params[nr]);
@ -261,6 +263,7 @@ function button_click()
var url = document.getElementById("server").value + 'callFunction';
var request = {};
request.security_token = document.getElementById("security_token").value;
request.method = document.getElementById("fn_name").value;
request.params = new Array(func.params.length);
@ -310,7 +313,7 @@ function prepare_call(f)
}
document.getElementById("td_param").disabled = false;
func_params = new Array(func.params.length, '');
func_params = new Array(func.params.length);
var len = f.params.length;
if(len==0)


+ 1
- 1
server/json_rpc.cc View File

@ -56,7 +56,7 @@ js::Object call(const FunctionMap& fm, const js::Object& request)
return make_error(JSON_RPC::INVALID_REQUEST, "Invalid request: no valid member \"jsonrpc\" found.", request, request_id);
}
const auto sec_token = find_value(request, "security-token");
const auto sec_token = find_value(request, "security_token");
if(sec_token.type()!=js::str_type || verify_security_token(sec_token.get_str()) == false)
{
return make_error(JSON_RPC::INVALID_REQUEST, "Invalid request: Wrong security token.", request, request_id);


+ 2
- 0
server/mt-server.cc View File

@ -160,6 +160,8 @@ const FunctionMap functions = {
// my own example function that does something useful. :-)
FP( "—— Other ——", new Separator ),
FP( "encrypt_and_sign", new Func<PEP_STATUS, In<PEP_SESSION>, In<stringlist_t*>, In<const char*>, In<size_t>, Out<char*>, Out<size_t>> ( &encrypt_and_sign) ),
FP( "version", new Func<std::string>( &getVersion ) ),
FP( "releaseSession", new Func<PEP_STATUS, InRaw<PEP_SESSION>>(&releaseSession) ),
};


+ 3
- 3
server/security-token.cc View File

@ -44,7 +44,7 @@ std::string get_token_filename()
const char* const temp_dir = getenv("TEMP");
const char* const user_name = getenv("USER");
const std::string ret = std::string(temp_dir ? temp_dir : "/tmp") + "pEp-json-token-" + std::string( user_name ? user_name : "XXX" );
const std::string ret = std::string(temp_dir ? temp_dir : "/tmp") + "/pEp-json-token-" + std::string( user_name ? user_name : "XXX" );
return ret;
}
@ -64,9 +64,9 @@ void create_security_token(const std::string& server_address, unsigned port_nr,
o.emplace_back("address", server_address);
o.emplace_back("port", uint64_t(port_nr));
o.emplace_back("path", path);
o.emplace_back("security-token", sec_token );
o.emplace_back("security_token", sec_token );
const std::string content = js::write( o, js::pretty_print | js::raw_utf8 );
const std::string content = js::write( o, js::pretty_print | js::raw_utf8 ) + '\n';
write(fd, content.data(), content.size());
close(fd);
}


Loading…
Cancel
Save