1 // Copyright 2014 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.
5 #ifndef CHROMEOS_DBUS_EASY_UNLOCK_CLIENT_H_
6 #define CHROMEOS_DBUS_EASY_UNLOCK_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
17 // Client for calling EasyUnlock dbus service. The service provides
18 // methods used by Easy Unlock for establishing secure communication channel
19 // over (unsecure) bluetooth with devices registered to unlock ChromeOS.
20 // Ideally, this would be done in Chrome, but unfortunatelly, the library used
21 // for wrapping and unwrapping messages sent over the communication channel
22 // depends on OpenSSL for encryption, which is not currently available in
23 // Chrome. To work around this, the message processing will be done in ChromeOS,
24 // where OpenSSL is already supported.
25 // TODO(tbarzic): Get rid of this client when Chrome switches from NSS to
26 // OpenSSL (http://crbug.com/338888).
27 class CHROMEOS_EXPORT EasyUnlockClient
: public DBusClient
{
29 virtual ~EasyUnlockClient();
31 typedef base::Callback
<void(const std::string
& data
)> DataCallback
;
33 // Callback for |GenerateEcP256KeyAgreement|. Carries the generated keys.
34 typedef base::Callback
<void(const std::string
& public_key
,
35 const std::string
& private_key
)>
38 // Generates ECDSA key pair using P256 curve.
39 // The created keys should only be used with this client.
40 virtual void GenerateEcP256KeyPair(const KeyPairCallback
& callback
) = 0;
42 // Given a private and a public key, creates a symetric secret key using
43 // EC Diffe-Hellman key exchange. The provided keys come from different
44 // asymetric key pairs, and are expected to be in the same format as the ones
45 // returned by |GenerateEcP256KeyAgreement|. Reversing key pairs from which
46 // private and public key come generates the same secret key.
47 virtual void PerformECDHKeyAgreement(const std::string
& private_key
,
48 const std::string
& public_key
,
49 const DataCallback
& callback
) = 0;
51 // Creates signed and, if specified, encrypted message in format used by Easy
53 // |payload|: The cleartext message body.
54 // |key|: The key used to sign, and if needed, encrypt the message. If
55 // encryption is required, the key must be symetric.
56 // |associated_data|: Data associated with the message. The data will not
57 // actually be added to the message, but it will be used while
58 // signing the message (the receiver will use the same data to
59 // authenticate the signature).
60 // |public_metadata|: Metadata added to the message header.
61 // |verification_key_id|: The key id added to the message header. Has to be
62 // set if the message is signed with private asymetric key. This value
63 // is used by the receiver to identify the public key that should be used
64 // to verify the signature.
65 // |encryption_type|: The encryption algorithm to use for encrypting the
66 // message. (May be set to none).
67 // |signature_type|: The algorithm to use to sign the message.
68 // |callback|: Called with the created message. On failure, the message will
70 virtual void CreateSecureMessage(const std::string
& payload
,
71 const std::string
& secret_key
,
72 const std::string
& associated_data
,
73 const std::string
& public_metadata
,
74 const std::string
& verification_key_id
,
75 const std::string
& encryption_type
,
76 const std::string
& signature_type
,
77 const DataCallback
& callback
) = 0;
79 // Authenticates and, if specified, decrypts a secure message.
80 // |message|: The message to unwrap. It is in the same format as the message
81 // returned by |CreateSecureMessage|.
82 // |key|: The key used to authenticate message signature and, if needed,
83 // decrypt the message. If the message is encrypted, only symetric key
85 // |associated_data|: Data associated with the message. Message
86 // authentication will succeed only if the message was created with the
88 // |encryption_type|: The encryption algorithm to use for decrypting the
89 // message. (May be set to none).
90 // |signature_type|: The algorithm to use to verify the message signature.
91 // |callback|: Called with the cleartext message header and body in a signle
92 // protobuf. If the message could not be authenticated or decrypted, it
93 // will be called with an empty string.
94 virtual void UnwrapSecureMessage(const std::string
& message
,
95 const std::string
& secret_key
,
96 const std::string
& associated_data
,
97 const std::string
& encryption_type
,
98 const std::string
& signature_type
,
99 const DataCallback
& callback
) = 0;
101 // Factory function, creates a new instance and returns ownership.
102 // For normal usage, access the singleton via DBusThreadManager::Get().
103 static EasyUnlockClient
* Create();
106 // Create() should be used instead.
110 DISALLOW_COPY_AND_ASSIGN(EasyUnlockClient
);
113 } // namespace chromeos
115 #endif // CHROMEOS_DBUS_EASY_UNLOCK_CLIENT_H_