Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 8 | #include <ndn-cxx/security/key-chain.hpp> |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 9 | |
| 10 | using namespace ndn; |
| 11 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 12 | int |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 13 | main() |
| 14 | { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 15 | KeyChain keyChain("sqlite3", "file"); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 16 | std::vector<CertificateSubjectDescription> subjectDescription; |
| 17 | |
| 18 | Name root("/ndn"); |
| 19 | Name rootCertName = keyChain.createIdentity(root); |
| 20 | |
| 21 | Name test("/ndn/test"); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 22 | Name testKeyName = keyChain.generateRsaKeyPairAsDefault(test, true); |
| 23 | shared_ptr<IdentityCertificate> testCert = |
| 24 | keyChain.prepareUnsignedIdentityCertificate(testKeyName, root, |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 25 | time::system_clock::now(), |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 26 | time::system_clock::now() + time::days(7300), |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 27 | subjectDescription); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 28 | keyChain.signByIdentity(*testCert, root); |
| 29 | keyChain.addCertificateAsIdentityDefault(*testCert); |
| 30 | |
| 31 | Name alice("/ndn/test/alice"); |
| 32 | if(!keyChain.doesIdentityExist(alice)) |
| 33 | { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 34 | Name aliceKeyName = keyChain.generateRsaKeyPairAsDefault(alice, true); |
| 35 | shared_ptr<IdentityCertificate> aliceCert = |
| 36 | keyChain.prepareUnsignedIdentityCertificate(aliceKeyName, test, |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 37 | time::system_clock::now(), |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 38 | time::system_clock::now() + time::days(7300), |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 39 | subjectDescription); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 40 | keyChain.signByIdentity(*aliceCert, test); |
| 41 | keyChain.addCertificateAsIdentityDefault(*aliceCert); |
| 42 | } |
| 43 | |
| 44 | Name bob("/ndn/test/bob"); |
| 45 | if(!keyChain.doesIdentityExist(bob)) |
| 46 | { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 47 | Name bobKeyName = keyChain.generateRsaKeyPairAsDefault(bob, true); |
| 48 | shared_ptr<IdentityCertificate> bobCert = |
| 49 | keyChain.prepareUnsignedIdentityCertificate(bobKeyName, test, |
| 50 | time::system_clock::now(), |
| 51 | time::system_clock::now() + time::days(7300), |
| 52 | subjectDescription); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 53 | keyChain.signByIdentity(*bobCert, test); |
| 54 | keyChain.addCertificateAsIdentityDefault(*bobCert); |
| 55 | } |
| 56 | |
| 57 | Name cathy("/ndn/test/cathy"); |
| 58 | if(!keyChain.doesIdentityExist(cathy)) |
| 59 | { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 60 | Name cathyKeyName = keyChain.generateRsaKeyPairAsDefault(cathy, true); |
| 61 | shared_ptr<IdentityCertificate> cathyCert = |
| 62 | keyChain.prepareUnsignedIdentityCertificate(cathyKeyName, test, |
| 63 | time::system_clock::now(), |
| 64 | time::system_clock::now() + time::days(7300), |
| 65 | subjectDescription); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 66 | keyChain.signByIdentity(*cathyCert, test); |
| 67 | keyChain.addCertificateAsIdentityDefault(*cathyCert); |
| 68 | } |
| 69 | } |