File: verification.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (59 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 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/reporting/encryption/verification.h"

#include "components/reporting/encryption/primitives.h"
#include "components/reporting/util/status.h"

namespace reporting {

namespace {

// Well-known public signature verification keys.
constexpr uint8_t kProdVerificationKey[kKeySize] = {
    0x51, 0x2D, 0x53, 0xA3, 0xF5, 0xEB, 0x01, 0xCE, 0xDA, 0xFC, 0x8E,
    0x79, 0xE7, 0x0F, 0xE1, 0x65, 0xDC, 0x14, 0x86, 0x53, 0x8B, 0x97,
    0x5A, 0x2D, 0x70, 0x08, 0xCB, 0xCA, 0x60, 0xC3, 0x55, 0xE6};

constexpr uint8_t kDevVerificationKey[kKeySize] = {
    0xC6, 0x2C, 0x4D, 0x25, 0x9E, 0x3E, 0x99, 0xA0, 0x2E, 0x08, 0x15,
    0x8C, 0x38, 0xB7, 0x6C, 0x08, 0xDF, 0xE7, 0x6E, 0x3A, 0xD6, 0x5A,
    0xC5, 0x58, 0x09, 0xE4, 0xAB, 0x89, 0x3A, 0x31, 0x53, 0x07};

}  // namespace

// static
std::string_view SignatureVerifier::VerificationKey() {
  return std::string_view(reinterpret_cast<const char*>(kProdVerificationKey),
                          kKeySize);
}

// static
std::string_view SignatureVerifier::VerificationKeyDev() {
  return std::string_view(reinterpret_cast<const char*>(kDevVerificationKey),
                          kKeySize);
}

SignatureVerifier::SignatureVerifier(std::string_view verification_public_key)
    : verification_public_key_(verification_public_key) {}

Status SignatureVerifier::Verify(std::string_view message,
                                 std::string_view signature) {
  if (signature.size() != kSignatureSize) {
    return Status{error::FAILED_PRECONDITION, "Wrong signature size"};
  }
  if (verification_public_key_.size() != kKeySize) {
    return Status{error::FAILED_PRECONDITION, "Wrong public key size"};
  }
  if (!VerifySignature(
          reinterpret_cast<const uint8_t*>(verification_public_key_.data()),
          message, reinterpret_cast<const uint8_t*>(signature.data()))) {
    return Status{error::INVALID_ARGUMENT, "Verification failed"};
  }

  return Status::StatusOK();
}

}  // namespace reporting