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; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 21 | |
| 22 | INIT_LOGGER("ndn.der.CertificateDataVisitor"); |
| 23 | |
| 24 | namespace ndn { |
| 25 | |
| 26 | namespace der { |
| 27 | |
| 28 | /* |
| 29 | * CertificateDataVisitor |
| 30 | */ |
| 31 | void |
| 32 | CertificateDataVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
| 33 | { |
| 34 | // _LOG_DEBUG("CertificateDataVisitor::visit"); |
| 35 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 36 | DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 37 | CertificateValidityVisitor validityVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 38 | children[0]->accept(validityVisitor, param); |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 39 | CertificateSubjectVisitor subjectVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 40 | children[1]->accept(subjectVisitor, param); |
| 41 | PublicKeyVisitor pubkeyVisitor; |
| 42 | Certificate* certData = ndnboost::any_cast<Certificate*>(param); |
Jeff Thompson | ce11576 | 2013-12-18 14:59:56 -0800 | [diff] [blame] | 43 | certData->setPublicKeyInfo(*ndnboost::any_cast<ptr_lib::shared_ptr<PublicKey> >(children[2]->accept(pubkeyVisitor))); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 44 | |
| 45 | if(children.size() > 3) |
| 46 | { |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 47 | CertificateExtensionVisitor extnVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 48 | children[3]->accept(extnVisitor, param); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * CertValidityVisitor |
| 54 | */ |
| 55 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 56 | CertificateValidityVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 57 | { |
| 58 | // _LOG_DEBUG("CertValidityVisitor::visit"); |
| 59 | |
| 60 | Certificate* certData = ndnboost::any_cast<Certificate*>(param); |
| 61 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 62 | DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 63 | |
| 64 | SimpleVisitor simpleVisitor; |
| 65 | |
| 66 | MillisecondsSince1970 notBefore = ndnboost::any_cast<MillisecondsSince1970>(children[0]->accept(simpleVisitor)); |
| 67 | MillisecondsSince1970 notAfter = ndnboost::any_cast<MillisecondsSince1970>(children[1]->accept(simpleVisitor)); |
| 68 | |
| 69 | // _LOG_DEBUG("parsed notBefore: " << notBefore); |
| 70 | // _LOG_DEBUG("parsed notAfter: " << notAfter); |
| 71 | |
| 72 | certData->setNotBefore(notBefore); |
| 73 | certData->setNotAfter(notAfter); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * CertSubDescryptVisitor |
| 78 | */ |
| 79 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 80 | CertificateSubjectDescriptionVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 81 | { |
| 82 | Certificate* certData = ndnboost::any_cast<Certificate*>(param); |
| 83 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 84 | DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 85 | |
| 86 | SimpleVisitor simpleVisitor; |
| 87 | |
| 88 | OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor)); |
| 89 | string value = ndnboost::any_cast<string>(children[1]->accept(simpleVisitor)); |
| 90 | |
| 91 | CertificateSubjectDescription subDescrypt(oid, value); |
| 92 | |
| 93 | certData->addSubjectDescription(subDescrypt); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * CertSubjectVisitor |
| 98 | */ |
| 99 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 100 | CertificateSubjectVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 101 | { |
| 102 | // _LOG_DEBUG("CertSubjectVisitor::visit"); |
| 103 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 104 | DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 105 | |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 106 | CertificateSubjectDescriptionVisitor descryptVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 107 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 108 | DerNodePtrList::iterator it = children.begin(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 109 | |
| 110 | while(it != children.end()) { |
| 111 | (*it)->accept(descryptVisitor, param); |
| 112 | it++; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * CertExtnEntryVisitor |
| 118 | */ |
| 119 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 120 | CertificateExtensionEntryVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 121 | { |
| 122 | Certificate* certData = ndnboost::any_cast<Certificate*>(param); |
| 123 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 124 | DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 125 | |
| 126 | SimpleVisitor simpleVisitor; |
| 127 | |
| 128 | OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor)); |
| 129 | bool critical = ndnboost::any_cast<bool>(children[1]->accept(simpleVisitor)); |
Jeff Thompson | b8b6758 | 2013-11-20 18:37:36 -0800 | [diff] [blame] | 130 | const vector<uint8_t>& value = ndnboost::any_cast<const vector<uint8_t>&>(children[2]->accept(simpleVisitor)); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 131 | |
| 132 | CertificateExtension extension(oid, critical, value); |
| 133 | |
| 134 | certData->addExtension(extension); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * CertExtensionVisitor |
| 139 | */ |
| 140 | void |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 141 | CertificateExtensionVisitor::visit(DerSequence& derSeq, ndnboost::any param) |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 142 | { |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 143 | DerNodePtrList& children = derSeq.getChildren(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 144 | |
Jeff Thompson | 6759833 | 2013-10-17 17:57:22 -0700 | [diff] [blame] | 145 | CertificateExtensionEntryVisitor extnEntryVisitor; |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 146 | |
Jeff Thompson | 3d5096c | 2013-12-11 16:40:05 -0800 | [diff] [blame] | 147 | DerNodePtrList::iterator it = children.begin(); |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 148 | |
| 149 | while(it != children.end()) { |
| 150 | (*it)->accept(extnEntryVisitor, param); |
| 151 | it++; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | } // der |
| 156 | |
| 157 | } |