Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: components/gcm_driver/crypto/message_payload_parser.cc

Issue 2888763006: Add a parser for messages with a Web Push Protocol-based payload (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/gcm_driver/crypto/message_payload_parser.h"
6
7 #include "base/big_endian.h"
8
9 namespace gcm {
10
11 namespace {
12
13 // Size, in bytes, of the salt included in the message header.
14 constexpr size_t kSaltSize = 16;
15
16 // Size, in bytes, of the uncompressed point included in the message header.
17 constexpr size_t kUncompressedPointSize = 65;
18
19 // Size, in bytes, of the smallest allowable record_size value.
20 constexpr size_t kMinimumRecordSize = 18;
21
22 // Size, in bytes, of an empty message with the minimum amount of padding.
23 constexpr size_t kMinimumMessageSize =
24 kSaltSize + sizeof(uint32_t) + sizeof(uint8_t) + kUncompressedPointSize +
25 kMinimumRecordSize;
26
27 } // namespace
28
29 MessagePayloadParser::MessagePayloadParser(base::StringPiece message) {
30 if (message.size() < kMinimumMessageSize)
31 return;
32
33 salt_ = message.substr(0, kSaltSize).as_string();
34 message.remove_prefix(kSaltSize);
35
36 base::ReadBigEndian(message.data(), &record_size_);
37 message.remove_prefix(sizeof(record_size_));
38
39 if (record_size_ < kMinimumRecordSize)
40 return;
41
42 uint8_t public_key_length;
43 base::ReadBigEndian(message.data(), &public_key_length);
44 message.remove_prefix(sizeof(public_key_length));
45
46 if (public_key_length != kUncompressedPointSize)
47 return;
48
49 if (message[0] != 0x04)
50 return;
51
52 public_key_ = message.substr(0, kUncompressedPointSize).as_string();
53 message.remove_prefix(kUncompressedPointSize);
54
55 ciphertext_ = message.as_string();
56
57 if (ciphertext_.size() < kMinimumRecordSize)
58 return;
59
60 is_valid_ = true;
61 }
62
63 MessagePayloadParser::~MessagePayloadParser() = default;
64
65 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/crypto/message_payload_parser.h ('k') | components/gcm_driver/crypto/message_payload_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698