secure_message_delegate.h 4.2 KB

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