• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2018, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #include <android-base/logging.h>
19 #include <android/hardware/keymaster/4.1/IKeymasterDevice.h>
20 #include <cutils/properties.h>
21 #include <gflags/gflags.h>
22 #include <hidl/HidlTransportSupport.h>
23 
24 #include "common/libs/fs/shared_fd.h"
25 #include "common/libs/security/keymaster_channel.h"
26 #include <guest/hals/keymaster/remote/remote_keymaster.h>
27 #include <guest/hals/keymaster/remote/remote_keymaster4_device.h>
28 
29 const char device[] = "/dev/hvc3";
30 
main(int argc,char ** argv)31 int main(int argc, char** argv) {
32   ::android::base::InitLogging(argv, ::android::base::KernelLogger);
33   gflags::ParseCommandLineFlags(&argc, &argv, true);
34   ::android::hardware::configureRpcThreadpool(1, true);
35 
36   LOG(INFO) << "Starting keymaster service4";
37 
38   auto fd = cuttlefish::SharedFD::Open(device, O_RDWR);
39   if (!fd->IsOpen()) {
40     LOG(FATAL) << "Could not connect to keymaster: " << fd->StrError();
41   }
42 
43   if (fd->SetTerminalRaw() < 0) {
44     LOG(FATAL) << "Could not make " << device << " a raw terminal: "
45                 << fd->StrError();
46   }
47 
48   cuttlefish::KeymasterChannel keymasterChannel(fd, fd);
49 
50   auto remoteKeymaster = new keymaster::RemoteKeymaster(&keymasterChannel);
51 
52   if (!remoteKeymaster->Initialize()) {
53     LOG(FATAL) << "Could not initialize keymaster";
54   }
55 
56   auto keymaster = new ::keymaster::V4_1::RemoteKeymaster4Device(remoteKeymaster);
57 
58   auto status = keymaster->registerAsService();
59   if (status != android::OK) {
60     LOG(FATAL) << "Could not register service for Keymaster 4.1 (" << status << ")";
61     return -1;
62   }
63 
64   android::hardware::joinRpcThreadpool();
65   return -1;  // Should never get here.
66 }
67