Home | History | Annotate | Download | only in client
      1 //
      2 // Copyright (C) 2015 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_CLIENT_DBUS_PROXY_H_
     18 #define ATTESTATION_CLIENT_DBUS_PROXY_H_
     19 
     20 #include "attestation/common/attestation_interface.h"
     21 
     22 #include <string>
     23 
     24 #include <base/memory/ref_counted.h>
     25 #include <dbus/bus.h>
     26 #include <dbus/object_proxy.h>
     27 
     28 namespace attestation {
     29 
     30 // An implementation of AttestationInterface that forwards requests over D-Bus.
     31 // Usage:
     32 //   std::unique_ptr<AttestationInterface> attestation = new DBusProxy();
     33 //   attestation->Initialize();
     34 //   attestation->CreateGoogleAttestedKey(...);
     35 class DBusProxy : public AttestationInterface {
     36  public:
     37   DBusProxy();
     38   virtual ~DBusProxy();
     39 
     40   // AttestationInterface methods.
     41   bool Initialize() override;
     42   void CreateGoogleAttestedKey(
     43       const CreateGoogleAttestedKeyRequest& request,
     44       const CreateGoogleAttestedKeyCallback& callback) override;
     45   void GetKeyInfo(const GetKeyInfoRequest& request,
     46                   const GetKeyInfoCallback& callback) override;
     47   void GetEndorsementInfo(const GetEndorsementInfoRequest& request,
     48                           const GetEndorsementInfoCallback& callback) override;
     49   void GetAttestationKeyInfo(
     50       const GetAttestationKeyInfoRequest& request,
     51       const GetAttestationKeyInfoCallback& callback) override;
     52   void ActivateAttestationKey(
     53       const ActivateAttestationKeyRequest& request,
     54       const ActivateAttestationKeyCallback& callback) override;
     55   void CreateCertifiableKey(
     56       const CreateCertifiableKeyRequest& request,
     57       const CreateCertifiableKeyCallback& callback) override;
     58   void Decrypt(const DecryptRequest& request,
     59                const DecryptCallback& callback) override;
     60   void Sign(const SignRequest& request, const SignCallback& callback) override;
     61   void RegisterKeyWithChapsToken(
     62       const RegisterKeyWithChapsTokenRequest& request,
     63       const RegisterKeyWithChapsTokenCallback& callback) override;
     64 
     65   // Useful for testing.
     66   void set_object_proxy(dbus::ObjectProxy* object_proxy) {
     67     object_proxy_ = object_proxy;
     68   }
     69 
     70  private:
     71   scoped_refptr<dbus::Bus> bus_;
     72   dbus::ObjectProxy* object_proxy_;
     73 };
     74 
     75 }  // namespace attestation
     76 
     77 #endif  // ATTESTATION_CLIENT_DBUS_PROXY_H_
     78