Skip to content

Commit 9b911e9

Browse files
committed
security+tools: deprecate TPM unlock functionality
And remove the implementation in the tpm-osxkeychain backend Refs: #4754 Change-Id: I6d61b7aab83aba2c9128b524e178c71de8635b75
1 parent 102f057 commit 9b911e9

File tree

10 files changed

+56
-109
lines changed

10 files changed

+56
-109
lines changed

docs/manpages/ndnsec-unlock-tpm.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ Synopsis
99
Description
1010
-----------
1111

12+
**DEPRECATED**
13+
1214
This command can be used to (temporarily) unlock the local
1315
**Trusted Platform Module (TPM)** that manages the private keys.

docs/manpages/ndnsec.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ The following commands are understood:
5656
:doc:`import <ndnsec-import>`
5757
Import an identity from a SafeBag.
5858

59-
:doc:`unlock-tpm <ndnsec-unlock-tpm>`
60-
Unlock the TPM.
61-
6259
Exit Status
6360
-----------
6461

ndn-cxx/security/tpm/back-end.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -145,27 +145,4 @@ BackEnd::constructHmacKeyName(const transform::PrivateKey& key, const Name& iden
145145
return Name(identity).append(name::Component(key.getKeyDigest(DigestAlgorithm::SHA256)));
146146
}
147147

148-
bool
149-
BackEnd::isTerminalMode() const
150-
{
151-
return true;
152-
}
153-
154-
void
155-
BackEnd::setTerminalMode(bool isTerminal) const
156-
{
157-
}
158-
159-
bool
160-
BackEnd::isTpmLocked() const
161-
{
162-
return false;
163-
}
164-
165-
bool
166-
BackEnd::unlockTpm(const char* pw, size_t pwLen) const
167-
{
168-
return !isTpmLocked();
169-
}
170-
171148
} // namespace ndn::security::tpm

ndn-cxx/security/tpm/back-end.hpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -116,45 +116,59 @@ class BackEnd : noncopyable
116116

117117
/**
118118
* @brief Check if the TPM is in terminal mode.
119+
* @deprecated
119120
*
120121
* The default implementation always returns true.
121-
*
122-
* @return True if in terminal mode, false otherwise.
123122
*/
123+
[[deprecated]]
124124
virtual bool
125-
isTerminalMode() const;
125+
isTerminalMode() const
126+
{
127+
return true;
128+
}
126129

127130
/**
128131
* @brief Set the terminal mode of the TPM.
132+
* @deprecated
129133
*
130134
* In terminal mode, the TPM will not ask for a password from the GUI.
131135
* The default implementation does nothing.
132136
*/
137+
[[deprecated]]
133138
virtual void
134-
setTerminalMode(bool isTerminal) const;
139+
setTerminalMode(bool isTerminal) const
140+
{
141+
}
135142

136143
/**
137144
* @brief Check if the TPM is locked.
145+
* @deprecated
138146
*
139147
* The default implementation always returns false.
140-
*
141-
* @return True if locked, false otherwise.
142148
*/
149+
[[deprecated]]
143150
virtual bool
144-
isTpmLocked() const;
151+
isTpmLocked() const
152+
{
153+
return false;
154+
}
145155

146156
/**
147157
* @brief Unlock the TPM.
158+
* @deprecated
148159
*
149-
* The default implementation does nothing and returns `!isTpmLocked()`.
160+
* The default implementation does nothing and always returns true.
150161
*
151162
* @param pw The password to unlock the TPM.
152163
* @param pwLen The length of the password.
153-
*
154164
* @return True if the TPM was unlocked.
155165
*/
166+
[[deprecated]]
156167
[[nodiscard]] virtual bool
157-
unlockTpm(const char* pw, size_t pwLen) const;
168+
unlockTpm(const char* pw, size_t pwLen) const
169+
{
170+
return true;
171+
}
158172

159173
protected: // helper methods
160174
/**

ndn-cxx/security/tpm/impl/back-end-osx.cpp

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -38,11 +38,9 @@ namespace ndn::security::tpm {
3838
namespace cfstring = ndn::detail::cfstring;
3939
using ndn::detail::CFReleaser;
4040

41-
class BackEndOsx::Impl
41+
struct BackEndOsx::Impl
4242
{
43-
public:
4443
SecKeychainRef keyChainRef;
45-
bool isTerminalMode = false;
4644
};
4745

4846
static CFReleaser<CFDataRef>
@@ -187,8 +185,6 @@ exportItem(const KeyRefOsx& keyRef, transform::PrivateKey& outKey)
187185
BackEndOsx::BackEndOsx(const std::string&)
188186
: m_impl(make_unique<Impl>())
189187
{
190-
SecKeychainSetUserInteractionAllowed(!m_impl->isTerminalMode);
191-
192188
OSStatus res = SecKeychainCopyDefault(&m_impl->keyChainRef);
193189
if (res == errSecNoDefaultKeychain) {
194190
NDN_THROW(Error("No default keychain, create one first"));
@@ -204,49 +200,6 @@ BackEndOsx::getScheme()
204200
return scheme;
205201
}
206202

207-
bool
208-
BackEndOsx::isTerminalMode() const
209-
{
210-
return m_impl->isTerminalMode;
211-
}
212-
213-
void
214-
BackEndOsx::setTerminalMode(bool isTerminal) const
215-
{
216-
m_impl->isTerminalMode = isTerminal;
217-
SecKeychainSetUserInteractionAllowed(!isTerminal);
218-
}
219-
220-
bool
221-
BackEndOsx::isTpmLocked() const
222-
{
223-
SecKeychainStatus keychainStatus;
224-
OSStatus res = SecKeychainGetStatus(m_impl->keyChainRef, &keychainStatus);
225-
if (res != errSecSuccess)
226-
return true;
227-
else
228-
return (kSecUnlockStateStatus & keychainStatus) == 0;
229-
}
230-
231-
bool
232-
BackEndOsx::unlockTpm(const char* pw, size_t pwLen) const
233-
{
234-
// If the default key chain is already unlocked, return immediately.
235-
if (!isTpmLocked())
236-
return true;
237-
238-
if (m_impl->isTerminalMode) {
239-
// Use the supplied password.
240-
SecKeychainUnlock(m_impl->keyChainRef, pwLen, pw, true);
241-
}
242-
else {
243-
// If inTerminal is not set, get the password from GUI.
244-
SecKeychainUnlock(m_impl->keyChainRef, 0, nullptr, false);
245-
}
246-
247-
return !isTpmLocked();
248-
}
249-
250203
ConstBufferPtr
251204
BackEndOsx::sign(const KeyRefOsx& key, DigestAlgorithm digestAlgo, const InputBuffers& bufs)
252205
{

ndn-cxx/security/tpm/impl/back-end-osx.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -51,19 +51,6 @@ class BackEndOsx final : public BackEnd
5151
static const std::string&
5252
getScheme();
5353

54-
public: // management
55-
bool
56-
isTerminalMode() const final;
57-
58-
void
59-
setTerminalMode(bool isTerminal) const final;
60-
61-
bool
62-
isTpmLocked() const final;
63-
64-
bool
65-
unlockTpm(const char* pw, size_t pwLen) const final;
66-
6754
public: // crypto transformation
6855
/**
6956
* @brief Sign @p bufs with @p key using @p digestAlgorithm.
@@ -103,7 +90,7 @@ class BackEndOsx final : public BackEnd
10390
doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key) final;
10491

10592
private:
106-
class Impl;
93+
struct Impl;
10794
const unique_ptr<Impl> m_impl;
10895
};
10996

ndn-cxx/security/tpm/tpm.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -91,6 +91,9 @@ Tpm::decrypt(span<const uint8_t> buf, const Name& keyName) const
9191
return key ? key->decrypt(buf) : nullptr;
9292
}
9393

94+
#pragma GCC diagnostic push
95+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
96+
9497
bool
9598
Tpm::isTerminalMode() const
9699
{
@@ -115,6 +118,8 @@ Tpm::unlockTpm(const char* password, size_t passwordLength) const
115118
return m_backEnd->unlockTpm(password, passwordLength);
116119
}
117120

121+
#pragma GCC diagnostic pop
122+
118123
ConstBufferPtr
119124
Tpm::exportPrivateKey(const Name& keyName, const char* pw, size_t pwLen) const
120125
{

ndn-cxx/security/tpm/tpm.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -129,30 +129,38 @@ class Tpm : noncopyable
129129
public: // Management
130130
/**
131131
* @brief Check if the TPM is in terminal mode.
132+
* @deprecated
132133
*/
134+
[[deprecated]]
133135
bool
134136
isTerminalMode() const;
135137

136138
/**
137139
* @brief Set the terminal mode of the TPM.
140+
* @deprecated
138141
*
139142
* When in terminal mode, the TPM will not ask user permission from GUI.
140143
*/
144+
[[deprecated]]
141145
void
142146
setTerminalMode(bool isTerminal) const;
143147

144148
/**
145149
* @return true if the TPM is locked, otherwise false.
150+
* @deprecated
146151
*/
152+
[[deprecated]]
147153
bool
148154
isTpmLocked() const;
149155

150156
/**
151157
* @brief Unlock the TPM.
158+
* @deprecated
152159
*
153160
* @param password The password to unlock the TPM.
154161
* @param passwordLength The password size.
155162
*/
163+
[[deprecated]]
156164
[[nodiscard]] bool
157165
unlockTpm(const char* password, size_t passwordLength) const;
158166

tools/ndnsec/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -35,7 +35,6 @@ constexpr std::string_view NDNSEC_HELP_TEXT = R"STR(Usage: ndnsec COMMAND [OPTIO
3535
3636
Available commands:
3737
help Print this help text
38-
version Print program version
3938
list List all known identities/keys/certificates
4039
get-default Show the default identity/key/certificate
4140
set-default Change the default identity/key/certificate
@@ -47,9 +46,9 @@ Available commands:
4746
cert-install Import a certificate from a file
4847
export Export an identity as a SafeBag
4948
import Import an identity from a SafeBag
50-
unlock-tpm Unlock the TPM
49+
version Print version information
5150
52-
Try 'ndnsec COMMAND --help' for more information on a command.
51+
Run 'ndnsec COMMAND --help' for more information on a command.
5352
)STR";
5453

5554
int

tools/ndnsec/unlock-tpm.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/*
3-
* Copyright (c) 2013-2023 Regents of the University of California.
3+
* Copyright (c) 2013-2024 Regents of the University of California.
44
*
55
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
66
*
@@ -33,6 +33,8 @@ namespace ndn::ndnsec {
3333
int
3434
ndnsec_unlock_tpm(int argc, char** argv)
3535
{
36+
std::cerr << "DEPRECATION NOTICE: ndnsec-unlock-tpm is deprecated.\n";
37+
3638
namespace po = boost::program_options;
3739

3840
po::options_description description(
@@ -68,7 +70,10 @@ ndnsec_unlock_tpm(int argc, char** argv)
6870
return 1;
6971
}
7072

73+
#pragma GCC diagnostic push
74+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
7175
bool isUnlocked = keyChain.getTpm().unlockTpm(password, std::strlen(password));
76+
#pragma GCC diagnostic pop
7277
OPENSSL_cleanse(password, std::strlen(password));
7378

7479
if (isUnlocked) {

0 commit comments

Comments
 (0)