blob: 36765a6253487318e79a27a252cbbeb3eaa4b273 [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 =
24 keyChain.prepareUnsignedIdentityCertificate(testKeyName, root, getNow(), getNow() + 630720000, subjectDescription);
25 keyChain.signByIdentity(*testCert, root);
26 keyChain.addCertificateAsIdentityDefault(*testCert);
27
28 Name alice("/ndn/test/alice");
29 if(!keyChain.doesIdentityExist(alice))
30 {
31 Name aliceKeyName = keyChain.generateRSAKeyPairAsDefault(alice, true);
32 shared_ptr<IdentityCertificate> aliceCert =
33 keyChain.prepareUnsignedIdentityCertificate(aliceKeyName, test, getNow(), getNow() + 630720000, subjectDescription);
34 keyChain.signByIdentity(*aliceCert, test);
35 keyChain.addCertificateAsIdentityDefault(*aliceCert);
36 }
37
38 Name bob("/ndn/test/bob");
39 if(!keyChain.doesIdentityExist(bob))
40 {
41 Name bobKeyName = keyChain.generateRSAKeyPairAsDefault(bob, true);
42 shared_ptr<IdentityCertificate> bobCert =
43 keyChain.prepareUnsignedIdentityCertificate(bobKeyName, test, getNow(), getNow() + 630720000, subjectDescription);
44 keyChain.signByIdentity(*bobCert, test);
45 keyChain.addCertificateAsIdentityDefault(*bobCert);
46 }
47
48 Name cathy("/ndn/test/cathy");
49 if(!keyChain.doesIdentityExist(cathy))
50 {
51 Name cathyKeyName = keyChain.generateRSAKeyPairAsDefault(cathy, true);
52 shared_ptr<IdentityCertificate> cathyCert =
53 keyChain.prepareUnsignedIdentityCertificate(cathyKeyName, test, getNow(), getNow() + 630720000, subjectDescription);
54 keyChain.signByIdentity(*cathyCert, test);
55 keyChain.addCertificateAsIdentityDefault(*cathyCert);
56 }
57}