1 // 2 // Copyright (C) 2014 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef ATTESTATION_SERVER_DBUS_SERVICE_H_ 18 #define ATTESTATION_SERVER_DBUS_SERVICE_H_ 19 20 #include <memory> 21 22 #include <brillo/dbus/dbus_method_response.h> 23 #include <brillo/dbus/dbus_object.h> 24 #include <dbus/bus.h> 25 26 #include "attestation/common/attestation_interface.h" 27 28 namespace attestation { 29 30 using CompletionAction = 31 brillo::dbus_utils::AsyncEventSequencer::CompletionAction; 32 33 // Handles D-Bus calls to the attestation daemon. 34 class DBusService { 35 public: 36 // DBusService does not take ownership of |service|; it must remain valid for 37 // the lifetime of the DBusService instance. 38 DBusService(const scoped_refptr<dbus::Bus>& bus, 39 AttestationInterface* service); 40 virtual ~DBusService() = default; 41 42 // Connects to D-Bus system bus and exports methods. 43 void Register(const CompletionAction& callback); 44 45 // Useful for testing. set_service(AttestationInterface * service)46 void set_service(AttestationInterface* service) { 47 service_ = service; 48 } 49 50 private: 51 friend class DBusServiceTest; 52 53 // Handles a CreateGoogleAttestedKey D-Bus call. 54 void HandleCreateGoogleAttestedKey( 55 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 56 const CreateGoogleAttestedKeyReply&>> response, 57 const CreateGoogleAttestedKeyRequest& request); 58 59 // Handles a GetKeyInfo D-Bus call. 60 void HandleGetKeyInfo( 61 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 62 const GetKeyInfoReply&>> response, 63 const GetKeyInfoRequest& request); 64 65 // Handles a GetEndorsementInfo D-Bus call. 66 void HandleGetEndorsementInfo( 67 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 68 const GetEndorsementInfoReply&>> response, 69 const GetEndorsementInfoRequest& request); 70 71 // Handles a GetAttestationKeyInfo D-Bus call. 72 void HandleGetAttestationKeyInfo( 73 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 74 const GetAttestationKeyInfoReply&>> response, 75 const GetAttestationKeyInfoRequest& request); 76 77 // Handles a ActivateAttestationKey D-Bus call. 78 void HandleActivateAttestationKey( 79 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 80 const ActivateAttestationKeyReply&>> response, 81 const ActivateAttestationKeyRequest& request); 82 83 // Handles a CreateCertifiableKey D-Bus call. 84 void HandleCreateCertifiableKey( 85 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 86 const CreateCertifiableKeyReply&>> response, 87 const CreateCertifiableKeyRequest& request); 88 89 // Handles a Decrypt D-Bus call. 90 void HandleDecrypt( 91 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 92 const DecryptReply&>> response, 93 const DecryptRequest& request); 94 95 // Handles a Sign D-Bus call. 96 void HandleSign( 97 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 98 const SignReply&>> response, 99 const SignRequest& request); 100 101 // Handles a RegisterKeyWithChapsToken D-Bus call. 102 void HandleRegisterKeyWithChapsToken( 103 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 104 const RegisterKeyWithChapsTokenReply&>> response, 105 const RegisterKeyWithChapsTokenRequest& request); 106 107 brillo::dbus_utils::DBusObject dbus_object_; 108 AttestationInterface* service_; 109 110 DISALLOW_COPY_AND_ASSIGN(DBusService); 111 }; 112 113 } // namespace attestation 114 115 #endif // ATTESTATION_SERVER_DBUS_SERVICE_H_ 116