Commit 880c16e0 authored by Steven Valdez's avatar Steven Valdez Committed by Commit Bot

Add version to Trust Token.

This change plumbs the protocol_version and id from the key commitment
to allow it be used to determine what crypto method to use and to
include in requests via the Sec-Trust-Token-Version header.

Design: https://docs.google.com/document/d/197OckoDGNe9-gSlB3dq9bufYoVimuFdon80ERHgK87E/edit#

Change-Id: If7e06fa7ce74d7584230566898db74528d843c9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425432
Auto-Submit: Steven Valdez <svaldez@chromium.org>
Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Reviewed-by: default avatarMatthew Denton <mpdenton@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarDavid Van Cleve <davidvc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812910}
parent 4a6d1681
...@@ -1215,11 +1215,14 @@ TEST_F(NetworkServiceTestWithService, SetsTrustTokenKeyCommitments) { ...@@ -1215,11 +1215,14 @@ TEST_F(NetworkServiceTestWithService, SetsTrustTokenKeyCommitments) {
auto expectation = mojom::TrustTokenKeyCommitmentResult::New(); auto expectation = mojom::TrustTokenKeyCommitmentResult::New();
ASSERT_TRUE(base::Base64Decode( ASSERT_TRUE(base::Base64Decode(
"aaaa", &expectation->signed_redemption_record_verification_key)); "aaaa", &expectation->signed_redemption_record_verification_key));
expectation->protocol_version =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
expectation->id = 1;
expectation->batch_size = 5; expectation->batch_size = 5;
base::RunLoop run_loop; base::RunLoop run_loop;
network_service_->SetTrustTokenKeyCommitments( network_service_->SetTrustTokenKeyCommitments(
R"( { "https://issuer.example": { "batchsize": 5, "srrkey": "aaaa" } } )", R"( { "https://issuer.example": { "protocol_version": "TrustTokenV1", "id": 1, "batchsize": 5, "srrkey": "aaaa" } } )",
run_loop.QuitClosure()); run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
......
...@@ -7,6 +7,17 @@ module network.mojom; ...@@ -7,6 +7,17 @@ module network.mojom;
import "url/mojom/origin.mojom"; import "url/mojom/origin.mojom";
import "mojo/public/mojom/base/time.mojom"; import "mojo/public/mojom/base/time.mojom";
// TrustTokenProtocolVersion enumerates the versions of Trust Token that the
// client knows about. Different versions represent different configuration
// flows, data structure meanings, etc and may require clearing the database
// due to incompatibilities.
// TODO(crbug/1133969): Schema versioning needs to be implemented for future
// versions that need to clear the database on schema changes.
enum TrustTokenProtocolVersion {
kTrustTokenV1,
};
// TrustTokenOperationStatus enumerates (an incomplete collection of) outcomes // TrustTokenOperationStatus enumerates (an incomplete collection of) outcomes
// for a Trust Tokens protocol operation. // for a Trust Tokens protocol operation.
// //
...@@ -160,6 +171,13 @@ struct TrustTokenVerificationKey { ...@@ -160,6 +171,13 @@ struct TrustTokenVerificationKey {
}; };
struct TrustTokenKeyCommitmentResult { struct TrustTokenKeyCommitmentResult {
// |protocol_version| is the Trust Token version that this key commitment is
// for.
TrustTokenProtocolVersion protocol_version;
// |id| is the ID for this key commitment.
int32 id;
// |batch_size| is the issuer's number of tokens it wishes the client // |batch_size| is the issuer's number of tokens it wishes the client
// to request per Trust Tokens issuance operation. // to request per Trust Tokens issuance operation.
int32 batch_size; int32 batch_size;
......
...@@ -29,13 +29,20 @@ BoringsslTrustTokenIssuanceCryptographer:: ...@@ -29,13 +29,20 @@ BoringsslTrustTokenIssuanceCryptographer::
~BoringsslTrustTokenIssuanceCryptographer() = default; ~BoringsslTrustTokenIssuanceCryptographer() = default;
bool BoringsslTrustTokenIssuanceCryptographer::Initialize( bool BoringsslTrustTokenIssuanceCryptographer::Initialize(
mojom::TrustTokenProtocolVersion issuer_configured_version,
int issuer_configured_batch_size) { int issuer_configured_batch_size) {
if (!base::IsValueInRangeForNumericType<size_t>(issuer_configured_batch_size)) if (!base::IsValueInRangeForNumericType<size_t>(issuer_configured_batch_size))
return false; return false;
const TRUST_TOKEN_METHOD* method = nullptr;
switch (issuer_configured_version) {
case mojom::TrustTokenProtocolVersion::kTrustTokenV1:
method = TRUST_TOKEN_experiment_v1();
break;
}
ctx_ = bssl::UniquePtr<TRUST_TOKEN_CLIENT>(TRUST_TOKEN_CLIENT_new( ctx_ = bssl::UniquePtr<TRUST_TOKEN_CLIENT>(TRUST_TOKEN_CLIENT_new(
TRUST_TOKEN_experiment_v1(), method, static_cast<size_t>(issuer_configured_batch_size)));
static_cast<size_t>(issuer_configured_batch_size)));
return !!ctx_; return !!ctx_;
} }
......
...@@ -22,7 +22,8 @@ class BoringsslTrustTokenIssuanceCryptographer ...@@ -22,7 +22,8 @@ class BoringsslTrustTokenIssuanceCryptographer
~BoringsslTrustTokenIssuanceCryptographer() override; ~BoringsslTrustTokenIssuanceCryptographer() override;
// TrustTokenRequestIssuanceHelper::Cryptographer implementation: // TrustTokenRequestIssuanceHelper::Cryptographer implementation:
bool Initialize(int issuer_configured_batch_size) override; bool Initialize(mojom::TrustTokenProtocolVersion issuer_configured_version,
int issuer_configured_batch_size) override;
bool AddKey(base::StringPiece key) override; bool AddKey(base::StringPiece key) override;
base::Optional<std::string> BeginIssuance(size_t num_tokens) override; base::Optional<std::string> BeginIssuance(size_t num_tokens) override;
std::unique_ptr<UnblindedTokens> ConfirmIssuance( std::unique_ptr<UnblindedTokens> ConfirmIssuance(
......
...@@ -38,7 +38,9 @@ TEST(BoringsslTrustTokenIssuanceCryptographer, RespectsKeyLimit) { ...@@ -38,7 +38,9 @@ TEST(BoringsslTrustTokenIssuanceCryptographer, RespectsKeyLimit) {
// kMaximumConcurrentlyValidTrustTokenVerificationKeys is no greater than // kMaximumConcurrentlyValidTrustTokenVerificationKeys is no greater than
// BoringSSL's internally-configured maximum number of permitted keys. // BoringSSL's internally-configured maximum number of permitted keys.
BoringsslTrustTokenIssuanceCryptographer cryptographer; BoringsslTrustTokenIssuanceCryptographer cryptographer;
ASSERT_TRUE(cryptographer.Initialize(/*issuer_configured_batch_size=*/10)); ASSERT_TRUE(
cryptographer.Initialize(mojom::TrustTokenProtocolVersion::kTrustTokenV1,
/*issuer_configured_batch_size=*/10));
for (size_t i = 0; i < kMaximumConcurrentlyValidTrustTokenVerificationKeys; for (size_t i = 0; i < kMaximumConcurrentlyValidTrustTokenVerificationKeys;
++i) { ++i) {
......
...@@ -25,14 +25,21 @@ BoringsslTrustTokenRedemptionCryptographer:: ...@@ -25,14 +25,21 @@ BoringsslTrustTokenRedemptionCryptographer::
~BoringsslTrustTokenRedemptionCryptographer() = default; ~BoringsslTrustTokenRedemptionCryptographer() = default;
bool BoringsslTrustTokenRedemptionCryptographer::Initialize( bool BoringsslTrustTokenRedemptionCryptographer::Initialize(
mojom::TrustTokenProtocolVersion issuer_configured_version,
int issuer_configured_batch_size, int issuer_configured_batch_size,
base::StringPiece signed_redemption_record_verification_key) { base::StringPiece signed_redemption_record_verification_key) {
if (!base::IsValueInRangeForNumericType<size_t>(issuer_configured_batch_size)) if (!base::IsValueInRangeForNumericType<size_t>(issuer_configured_batch_size))
return false; return false;
const TRUST_TOKEN_METHOD* method = nullptr;
switch (issuer_configured_version) {
case mojom::TrustTokenProtocolVersion::kTrustTokenV1:
method = TRUST_TOKEN_experiment_v1();
break;
}
ctx_ = bssl::UniquePtr<TRUST_TOKEN_CLIENT>(TRUST_TOKEN_CLIENT_new( ctx_ = bssl::UniquePtr<TRUST_TOKEN_CLIENT>(TRUST_TOKEN_CLIENT_new(
TRUST_TOKEN_experiment_v1(), method, static_cast<size_t>(issuer_configured_batch_size)));
static_cast<size_t>(issuer_configured_batch_size)));
if (!ctx_) if (!ctx_)
return false; return false;
......
...@@ -20,6 +20,7 @@ class BoringsslTrustTokenRedemptionCryptographer ...@@ -20,6 +20,7 @@ class BoringsslTrustTokenRedemptionCryptographer
// TrustTokenRequestRedemptionHelper::Cryptographer implementation: // TrustTokenRequestRedemptionHelper::Cryptographer implementation:
bool Initialize( bool Initialize(
mojom::TrustTokenProtocolVersion issuer_configured_version,
int issuer_configured_batch_size, int issuer_configured_batch_size,
base::StringPiece signed_redemption_record_verification_key) override; base::StringPiece signed_redemption_record_verification_key) override;
base::Optional<std::string> BeginRedemption( base::Optional<std::string> BeginRedemption(
......
...@@ -64,7 +64,8 @@ void RegisterTrustTokenTestHandlers(net::EmbeddedTestServer* test_server, ...@@ -64,7 +64,8 @@ void RegisterTrustTokenTestHandlers(net::EmbeddedTestServer* test_server,
if (request.relative_url != kIssuanceRelativePath) if (request.relative_url != kIssuanceRelativePath)
return nullptr; return nullptr;
if (!base::Contains(request.headers, "Sec-Trust-Token")) if (!base::Contains(request.headers, "Sec-Trust-Token") ||
!base::Contains(request.headers, "Sec-Trust-Token-Version"))
return MakeTrustTokenFailureResponse(); return MakeTrustTokenFailureResponse();
base::Optional<std::string> operation_result = base::Optional<std::string> operation_result =
...@@ -82,7 +83,8 @@ void RegisterTrustTokenTestHandlers(net::EmbeddedTestServer* test_server, ...@@ -82,7 +83,8 @@ void RegisterTrustTokenTestHandlers(net::EmbeddedTestServer* test_server,
if (request.relative_url != kRedemptionRelativePath) if (request.relative_url != kRedemptionRelativePath)
return nullptr; return nullptr;
if (!base::Contains(request.headers, "Sec-Trust-Token")) if (!base::Contains(request.headers, "Sec-Trust-Token") ||
!base::Contains(request.headers, "Sec-Trust-Token-Version"))
return MakeTrustTokenFailureResponse(); return MakeTrustTokenFailureResponse();
base::Optional<std::string> operation_result = base::Optional<std::string> operation_result =
......
...@@ -67,6 +67,12 @@ bool HasKeyPairExpired(const IssuanceKeyPair& p) { ...@@ -67,6 +67,12 @@ bool HasKeyPairExpired(const IssuanceKeyPair& p) {
} // namespace } // namespace
struct TrustTokenRequestHandler::Rep { struct TrustTokenRequestHandler::Rep {
// The protocol version to use.
std::string protocol_version;
// The commitment ID to use.
int id;
// Issue at most this many tokens per issuance. // Issue at most this many tokens per issuance.
int batch_size; int batch_size;
...@@ -222,6 +228,8 @@ std::string TrustTokenRequestHandler::GetKeyCommitmentRecord() const { ...@@ -222,6 +228,8 @@ std::string TrustTokenRequestHandler::GetKeyCommitmentRecord() const {
base::Value value(base::Value::Type::DICTIONARY); base::Value value(base::Value::Type::DICTIONARY);
value.SetStringKey( value.SetStringKey(
"srrkey", base::Base64Encode(base::make_span(rep_->srr_verification))); "srrkey", base::Base64Encode(base::make_span(rep_->srr_verification)));
value.SetStringKey("protocol_version", rep_->protocol_version);
value.SetIntKey("id", rep_->id);
value.SetIntKey("batchsize", rep_->batch_size); value.SetIntKey("batchsize", rep_->batch_size);
for (size_t i = 0; i < rep_->issuance_keys.size(); ++i) { for (size_t i = 0; i < rep_->issuance_keys.size(); ++i) {
...@@ -449,6 +457,8 @@ void TrustTokenRequestHandler::UpdateOptions(Options options) { ...@@ -449,6 +457,8 @@ void TrustTokenRequestHandler::UpdateOptions(Options options) {
rep_ = std::make_unique<Rep>(); rep_ = std::make_unique<Rep>();
rep_->protocol_version = options.protocol_version;
rep_->id = options.id;
rep_->batch_size = options.batch_size; rep_->batch_size = options.batch_size;
rep_->client_signing_outcome = options.client_signing_outcome; rep_->client_signing_outcome = options.client_signing_outcome;
rep_->issuance_outcome = options.issuance_outcome; rep_->issuance_outcome = options.issuance_outcome;
......
...@@ -59,6 +59,12 @@ class TrustTokenRequestHandler { ...@@ -59,6 +59,12 @@ class TrustTokenRequestHandler {
// the expected request. // the expected request.
SigningOutcome client_signing_outcome = SigningOutcome::kSuccess; SigningOutcome client_signing_outcome = SigningOutcome::kSuccess;
// The protocol version to use.
std::string protocol_version = "TrustTokenV1";
// The commitment ID to use.
int id = 1;
// The number of tokens to sign per issuance operation; this value is also // The number of tokens to sign per issuance operation; this value is also
// provided to the client as part of key commitment results. // provided to the client as part of key commitment results.
int batch_size = 10; int batch_size = 10;
...@@ -78,8 +84,9 @@ class TrustTokenRequestHandler { ...@@ -78,8 +84,9 @@ class TrustTokenRequestHandler {
// Returns a key commitment record suitable for inserting into a {issuer: // Returns a key commitment record suitable for inserting into a {issuer:
// commitment} dictionary passed to the network service via // commitment} dictionary passed to the network service via
// NetworkService::SetTrustTokenKeyCommitments. This comprises |num_keys| // NetworkService::SetTrustTokenKeyCommitments. This comprises |num_keys|
// token verification keys and a batch size of |batch_size| (or none if // token verification keys, a protocol version of |protocol_version|, an ID of
// |batch_size| is nullopt). // |id| and a batch size of |batch_size| (or none if |batch_size| is
// nullopt).
std::string GetKeyCommitmentRecord() const; std::string GetKeyCommitmentRecord() const;
// Given a base64-encoded issuance request, processes the // Given a base64-encoded issuance request, processes the
......
...@@ -48,6 +48,9 @@ struct ProtocolKeys { ...@@ -48,6 +48,9 @@ struct ProtocolKeys {
std::vector<uint8_t> srr_verification; std::vector<uint8_t> srr_verification;
}; };
const mojom::TrustTokenProtocolVersion kProtocolVersion =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
// Choose this number to be > 1 but fairly small: setting it to 10 // Choose this number to be > 1 but fairly small: setting it to 10
// led to the test running for 2.5 sec on a debug build. // led to the test running for 2.5 sec on a debug build.
constexpr size_t kNumTokensToRequest = 3; constexpr size_t kNumTokensToRequest = 3;
...@@ -112,7 +115,8 @@ void RequestManyTokensAndRetainOneArbitrarily( ...@@ -112,7 +115,8 @@ void RequestManyTokensAndRetainOneArbitrarily(
TRUST_TOKEN_ISSUER* issuer_ctx, TRUST_TOKEN_ISSUER* issuer_ctx,
TrustToken* out_token) { TrustToken* out_token) {
BoringsslTrustTokenIssuanceCryptographer issuance_cryptographer; BoringsslTrustTokenIssuanceCryptographer issuance_cryptographer;
ASSERT_TRUE(issuance_cryptographer.Initialize(kNumTokensToRequest)); ASSERT_TRUE(
issuance_cryptographer.Initialize(kProtocolVersion, kNumTokensToRequest));
for (const TokenKeyPair& token_keys : keys.token_keys) { for (const TokenKeyPair& token_keys : keys.token_keys) {
ASSERT_TRUE(issuance_cryptographer.AddKey(std::string( ASSERT_TRUE(issuance_cryptographer.AddKey(std::string(
...@@ -165,7 +169,7 @@ void RedeemSingleToken(const ProtocolKeys& keys, ...@@ -165,7 +169,7 @@ void RedeemSingleToken(const ProtocolKeys& keys,
url::Origin::Create(GURL("https://topframe.example")); url::Origin::Create(GURL("https://topframe.example"));
ASSERT_TRUE(redemption_cryptographer.Initialize( ASSERT_TRUE(redemption_cryptographer.Initialize(
kNumTokensToRequest, as_string(keys.srr_verification))); kProtocolVersion, kNumTokensToRequest, as_string(keys.srr_verification)));
base::Optional<std::string> maybe_base64_encoded_redemption_request = base::Optional<std::string> maybe_base64_encoded_redemption_request =
redemption_cryptographer.BeginRedemption( redemption_cryptographer.BeginRedemption(
......
...@@ -14,6 +14,7 @@ const std::vector<base::StringPiece>& TrustTokensRequestHeaders() { ...@@ -14,6 +14,7 @@ const std::vector<base::StringPiece>& TrustTokensRequestHeaders() {
{kTrustTokensRequestHeaderSecSignature, {kTrustTokensRequestHeaderSecSignature,
kTrustTokensRequestHeaderSecSignedRedemptionRecord, kTrustTokensRequestHeaderSecSignedRedemptionRecord,
kTrustTokensRequestHeaderSecTime, kTrustTokensSecTrustTokenHeader, kTrustTokensRequestHeaderSecTime, kTrustTokensSecTrustTokenHeader,
kTrustTokensSecTrustTokenVersionHeader,
kTrustTokensRequestHeaderSecTrustTokensAdditionalSigningData}}; kTrustTokensRequestHeaderSecTrustTokensAdditionalSigningData}};
return *headers; return *headers;
} }
......
...@@ -25,6 +25,11 @@ namespace network { ...@@ -25,6 +25,11 @@ namespace network {
// Record. // Record.
constexpr char kTrustTokensSecTrustTokenHeader[] = "Sec-Trust-Token"; constexpr char kTrustTokensSecTrustTokenHeader[] = "Sec-Trust-Token";
// As a request header, provides the version of Trust Token being used in the
// Sec-Trust-Token header.
constexpr char kTrustTokensSecTrustTokenVersionHeader[] =
"Sec-Trust-Token-Version";
// As a request header, provides a timestamp associated with a // As a request header, provides a timestamp associated with a
// particular Trust Tokens signature-bearing request. // particular Trust Tokens signature-bearing request.
constexpr char kTrustTokensRequestHeaderSecTime[] = "Sec-Time"; constexpr char kTrustTokensRequestHeaderSecTime[] = "Sec-Time";
......
...@@ -78,6 +78,24 @@ mojom::TrustTokenKeyCommitmentResultPtr ParseSingleIssuer( ...@@ -78,6 +78,24 @@ mojom::TrustTokenKeyCommitmentResultPtr ParseSingleIssuer(
auto result = mojom::TrustTokenKeyCommitmentResult::New(); auto result = mojom::TrustTokenKeyCommitmentResult::New();
// Confirm that the protocol_version field is present.
const std::string* maybe_version =
value.FindStringKey(kTrustTokenKeyCommitmentProtocolVersionField);
if (!maybe_version)
return nullptr;
if (*maybe_version == "TrustTokenV1") {
result->protocol_version = mojom::TrustTokenProtocolVersion::kTrustTokenV1;
} else {
return nullptr;
}
// Confirm that the id field is present and type-safe.
base::Optional<int> maybe_id =
value.FindIntKey(kTrustTokenKeyCommitmentIDField);
if (!maybe_id || *maybe_id <= 0)
return nullptr;
result->id = *maybe_id;
// Confirm that the batchsize field is present and type-safe. // Confirm that the batchsize field is present and type-safe.
base::Optional<int> maybe_batch_size = base::Optional<int> maybe_batch_size =
value.FindIntKey(kTrustTokenKeyCommitmentBatchsizeField); value.FindIntKey(kTrustTokenKeyCommitmentBatchsizeField);
...@@ -137,6 +155,8 @@ mojom::TrustTokenKeyCommitmentResultPtr& commitment(Entry& e) { ...@@ -137,6 +155,8 @@ mojom::TrustTokenKeyCommitmentResultPtr& commitment(Entry& e) {
} // namespace } // namespace
const char kTrustTokenKeyCommitmentProtocolVersionField[] = "protocol_version";
const char kTrustTokenKeyCommitmentIDField[] = "id";
const char kTrustTokenKeyCommitmentBatchsizeField[] = "batchsize"; const char kTrustTokenKeyCommitmentBatchsizeField[] = "batchsize";
const char kTrustTokenKeyCommitmentSrrkeyField[] = "srrkey"; const char kTrustTokenKeyCommitmentSrrkeyField[] = "srrkey";
const char kTrustTokenKeyCommitmentExpiryField[] = "expiry"; const char kTrustTokenKeyCommitmentExpiryField[] = "expiry";
...@@ -144,18 +164,21 @@ const char kTrustTokenKeyCommitmentKeyField[] = "Y"; ...@@ -144,18 +164,21 @@ const char kTrustTokenKeyCommitmentKeyField[] = "Y";
// https://docs.google.com/document/d/1TNnya6B8pyomDK2F1R9CL3dY10OAmqWlnCxsWyOBDVQ/edit#bookmark=id.6wh9crbxdizi // https://docs.google.com/document/d/1TNnya6B8pyomDK2F1R9CL3dY10OAmqWlnCxsWyOBDVQ/edit#bookmark=id.6wh9crbxdizi
// { // {
// "batchsize" : ..., // Batch size; value of type int. // "protocol_version" : ..., // Protocol Version; value of type string.
// "srrkey" : ..., // Required Signed Redemption Record (SRR) // "id" : ..., // ID; value of type int.
// // verification key, in base64. // "batchsize" : ..., // Batch size; value of type int.
// "srrkey" : ..., // Required Signed Redemption Record (SRR)
// // verification key, in base64.
// //
// "1" : { // Key label, a number in uint32_t range; ignored except // "1" : { // Key label, a number in uint32_t range; ignored
// // for checking that it is present and type-safe. // // except for checking that it is present and
// "Y" : ..., // Required token issuance verification key, in // // type-safe.
// // base64. // "Y" : ..., // Required token issuance verification key, in
// "expiry" : ..., // Required token issuance key expiry time, in // // base64.
// // microseconds since the Unix epoch. // "expiry" : ..., // Required token issuance key expiry time, in
// // microseconds since the Unix epoch.
// }, // },
// "17" : { // No guarantee that key labels (1, 17) are dense. // "17" : { // No guarantee that key labels (1, 7) are dense.
// "Y" : ..., // "Y" : ...,
// "expiry" : ..., // "expiry" : ...,
// } // }
......
...@@ -17,6 +17,10 @@ namespace network { ...@@ -17,6 +17,10 @@ namespace network {
// Field names from the key commitment JSON format specified in the Trust Tokens // Field names from the key commitment JSON format specified in the Trust Tokens
// design doc // design doc
// (https://docs.google.com/document/d/1TNnya6B8pyomDK2F1R9CL3dY10OAmqWlnCxsWyOBDVQ/edit#bookmark=id.6wh9crbxdizi): // (https://docs.google.com/document/d/1TNnya6B8pyomDK2F1R9CL3dY10OAmqWlnCxsWyOBDVQ/edit#bookmark=id.6wh9crbxdizi):
// - "protocol_version" (version of Trust Token used for this commitment)
extern const char kTrustTokenKeyCommitmentProtocolVersionField[];
// - "id" (ID for this key commitment)
extern const char kTrustTokenKeyCommitmentIDField[];
// - "batch size" (number of blinded tokens to provide per issuance request) // - "batch size" (number of blinded tokens to provide per issuance request)
extern const char kTrustTokenKeyCommitmentBatchsizeField[]; extern const char kTrustTokenKeyCommitmentBatchsizeField[];
// - verification key for the signatures the issuer provides over its Signed // - verification key for the signatures the issuer provides over its Signed
......
...@@ -64,6 +64,9 @@ TEST(TrustTokenKeyCommitments, CanRetrieveRecordForSuitableOrigin) { ...@@ -64,6 +64,9 @@ TEST(TrustTokenKeyCommitments, CanRetrieveRecordForSuitableOrigin) {
TrustTokenKeyCommitments commitments; TrustTokenKeyCommitments commitments;
auto expectation = mojom::TrustTokenKeyCommitmentResult::New(); auto expectation = mojom::TrustTokenKeyCommitmentResult::New();
expectation->protocol_version =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
expectation->id = 1;
expectation->batch_size = 5; expectation->batch_size = 5;
auto suitable_origin = *SuitableTrustTokenOrigin::Create( auto suitable_origin = *SuitableTrustTokenOrigin::Create(
...@@ -88,6 +91,9 @@ TEST(TrustTokenKeyCommitments, CantRetrieveRecordForOriginNotPresent) { ...@@ -88,6 +91,9 @@ TEST(TrustTokenKeyCommitments, CantRetrieveRecordForOriginNotPresent) {
auto an_origin = auto an_origin =
*SuitableTrustTokenOrigin::Create(GURL("https://an-origin.example")); *SuitableTrustTokenOrigin::Create(GURL("https://an-origin.example"));
auto an_expectation = mojom::TrustTokenKeyCommitmentResult::New(); auto an_expectation = mojom::TrustTokenKeyCommitmentResult::New();
an_expectation->protocol_version =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
an_expectation->id = 1;
an_expectation->batch_size = 5; an_expectation->batch_size = 5;
base::flat_map<url::Origin, mojom::TrustTokenKeyCommitmentResultPtr> to_set; base::flat_map<url::Origin, mojom::TrustTokenKeyCommitmentResultPtr> to_set;
...@@ -114,7 +120,13 @@ TEST(TrustTokenKeyCommitments, MultipleOrigins) { ...@@ -114,7 +120,13 @@ TEST(TrustTokenKeyCommitments, MultipleOrigins) {
mojom::TrustTokenKeyCommitmentResult::New(), mojom::TrustTokenKeyCommitmentResult::New(),
}; };
expectations[0]->protocol_version =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
expectations[0]->id = 1;
expectations[0]->batch_size = 0; expectations[0]->batch_size = 0;
expectations[1]->protocol_version =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
expectations[1]->id = 1;
expectations[1]->batch_size = 1; expectations[1]->batch_size = 1;
base::flat_map<url::Origin, mojom::TrustTokenKeyCommitmentResultPtr> to_set; base::flat_map<url::Origin, mojom::TrustTokenKeyCommitmentResultPtr> to_set;
...@@ -132,7 +144,7 @@ TEST(TrustTokenKeyCommitments, MultipleOrigins) { ...@@ -132,7 +144,7 @@ TEST(TrustTokenKeyCommitments, MultipleOrigins) {
TEST(TrustTokenKeyCommitments, ParseAndSet) { TEST(TrustTokenKeyCommitments, ParseAndSet) {
TrustTokenKeyCommitments commitments; TrustTokenKeyCommitments commitments;
commitments.ParseAndSet( commitments.ParseAndSet(
R"( { "https://issuer.example": { "batchsize": 5, "srrkey": "aaaa" } } )"); R"( { "https://issuer.example": { "protocol_version": "TrustTokenV1", "id": 1, "batchsize": 5, "srrkey": "aaaa" } } )");
EXPECT_TRUE(GetCommitmentForOrigin( EXPECT_TRUE(GetCommitmentForOrigin(
commitments, commitments,
...@@ -143,7 +155,7 @@ TEST(TrustTokenKeyCommitments, KeysFromCommandLine) { ...@@ -143,7 +155,7 @@ TEST(TrustTokenKeyCommitments, KeysFromCommandLine) {
base::test::ScopedCommandLine command_line; base::test::ScopedCommandLine command_line;
command_line.GetProcessCommandLine()->AppendSwitchASCII( command_line.GetProcessCommandLine()->AppendSwitchASCII(
switches::kAdditionalTrustTokenKeyCommitments, switches::kAdditionalTrustTokenKeyCommitments,
R"( { "https://issuer.example": { "batchsize": 5, "srrkey": "aaaa" } } )"); R"( { "https://issuer.example": { "protocol_version": "TrustTokenV1", "id": 1, "batchsize": 5, "srrkey": "aaaa" } } )");
TrustTokenKeyCommitments commitments; TrustTokenKeyCommitments commitments;
...@@ -152,7 +164,7 @@ TEST(TrustTokenKeyCommitments, KeysFromCommandLine) { ...@@ -152,7 +164,7 @@ TEST(TrustTokenKeyCommitments, KeysFromCommandLine) {
*SuitableTrustTokenOrigin::Create(GURL("https://issuer.example")))); *SuitableTrustTokenOrigin::Create(GURL("https://issuer.example"))));
commitments.ParseAndSet( commitments.ParseAndSet(
R"( { "https://issuer.example": { "batchsize": 10, "srrkey": "bbbb" } } )"); R"( { "https://issuer.example": { "protocol_version": "TrustTokenV1", "id": 1, "batchsize": 10, "srrkey": "bbbb" } } )");
// A commitment provided through |Set| should defer to the one passed // A commitment provided through |Set| should defer to the one passed
// through the command line. // through the command line.
...@@ -164,6 +176,9 @@ TEST(TrustTokenKeyCommitments, KeysFromCommandLine) { ...@@ -164,6 +176,9 @@ TEST(TrustTokenKeyCommitments, KeysFromCommandLine) {
*SuitableTrustTokenOrigin::Create(GURL("https://issuer.example"))); *SuitableTrustTokenOrigin::Create(GURL("https://issuer.example")));
ASSERT_TRUE(result); ASSERT_TRUE(result);
EXPECT_EQ(result->signed_redemption_record_verification_key, expected_srrkey); EXPECT_EQ(result->signed_redemption_record_verification_key, expected_srrkey);
EXPECT_EQ(result->protocol_version,
mojom::TrustTokenProtocolVersion::kTrustTokenV1);
EXPECT_EQ(result->id, 1);
EXPECT_EQ(result->batch_size, 5); EXPECT_EQ(result->batch_size, 5);
} }
...@@ -216,6 +231,9 @@ TEST(TrustTokenKeyCommitments, GetSync) { ...@@ -216,6 +231,9 @@ TEST(TrustTokenKeyCommitments, GetSync) {
TrustTokenKeyCommitments commitments; TrustTokenKeyCommitments commitments;
auto expectation = mojom::TrustTokenKeyCommitmentResult::New(); auto expectation = mojom::TrustTokenKeyCommitmentResult::New();
expectation->protocol_version =
mojom::TrustTokenProtocolVersion::kTrustTokenV1;
expectation->id = 1;
expectation->batch_size = 5; expectation->batch_size = 5;
auto suitable_origin = *SuitableTrustTokenOrigin::Create( auto suitable_origin = *SuitableTrustTokenOrigin::Create(
......
...@@ -144,8 +144,10 @@ void TrustTokenRequestIssuanceHelper::OnGotKeyCommitment( ...@@ -144,8 +144,10 @@ void TrustTokenRequestIssuanceHelper::OnGotKeyCommitment(
return; return;
} }
protocol_version_ = commitment_result->protocol_version;
if (!commitment_result->batch_size || if (!commitment_result->batch_size ||
!cryptographer_->Initialize(commitment_result->batch_size)) { !cryptographer_->Initialize(protocol_version_,
commitment_result->batch_size)) {
LogOutcome(net_log_, kBegin, LogOutcome(net_log_, kBegin,
"Internal error initializing cryptography delegate"); "Internal error initializing cryptography delegate");
std::move(done).Run(mojom::TrustTokenOperationStatus::kInternalError); std::move(done).Run(mojom::TrustTokenOperationStatus::kInternalError);
...@@ -198,6 +200,12 @@ void TrustTokenRequestIssuanceHelper::OnDelegateBeginIssuanceCallComplete( ...@@ -198,6 +200,12 @@ void TrustTokenRequestIssuanceHelper::OnDelegateBeginIssuanceCallComplete(
std::move(*maybe_blinded_tokens), std::move(*maybe_blinded_tokens),
/*overwrite=*/true); /*overwrite=*/true);
std::string protocol_string_version =
internal::ProtocolVersionToString(protocol_version_);
request->SetExtraRequestHeaderByName(kTrustTokensSecTrustTokenVersionHeader,
protocol_string_version,
/*overwrite=*/true);
// We don't want cache reads, because the highest priority is to execute the // We don't want cache reads, because the highest priority is to execute the
// protocol operation by sending the server the Trust Tokens request header // protocol operation by sending the server the Trust Tokens request header
// and getting the corresponding response header, but we want cache writes // and getting the corresponding response header, but we want cache writes
......
...@@ -55,12 +55,15 @@ class TrustTokenRequestIssuanceHelper : public TrustTokenRequestHelper { ...@@ -55,12 +55,15 @@ class TrustTokenRequestIssuanceHelper : public TrustTokenRequestHelper {
public: public:
virtual ~Cryptographer() = default; virtual ~Cryptographer() = default;
// Initializes the delegate. |issuer_configured_batch_size| must be the // Initializes the delegate. |issuer_configured_version| and
// "batchsize" value from an issuer-provided key commitment result. // |issuer_configured_batch_size| must be the "protocol_version" and
// "batchsize" values from an issuer-provided key commitment result.
// //
// Returns true on success and false if the batch size is unacceptable or an // Returns true on success and false if the batch size is unacceptable or an
// internal error occurred in the underlying cryptographic library. // internal error occurred in the underlying cryptographic library.
virtual bool Initialize(int issuer_configured_batch_size) = 0; virtual bool Initialize(
mojom::TrustTokenProtocolVersion issuer_configured_version,
int issuer_configured_batch_size) = 0;
// Stores a Trust Tokens issuance verification key for subsequent use // Stores a Trust Tokens issuance verification key for subsequent use
// verifying signed tokens in |ConfirmIssuance|. May be called multiple // verifying signed tokens in |ConfirmIssuance|. May be called multiple
...@@ -211,6 +214,8 @@ class TrustTokenRequestIssuanceHelper : public TrustTokenRequestHelper { ...@@ -211,6 +214,8 @@ class TrustTokenRequestIssuanceHelper : public TrustTokenRequestHelper {
TrustTokenStore* const token_store_; TrustTokenStore* const token_store_;
const TrustTokenKeyCommitmentGetter* const key_commitment_getter_; const TrustTokenKeyCommitmentGetter* const key_commitment_getter_;
mojom::TrustTokenProtocolVersion protocol_version_;
// Relinquishes ownership during posted tasks for the potentially // Relinquishes ownership during posted tasks for the potentially
// computationally intensive cryptographic operations // computationally intensive cryptographic operations
// (Cryptographer::BeginIssuance, Cryptographer::ConfirmIssuance); repopulated // (Cryptographer::BeginIssuance, Cryptographer::ConfirmIssuance); repopulated
......
...@@ -135,7 +135,7 @@ void TrustTokenRequestRedemptionHelper::OnGotKeyCommitment( ...@@ -135,7 +135,7 @@ void TrustTokenRequestRedemptionHelper::OnGotKeyCommitment(
if (!commitment_result->batch_size || if (!commitment_result->batch_size ||
!cryptographer_->Initialize( !cryptographer_->Initialize(
commitment_result->batch_size, commitment_result->protocol_version, commitment_result->batch_size,
commitment_result->signed_redemption_record_verification_key)) { commitment_result->signed_redemption_record_verification_key)) {
LogOutcome(net_log_, kBegin, LogOutcome(net_log_, kBegin,
"Internal error initializing BoringSSL redemption state " "Internal error initializing BoringSSL redemption state "
...@@ -166,6 +166,12 @@ void TrustTokenRequestRedemptionHelper::OnGotKeyCommitment( ...@@ -166,6 +166,12 @@ void TrustTokenRequestRedemptionHelper::OnGotKeyCommitment(
std::move(*maybe_redemption_header), std::move(*maybe_redemption_header),
/*overwrite=*/true); /*overwrite=*/true);
std::string protocol_string_version =
internal::ProtocolVersionToString(commitment_result->protocol_version);
request->SetExtraRequestHeaderByName(kTrustTokensSecTrustTokenVersionHeader,
protocol_string_version,
/*overwrite=*/true);
// We don't want cache reads, because the highest priority is to execute the // We don't want cache reads, because the highest priority is to execute the
// protocol operation by sending the server the Trust Tokens request header // protocol operation by sending the server the Trust Tokens request header
// and getting the corresponding response header, but we want cache writes // and getting the corresponding response header, but we want cache writes
......
...@@ -68,14 +68,16 @@ class TrustTokenRequestRedemptionHelper : public TrustTokenRequestHelper { ...@@ -68,14 +68,16 @@ class TrustTokenRequestRedemptionHelper : public TrustTokenRequestHelper {
public: public:
virtual ~Cryptographer() = default; virtual ~Cryptographer() = default;
// Initializes the delegate. |issuer_configured_batch_size| must be the // Initializes the delegate. |issuer_configured_version| and
// "batchsize" value, and |signed_Redemption_record_verification_key| the // |issuer_configured_batch_size| must be the "protocol_version" and
// "batchsize" values, and |signed_redemption_record_verification_key| the
// "srrkey" value, from an issuer-provided key commitment result. // "srrkey" value, from an issuer-provided key commitment result.
// //
// Returns true on success and false if the batch size or key is // Returns true on success and false if the batch size or key is
// unacceptable or an internal error occurred in the underlying // unacceptable or an internal error occurred in the underlying
// cryptographic library. // cryptographic library.
virtual bool Initialize( virtual bool Initialize(
mojom::TrustTokenProtocolVersion issuer_configured_version,
int issuer_configured_batch_size, int issuer_configured_batch_size,
base::StringPiece signed_redemption_record_verification_key) = 0; base::StringPiece signed_redemption_record_verification_key) = 0;
......
...@@ -33,5 +33,13 @@ base::StringPiece TrustTokenOperationTypeToString( ...@@ -33,5 +33,13 @@ base::StringPiece TrustTokenOperationTypeToString(
} }
} }
std::string ProtocolVersionToString(
mojom::TrustTokenProtocolVersion my_version) {
switch (my_version) {
case mojom::TrustTokenProtocolVersion::kTrustTokenV1:
return "TrustTokenV1";
}
}
} // namespace internal } // namespace internal
} // namespace network } // namespace network
...@@ -29,6 +29,9 @@ std::string TimeToString(base::Time my_time); ...@@ -29,6 +29,9 @@ std::string TimeToString(base::Time my_time);
base::StringPiece TrustTokenOperationTypeToString( base::StringPiece TrustTokenOperationTypeToString(
mojom::TrustTokenOperationType type); mojom::TrustTokenOperationType type);
// Serializes a mojom::TrustTokenProtocolVersion.
std::string ProtocolVersionToString(mojom::TrustTokenProtocolVersion);
} // namespace internal } // namespace internal
} // namespace network } // namespace network
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment