void DESFireProfile::setDefaultKeysAt(boost::shared_ptr<Location> location) { EXCEPTION_ASSERT_WITH_LOG(location, std::invalid_argument, "location cannot be null."); boost::shared_ptr<DESFireLocation> dfLocation = boost::dynamic_pointer_cast<DESFireLocation>(location); EXCEPTION_ASSERT_WITH_LOG(dfLocation, std::invalid_argument, "location must be a DESFireLocation."); // Application (File keys are Application keys) if (dfLocation->aid != -1) { for (unsigned char i = 0; i < 14; ++i) { setKey(dfLocation->aid, i, getDefaultKey(DF_KEY_DES)); } } // Card else { setKey(0, 0, getDefaultKey(DF_KEY_DES)); } }
security::Identity IdentityManagementFixture::addSubCertificate(const Name& subIdentityName, const security::Identity& issuer, const KeyParams& params) { auto subIdentity = addIdentity(subIdentityName, params); v2::Certificate request = subIdentity.getDefaultKey().getDefaultCertificate(); request.setName(request.getKeyName().append("parent").appendVersion()); SignatureInfo info; auto now = time::system_clock::now(); info.setValidityPeriod(security::ValidityPeriod(now, now + 7300_days)); v2::AdditionalDescription description; description.set("type", "sub-certificate"); info.appendTypeSpecificTlv(description.wireEncode()); m_keyChain.sign(request, signingByIdentity(issuer).setSignatureInfo(info)); m_keyChain.setDefaultCertificate(subIdentity.getDefaultKey(), request); return subIdentity; }
int ndnsec_get_default(int argc, char** argv) { namespace po = boost::program_options; bool wantDefaultKey = false; bool wantDefaultCert = false; bool isQuiet = false; Name identityName; Name keyName; po::options_description description( "Usage: ndnsec get-default [-h] [-k|-c] [-i ID|-K KEY] [-q]\n" "\n" "Options"); description.add_options() ("help,h", "produce help message") ("default-key,k", po::bool_switch(&wantDefaultKey), "show default key, instead of identity") ("default-cert,c", po::bool_switch(&wantDefaultCert), "show default certificate, instead of identity") ("identity,i", po::value<Name>(&identityName), "target identity") ("key,K", po::value<Name>(&keyName), "target key") ("quiet,q", po::bool_switch(&isQuiet), "do not print trailing newline") ; po::variables_map vm; try { po::store(po::parse_command_line(argc, argv, description), vm); po::notify(vm); } catch (const std::exception& e) { std::cerr << "ERROR: " << e.what() << "\n\n" << description << std::endl; return 2; } if (vm.count("help") > 0) { std::cout << description << std::endl; return 0; } if (wantDefaultKey && wantDefaultCert) { std::cerr << "ERROR: cannot specify both '--default-key' and '--default-cert'" << std::endl; return 2; } if (vm.count("identity") && vm.count("key")) { std::cerr << "ERROR: cannot specify both '--identity' and '--key'" << std::endl; return 2; } security::v2::KeyChain keyChain; if (vm.count("key") > 0) { if (wantDefaultCert) { auto cert = keyChain.getPib() .getIdentity(security::v2::extractIdentityFromKeyName(keyName)) .getKey(keyName) .getDefaultCertificate(); std::cout << cert.getName(); if (!isQuiet) { std::cout << std::endl; } return 0; } return 2; } else if (vm.count("identity") > 0) { auto key = keyChain.getPib() .getIdentity(identityName) .getDefaultKey(); if (wantDefaultKey) { std::cout << key.getName(); if (!isQuiet) std::cout << std::endl; return 0; } if (wantDefaultCert) { std::cout << key.getDefaultCertificate().getName(); if (!isQuiet) std::cout << std::endl; return 0; } return 2; } else { auto identity = keyChain.getPib() .getDefaultIdentity(); if (wantDefaultKey) { std::cout << identity.getDefaultKey().getName(); } else if (wantDefaultCert) { std::cout << identity.getDefaultKey().getDefaultCertificate().getName(); } else { std::cout << identity.getName(); } if (!isQuiet) std::cout << std::endl; return 0; } }