summaryrefslogtreecommitdiffstats
path: root/chromeos/cryptohome/cryptohome_util.cc
blob: 5e2b310ba631cb417256896aea0bd2cb1130988b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/cryptohome/cryptohome_util.h"

#include "base/logging.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"

namespace chromeos {
namespace cryptohome_util {

bool TpmIsEnabled() {
  bool result = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsEnabledAndBlock(
      &result);
  return result;
}

bool TpmIsOwned() {
  bool result = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsOwnedAndBlock(
      &result);
  return result;
}

bool TpmIsBeingOwned() {
  bool result = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->
      CallTpmIsBeingOwnedAndBlock(&result);
  return result;
}

bool InstallAttributesGet(
    const std::string& name, std::string* value) {
  std::vector<uint8> buf;
  bool success = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->
      InstallAttributesGet(name, &buf, &success);
  if (success) {
    // Cryptohome returns 'buf' with a terminating '\0' character.
    DCHECK(!buf.empty());
    DCHECK_EQ(buf.back(), 0);
    value->assign(reinterpret_cast<char*>(buf.data()), buf.size() - 1);
  }
  return success;
}

bool InstallAttributesSet(
    const std::string& name, const std::string& value) {
  std::vector<uint8> buf(value.c_str(), value.c_str() + value.size() + 1);
  bool success = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->
      InstallAttributesSet(name, buf, &success);
  return success;
}

bool InstallAttributesFinalize() {
  bool success = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->
      InstallAttributesFinalize(&success);
  return success;
}

bool InstallAttributesIsInvalid() {
  bool result = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->
      InstallAttributesIsInvalid(&result);
  return result;
}

bool InstallAttributesIsFirstInstall() {
  bool result = false;
  DBusThreadManager::Get()->GetCryptohomeClient()->
      InstallAttributesIsFirstInstall(&result);
  return result;
}

}  // namespace cryptohome_util
}  // namespace chromeos