Update path to Widevine MediaDrm engine credentials
Use separate directories for unit test-generated credentials vs actual credentials, so the unit test credentials don't interfere with the real ones. related-to-bug: 8620943 Merge of: Update path to where CDM persistently stores data https://widevine-internal-review.googlesource.com/#/c/5300/ Rename Keybox File https://widevine-internal-review.googlesource.com/#/c/5240/ ... from the widevine CDM repo. Change-Id: Idefa484b3a2f71f723238f033460bf431ce4209b
This commit is contained in:
@@ -14,10 +14,9 @@ class DeviceFiles {
|
||||
static bool RetrieveCertificate(std::string* certificate,
|
||||
std::string* wrapped_private_key);
|
||||
|
||||
static std::string GetPath(const char* dir, const char * filename);
|
||||
static std::string GetBasePath(const char* dir);
|
||||
static const char* kBasePath;
|
||||
static const char* kIdmPath;
|
||||
static const char* kCencPath;
|
||||
static const char* kPathDelimiter;
|
||||
static const char* kDeviceCertificateFileName;
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "device_files.pb.h"
|
||||
#include "file_store.h"
|
||||
@@ -14,9 +15,8 @@
|
||||
namespace wvcdm {
|
||||
|
||||
// TODO(rfrias): Make this work for non-unix paths
|
||||
const char* DeviceFiles::kBasePath = "/data/mediadrm";
|
||||
const char* DeviceFiles::kIdmPath = "/data/mediadrm/IDM";
|
||||
const char* DeviceFiles::kCencPath = "/data/mediadrm/IDM/CENC";
|
||||
const char* DeviceFiles::kBasePath = "/data/mediadrm/IDM";
|
||||
const char* DeviceFiles::kPathDelimiter = "/";
|
||||
const char* DeviceFiles::kDeviceCertificateFileName = "cert.bin";
|
||||
|
||||
// Protobuf generated classes.
|
||||
@@ -123,12 +123,14 @@ bool DeviceFiles::StoreFile(const char* name, const std::string& data) {
|
||||
if (!name)
|
||||
return false;
|
||||
|
||||
if (!File::IsDirectory(kCencPath)) {
|
||||
if (!File::CreateDirectory(kCencPath))
|
||||
std::string path = GetBasePath(kBasePath);
|
||||
|
||||
if (!File::IsDirectory(path)) {
|
||||
if (!File::CreateDirectory(path))
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string path = GetPath(kCencPath, name);
|
||||
path += name;
|
||||
|
||||
File file(path, File::kCreate | File::kTruncate | File::kBinary);
|
||||
if (file.IsBad()) {
|
||||
@@ -152,7 +154,7 @@ bool DeviceFiles::RetrieveFile(const char* name, std::string* data) {
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
std::string path = GetPath(kCencPath, name);
|
||||
std::string path = GetBasePath(kBasePath) + name;
|
||||
|
||||
if (!File::Exists(path)) {
|
||||
LOGW("DeviceFiles::RetrieveFile: %s does not exist", path.c_str());
|
||||
@@ -185,12 +187,11 @@ bool DeviceFiles::RetrieveFile(const char* name, std::string* data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string DeviceFiles::GetPath(const char* dir, const char * filename) {
|
||||
std::string DeviceFiles::GetBasePath(const char* dir) {
|
||||
// TODO(rfrias): Make this work for non-unix paths
|
||||
std::string path = dir;
|
||||
path += "/";
|
||||
path += filename;
|
||||
return path;
|
||||
std::stringstream ss;
|
||||
ss << dir << getuid() << kPathDelimiter;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
namespace wvcdm {
|
||||
|
||||
TEST(DeviceFilesTest, StoreCertificate) {
|
||||
std::string device_base_path =
|
||||
DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string device_certificate_path =
|
||||
DeviceFiles::GetPath(DeviceFiles::kCencPath,
|
||||
DeviceFiles::kDeviceCertificateFileName);
|
||||
device_base_path + DeviceFiles::kDeviceCertificateFileName;
|
||||
|
||||
if (!File::Exists(DeviceFiles::kCencPath))
|
||||
EXPECT_TRUE(File::CreateDirectory(DeviceFiles::kCencPath));
|
||||
if (!File::Exists(device_base_path))
|
||||
EXPECT_TRUE(File::CreateDirectory(device_base_path));
|
||||
if (File::Exists(device_certificate_path))
|
||||
EXPECT_TRUE(File::Remove(device_certificate_path));
|
||||
|
||||
@@ -33,12 +34,13 @@ TEST(DeviceFilesTest, StoreCertificate) {
|
||||
}
|
||||
|
||||
TEST(DeviceFilesTest, StoreCertificateInitial) {
|
||||
std::string device_base_path =
|
||||
DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string device_certificate_path =
|
||||
DeviceFiles::GetPath(DeviceFiles::kCencPath,
|
||||
DeviceFiles::kDeviceCertificateFileName);
|
||||
device_base_path + DeviceFiles::kDeviceCertificateFileName;
|
||||
|
||||
if (File::Exists(DeviceFiles::kCencPath))
|
||||
EXPECT_TRUE(File::Remove(DeviceFiles::kIdmPath));
|
||||
if (File::Exists(device_base_path))
|
||||
EXPECT_TRUE(File::Remove(device_base_path));
|
||||
|
||||
char test_buf[1200];
|
||||
for (size_t i = 0; i < sizeof(test_buf); i++) {
|
||||
@@ -57,12 +59,13 @@ TEST(DeviceFilesTest, StoreCertificateInitial) {
|
||||
}
|
||||
|
||||
TEST(DeviceFilesTest, RetrieveCertificate) {
|
||||
std::string device_base_path =
|
||||
DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string device_certificate_path =
|
||||
DeviceFiles::GetPath(DeviceFiles::kCencPath,
|
||||
DeviceFiles::kDeviceCertificateFileName);
|
||||
device_base_path + DeviceFiles::kDeviceCertificateFileName;
|
||||
|
||||
if (File::Exists(DeviceFiles::kCencPath))
|
||||
EXPECT_TRUE(File::Remove(DeviceFiles::kIdmPath));
|
||||
if (File::Exists(device_base_path))
|
||||
EXPECT_TRUE(File::Remove(device_base_path));
|
||||
|
||||
char test_buf[1200];
|
||||
for (size_t i = 0; i < sizeof(test_buf); i++) {
|
||||
@@ -87,6 +90,7 @@ TEST(DeviceFilesTest, RetrieveCertificate) {
|
||||
certificate.size()) == 0);
|
||||
EXPECT_TRUE(memcmp(wrapped_private_key.data(), in_wrapped_private_key.data(),
|
||||
wrapped_private_key.size()) == 0);
|
||||
EXPECT_TRUE(File::Remove(device_base_path));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "device_files.h"
|
||||
#include "file_store.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
// TODO(rfrias): Make this work for non-unix paths
|
||||
const std::string kDataDrmDir = "/data/mediadrm";
|
||||
const std::string kIdmTestDir = "/data/mediadrm/IDMtest";
|
||||
const std::string kCencTestDir = "/data/mediadrm/IDMtest/CENCtest";
|
||||
const std::string kCencTestDirWithSlash = "/data/mediadrm/IDMtest/CENCtest/";
|
||||
const std::string kTestFile01 = "/data/mediadrm/IDMtest/CENCtest/file01.txt";
|
||||
|
||||
const std::string kFileExists = "/system/bin/sh";
|
||||
const std::string kDirExists = "/system/bin";
|
||||
const std::string kFileDoesNotExist = "/system/bin/shxyxyxy";
|
||||
@@ -27,102 +22,117 @@ TEST(FileTest, FileExists) {
|
||||
}
|
||||
|
||||
TEST(FileTest, CreateDirectory) {
|
||||
if (File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::Remove(kIdmTestDir));
|
||||
EXPECT_FALSE(File::Exists(kCencTestDir));
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
EXPECT_TRUE(File::Remove(kIdmTestDir));
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDirWithSlash));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
EXPECT_TRUE(File::Remove(kIdmTestDir));
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string dirWoDelimiter = dir.substr(0, dir.size()-1);
|
||||
if (File::Exists(dirWoDelimiter))
|
||||
EXPECT_TRUE(File::Remove(dirWoDelimiter));
|
||||
EXPECT_FALSE(File::Exists(dirWoDelimiter));
|
||||
EXPECT_TRUE(File::CreateDirectory(dirWoDelimiter));
|
||||
EXPECT_TRUE(File::Exists(dirWoDelimiter));
|
||||
EXPECT_TRUE(File::Remove(dirWoDelimiter));
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
EXPECT_TRUE(File::Remove(dir));
|
||||
}
|
||||
|
||||
TEST(FileTest, RemoveDir) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
EXPECT_TRUE(File::Remove(kCencTestDir));
|
||||
EXPECT_FALSE(File::Exists(kCencTestDir));
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
EXPECT_TRUE(File::Remove(dir));
|
||||
EXPECT_FALSE(File::Exists(dir));
|
||||
}
|
||||
|
||||
TEST(FileTest, OpenFileUsingConstructor) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File::Remove(kTestFile01);
|
||||
File file(kTestFile01, File::kCreate);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File::Remove(path);
|
||||
File file(path, File::kCreate);
|
||||
EXPECT_TRUE(file.IsOpen());
|
||||
file.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
}
|
||||
|
||||
TEST(FileTest, OpenFile) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File::Remove(kTestFile01);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File::Remove(path);
|
||||
File file;
|
||||
file.Open(kTestFile01, File::kCreate);
|
||||
file.Open(path, File::kCreate);
|
||||
EXPECT_TRUE(file.IsOpen());
|
||||
file.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
}
|
||||
|
||||
TEST(FileTest, RemoveDirAndFile) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File file(kTestFile01, File::kCreate);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File file(path, File::kCreate);
|
||||
EXPECT_TRUE(file.IsOpen());
|
||||
file.Close();
|
||||
EXPECT_TRUE(File::Remove(kTestFile01));
|
||||
EXPECT_TRUE(File::Remove(kCencTestDir));
|
||||
EXPECT_FALSE(File::Exists(kTestFile01));
|
||||
EXPECT_FALSE(File::Exists(kCencTestDir));
|
||||
EXPECT_TRUE(File::Remove(path));
|
||||
EXPECT_TRUE(File::Remove(dir));
|
||||
EXPECT_FALSE(File::Exists(path));
|
||||
EXPECT_FALSE(File::Exists(dir));
|
||||
}
|
||||
|
||||
TEST(FileTest, IsDir) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File file(kTestFile01, File::kCreate);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File file(path, File::kCreate);
|
||||
EXPECT_TRUE(file.IsOpen());
|
||||
file.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
EXPECT_FALSE(File::IsDirectory(kTestFile01));
|
||||
EXPECT_TRUE(File::IsDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
EXPECT_FALSE(File::IsDirectory(path));
|
||||
EXPECT_TRUE(File::IsDirectory(dir));
|
||||
}
|
||||
|
||||
TEST(FileTest, IsRegularFile) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File file(kTestFile01, File::kCreate);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File file(path, File::kCreate);
|
||||
EXPECT_TRUE(file.IsOpen());
|
||||
file.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
EXPECT_TRUE(File::IsRegularFile(kTestFile01));
|
||||
EXPECT_FALSE(File::IsRegularFile(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
EXPECT_TRUE(File::IsRegularFile(path));
|
||||
EXPECT_FALSE(File::IsRegularFile(dir));
|
||||
}
|
||||
|
||||
TEST(FileTest, WriteReadTextFile) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File::Remove(kTestFile01);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File::Remove(path);
|
||||
|
||||
const char* test_string = "This is a test";
|
||||
File file1(kTestFile01, File::kCreate);
|
||||
File file1(path, File::kCreate);
|
||||
EXPECT_TRUE(file1.IsOpen());
|
||||
EXPECT_TRUE(file1.Write(test_string, strlen(test_string)+1));
|
||||
file1.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
|
||||
char buf[100];
|
||||
File file2(kTestFile01, File::kReadOnly);
|
||||
File file2(path, File::kReadOnly);
|
||||
EXPECT_TRUE(file2.IsOpen());
|
||||
EXPECT_EQ((ssize_t)strlen(test_string)+1, file2.Read(buf, sizeof(buf)));
|
||||
file2.Close();
|
||||
@@ -130,23 +140,25 @@ TEST(FileTest, WriteReadTextFile) {
|
||||
}
|
||||
|
||||
TEST(FileTest, WriteReadBinaryFile) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
EXPECT_TRUE(File::Exists(kCencTestDir));
|
||||
File::Remove(kTestFile01);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
EXPECT_TRUE(File::Exists(dir));
|
||||
File::Remove(path);
|
||||
|
||||
unsigned char test_buf[600];
|
||||
for (size_t i = 0; i < sizeof(test_buf); i++) {
|
||||
test_buf[i] = i % 128;
|
||||
}
|
||||
File file1(kTestFile01, File::kCreate | File::kBinary);
|
||||
File file1(path, File::kCreate | File::kBinary);
|
||||
EXPECT_TRUE(file1.IsOpen());
|
||||
EXPECT_TRUE(file1.Write(test_buf, sizeof(test_buf)));
|
||||
file1.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
|
||||
char buf[1000];
|
||||
File file2(kTestFile01, File::kReadOnly);
|
||||
File file2(path, File::kReadOnly);
|
||||
EXPECT_TRUE(file2.IsOpen());
|
||||
EXPECT_EQ((ssize_t)sizeof(test_buf), file2.Read(buf, sizeof(buf)));
|
||||
file2.Close();
|
||||
@@ -154,21 +166,24 @@ TEST(FileTest, WriteReadBinaryFile) {
|
||||
}
|
||||
|
||||
TEST(FileTest, FileSize) {
|
||||
if (!File::Exists(kCencTestDir))
|
||||
EXPECT_TRUE(File::CreateDirectory(kCencTestDir));
|
||||
File::Remove(kTestFile01);
|
||||
std::string dir = DeviceFiles::GetBasePath(DeviceFiles::kBasePath);
|
||||
std::string path = dir + DeviceFiles::kDeviceCertificateFileName;
|
||||
if (!File::Exists(dir))
|
||||
EXPECT_TRUE(File::CreateDirectory(dir));
|
||||
File::Remove(path);
|
||||
|
||||
unsigned char test_buf[600];
|
||||
for (size_t i = 0; i < sizeof(test_buf); i++) {
|
||||
test_buf[i] = i % 128;
|
||||
}
|
||||
File file1(kTestFile01, File::kCreate | File::kBinary);
|
||||
File file1(path, File::kCreate | File::kBinary);
|
||||
EXPECT_TRUE(file1.IsOpen());
|
||||
EXPECT_TRUE(file1.Write(test_buf, sizeof(test_buf)));
|
||||
file1.Close();
|
||||
EXPECT_TRUE(File::Exists(kTestFile01));
|
||||
EXPECT_TRUE(File::Exists(path));
|
||||
|
||||
EXPECT_EQ((ssize_t)sizeof(test_buf), File::FileSize(kTestFile01));
|
||||
EXPECT_EQ((ssize_t)sizeof(test_buf), File::FileSize(path));
|
||||
EXPECT_TRUE(File::Remove(dir));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user