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) { service_ = service; } 47 48 private: 49 friend class DBusServiceTest; 50 51 // Handles a CreateGoogleAttestedKey D-Bus call. 52 void HandleCreateGoogleAttestedKey( 53 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 54 const CreateGoogleAttestedKeyReply&>> response, 55 const CreateGoogleAttestedKeyRequest& request); 56 57 // Handles a GetKeyInfo D-Bus call. 58 void HandleGetKeyInfo(std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 59 const GetKeyInfoReply&>> response, 60 const GetKeyInfoRequest& request); 61 62 // Handles a GetEndorsementInfo D-Bus call. 63 void HandleGetEndorsementInfo( 64 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 65 const GetEndorsementInfoReply&>> response, 66 const GetEndorsementInfoRequest& request); 67 68 // Handles a GetAttestationKeyInfo D-Bus call. 69 void HandleGetAttestationKeyInfo( 70 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 71 const GetAttestationKeyInfoReply&>> response, 72 const GetAttestationKeyInfoRequest& request); 73 74 // Handles a ActivateAttestationKey D-Bus call. 75 void HandleActivateAttestationKey( 76 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 77 const ActivateAttestationKeyReply&>> response, 78 const ActivateAttestationKeyRequest& request); 79 80 // Handles a CreateCertifiableKey D-Bus call. 81 void HandleCreateCertifiableKey( 82 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 83 const CreateCertifiableKeyReply&>> response, 84 const CreateCertifiableKeyRequest& request); 85 86 // Handles a Decrypt D-Bus call. 87 void HandleDecrypt( 88 std::unique_ptr< 89 brillo::dbus_utils::DBusMethodResponse<const DecryptReply&>> response, 90 const DecryptRequest& request); 91 92 // Handles a Sign D-Bus call. 93 void HandleSign( 94 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse<const SignReply&>> 95 response, 96 const SignRequest& request); 97 98 // Handles a RegisterKeyWithChapsToken D-Bus call. 99 void HandleRegisterKeyWithChapsToken( 100 std::unique_ptr<brillo::dbus_utils::DBusMethodResponse< 101 const RegisterKeyWithChapsTokenReply&>> response, 102 const RegisterKeyWithChapsTokenRequest& request); 103 104 brillo::dbus_utils::DBusObject dbus_object_; 105 AttestationInterface* service_; 106 107 DISALLOW_COPY_AND_ASSIGN(DBusService); 108 }; 109 110 } // namespace attestation 111 112 #endif // ATTESTATION_SERVER_DBUS_SERVICE_H_ 113