chromium/components/web_package/signed_web_bundles/signed_web_bundle_signature_verifier_unittest.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/web_package/signed_web_bundles/signed_web_bundle_signature_verifier.h"

#include <limits>
#include <memory>
#include <optional>
#include <utility>

#include "base/base_paths.h"
#include "base/containers/extend.h"
#include "base/containers/map_util.h"
#include "base/containers/to_vector.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/overloaded.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/scoped_observation.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "components/cbor/values.h"
#include "components/web_package/mojom/web_bundle_parser.mojom.h"
#include "components/web_package/signed_web_bundles/constants.h"
#include "components/web_package/signed_web_bundles/ecdsa_p256_public_key.h"
#include "components/web_package/signed_web_bundles/ecdsa_p256_sha256_signature.h"
#include "components/web_package/signed_web_bundles/ed25519_public_key.h"
#include "components/web_package/signed_web_bundles/identity_validator.h"
#include "components/web_package/signed_web_bundles/integrity_block_attributes.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_id.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_integrity_block.h"
#include "components/web_package/signed_web_bundles/signed_web_bundle_signature_stack_entry.h"
#include "components/web_package/test_support/signed_web_bundles/signature_verifier_test_utils.h"
#include "components/web_package/test_support/signed_web_bundles/web_bundle_signer.h"
#include "components/web_package/web_bundle_builder.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace web_package::test {

namespace {

// The following values are representations of the keys used to generate
// components/test/data/web_package/simple_b2_signed_v2.swbn
// It has been generated using
// components/web_package/test_support/signed_web_bundles/web_bundle_signer.h.
constexpr uint8_t kEd25519PublicKey[] =;

constexpr uint8_t kEd25519Signature[] =;

constexpr uint8_t kEd25519PubkeyCbor[] =;

constexpr uint8_t kEcdsaP256PublicKey[] =;

constexpr uint8_t kEcdsaP256Signature[] =;

constexpr uint8_t kEcdsaP256PubkeyCbor[] =;

constexpr char kEcdsaP256BundleId[] =;

constexpr uint8_t kEcdsaP256BundleIdCbor[] =;

SignedWebBundleId CreateForKeyPair(const KeyPair& key_pair) {}

}  // namespace

// Tests that signatures created with the Go tool from
// github.com/WICG/webpackage are verified correctly.
class SignedWebBundleSignatureVerifierGoToolTest
    : public ::testing::TestWithParam<std::tuple<
          std::pair<base::FilePath,
                    std::optional<SignedWebBundleSignatureVerifier::Error>>,
          uint64_t>> {};

// TODO(crbug.com/40239682): Add additional tests for Signed Web Bundles that
// have more than one signature once the Go tool supports it.
TEST_P(SignedWebBundleSignatureVerifierGoToolTest, VerifySimpleWebBundle) {}

INSTANTIATE_TEST_SUITE_P();

class SignedWebBundleSignatureVerifierTestBase : public ::testing::Test {};

class SignedWebBundleSignatureVerifierTest
    : public SignedWebBundleSignatureVerifierTestBase,
      public ::testing::WithParamInterface<
          std::pair<KeyPairs,
                    std::optional<SignedWebBundleSignatureVerifier::Error>>> {};

TEST_P(SignedWebBundleSignatureVerifierTest, VerifySignatures) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace web_package::test