summaryrefslogtreecommitdiffstats
path: root/chrome/nacl/nacl_validation_query.h
diff options
context:
space:
mode:
authorncbray@google.com <ncbray@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-17 00:04:36 +0000
committerncbray@google.com <ncbray@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-17 00:04:36 +0000
commit2121caa6462d67a8cc37aa9318ea05891fdcef65 (patch)
tree7373a2ad1fbed29dfcb8557d1fa16d0c2fc86138 /chrome/nacl/nacl_validation_query.h
parentf94d4ccdc558d078fe913f190939766a26786fcb (diff)
downloadchromium_src-2121caa6462d67a8cc37aa9318ea05891fdcef65.zip
chromium_src-2121caa6462d67a8cc37aa9318ea05891fdcef65.tar.gz
chromium_src-2121caa6462d67a8cc37aa9318ea05891fdcef65.tar.bz2
Add the first part of Chrome-side support for NaCl validation caching.
This code injects a validation caching implementation into sel_ldr that hashes all of the data it is given and then queries against a stub database. The stub database returns whatever value is specified in the NACL_VALIDATION_RESULT env var for all validation requests. This code is inactive in Chrome unless NACL_VALIDATION_CACHE=1 is set in the environment. BUG= http://code.google.com/p/nativeclient/issues/detail?id=2515 TEST= unit_tests --gtest_filter=NaClValidationQueryTest* Review URL: https://chromiumcodereview.appspot.com/9553009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127304 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/nacl/nacl_validation_query.h')
-rw-r--r--chrome/nacl/nacl_validation_query.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/chrome/nacl/nacl_validation_query.h b/chrome/nacl/nacl_validation_query.h
new file mode 100644
index 0000000..1a21bb4
--- /dev/null
+++ b/chrome/nacl/nacl_validation_query.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2012 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.
+
+#ifndef CHROME_NACL_NACL_VALIDATION_QUERY_H_
+#define CHROME_NACL_NACL_VALIDATION_QUERY_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/string_piece.h"
+#include "crypto/hmac.h"
+
+struct NaClValidationCache;
+class NaClValidationDB;
+class NaClValidationQuery;
+
+class NaClValidationQueryContext {
+ public:
+ NaClValidationQueryContext(NaClValidationDB* db,
+ const std::string& profile_key,
+ const std::string& nacl_version);
+
+ NaClValidationQuery* CreateQuery();
+
+ private:
+ NaClValidationDB* db_;
+
+ // A key used by HMAC that is specific to this installation of Chrome.
+ std::string profile_key_;
+
+ // Bytes indicating the "version" of the validator being used. This is used
+ // to implicitly invalidate the cache - changing the version will change the
+ // hashes that are produced.
+ std::string nacl_version_;
+};
+
+class NaClValidationQuery {
+ public:
+ // SHA256 digest size.
+ static const int kDigestLength = 32;
+
+ NaClValidationQuery(NaClValidationDB* db, const std::string& profile_key);
+
+ void AddData(const char* data, size_t length);
+ void AddData(const unsigned char* data, size_t length);
+ void AddData(const base::StringPiece& data);
+
+ int QueryKnownToValidate();
+
+ void SetKnownToValidate();
+
+ NaClValidationQueryContext* context_;
+
+ private:
+ enum QueryState {
+ READY,
+ GET_CALLED,
+ SET_CALLED
+ };
+
+ // The HMAC interface currently does not support incremental signing. To work
+ // around this, each piece of data is signed and the signature is added to a
+ // buffer. If there is not enough space in the buffer to accommodate new
+ // data, the buffer contents are signed and the new signature replaces the
+ // contents of the buffer. CompressBuffer performs this operation. In
+ // affect, a hash tree is constructed to emulate incremental signing.
+ void CompressBuffer();
+
+ // Track the state of the query to detect suspicious method calls.
+ QueryState state_;
+
+ crypto::HMAC hasher_;
+ NaClValidationDB* db_;
+
+ // The size of buffer_ is a somewhat arbitrary choice. It needs to be at
+ // at least kDigestLength * 2, but it can be arbitrarily large. In practice
+ // there are 4 calls to AddData (version, architechture, cpu features, and
+ // code), so 4 times digest length means the buffer will not need to be
+ // compressed as an intermediate step in the expected use cases.
+ char buffer_[kDigestLength * 4];
+ int buffer_length_;
+
+ DISALLOW_COPY_AND_ASSIGN(NaClValidationQuery);
+};
+
+// Create a validation cache interface for use by sel_ldr.
+struct NaClValidationCache* CreateValidationCache(
+ NaClValidationDB* db, const std::string& profile_key,
+ const std::string& nacl_version);
+
+#endif // CHROME_NACL_NACL_VALIDATION_QUERY_H_