Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 20 | using namespace std; |
| 21 | using namespace ndn::ptr_lib; |
| 22 | |
| 23 | INIT_LOGGER("ndn.der.CertificateDataVisitor"); |
| 24 | |
| 25 | namespace ndn { |
| 26 | |
| 27 | namespace der { |
| 28 | |
| 29 | /* |
| 30 | * CertificateDataVisitor |
| 31 | */ |
| 32 | void |
| 33 | CertificateDataVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
| 34 | { |
| 35 | // _LOG_DEBUG("CertificateDataVisitor::visit"); |
| 36 | |
| 37 | const DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 38 | CertificateValidityVisitor validityVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 39 | children[0]->accept(validityVisitor, param); |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 40 | CertificateSubjectVisitor subjectVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 41 | 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 Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 48 | CertificateExtensionVisitor extnVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 49 | children[3]->accept(extnVisitor, param); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * CertValidityVisitor |
| 55 | */ |
| 56 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 57 | CertificateValidityVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 58 | { |
| 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 | */ |
| 80 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 81 | CertificateSubjectDescriptionVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 82 | { |
| 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 | */ |
| 100 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 101 | CertificateSubjectVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 102 | { |
| 103 | // _LOG_DEBUG("CertSubjectVisitor::visit"); |
| 104 | |
| 105 | const DerNodePtrList& children = derSeq.getChildren(); |
| 106 | |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 107 | CertificateSubjectDescriptionVisitor descryptVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 108 | |
| 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 | */ |
| 120 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 121 | CertificateExtensionEntryVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 122 | { |
| 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)); |
| 131 | const Blob& value = ndnboost::any_cast<const Blob&>(children[2]->accept(simpleVisitor)); |
| 132 | |
| 133 | CertificateExtension extension(oid, critical, value); |
| 134 | |
| 135 | certData->addExtension(extension); |
| 136 | } |
| 137 | |
| 138 | /* |
| 139 | * CertExtensionVisitor |
| 140 | */ |
| 141 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 142 | CertificateExtensionVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 143 | { |
| 144 | const DerNodePtrList& children = derSeq.getChildren(); |
| 145 | |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame^] | 146 | CertificateExtensionEntryVisitor extnEntryVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 147 | |
| 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 | } |