blob: c96d9888ba500a10f2f49401c62cf4d3f7ce7916 [file] [log] [blame]
Jeff Thompson415da1e2013-10-17 16:52:59 -07001/* -*- 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 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
9#include "simple-visitor.hpp"
10#include "public-key-visitor.hpp"
11#include "../der.hpp"
12
13#include <ndn-cpp/security/certificate/certificate.hpp>
14#include <ndn-cpp/security/certificate/certificate-subject-description.hpp>
15#include <ndn-cpp/security/certificate/certificate-extension.hpp>
16
17#include "../../../util/logging.hpp"
18#include "certificate-data-visitor.hpp"
19
20using namespace std;
21using namespace ndn::ptr_lib;
22
23INIT_LOGGER("ndn.der.CertificateDataVisitor");
24
25namespace ndn {
26
27namespace der {
28
29/*
30 * CertificateDataVisitor
31 */
32void
33CertificateDataVisitor::visit(DerSequence& derSeq, ndnboost::any param)
34{
35 // _LOG_DEBUG("CertificateDataVisitor::visit");
36
37 const DerNodePtrList& children = derSeq.getChildren();
Jeff Thompson67598332013-10-17 17:57:22 -070038 CertificateValidityVisitor validityVisitor;
Jeff Thompson415da1e2013-10-17 16:52:59 -070039 children[0]->accept(validityVisitor, param);
Jeff Thompson67598332013-10-17 17:57:22 -070040 CertificateSubjectVisitor subjectVisitor;
Jeff Thompson415da1e2013-10-17 16:52:59 -070041 children[1]->accept(subjectVisitor, param);
42 PublicKeyVisitor pubkeyVisitor;
43 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
44 certData->setPublicKeyInfo(*ndnboost::any_cast<shared_ptr<PublicKey> >(children[2]->accept(pubkeyVisitor)));
45
46 if(children.size() > 3)
47 {
Jeff Thompson67598332013-10-17 17:57:22 -070048 CertificateExtensionVisitor extnVisitor;
Jeff Thompson415da1e2013-10-17 16:52:59 -070049 children[3]->accept(extnVisitor, param);
50 }
51}
52
53/*
54 * CertValidityVisitor
55 */
56void
Jeff Thompson67598332013-10-17 17:57:22 -070057CertificateValidityVisitor::visit(DerSequence& derSeq, ndnboost::any param)
Jeff Thompson415da1e2013-10-17 16:52:59 -070058{
59 // _LOG_DEBUG("CertValidityVisitor::visit");
60
61 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
62
63 const DerNodePtrList& children = derSeq.getChildren();
64
65 SimpleVisitor simpleVisitor;
66
67 MillisecondsSince1970 notBefore = ndnboost::any_cast<MillisecondsSince1970>(children[0]->accept(simpleVisitor));
68 MillisecondsSince1970 notAfter = ndnboost::any_cast<MillisecondsSince1970>(children[1]->accept(simpleVisitor));
69
70 // _LOG_DEBUG("parsed notBefore: " << notBefore);
71 // _LOG_DEBUG("parsed notAfter: " << notAfter);
72
73 certData->setNotBefore(notBefore);
74 certData->setNotAfter(notAfter);
75}
76
77/*
78 * CertSubDescryptVisitor
79 */
80void
Jeff Thompson67598332013-10-17 17:57:22 -070081CertificateSubjectDescriptionVisitor::visit(DerSequence& derSeq, ndnboost::any param)
Jeff Thompson415da1e2013-10-17 16:52:59 -070082{
83 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
84
85 const DerNodePtrList& children = derSeq.getChildren();
86
87 SimpleVisitor simpleVisitor;
88
89 OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
90 string value = ndnboost::any_cast<string>(children[1]->accept(simpleVisitor));
91
92 CertificateSubjectDescription subDescrypt(oid, value);
93
94 certData->addSubjectDescription(subDescrypt);
95}
96
97/*
98 * CertSubjectVisitor
99 */
100void
Jeff Thompson67598332013-10-17 17:57:22 -0700101CertificateSubjectVisitor::visit(DerSequence& derSeq, ndnboost::any param)
Jeff Thompson415da1e2013-10-17 16:52:59 -0700102{
103 // _LOG_DEBUG("CertSubjectVisitor::visit");
104
105 const DerNodePtrList& children = derSeq.getChildren();
106
Jeff Thompson67598332013-10-17 17:57:22 -0700107 CertificateSubjectDescriptionVisitor descryptVisitor;
Jeff Thompson415da1e2013-10-17 16:52:59 -0700108
109 DerNodePtrList::const_iterator it = children.begin();
110
111 while(it != children.end()) {
112 (*it)->accept(descryptVisitor, param);
113 it++;
114 }
115}
116
117/*
118 * CertExtnEntryVisitor
119 */
120void
Jeff Thompson67598332013-10-17 17:57:22 -0700121CertificateExtensionEntryVisitor::visit(DerSequence& derSeq, ndnboost::any param)
Jeff Thompson415da1e2013-10-17 16:52:59 -0700122{
123 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
124
125 const DerNodePtrList& children = derSeq.getChildren();
126
127 SimpleVisitor simpleVisitor;
128
129 OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
130 bool critical = ndnboost::any_cast<bool>(children[1]->accept(simpleVisitor));
Jeff Thompsonb8b67582013-11-20 18:37:36 -0800131 const vector<uint8_t>& value = ndnboost::any_cast<const vector<uint8_t>&>(children[2]->accept(simpleVisitor));
Jeff Thompson415da1e2013-10-17 16:52:59 -0700132
133 CertificateExtension extension(oid, critical, value);
134
135 certData->addExtension(extension);
136}
137
138/*
139 * CertExtensionVisitor
140 */
141void
Jeff Thompson67598332013-10-17 17:57:22 -0700142CertificateExtensionVisitor::visit(DerSequence& derSeq, ndnboost::any param)
Jeff Thompson415da1e2013-10-17 16:52:59 -0700143{
144 const DerNodePtrList& children = derSeq.getChildren();
145
Jeff Thompson67598332013-10-17 17:57:22 -0700146 CertificateExtensionEntryVisitor extnEntryVisitor;
Jeff Thompson415da1e2013-10-17 16:52:59 -0700147
148 DerNodePtrList::const_iterator it = children.begin();
149
150 while(it != children.end()) {
151 (*it)->accept(extnEntryVisitor, param);
152 it++;
153 }
154}
155
156} // der
157
158}