Commit 7f4be8f2 authored by mseaborn's avatar mseaborn Committed by Commit bot

NaCl: Remove old SRPC-based name service test that checks for SecureRandom

SecureRandom is being removed from the name service on the NaCl side.

This test also checks for ManifestNameService, which we are in the
process of replacing with a Chrome-IPC-based implementation.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3864
BUG=394130
TEST=browser_tests

Review URL: https://codereview.chromium.org/563583002

Cr-Commit-Position: refs/heads/master@{#294212}
parent 857fde27
......@@ -611,46 +611,6 @@
}],
],
},
{
'target_name': 'pm_nameservice_test',
'type': 'none',
'variables': {
'nexe_target': 'pm_nameservice_test',
'build_newlib': 1,
'build_glibc': 1,
'build_pnacl_newlib': 1,
'nexe_destination_dir': 'nacl_test_data',
'link_flags': [
'-lnacl_ppapi_util',
'-lppapi_cpp',
'-lppapi',
'-lsrpc',
'-lplatform',
'-lgio',
'-limc',
'-limc_syscalls',
'-lweak_ref',
],
'sources': [
'nameservice/pm_nameservice_test.cc',
],
'test_files': [
'nameservice/pm_nameservice_test.html',
],
},
'dependencies': [
'<(DEPTH)/native_client/tools.gyp:prep_toolchain',
'<(DEPTH)/ppapi/ppapi_nacl.gyp:ppapi_cpp_lib',
'<(DEPTH)/ppapi/native_client/native_client.gyp:ppapi_lib',
'<(DEPTH)/native_client/src/shared/srpc/srpc.gyp:srpc_lib',
'<(DEPTH)/native_client/src/shared/platform/platform.gyp:platform_lib',
'<(DEPTH)/native_client/src/shared/gio/gio.gyp:gio_lib',
'<(DEPTH)/native_client/src/shared/imc/imc.gyp:imc_lib',
'<(DEPTH)/native_client/src/untrusted/nacl/nacl.gyp:imc_syscalls_lib',
'<(DEPTH)/native_client/src/trusted/weak_ref/weak_ref.gyp:weak_ref_lib',
'nacl_ppapi_util',
],
},
{
'target_name': 'ppapi_extension_mime_handler',
'type': 'none',
......
/*
* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* Post-message based test for simple rpc based access to name services.
*
* Converted from srpc_nameservice_test (deprecated), i.e., C -> C++,
* srpc -> post message.
*/
#include <string>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/fcntl.h>
#include <string.h>
#include <unistd.h>
#include "native_client/src/include/nacl_scoped_ptr.h"
#include "native_client/src/public/imc_syscalls.h"
#include "native_client/src/public/name_service.h"
#include "native_client/src/shared/srpc/nacl_srpc.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
#include "ppapi/native_client/src/untrusted/nacl_ppapi_util/nacl_ppapi_util.h"
#include "ppapi/native_client/src/untrusted/nacl_ppapi_util/string_buffer.h"
#define RNG_OUTPUT_BYTES 1024
#define BYTES_PER_LINE 32
#define BYTE_SPACING 4
bool g_ns_channel_initialized = false;
NaClSrpcChannel g_ns_channel;
void dump_output(nacl::StringBuffer *sb, int d, size_t nbytes) {
nacl::scoped_array<uint8_t> bytes;
size_t got;
int copied;
bytes.reset(new uint8_t[nbytes]);
if (NULL == bytes.get()) {
perror("dump_output");
fprintf(stderr, "No memory\n");
return;
}
// Read the RNG output.
for (got = 0; got < nbytes; got += copied) {
copied = read(d, bytes.get() + got, nbytes - got);
if (-1 == copied) {
perror("dump_output:read");
fprintf(stderr, "read failure\n");
break;
}
printf("read(%d, ..., %u) -> %d\n", d, nbytes - got, copied);
}
// Hex dump it so we can eyeball it for randomness. Ideally we
// would have a chi-square test here to test randomness.
for (size_t ix = 0; ix < got; ++ix) {
if (0 == (ix & (BYTES_PER_LINE - 1))) {
sb->Printf("\n%04x:", ix);
} else if (0 == (ix & (BYTE_SPACING - 1))) {
sb->Printf(" ");
}
sb->Printf("%02x", bytes[ix]);
}
sb->Printf("\n");
}
void Initialize(const pp::Var& message_data, nacl::StringBuffer* sb) {
if (g_ns_channel_initialized) {
return;
}
int ns = -1;
nacl_nameservice(&ns);
printf("ns = %d\n", ns);
assert(-1 != ns);
int connected_socket = imc_connect(ns);
assert(-1 != connected_socket);
if (!NaClSrpcClientCtor(&g_ns_channel, connected_socket)) {
sb->Printf("Srpc client channel ctor failed\n");
close(ns);
}
sb->Printf("NaClSrpcClientCtor succeeded\n");
close(ns);
g_ns_channel_initialized = 1;
}
//
// Dump RNG output into a string.
//
void RngDump(const pp::Var& message_data, nacl::StringBuffer* sb) {
NaClSrpcError rpc_result __attribute__((unused));
int status;
int rng;
Initialize(message_data, sb);
rpc_result = NaClSrpcInvokeBySignature(&g_ns_channel,
NACL_NAME_SERVICE_LOOKUP,
"SecureRandom", O_RDONLY,
&status, &rng);
assert(NACL_SRPC_RESULT_OK == rpc_result);
printf("rpc status %d\n", status);
assert(NACL_NAME_SERVICE_SUCCESS == status);
printf("rng descriptor %d\n", rng);
dump_output(sb, rng, RNG_OUTPUT_BYTES);
close(rng);
}
void ManifestTest(const pp::Var& message_data, nacl::StringBuffer* sb) {
int status = -1;
int manifest;
Initialize(message_data, sb);
// Make the name service lookup for the manifest service descriptor.
if (NACL_SRPC_RESULT_OK !=
NaClSrpcInvokeBySignature(&g_ns_channel, NACL_NAME_SERVICE_LOOKUP,
"ManifestNameService", O_RDWR,
&status, &manifest) ||
NACL_NAME_SERVICE_SUCCESS != status) {
fprintf(stderr, "nameservice lookup failed, status %d\n", status);
return;
}
sb->Printf("Got manifest descriptor %d\n", manifest);
if (-1 == manifest) {
return;
}
// Connect to manifest name server.
int manifest_conn = imc_connect(manifest);
close(manifest);
sb->Printf("got manifest connection %d\n", manifest_conn);
if (-1 == manifest_conn) {
sb->Printf("could not connect\n");
return;
}
sb->DiscardOutput();
sb->Printf("ManifestTest: basic connectivity ok\n");
close(manifest_conn);
}
struct PostMessageHandlerDesc {
char const *request;
void (*handler)(const pp::Var& message_data, nacl::StringBuffer* out);
};
// This object represents one time the page says <embed>.
class MyInstance : public pp::Instance {
public:
explicit MyInstance(PP_Instance instance) : pp::Instance(instance) {}
virtual ~MyInstance() {}
virtual void HandleMessage(const pp::Var& message_data);
};
// HandleMessage gets invoked when postMessage is called on the DOM
// element associated with this plugin instance. In this case, if we
// are given a string, we'll post a message back to JavaScript with a
// reply string -- essentially treating this as a string-based RPC.
void MyInstance::HandleMessage(const pp::Var& message_data) {
static struct PostMessageHandlerDesc kMsgHandlers[] = {
{ "init", Initialize },
{ "rng", RngDump },
{ "manifest_test", ManifestTest },
{ reinterpret_cast<char const *>(NULL),
reinterpret_cast<void (*)(const pp::Var&, nacl::StringBuffer*)>(NULL) }
};
nacl::StringBuffer sb;
if (message_data.is_string()) {
std::string op_name(message_data.AsString());
std::string reply;
size_t len;
fprintf(stderr, "Searching for handler for request \"%s\".\n",
op_name.c_str());
for (size_t ix = 0; kMsgHandlers[ix].request != NULL; ++ix) {
if (op_name == kMsgHandlers[ix].request) {
fprintf(stderr, "found at index %u\n", ix);
kMsgHandlers[ix].handler(message_data, &sb);
break;
}
}
reply = sb.ToString();
len = strlen(reply.c_str());
fprintf(stderr, "posting reply len %d\n", len);
// fprintf(stderr, "posting reply \"%s\".\n", sb.ToString().c_str());
fprintf(stderr, "posting reply \"");
fflush(stderr);
write(2, reply.c_str(), len);
fprintf(stderr, "\".\n");
fflush(stderr);
PostMessage(pp::Var(sb.ToString()));
fprintf(stderr, "returning\n");
fflush(stderr);
}
}
// This object is the global object representing this plugin library as long
// as it is loaded.
class MyModule : public pp::Module {
public:
MyModule() : pp::Module() {}
virtual ~MyModule() {}
// Override CreateInstance to create your customized Instance object.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new MyInstance(instance);
}
};
namespace pp {
// Factory function for your specialization of the Module object.
Module* CreateModule() {
return new MyModule();
}
} // namespace pp
<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can
be found in the LICENSE file.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<script type="text/javascript" src="nacltest.js"></script>
<title>Native Client Post Message Name Service Test</title>
</head>
<body>
<h1>Native Client Post Message Name Service Test</h1>
<script type="text/javascript">
//<![CDATA[
function createModule(id, src, type) {
return createNaClEmbed({
id: id,
src: src,
width: 400,
height: 400,
type: type
});
}
var mime = 'application/x-nacl';
if (getTestArguments()['pnacl'] !== undefined) {
mime = 'application/x-pnacl';
}
var embed = createModule('naclModule', 'pm_nameservice_test.nmf', mime);
embed.basic_tests ='2';
embed.stress_tests = '0';
document.body.appendChild(embed);
function setupTests(tester, plugin) {
tester.addAsyncTest('TestInit', function(status) {
plugin.addEventListener('message', function(message_event) {
this.removeEventListener('message', arguments.callee, false);
status.assertEqual(message_event.data,
'NaClSrpcClientCtor succeeded\n');
status.pass();
}, false);
plugin.postMessage('init');
});
tester.addAsyncTest('TestRng', function(status) {
plugin.addEventListener('message', function(message_event) {
this.removeEventListener('message', arguments.callee, false);
// alert(message_event.data);
status.pass();
}, false);
plugin.postMessage('rng');
});
tester.addAsyncTest('TestManifest', function(status) {
plugin.addEventListener('message', function(message_event) {
this.removeEventListener('message', arguments.callee, false);
status.assertEqual(message_event.data,
'ManifestTest: basic connectivity ok\n');
status.pass();
}, false);
plugin.postMessage('manifest_test');
});
}
var tester = new Tester();
setupTests(tester, $('naclModule'));
tester.waitFor($('naclModule'));
tester.run();
//]]>
</script>
</body>
</html>
......@@ -130,10 +130,6 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnaclNonSfi,
RunNaClIntegrationTest(FILE_PATH_LITERAL("irt_exception_test.html"));
}
NACL_BROWSER_TEST_F(NaClBrowserTest, Nameservice, {
RunNaClIntegrationTest(FILE_PATH_LITERAL("pm_nameservice_test.html"));
})
// Some versions of Visual Studio does not like preprocessor
// conditionals inside the argument of a macro, so we put the
// conditionals on a helper function. We are already in an anonymous
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment