chromium/components/gcm_driver/crypto/gcm_message_cryptographer_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/gcm_driver/crypto/gcm_message_cryptographer.h"

#include <memory>
#include <string_view>

#include "base/base64url.h"
#include "base/big_endian.h"
#include "base/containers/span.h"
#include "base/logging.h"
#include "components/gcm_driver/crypto/message_payload_parser.h"
#include "components/gcm_driver/crypto/p256_key_util.h"
#include "crypto/ec_private_key.h"
#include "crypto/random.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace gcm {

namespace {

// Example plaintext data to use in the tests.
const char kExamplePlaintext[] =;

// Expected sizes of the different input given to the cryptographer.
constexpr size_t kEcdhSharedSecretSize =;
constexpr size_t kAuthSecretSize =;
constexpr size_t kSaltSize =;

// Keying material for both parties as P-256 EC points. Used to make sure that
// the test vectors are reproducible.
const unsigned char kCommonSenderPublicKey[] =;
static_assert;

const unsigned char kCommonRecipientPublicKey[] =;
static_assert;

const unsigned char kCommonRecipientPrivateKey[] =;

const unsigned char kCommonAuthSecret[] =;
static_assert;

// Test vectors containing reference input for draft-ietf-webpush-encryption
// that was created using an separate JavaScript implementation of the draft.
struct TestVector {};

const TestVector kEncryptionTestVectorsDraft03[] =;

const TestVector kEncryptionTestVectorsDraft08[] =;

const TestVector kDecryptionTestVectorsDraft03[] =;

const TestVector kDecryptionTestVectorsDraft08[] =;

// Computes the shared secret between the sender and the receiver. The sender
// must have a ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo block, whereas
// the receiver must have a public key in uncompressed EC point format.
bool ComputeSharedP256SecretFromPrivateKeyStr(std::string_view private_key,
                                              std::string_view peer_public_key,
                                              std::string* out_shared_secret) {}

void ComputeSharedSecret(std::string_view encoded_sender_private_key,
                         std::string_view encoded_receiver_public_key,
                         std::string* shared_secret) {}

}  // namespace

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

class GCMMessageCryptographerTest
    : public GCMMessageCryptographerTestBase,
      public testing::WithParamInterface<GCMMessageCryptographer::Version> {};

TEST_P(GCMMessageCryptographerTest, RoundTrip) {}

TEST_P(GCMMessageCryptographerTest, RoundTripEmptyMessage) {}

TEST_P(GCMMessageCryptographerTest, InvalidRecordSize) {}

TEST_P(GCMMessageCryptographerTest, InvalidRecordPadding) {}

TEST_P(GCMMessageCryptographerTest, AuthSecretAffectsPRK) {}

INSTANTIATE_TEST_SUITE_P();

class GCMMessageCryptographerTestVectorTest
    : public GCMMessageCryptographerTestBase {};

TEST_F(GCMMessageCryptographerTestVectorTest, EncryptionVectorsDraft03) {}

TEST_F(GCMMessageCryptographerTestVectorTest, DecryptionVectorsDraft03) {}

TEST_F(GCMMessageCryptographerTestVectorTest, EncryptionVectorsDraft08) {}

TEST_F(GCMMessageCryptographerTestVectorTest, DecryptionVectorsDraft08) {}

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

// Reference test included for the Version::DRAFT_03 implementation.
// https://tools.ietf.org/html/draft-ietf-webpush-encryption-03
// https://tools.ietf.org/html/draft-ietf-httpbis-encryption-encoding-02
TEST_F(GCMMessageCryptographerReferenceTest, ReferenceDraft03) {}

// Reference test included for the Version::DRAFT_08 implementation.
// https://tools.ietf.org/html/draft-ietf-webpush-encryption-08
// https://tools.ietf.org/html/draft-ietf-httpbis-encryption-encoding-07
TEST_F(GCMMessageCryptographerReferenceTest, ReferenceDraft08) {}

}  // namespace gcm