blob: 69052ebe26ec6f118db302ce0bed7de19cf2b8d2 [file] [log] [blame]
akmhoqueba094742014-02-28 11:47:21 -06001#include <ndn-cpp-dev/security/identity-certificate.hpp>
2#include <ndn-cpp-dev/encoding/block.hpp>
3#include "nlsr_sm.hpp"
4#include "nlsr_km.hpp"
5
6namespace nlsr
7{
8 void
9 KeyManager::initKeyManager(ConfParameter &cp)
10 {
11 string processIdentityName(cp.getRootKeyPrefix());
12 processIdentityName += "/";
13 processIdentityName += cp.getSiteName();
14 processIdentityName += "/";
15 processIdentityName += "R.Start";
16 processIdentityName += "/";
17 processIdentityName += cp.getRouterName();
18 processIdentityName += "/";
19 processIdentityName += "nlsr";
20 cout<<"Proces Identity Name: "<<processIdentityName<<endl;
21 ndn::Name identityName(processIdentityName);
22 routerIdentity=identityName;
23 ndn::KeyChain::deleteIdentity(routerIdentity);
24 routerCertName = ndn::KeyChain::createIdentity(routerIdentity);
25 cout<<"Certificate Name: "<<routerCertName.toUri()<<endl;
26 routerKeyName=
27 ndn::IdentityCertificate::certificateNameToPublicKeyName(routerCertName);
28 cout<<"Key Name: "<<routerKeyName.toUri()<<endl;
29 initCertSeqFromFile(cp.getSeqFileDir());
30 }
31
32 ndn::Name
33 KeyManager::getRouterCertName()
34 {
35 return routerCertName;
36 }
37
38 uint32_t
39 KeyManager::getCertSeqNo()
40 {
41 return certSeqNo;
42 }
43
44 void
45 KeyManager::setCerSeqNo(uint32_t csn)
46 {
47 certSeqNo=csn;
48 }
49
50 void
51 KeyManager::initCertSeqFromFile(string certSeqFileDir)
52 {
53 certSeqFileNameWithPath=certSeqFileDir;
54 if( certSeqFileNameWithPath.empty() )
55 {
56 SequencingManager sm;
57 certSeqFileNameWithPath=sm.getUserHomeDirectory();
58 }
59 certSeqFileNameWithPath += "/nlsrCertSeqNo.txt";
60 cout<<"Key Seq File Name: "<< certSeqFileNameWithPath<<endl;
61 std::ifstream inputFile(certSeqFileNameWithPath.c_str(),ios::binary);
62 if ( inputFile.good() )
63 {
64 inputFile>>certSeqNo;
65 certSeqNo++;
66 }
67 else
68 {
69 certSeqNo=1;
70 }
71 writeCertSeqToFile();
72 }
73
74 void
75 KeyManager::writeCertSeqToFile()
76 {
77 std::ofstream outputFile(certSeqFileNameWithPath.c_str(),ios::binary);
78 outputFile<<certSeqNo;
79 outputFile.close();
80 }
81}
82
83
84