Below are a set of CLs being merged from the wv cdm repo to the android repo. * Fix handling of OEM Cert public key. Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/27921 ] This is a potential fix for b/36656190. Set aside public key on first call to get the public key, and use it afterwards. This gets rid of extra calls to OEMCrypto_GetOEMPublicCertificate(), which has side-effect of staging the OEM private key. This also fixes a problem where the public cert string was not being trimmed to match the size returned by OEMCrypto_GetOEMPublicCertificate(). * Complete provisioning request/response for Provisioning 3.0 Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27780 ] Fix bug on provisioning request path where GenerateDerivedKeys() was being called when preparing to generate the signature. Add message signature verification, and call correct OEMCrypto routine to rewrap the private key (OEMCrypto_RewrapDeviceRSAKey30). * Implement Cdm::deleteAllUsageRecords() Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27780 ] Delete all usage records for current origin. Removes usage records from file system and retains the PSTs. The deletes any usage entries matching those PSTs held by OEMCrypto. BUG: 35319024 * Remove stringencoders library from third_party. Author: Jacob Trimble <modmaker@google.com> [ Merge of http://go/wvgerrit/27585 ] We have a fork of the stringencoders library that we use for base64 encoding. This reimplements base64 encoding to remove the extra dependency and to reduce the amount of code. * Add Cdm::deleteUsageRecord() based on key_set_id. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27605 ] Delete specified usage record from file system usage info and from OEMCrypto. BUG: 35319024 * Modifiable OEMCrypto Author: Fred Gylys-Colwell <fredgc@google.com> [ Merge of http://go/wvgerrit/24729 ] This CL adds a new variant of the OEMCrypto mock code that adjusts its behavior based on a configuration file. This is intended for testing. For example, a tester can set current_hdcp to 2 in the options.txt file, push it to the device, and verify that a license is granted for HDCP 2.0. Then the tester can edit the value of current_hdcp to 1 and push the file to the device. Playback should stop because the license is no longer valid. This variant uses a real level 1 liboemcrypto.so to push data to a secure buffer. That means we can test playback for a license that requires secure buffers on an Android device with real secure buffers. BUG: 35141278 BUG: 37353534 BUG: 71650075 Test: Not currently passing. Will be addressed in a subsequent commit in the chain. Change-Id: I58443c510919e992bb455192e70373490a00e2b6
129 lines
4.5 KiB
C++
129 lines
4.5 KiB
C++
// Copyright 2017 Google Inc. All Rights Reserved.
|
|
//
|
|
// This file contains the helper classes and methods for using field tuples
|
|
// used by metrics classes to record variations of a single metric.
|
|
#ifndef WVCDM_METRICS_FIELD_TUPLES_H_
|
|
#define WVCDM_METRICS_FIELD_TUPLES_H_
|
|
|
|
#include <cstdarg>
|
|
#include <memory>
|
|
#include <ostream>
|
|
#include <sstream>
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace wvcdm {
|
|
namespace metrics {
|
|
namespace util {
|
|
|
|
// TODO(blueeyes): Change to use C++ 11 support for variadic template args.
|
|
// The C++ 03 pattern is no longer needed since we require C++11. b/68766426.
|
|
|
|
// This is a placeholder type for unused type parameters. It aids in supporting
|
|
// templated classes with "variable" type arguments.
|
|
struct Unused {
|
|
// Required for compilation. Should never be used.
|
|
inline friend std::ostream& operator<< (std::ostream& out, const Unused&)
|
|
{ return out; }
|
|
};
|
|
|
|
// This utility method formats the collection of field name/value pairs.
|
|
// The format of the string is:
|
|
//
|
|
// [{field:value[&field:value]*}]
|
|
//
|
|
// If there are no pairs, returns a blank string.
|
|
template<typename F1, typename F2, typename F3, typename F4>
|
|
std::string MakeFieldNameString(const std::vector<std::string>& field_names,
|
|
const F1 field1, const F2 field2,
|
|
const F3 field3, const F4 field4) {
|
|
std::stringstream field_name_and_values;
|
|
std::vector<std::string>::const_iterator field_name_iterator =
|
|
field_names.begin();
|
|
if (field_name_iterator == field_names.end()) {
|
|
return field_name_and_values.str();
|
|
}
|
|
// There is at least one name/value pair. Prepend open brace.
|
|
field_name_and_values << "{";
|
|
field_name_and_values << *field_name_iterator << ':' << field1;
|
|
if (++field_name_iterator == field_names.end()) {
|
|
field_name_and_values << "}";
|
|
return field_name_and_values.str();
|
|
}
|
|
field_name_and_values << '&' << *field_name_iterator << ':' << field2;
|
|
if (++field_name_iterator == field_names.end()) {
|
|
field_name_and_values << "}";
|
|
return field_name_and_values.str();
|
|
}
|
|
field_name_and_values << '&' << *field_name_iterator << ':' << field3;
|
|
if (++field_name_iterator == field_names.end()) {
|
|
field_name_and_values << "}";
|
|
return field_name_and_values.str();
|
|
}
|
|
field_name_and_values << '&' << *field_name_iterator << ':' << field4;
|
|
field_name_and_values << "}";
|
|
return field_name_and_values.str();
|
|
}
|
|
|
|
// This specialization of the helper method is a shortcut for class
|
|
// instances with no fields.
|
|
template<>
|
|
inline std::string MakeFieldNameString<Unused, Unused, Unused, Unused>(
|
|
const std::vector<std::string>& /* field_names */,
|
|
const Unused /* unused1 */, const Unused /* unused2 */,
|
|
const Unused /* unused3 */, const Unused /* unused4 */) {
|
|
return "";
|
|
}
|
|
|
|
// This helper function appends the field names to a vector of strings.
|
|
inline void AppendFieldNames(std::vector<std::string>* field_name_vector,
|
|
int field_count, ...) {
|
|
va_list field_names;
|
|
|
|
va_start(field_names, field_count);
|
|
for (int x = 0; x < field_count; x++) {
|
|
field_name_vector->push_back(va_arg(field_names, const char*));
|
|
}
|
|
va_end(field_names);
|
|
}
|
|
|
|
// These helper methods and FirstUnusedType assure that there is no mismatch
|
|
// between the specified types for metrics type parameters and the constructors
|
|
// and methods used for the specializations.
|
|
template <bool>
|
|
struct CompileAssert {};
|
|
#define COMPILE_ASSERT(expr, msg) \
|
|
typedef util::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
|
|
|
|
template <typename T> struct is_unused { static const bool value = false; };
|
|
template <> struct is_unused<Unused> { static const bool value = true; };
|
|
|
|
template <typename F1, typename F2, typename F3, typename F4>
|
|
class FirstUnusedType {
|
|
static const bool a = is_unused<F1>::value;
|
|
static const bool b = is_unused<F2>::value;
|
|
static const bool c = is_unused<F3>::value;
|
|
static const bool d = is_unused<F4>::value;
|
|
// Check that all types after the first Unused are also Unused.
|
|
COMPILE_ASSERT(a <= b, Invalid_Unused_At_Position_2);
|
|
COMPILE_ASSERT(b <= c, Invalid_Unused_At_Position_3);
|
|
COMPILE_ASSERT(c <= d, Invalid_Unused_At_Position_4);
|
|
|
|
public:
|
|
static const int value = 5 - (a + b + c + d);
|
|
};
|
|
|
|
// Asserts that no Unused types exist before N; after N, are all Unused types.
|
|
#define ASSERT_METRIC_UNUSED_START_FROM(N) \
|
|
COMPILE_ASSERT((\
|
|
util::FirstUnusedType<F1, F2, F3, F4>::value) == N, \
|
|
Unused_Start_From_##N)
|
|
|
|
} // namespace util
|
|
} // namespace metrics
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_METRICS_FIELD_TUPLES_H_
|
|
|