NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
back-end-osx.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
27 
28 #include <Security/Security.h>
29 #include <cstring>
30 
31 #include <boost/lexical_cast.hpp>
32 
33 namespace ndn {
34 namespace security {
35 namespace tpm {
36 
37 namespace cfstring = detail::cfstring;
38 using detail::CFReleaser;
39 
41 {
42 public:
43  SecKeychainRef keyChainRef;
44  bool isTerminalMode = false;
45 };
46 
48 makeCFDataNoCopy(const uint8_t* buf, size_t buflen)
49 {
50  return CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, buf, buflen, kCFAllocatorNull);
51 }
52 
53 static CFReleaser<CFMutableDictionaryRef>
55 {
56  return CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
57  &kCFTypeDictionaryKeyCallBacks,
58  &kCFTypeDictionaryValueCallBacks);
59 }
60 
61 static std::string
62 getErrorMessage(OSStatus status)
63 {
64  CFReleaser<CFStringRef> msg = SecCopyErrorMessageString(status, nullptr);
65  if (msg != nullptr)
66  return cfstring::toStdString(msg.get());
67  else
68  return "<no error message>";
69 }
70 
71 static std::string
72 getFailureReason(CFErrorRef err)
73 {
74  CFReleaser<CFStringRef> reason = CFErrorCopyFailureReason(err);
75  if (reason != nullptr)
76  return cfstring::toStdString(reason.get());
77  else
78  return "<unknown reason>";
79 }
80 
81 static CFTypeRef
83 {
84  switch (keyType) {
85  case KeyType::RSA:
86  return kSecAttrKeyTypeRSA;
87  case KeyType::EC:
88  return kSecAttrKeyTypeECDSA;
89  default:
91  }
92 }
93 
94 static CFTypeRef
96 {
97  switch (digestAlgo) {
102  return kSecDigestSHA2;
103  default:
104  return nullptr;
105  }
106 }
107 
108 static int
110 {
111  switch (digestAlgo) {
113  return 224;
115  return 256;
117  return 384;
119  return 512;
120  default:
121  return -1;
122  }
123 }
124 
128 static KeyRefOsx
129 getKeyRef(const Name& keyName)
130 {
131  auto keyLabel = cfstring::fromStdString(keyName.toUri());
132 
133  auto query = makeCFMutableDictionary();
134  CFDictionaryAddValue(query.get(), kSecClass, kSecClassKey);
135  CFDictionaryAddValue(query.get(), kSecAttrKeyClass, kSecAttrKeyClassPrivate);
136  CFDictionaryAddValue(query.get(), kSecAttrLabel, keyLabel.get());
137  CFDictionaryAddValue(query.get(), kSecReturnRef, kCFBooleanTrue);
138 
139  KeyRefOsx keyRef;
140  // C-style cast is used as per Apple convention
141  OSStatus res = SecItemCopyMatching(query.get(), (CFTypeRef*)&keyRef.get());
142  keyRef.retain();
143 
144  if (res == errSecSuccess) {
145  return keyRef;
146  }
147  else if (res == errSecItemNotFound) {
148  return nullptr;
149  }
150  else {
151  NDN_THROW(Tpm::Error("Key lookup in keychain failed: " + getErrorMessage(res)));
152  }
153 }
154 
158 static void
160 {
161  // use a temporary password for PKCS8 encoding
162  const char pw[] = "correct horse battery staple";
163  auto passphrase = cfstring::fromBuffer(reinterpret_cast<const uint8_t*>(pw), std::strlen(pw));
164 
165  SecItemImportExportKeyParameters keyParams;
166  std::memset(&keyParams, 0, sizeof(keyParams));
167  keyParams.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
168  keyParams.passphrase = passphrase.get();
169 
170  CFReleaser<CFDataRef> exportedKey;
171  OSStatus res = SecItemExport(keyRef.get(), // secItemOrArray
172  kSecFormatWrappedPKCS8, // outputFormat
173  0, // flags
174  &keyParams, // keyParams
175  &exportedKey.get()); // exportedData
176 
177  if (res != errSecSuccess) {
178  NDN_THROW(Tpm::Error("Failed to export private key: "s + getErrorMessage(res)));
179  }
180 
181  outKey.loadPkcs8(CFDataGetBytePtr(exportedKey.get()), CFDataGetLength(exportedKey.get()),
182  pw, std::strlen(pw));
183 }
184 
185 BackEndOsx::BackEndOsx(const std::string&)
186  : m_impl(make_unique<Impl>())
187 {
188  SecKeychainSetUserInteractionAllowed(!m_impl->isTerminalMode);
189 
190  OSStatus res = SecKeychainCopyDefault(&m_impl->keyChainRef);
191  if (res == errSecNoDefaultKeychain) {
192  NDN_THROW(Error("No default keychain, create one first"));
193  }
194 }
195 
196 BackEndOsx::~BackEndOsx() = default;
197 
198 const std::string&
200 {
201  static std::string scheme = "tpm-osxkeychain";
202  return scheme;
203 }
204 
205 bool
207 {
208  return m_impl->isTerminalMode;
209 }
210 
211 void
212 BackEndOsx::setTerminalMode(bool isTerminal) const
213 {
214  m_impl->isTerminalMode = isTerminal;
215  SecKeychainSetUserInteractionAllowed(!isTerminal);
216 }
217 
218 bool
220 {
221  SecKeychainStatus keychainStatus;
222  OSStatus res = SecKeychainGetStatus(m_impl->keyChainRef, &keychainStatus);
223  if (res != errSecSuccess)
224  return true;
225  else
226  return (kSecUnlockStateStatus & keychainStatus) == 0;
227 }
228 
229 bool
230 BackEndOsx::unlockTpm(const char* pw, size_t pwLen) const
231 {
232  // If the default key chain is already unlocked, return immediately.
233  if (!isTpmLocked())
234  return true;
235 
236  if (m_impl->isTerminalMode) {
237  // Use the supplied password.
238  SecKeychainUnlock(m_impl->keyChainRef, pwLen, pw, true);
239  }
240  else {
241  // If inTerminal is not set, get the password from GUI.
242  SecKeychainUnlock(m_impl->keyChainRef, 0, nullptr, false);
243  }
244 
245  return !isTpmLocked();
246 }
247 
249 BackEndOsx::sign(const KeyRefOsx& key, DigestAlgorithm digestAlgo, const uint8_t* buf, size_t size)
250 {
252  CFReleaser<SecTransformRef> signer = SecSignTransformCreate(key.get(), &error.get());
253  if (signer == nullptr) {
254  NDN_THROW(Error("Failed to create sign transform: " + getFailureReason(error.get())));
255  }
256 
257  // Set input
258  auto data = makeCFDataNoCopy(buf, size);
259  SecTransformSetAttribute(signer.get(), kSecTransformInputAttributeName, data.get(), &error.get());
260  if (error != nullptr) {
261  NDN_THROW(Error("Failed to configure input of sign transform: " + getFailureReason(error.get())));
262  }
263 
264  // Enable use of padding
265  SecTransformSetAttribute(signer.get(), kSecPaddingKey, kSecPaddingPKCS1Key, &error.get());
266  if (error != nullptr) {
267  NDN_THROW(Error("Failed to configure padding of sign transform: " + getFailureReason(error.get())));
268  }
269 
270  // Set digest type
271  SecTransformSetAttribute(signer.get(), kSecDigestTypeAttribute, getDigestAlgorithm(digestAlgo), &error.get());
272  if (error != nullptr) {
273  NDN_THROW(Error("Failed to configure digest type of sign transform: " + getFailureReason(error.get())));
274  }
275 
276  // Set digest length
277  int digestSize = getDigestSize(digestAlgo);
278  CFReleaser<CFNumberRef> cfDigestSize = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &digestSize);
279  SecTransformSetAttribute(signer.get(), kSecDigestLengthAttribute, cfDigestSize.get(), &error.get());
280  if (error != nullptr) {
281  NDN_THROW(Error("Failed to configure digest length of sign transform: " + getFailureReason(error.get())));
282  }
283 
284  // Actually sign
285  // C-style cast is used as per Apple convention
286  CFReleaser<CFDataRef> signature = (CFDataRef)SecTransformExecute(signer.get(), &error.get());
287  if (signature == nullptr) {
288  NDN_THROW(Error("Failed to sign data: " + getFailureReason(error.get())));
289  }
290 
291  return make_shared<Buffer>(CFDataGetBytePtr(signature.get()), CFDataGetLength(signature.get()));
292 }
293 
295 BackEndOsx::decrypt(const KeyRefOsx& key, const uint8_t* cipherText, size_t cipherSize)
296 {
298  CFReleaser<SecTransformRef> decryptor = SecDecryptTransformCreate(key.get(), &error.get());
299  if (decryptor == nullptr) {
300  NDN_THROW(Error("Failed to create decrypt transform: " + getFailureReason(error.get())));
301  }
302 
303  auto data = makeCFDataNoCopy(cipherText, cipherSize);
304  SecTransformSetAttribute(decryptor.get(), kSecTransformInputAttributeName, data.get(), &error.get());
305  if (error != nullptr) {
306  NDN_THROW(Error("Failed to configure input of decrypt transform: " + getFailureReason(error.get())));
307  }
308 
309  SecTransformSetAttribute(decryptor.get(), kSecPaddingKey, kSecPaddingOAEPKey, &error.get());
310  if (error != nullptr) {
311  NDN_THROW(Error("Failed to configure padding of decrypt transform: " + getFailureReason(error.get())));
312  }
313 
314  // C-style cast is used as per Apple convention
315  CFReleaser<CFDataRef> plainText = (CFDataRef)SecTransformExecute(decryptor.get(), &error.get());
316  if (plainText == nullptr) {
317  NDN_THROW(Error("Failed to decrypt data: " + getFailureReason(error.get())));
318  }
319 
320  return make_shared<Buffer>(CFDataGetBytePtr(plainText.get()), CFDataGetLength(plainText.get()));
321 }
322 
325 {
326  transform::PrivateKey privateKey;
327  exportItem(key, privateKey);
328  return privateKey.derivePublicKey();
329 }
330 
331 bool
332 BackEndOsx::doHasKey(const Name& keyName) const
333 {
334  return getKeyRef(keyName) != nullptr;
335 }
336 
337 unique_ptr<KeyHandle>
338 BackEndOsx::doGetKeyHandle(const Name& keyName) const
339 {
340  KeyRefOsx keyRef = getKeyRef(keyName);
341  if (keyRef == nullptr) {
342  return nullptr;
343  }
344 
345  return make_unique<KeyHandleOsx>(keyRef.get());
346 }
347 
348 unique_ptr<KeyHandle>
349 BackEndOsx::doCreateKey(const Name& identityName, const KeyParams& params)
350 {
351  KeyType keyType = params.getKeyType();
352  uint32_t keySize;
353  switch (keyType) {
354  case KeyType::RSA: {
355  const RsaKeyParams& rsaParams = static_cast<const RsaKeyParams&>(params);
356  keySize = rsaParams.getKeySize();
357  break;
358  }
359  case KeyType::EC: {
360  const EcKeyParams& ecParams = static_cast<const EcKeyParams&>(params);
361  keySize = ecParams.getKeySize();
362  break;
363  }
364  default: {
365  NDN_THROW(std::invalid_argument("macOS-based TPM does not support creating a key of type " +
366  boost::lexical_cast<std::string>(keyType)));
367  }
368  }
369  CFReleaser<CFNumberRef> cfKeySize = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &keySize);
370 
371  auto attrDict = makeCFMutableDictionary();
372  CFDictionaryAddValue(attrDict.get(), kSecAttrKeyType, getAsymKeyType(keyType));
373  CFDictionaryAddValue(attrDict.get(), kSecAttrKeySizeInBits, cfKeySize.get());
374 
375  KeyRefOsx publicKey, privateKey;
376  OSStatus res = SecKeyGeneratePair(attrDict.get(), &publicKey.get(), &privateKey.get());
377  publicKey.retain();
378  privateKey.retain();
379 
380  if (res != errSecSuccess) {
381  NDN_THROW(Error("Failed to generate key pair: " + getErrorMessage(res)));
382  }
383 
384  unique_ptr<KeyHandle> keyHandle = make_unique<KeyHandleOsx>(privateKey.get());
385  Name keyName = constructAsymmetricKeyName(*keyHandle, identityName, params);
386  keyHandle->setKeyName(keyName);
387 
388  SecKeychainAttribute attrs[1]; // maximum number of attributes
389  SecKeychainAttributeList attrList = {0, attrs};
390  std::string keyUri = keyName.toUri();
391  {
392  attrs[attrList.count].tag = kSecKeyPrintName;
393  attrs[attrList.count].length = keyUri.size();
394  attrs[attrList.count].data = const_cast<char*>(keyUri.data());
395  attrList.count++;
396  }
397 
398  SecKeychainItemModifyAttributesAndData((SecKeychainItemRef)privateKey.get(), &attrList, 0, nullptr);
399  SecKeychainItemModifyAttributesAndData((SecKeychainItemRef)publicKey.get(), &attrList, 0, nullptr);
400 
401  return keyHandle;
402 }
403 
404 void
405 BackEndOsx::doDeleteKey(const Name& keyName)
406 {
407  auto keyLabel = cfstring::fromStdString(keyName.toUri());
408 
409  auto query = makeCFMutableDictionary();
410  CFDictionaryAddValue(query.get(), kSecClass, kSecClassKey);
411  CFDictionaryAddValue(query.get(), kSecAttrLabel, keyLabel.get());
412  CFDictionaryAddValue(query.get(), kSecMatchLimit, kSecMatchLimitAll);
413 
414  OSStatus res = SecItemDelete(query.get());
415 
416  if (res != errSecSuccess && res != errSecItemNotFound) {
417  NDN_THROW(Error("Failed to delete key pair: " + getErrorMessage(res)));
418  }
419 }
420 
422 BackEndOsx::doExportKey(const Name& keyName, const char* pw, size_t pwLen)
423 {
424  KeyRefOsx keychainItem = getKeyRef(keyName);
425  if (keychainItem == nullptr) {
426  NDN_THROW(Error("Failed to export private key: " + getErrorMessage(errSecItemNotFound)));
427  }
428 
429  transform::PrivateKey exportedKey;
430  OBufferStream pkcs8;
431  try {
432  exportItem(keychainItem, exportedKey);
433  exportedKey.savePkcs8(pkcs8, pw, pwLen);
434  }
435  catch (const transform::PrivateKey::Error&) {
436  NDN_THROW_NESTED(Error("Failed to export private key"));
437  }
438  return pkcs8.buf();
439 }
440 
441 void
442 BackEndOsx::doImportKey(const Name& keyName, const uint8_t* buf, size_t size,
443  const char* pw, size_t pwLen)
444 {
445  transform::PrivateKey privKey;
446  OBufferStream pkcs1;
447  try {
448  // do the PKCS8 decoding ourselves, see bug #4450
449  privKey.loadPkcs8(buf, size, pw, pwLen);
450  privKey.savePkcs1(pkcs1);
451  }
452  catch (const transform::PrivateKey::Error&) {
453  NDN_THROW_NESTED(Error("Failed to import private key"));
454  }
455  auto keyToImport = makeCFDataNoCopy(pkcs1.buf()->data(), pkcs1.buf()->size());
456 
457  SecExternalFormat externalFormat = kSecFormatOpenSSL;
458  SecExternalItemType externalType = kSecItemTypePrivateKey;
459 
460  auto keyUri = keyName.toUri();
461  auto keyLabel = cfstring::fromStdString(keyUri);
462  CFReleaser<SecAccessRef> access;
463  OSStatus res = SecAccessCreate(keyLabel.get(), // descriptor
464  nullptr, // trustedlist (null == trust only the calling app)
465  &access.get()); // accessRef
466 
467  if (res != errSecSuccess) {
468  NDN_THROW(Error("Failed to import private key: " + getErrorMessage(res)));
469  }
470 
471  SecItemImportExportKeyParameters keyParams;
472  std::memset(&keyParams, 0, sizeof(keyParams));
473  keyParams.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
474  keyParams.accessRef = access.get();
475 
476  CFReleaser<CFArrayRef> outItems;
477  res = SecItemImport(keyToImport.get(), // importedData
478  nullptr, // fileNameOrExtension
479  &externalFormat, // inputFormat
480  &externalType, // itemType
481  0, // flags
482  &keyParams, // keyParams
483  m_impl->keyChainRef, // importKeychain
484  &outItems.get()); // outItems
485 
486  if (res != errSecSuccess) {
487  NDN_THROW(Error("Failed to import private key: " + getErrorMessage(res)));
488  }
489 
490  // C-style cast is used as per Apple convention
491  SecKeychainItemRef keychainItem = (SecKeychainItemRef)CFArrayGetValueAtIndex(outItems.get(), 0);
492  SecKeychainAttribute attrs[1]; // maximum number of attributes
493  SecKeychainAttributeList attrList = {0, attrs};
494  {
495  attrs[attrList.count].tag = kSecKeyPrintName;
496  attrs[attrList.count].length = keyUri.size();
497  attrs[attrList.count].data = const_cast<char*>(keyUri.data());
498  attrList.count++;
499  }
500  SecKeychainItemModifyAttributesAndData(keychainItem, &attrList, 0, nullptr);
501 }
502 
503 void
504 BackEndOsx::doImportKey(const Name& keyName, shared_ptr<transform::PrivateKey> key)
505 {
506  NDN_THROW(Error("macOS-based TPM does not support importing a transform::PrivateKey"));
507 }
508 
509 } // namespace tpm
510 } // namespace security
511 } // namespace ndn
ndn::detail::CFReleaser::retain
void retain(const T &typeRef)
Definition: cf-releaser-osx.hpp:105
ndn::detail::cfstring::toStdString
std::string toStdString(CFStringRef cfStr)
Convert a CFString to a std::string.
Definition: cf-string-osx.cpp:49
buf
const uint8_t * buf
Definition: verification-helpers.cpp:47
ndn::security::tpm::BackEndOsx::getScheme
static const std::string & getScheme()
Definition: back-end-osx.cpp:199
ndn::KeyType
KeyType
The type of a cryptographic key.
Definition: security-common.hpp:85
ndn::security::tpm::Tpm::Error
Definition: tpm.hpp:69
ndn::DigestAlgorithm::SHA224
@ SHA224
ndn::security::tpm::getAsymKeyType
static CFTypeRef getAsymKeyType(KeyType keyType)
Definition: back-end-osx.cpp:82
ndn::security::tpm::BackEndOsx::Impl::isTerminalMode
bool isTerminalMode
Definition: back-end-osx.cpp:44
ndn::security::tpm::getFailureReason
static std::string getFailureReason(CFErrorRef err)
Definition: back-end-osx.cpp:72
key-handle-osx.hpp
ndn::security::tpm::getKeyRef
static KeyRefOsx getKeyRef(const Name &keyName)
Get reference to private key with name keyName.
Definition: back-end-osx.cpp:129
ndn::DigestAlgorithm::SHA256
@ SHA256
ndn::security::tpm::BackEnd::Error
Tpm::Error Error
Definition: back-end.hpp:39
ndn::EcKeyParams
SimplePublicKeyParams< detail::EcKeyParamsInfo > EcKeyParams
EcKeyParams carries parameters for EC key.
Definition: key-params.hpp:202
NDN_CXX_UNREACHABLE
#define NDN_CXX_UNREACHABLE
Definition: backports.hpp:72
ndn::security::tpm::exportItem
static void exportItem(const KeyRefOsx &keyRef, transform::PrivateKey &outKey)
Export a private key from the Keychain to outKey.
Definition: back-end-osx.cpp:159
NDN_THROW_NESTED
#define NDN_THROW_NESTED(e)
Definition: exception.hpp:71
ndn::security::tpm::makeCFMutableDictionary
static CFReleaser< CFMutableDictionaryRef > makeCFMutableDictionary()
Definition: back-end-osx.cpp:54
ndn::RsaKeyParams
SimplePublicKeyParams< detail::RsaKeyParamsInfo > RsaKeyParams
RsaKeyParams carries parameters for RSA key.
Definition: key-params.hpp:199
ndn::KeyType::EC
@ EC
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
cf-string-osx.hpp
ndn::DigestAlgorithm
DigestAlgorithm
Definition: security-common.hpp:96
ndn::detail::CFReleaser
Helper class to wrap CoreFoundation object pointers.
Definition: cf-releaser-osx.hpp:50
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::security::tpm::BackEndOsx::isTerminalMode
bool isTerminalMode() const final
Check if the TPM is in terminal mode.
Definition: back-end-osx.cpp:206
ns3::ndn::Name
Name
Definition: ndn-common.cpp:25
ndn::security::transform::PrivateKey::loadPkcs8
void loadPkcs8(const uint8_t *buf, size_t size, const char *pw, size_t pwLen)
Load the private key in encrypted PKCS#8 format from a buffer buf with passphrase pw.
Definition: private-key.cpp:216
ndn::security::tpm::getErrorMessage
static std::string getErrorMessage(OSStatus status)
Definition: back-end-osx.cpp:62
private-key.hpp
ndn::security::tpm::getDigestAlgorithm
static CFTypeRef getDigestAlgorithm(DigestAlgorithm digestAlgo)
Definition: back-end-osx.cpp:95
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
ndn::DigestAlgorithm::SHA512
@ SHA512
ndn::security::tpm::makeCFDataNoCopy
static CFReleaser< CFDataRef > makeCFDataNoCopy(const uint8_t *buf, size_t buflen)
Definition: back-end-osx.cpp:48
ndn::security::tpm::BackEndOsx::Impl
Definition: back-end-osx.cpp:41
ndn::security::tpm::BackEnd::constructAsymmetricKeyName
Name constructAsymmetricKeyName(const KeyHandle &key, const Name &identity, const KeyParams &params) const
Construct and return the name of a RSA or EC key, based on identity and params.
Definition: back-end.cpp:114
transform::PrivateKey
ndn::Name::toUri
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
Definition: name.cpp:348
ndn::security::transform::PrivateKey::derivePublicKey
ConstBufferPtr derivePublicKey() const
Definition: private-key.cpp:342
back-end-osx.hpp
ndn::security::tpm::KeyRefOsx
detail::CFReleaser< SecKeyRef > KeyRefOsx
Definition: key-ref-osx.hpp:39
ndn::security::tpm::BackEndOsx::BackEndOsx
BackEndOsx(const std::string &location="")
Create TPM backed based on macOS Keychain Services.
Definition: back-end-osx.cpp:185
ndn::security::tpm::BackEndOsx::Impl::keyChainRef
SecKeychainRef keyChainRef
Definition: back-end-osx.cpp:43
ndn::security::tpm::getDigestSize
static int getDigestSize(DigestAlgorithm digestAlgo)
Definition: back-end-osx.cpp:109
ndn::detail::CFReleaser::get
const T & get() const
Definition: cf-releaser-osx.hpp:92
ndn::detail::cfstring::fromBuffer
CFReleaser< CFStringRef > fromBuffer(const uint8_t *buf, size_t buflen)
Create a CFString by copying bytes from a raw buffer.
Definition: cf-string-osx.cpp:29
ndn::DigestAlgorithm::SHA384
@ SHA384
ndn::security::tpm::BackEndOsx::unlockTpm
bool unlockTpm(const char *pw, size_t pwLen) const final
Unlock the TPM.
Definition: back-end-osx.cpp:230
ndn::security::tpm::BackEndOsx::isTpmLocked
bool isTpmLocked() const final
Check if the TPM is locked.
Definition: back-end-osx.cpp:219
ndn::security::tpm::BackEndOsx::setTerminalMode
void setTerminalMode(bool isTerminal) const final
Set the terminal mode of the TPM.
Definition: back-end-osx.cpp:212
ndn::security::tpm::BackEndOsx::decrypt
static ConstBufferPtr decrypt(const KeyRefOsx &key, const uint8_t *cipherText, size_t cipherSize)
Definition: back-end-osx.cpp:295
buffer-stream.hpp
ndn::detail::cfstring::fromStdString
CFReleaser< CFStringRef > fromStdString(const std::string &str)
Create a CFString by copying characters from a std::string.
Definition: cf-string-osx.cpp:39
ndn::security::tpm::BackEndOsx::derivePublicKey
static ConstBufferPtr derivePublicKey(const KeyRefOsx &key)
Definition: back-end-osx.cpp:324
ndn::security::tpm::BackEndOsx::~BackEndOsx
~BackEndOsx() final
ndn::KeyType::RSA
@ RSA
RSA key, supports sign/verify and encrypt/decrypt operations.
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
ndn::security::tpm::BackEndOsx::sign
static ConstBufferPtr sign(const KeyRefOsx &key, DigestAlgorithm digestAlgorithm, const uint8_t *buf, size_t size)
Sign buf with key using digestAlgorithm.
Definition: back-end-osx.cpp:249
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34