blob: 282c07e48804d8c35fcc6c92ca8cd6c4e85f7e00 [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- 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
8#include <ndn-cpp-dev/security/key-chain.hpp>
9
10using namespace ndn;
11
12int
13main()
14{
15 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
16 std::vector<CertificateSubjectDescription> subjectDescription;
17
18 Name root("/ndn");
19 Name rootCertName = keyChain.createIdentity(root);
20
21 Name test("/ndn/test");
22 Name testKeyName = keyChain.generateRSAKeyPairAsDefault(test, true);
23 shared_ptr<IdentityCertificate> testCert =
Yingdi Yua7876722014-03-25 14:46:55 -070024 keyChain.prepareUnsignedIdentityCertificate(testKeyName, root,
25 time::system_clock::now(),
26 time::system_clock::now() + time::days(7300),
27 subjectDescription);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080028 keyChain.signByIdentity(*testCert, root);
29 keyChain.addCertificateAsIdentityDefault(*testCert);
30
31 Name alice("/ndn/test/alice");
32 if(!keyChain.doesIdentityExist(alice))
33 {
34 Name aliceKeyName = keyChain.generateRSAKeyPairAsDefault(alice, true);
35 shared_ptr<IdentityCertificate> aliceCert =
Yingdi Yua7876722014-03-25 14:46:55 -070036 keyChain.prepareUnsignedIdentityCertificate(aliceKeyName, test,
37 time::system_clock::now(),
38 time::system_clock::now() + time::days(7300),
39 subjectDescription);
Yingdi Yu348f5ea2014-03-01 14:47:25 -080040 keyChain.signByIdentity(*aliceCert, test);
41 keyChain.addCertificateAsIdentityDefault(*aliceCert);
42 }
43
44 Name bob("/ndn/test/bob");
45 if(!keyChain.doesIdentityExist(bob))
46 {
47 Name bobKeyName = keyChain.generateRSAKeyPairAsDefault(bob, true);
48 shared_ptr<IdentityCertificate> bobCert =
49 keyChain.prepareUnsignedIdentityCertificate(bobKeyName, test, getNow(), getNow() + 630720000, subjectDescription);
50 keyChain.signByIdentity(*bobCert, test);
51 keyChain.addCertificateAsIdentityDefault(*bobCert);
52 }
53
54 Name cathy("/ndn/test/cathy");
55 if(!keyChain.doesIdentityExist(cathy))
56 {
57 Name cathyKeyName = keyChain.generateRSAKeyPairAsDefault(cathy, true);
58 shared_ptr<IdentityCertificate> cathyCert =
59 keyChain.prepareUnsignedIdentityCertificate(cathyKeyName, test, getNow(), getNow() + 630720000, subjectDescription);
60 keyChain.signByIdentity(*cathyCert, test);
61 keyChain.addCertificateAsIdentityDefault(*cathyCert);
62 }
63}