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

Side by Side Diff: components/gcm_driver/crypto/gcm_encryption_provider.h

Issue 2892033002: Enable support for draft-ietf-webpush-encryption-08 (Closed)
Patch Set: Enable support for draft-ietf-webpush-encryption-08 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_ 5 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_
6 #define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_ 6 #define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "components/gcm_driver/crypto/gcm_message_cryptographer.h"
17 18
18 namespace base { 19 namespace base {
19 class FilePath; 20 class FilePath;
20 class SequencedTaskRunner; 21 class SequencedTaskRunner;
21 } 22 }
22 23
23 namespace gcm { 24 namespace gcm {
24 25
25 class GCMKeyStore; 26 class GCMKeyStore;
26 struct IncomingMessage; 27 struct IncomingMessage;
27 class KeyPair; 28 class KeyPair;
28 29
29 // Provider that enables the GCM Driver to deal with encryption key management 30 // Provider that enables the GCM Driver to deal with encryption key management
30 // and decryption of incoming messages. 31 // and decryption of incoming messages.
31 class GCMEncryptionProvider { 32 class GCMEncryptionProvider {
32 public: 33 public:
33 // Result of decrypting an incoming message. The values of these reasons must 34 // Result of decrypting an incoming message. The values of these reasons must
34 // not be changed, because they are being recorded using UMA. 35 // not be changed, because they are being recorded using UMA.
35 enum DecryptionResult { 36 enum DecryptionResult {
36 // The message had not been encrypted by the sender. 37 // The message had not been encrypted by the sender.
37 DECRYPTION_RESULT_UNENCRYPTED = 0, 38 DECRYPTION_RESULT_UNENCRYPTED = 0,
38 39
39 // The message had been encrypted by the sender, and could successfully be 40 // The message had been encrypted by the sender, and could successfully be
40 // decrypted for the registration it has been received for. 41 // decrypted for the registration it has been received for. The encryption
41 DECRYPTION_RESULT_DECRYPTED = 1, 42 // scheme used for the message was draft-ietf-webpush-encryption-03.
43 DECRYPTION_RESULT_DECRYPTED_DRAFT_03 = 1,
42 44
43 // The contents of the Encryption HTTP header could not be parsed. 45 // The contents of the Encryption HTTP header could not be parsed.
44 DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER = 2, 46 DECRYPTION_RESULT_INVALID_ENCRYPTION_HEADER = 2,
45 47
46 // The contents of the Crypto-Key HTTP header could not be parsed. 48 // The contents of the Crypto-Key HTTP header could not be parsed.
47 DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER = 3, 49 DECRYPTION_RESULT_INVALID_CRYPTO_KEY_HEADER = 3,
48 50
49 // No public/private key-pair was associated with the app_id. 51 // No public/private key-pair was associated with the app_id.
50 DECRYPTION_RESULT_NO_KEYS = 4, 52 DECRYPTION_RESULT_NO_KEYS = 4,
51 53
52 // The shared secret cannot be derived from the keying material. 54 // The shared secret cannot be derived from the keying material.
53 DECRYPTION_RESULT_INVALID_SHARED_SECRET = 5, 55 DECRYPTION_RESULT_INVALID_SHARED_SECRET = 5,
54 56
55 // The payload could not be decrypted as AES-128-GCM. 57 // The payload could not be decrypted as AES-128-GCM.
56 DECRYPTION_RESULT_INVALID_PAYLOAD = 6, 58 DECRYPTION_RESULT_INVALID_PAYLOAD = 6,
57 59
58 DECRYPTION_RESULT_LAST = DECRYPTION_RESULT_INVALID_PAYLOAD 60 // The binary header leading the ciphertext could not be parsed. Only
61 // applicable to messages encrypted per draft-ietf-webpush-encryption-08.
62 DECRYPTION_RESULT_INVALID_BINARY_HEADER = 7,
63
64 // The message had been encrypted by the sender, and could successfully be
65 // decrypted for the registration it has been received for. The encryption
66 // scheme used for the message was draft-ietf-webpush-encryption-08.
67 DECRYPTION_RESULT_DECRYPTED_DRAFT_08 = 8,
68
69 DECRYPTION_RESULT_LAST = DECRYPTION_RESULT_DECRYPTED_DRAFT_08
59 }; 70 };
60 71
61 // Callback to be invoked when the public key and auth secret are available. 72 // Callback to be invoked when the public key and auth secret are available.
62 using EncryptionInfoCallback = 73 using EncryptionInfoCallback =
63 base::Callback<void(const std::string& p256dh, 74 base::Callback<void(const std::string& p256dh,
64 const std::string& auth_secret)>; 75 const std::string& auth_secret)>;
65 76
66 // Callback to be invoked when a message may have been decrypted, as indicated 77 // Callback to be invoked when a message may have been decrypted, as indicated
67 // by the |result|. The |message| contains the dispatchable message in success 78 // by the |result|. The |message| contains the dispatchable message in success
68 // cases, or will be initialized to an empty, default state for failure. 79 // cases, or will be initialized to an empty, default state for failure.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void DidGetEncryptionInfo(const std::string& app_id, 130 void DidGetEncryptionInfo(const std::string& app_id,
120 const std::string& authorized_entity, 131 const std::string& authorized_entity,
121 const EncryptionInfoCallback& callback, 132 const EncryptionInfoCallback& callback,
122 const KeyPair& pair, 133 const KeyPair& pair,
123 const std::string& auth_secret); 134 const std::string& auth_secret);
124 135
125 void DidCreateEncryptionInfo(const EncryptionInfoCallback& callback, 136 void DidCreateEncryptionInfo(const EncryptionInfoCallback& callback,
126 const KeyPair& pair, 137 const KeyPair& pair,
127 const std::string& auth_secret); 138 const std::string& auth_secret);
128 139
129 void DecryptMessageWithKey(const IncomingMessage& message, 140 void DecryptMessageWithKey(const std::string& collapse_key,
141 const std::string& sender_id,
142 const std::string& salt,
143 const std::string& public_key,
144 uint64_t record_size,
johnme 2017/05/23 17:37:48 Why isn't this uint32_t? Is it because the draft 0
Peter Beverloo 2017/05/23 17:58:32 Done.
145 const std::string& ciphertext,
146 GCMMessageCryptographer::Version version,
130 const MessageCallback& callback, 147 const MessageCallback& callback,
131 const std::string& salt,
132 const std::string& dh,
133 uint64_t rs,
134 const KeyPair& pair, 148 const KeyPair& pair,
135 const std::string& auth_secret); 149 const std::string& auth_secret);
136 150
137 std::unique_ptr<GCMKeyStore> key_store_; 151 std::unique_ptr<GCMKeyStore> key_store_;
138 152
139 base::WeakPtrFactory<GCMEncryptionProvider> weak_ptr_factory_; 153 base::WeakPtrFactory<GCMEncryptionProvider> weak_ptr_factory_;
140 154
141 DISALLOW_COPY_AND_ASSIGN(GCMEncryptionProvider); 155 DISALLOW_COPY_AND_ASSIGN(GCMEncryptionProvider);
142 }; 156 };
143 157
144 } // namespace gcm 158 } // namespace gcm
145 159
146 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_ 160 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698