AU: Add support for signing of update payloads after they're generated.
The change adds 2 methods -- one that takes an unsigned payload and a raw
signature size and returns the hash that needs to be signed, and another one
that takes an unsigned payload and a raw signature and generates the signed
payload.
BUG=chromium-os:10872
TEST=unit tests
Change-Id: I65bbe72a1ec67e603e78508c33893695b7de0e6a
Review URL: http://codereview.chromium.org/6265001
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index 51299fb..0d71a6e 100755
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -92,8 +92,11 @@
TEST_AND_RETURN_FALSE_ERRNO(return_code == 0);
return true;
}
+} // namespace {}
-void DoSmallImageTest(bool full_kernel, bool full_rootfs, bool noop) {
+namespace {
+void DoSmallImageTest(bool full_kernel, bool full_rootfs, bool noop,
+ bool post_sign) {
string a_img, b_img;
EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL));
ScopedPathUnlinker a_img_unlinker(a_img);
@@ -208,7 +211,33 @@
full_kernel ? "" : old_kernel,
new_kernel,
delta_path,
- kUnittestPrivateKeyPath));
+ post_sign ? "" : kUnittestPrivateKeyPath));
+ }
+
+ if (post_sign) {
+ int signature_size;
+ {
+ const vector<char> data(1, 'x');
+ vector<char> hash;
+ ASSERT_TRUE(OmahaHashCalculator::RawHashOfData(data, &hash));
+ vector<char> signature;
+ ASSERT_TRUE(PayloadSigner::SignHash(hash,
+ kUnittestPrivateKeyPath,
+ &signature));
+ signature_size = signature.size();
+ }
+
+ vector<char> hash;
+ ASSERT_TRUE(PayloadSigner::HashPayloadForSigning(delta_path,
+ signature_size,
+ &hash));
+ vector<char> signature;
+ ASSERT_TRUE(PayloadSigner::SignHash(hash,
+ kUnittestPrivateKeyPath,
+ &signature));
+ ASSERT_TRUE(PayloadSigner::AddSignatureToPayload(delta_path,
+ signature,
+ delta_path));
}
// Read delta into memory.
@@ -351,19 +380,23 @@
}
TEST(DeltaPerformerTest, RunAsRootSmallImageTest) {
- DoSmallImageTest(false, false, false);
+ DoSmallImageTest(false, false, false, false);
}
TEST(DeltaPerformerTest, RunAsRootFullKernelSmallImageTest) {
- DoSmallImageTest(true, false, false);
+ DoSmallImageTest(true, false, false, false);
}
TEST(DeltaPerformerTest, RunAsRootFullSmallImageTest) {
- DoSmallImageTest(true, true, false);
+ DoSmallImageTest(true, true, false, false);
}
TEST(DeltaPerformerTest, RunAsRootNoopSmallImageTest) {
- DoSmallImageTest(false, false, true);
+ DoSmallImageTest(false, false, true, false);
+}
+
+TEST(DeltaPerformerTest, RunAsRootSmallImagePostSignTest) {
+ DoSmallImageTest(false, false, false, true);
}
TEST(DeltaPerformerTest, BadDeltaMagicTest) {