blob: a565ebcf87e56c4615dfc03cbdaf7afa452b91cb [file] [log] [blame]
Yingdi Yu3c2a9762013-10-11 11:02:09 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "endorse-certificate.h"
12#include "exception.h"
13#include <ndn.cxx/security/certificate/certificate-subdescrpt.h>
14
15
16using namespace std;
17using namespace ndn;
18using namespace ndn::security;
19
20EndorseExtension::EndorseExtension(const Blob & value)
21 : CertificateExtension("1.3.6.1.5.32.2", true, value)
22{}
23
24EndorseCertificate::EndorseCertificate(const IdentityCertificate& kskCertificate,
25 const Name& signer,
26 const Time& notBefore,
27 const Time& notAfter)
28 : Certificate()
29 , m_keyName(kskCertificate.getPublicKeyName())
30 , m_signer(signer)
31{
32 setNotBefore(notBefore);
33 setNotAfter(notAfter);
34 addSubjectDescription(CertificateSubDescrypt("2.5.4.41", m_keyName.toUri()));
35 setPublicKeyInfo(kskCertificate.getPublicKeyInfo());
36}
37
38EndorseCertificate::EndorseCertificate(const EndorseCertificate& endorseCertificate)
39 : Certificate(endorseCertificate)
40 , m_keyName(endorseCertificate.m_keyName)
41 , m_signer(endorseCertificate.m_signer)
42 , m_profileList(endorseCertificate.m_profileList)
43{}
44
45EndorseCertificate::EndorseCertificate(const Data& data)
46 : Certificate(data)
47{
48 const Name& dataName = data.getName();
49 name::Component certFlag(string("PROFILE-CERT"));
50
51 int profileIndex = -1;
52 for(int i = 0; i < dataName.size(); i++)
53 {
54 if(0 == dataName.get(i).compare(certFlag))
55 {
56 profileIndex = i;
57 break;
58 }
59 }
60
61 if(profileIndex < 0)
62 throw LnException("No PROFILE-CERT component in data name!");
63
64 m_keyName = dataName.getSubName(0, profileIndex);
65 m_signer = dataName.getSubName(profileIndex + 1, dataName.size() - profileIndex - 2);
66
67 OID profileExtenstionOID("1.3.6.1.5.32.2");
68 ExtensionList::iterator it = m_extnList.begin();
69 for(; it != m_extnList.end(); it++)
70 {
71 if(profileExtenstionOID == it->getOID())
72 {
73 Ptr<Blob> valueBlob = Ptr<Blob>(new Blob(it->getValue().buf(), it->getValue().size()));
74 m_profileList.push_back(ProfileData(*(Data::decodeFromWire(valueBlob))));
75 }
76 }
77}