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

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

Issue 1243563002: Teach the GCM Driver how to decrypt incoming messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gcm-push-keys
Patch Set: Created 5 years, 4 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 #include <string> 9 #include <string>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 14
15 namespace base { 15 namespace base {
16 class FilePath; 16 class FilePath;
17 class SequencedTaskRunner; 17 class SequencedTaskRunner;
18 } 18 }
19 19
20 namespace gcm { 20 namespace gcm {
21 21
22 struct EncryptionHeaderValue;
23 struct EncryptionKeyHeaderValue;
22 class GCMKeyStore; 24 class GCMKeyStore;
25 struct IncomingMessage;
23 class KeyPair; 26 class KeyPair;
24 27
25 // Provider that enables the GCM Driver to deal with encryption key management 28 // Provider that enables the GCM Driver to deal with encryption key management
26 // and decryption of incoming messages. 29 // and decryption of incoming messages.
27 class GCMEncryptionProvider { 30 class GCMEncryptionProvider {
28 public: 31 public:
29 // Callback to be invoked when the public encryption key is available. 32 // Callback to be invoked when the public encryption key is available.
30 using PublicKeyCallback = base::Callback<void(const std::string&)>; 33 using PublicKeyCallback = base::Callback<void(const std::string&)>;
31 34
35 // Callback to be invoked when a message may have been decrypted.
36 using MessageCallback =
37 base::Callback<void(const IncomingMessage&, bool decryption_successful)>;
38
32 GCMEncryptionProvider(); 39 GCMEncryptionProvider();
33 ~GCMEncryptionProvider(); 40 ~GCMEncryptionProvider();
34 41
35 // Initializes the encryption provider with the |store_path| and the 42 // Initializes the encryption provider with the |store_path| and the
36 // |blocking_task_runner|. Done separately from the constructor in order to 43 // |blocking_task_runner|. Done separately from the constructor in order to
37 // avoid needing a blocking task runner for anything using GCMDriver. 44 // avoid needing a blocking task runner for anything using GCMDriver.
38 void Init( 45 void Init(
39 const base::FilePath& store_path, 46 const base::FilePath& store_path,
40 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); 47 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner);
41 48
42 // Retrieves the public encryption key belonging to |app_id|. If no keys have 49 // Retrieves the public encryption key belonging to |app_id|. If no keys have
43 // been associated with |app_id| yet, they will be created. 50 // been associated with |app_id| yet, they will be created.
44 void GetPublicKey(const std::string& app_id, 51 void GetPublicKey(const std::string& app_id,
45 const PublicKeyCallback& callback); 52 const PublicKeyCallback& callback);
46 53
54 // Determines whether |message| contains encrypted content.
55 bool IsEncryptedMessage(const IncomingMessage& message) const;
56
57 // Decrypts |message| and stores the result in |decrypted_message|. The return
58 // value indicates whether the message could be decrypted successfully.
59 void DecryptMessage(const std::string& app_id,
60 const IncomingMessage& message,
61 const MessageCallback& callback);
62
47 private: 63 private:
48 void DidGetPublicKey(const std::string& app_id, 64 void DidGetPublicKey(const std::string& app_id,
49 const PublicKeyCallback& callback, 65 const PublicKeyCallback& callback,
50 const KeyPair& pair); 66 const KeyPair& pair);
51 67
52 void DidCreatePublicKey(const PublicKeyCallback& callback, 68 void DidCreatePublicKey(const PublicKeyCallback& callback,
53 const KeyPair& pair); 69 const KeyPair& pair);
54 70
71 void DecryptMessageWithKey(
72 const IncomingMessage& message,
73 const MessageCallback& callback,
74 const EncryptionHeaderValue& encryption_header,
75 const EncryptionKeyHeaderValue& encryption_key_header,
76 const std::string& ciphertext,
77 const KeyPair& pair);
78
55 scoped_ptr<GCMKeyStore> key_store_; 79 scoped_ptr<GCMKeyStore> key_store_;
56 80
57 base::WeakPtrFactory<GCMEncryptionProvider> weak_ptr_factory_; 81 base::WeakPtrFactory<GCMEncryptionProvider> weak_ptr_factory_;
58 82
59 DISALLOW_COPY_AND_ASSIGN(GCMEncryptionProvider); 83 DISALLOW_COPY_AND_ASSIGN(GCMEncryptionProvider);
60 }; 84 };
61 85
62 } // namespace gcm 86 } // namespace gcm
63 87
64 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_ 88 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_ENCRYPTION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698