OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_PROXIMITY_AUTH_SECURE_MESSAGE_DELEGATE_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_SECURE_MESSAGE_DELEGATE_H | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "components/proximity_auth/cryptauth/proto/securemessage.pb.h" | |
12 | |
13 namespace proximity_auth { | |
14 | |
15 // Interface of delegate responsible for cryptographic operations based on the | |
16 // secure message library. This interface is asynchronous as the current | |
17 // implementation on ChromeOS communicates with a daemon process over IPC. | |
18 class SecureMessageDelegate { | |
19 public: | |
20 // Fields specifying how to create a SecureMessage. | |
21 struct CreateOptions { | |
22 CreateOptions(); | |
23 CreateOptions(const CreateOptions& other); | |
24 ~CreateOptions(); | |
25 | |
26 // The scheme used to encrypt the message. | |
27 securemessage::EncScheme encryption_scheme; | |
28 // The scheme used to sign the message. | |
29 securemessage::SigScheme signature_scheme; | |
30 // Additional data that is used as part of the signature computation but not | |
31 // included in the message contents. | |
32 std::string associated_data; | |
33 // Plain-text data included in the message header. | |
34 std::string public_metadata; | |
35 // Identifies the key to use for verifying the message signature. | |
36 std::string verification_key_id; | |
37 // Identifies the key to use for decrypting the message. | |
38 std::string decryption_key_id; | |
39 }; | |
40 | |
41 // Fields specifying how to unwrap a SecureMessage. | |
42 struct UnwrapOptions { | |
43 UnwrapOptions(); | |
44 ~UnwrapOptions(); | |
45 | |
46 // The scheme used to decrypt the message. | |
47 securemessage::EncScheme encryption_scheme; | |
48 // The scheme used to verify the message signature. | |
49 securemessage::SigScheme signature_scheme; | |
50 // Additional data that is used as part of the signature computation but not | |
51 // included in the message contents. | |
52 std::string associated_data; | |
53 }; | |
54 | |
55 SecureMessageDelegate(); | |
56 virtual ~SecureMessageDelegate(); | |
57 | |
58 // Generates a new asymmetric key pair. | |
59 typedef base::Callback<void(const std::string& public_key, | |
60 const std::string& private_key)> | |
61 GenerateKeyPairCallback; | |
62 virtual void GenerateKeyPair(const GenerateKeyPairCallback& callback) = 0; | |
63 | |
64 // Derives a symmetric key from our private key and the remote device's | |
65 // public key. | |
66 typedef base::Callback<void(const std::string& derived_key)> | |
67 DeriveKeyCallback; | |
68 virtual void DeriveKey(const std::string& private_key, | |
69 const std::string& public_key, | |
70 const DeriveKeyCallback& callback) = 0; | |
71 | |
72 // Creates a new secure message with a |payload| given the |key| and | |
73 // |create_options| specifying the cryptographic details. | |
74 // |callback| will be invoked with the serialized SecureMessage upon success | |
75 // or the empty string upon failure. | |
76 typedef base::Callback<void(const std::string& secure_message)> | |
77 CreateSecureMessageCallback; | |
78 virtual void CreateSecureMessage( | |
79 const std::string& payload, | |
80 const std::string& key, | |
81 const CreateOptions& create_options, | |
82 const CreateSecureMessageCallback& callback) = 0; | |
83 | |
84 // Unwraps |secure_message| given the |key| and |unwrap_options| specifying | |
85 // the cryptographic details. | |
86 // |callback| will be invoked with true for the |verified| argument if the | |
87 // message was verified and decrypted successfully. The |payload| and | |
88 // |header| fields will be non-empty if the message was verified successfully. | |
89 typedef base::Callback<void(bool verified, | |
90 const std::string& payload, | |
91 const securemessage::Header& header)> | |
92 UnwrapSecureMessageCallback; | |
93 virtual void UnwrapSecureMessage( | |
94 const std::string& serialized_message, | |
95 const std::string& key, | |
96 const UnwrapOptions& unwrap_options, | |
97 const UnwrapSecureMessageCallback& callback) = 0; | |
98 }; | |
99 | |
100 } // namespace proximity_auth | |
101 | |
102 #endif // COMPONENTS_PROXIMITY_AUTH_SECURE_MESSAGE_DELEGATE_H | |
OLD | NEW |