Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
| 22 | * @author Jeff Thompson <jefft0@remap.ucla.edu> |
| 23 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 26 | #include "common.hpp" |
Alexander Afanasyev | 8e96e58 | 2013-11-19 12:07:04 -0800 | [diff] [blame] | 27 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 28 | #include "certificate.hpp" |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 29 | #include "../util/time.hpp" |
Junxiao Shi | 482ccc5 | 2014-03-31 13:05:24 -0700 | [diff] [blame] | 30 | #include "cryptopp.hpp" |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 31 | #include "../encoding/cryptopp/asn_ext.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 32 | #include "../encoding/buffer-stream.hpp" |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 33 | #include "../util/concepts.hpp" |
Alexander Afanasyev | bbb31f9 | 2014-12-01 13:15:59 -0800 | [diff] [blame] | 34 | #include "../util/indented-stream.hpp" |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 35 | |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 36 | #include <boost/algorithm/string/split.hpp> |
| 37 | |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 38 | namespace ndn { |
| 39 | |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 40 | BOOST_CONCEPT_ASSERT((WireEncodable<Certificate>)); |
| 41 | BOOST_CONCEPT_ASSERT((WireDecodable<Certificate>)); |
| 42 | static_assert(std::is_base_of<tlv::Error, Certificate::Error>::value, |
| 43 | "Certificate::Error must inherit from tlv::Error"); |
| 44 | |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 45 | Certificate::Certificate() |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 46 | : m_notBefore(time::system_clock::TimePoint::max()) |
| 47 | , m_notAfter(time::system_clock::TimePoint::min()) |
| 48 | { |
| 49 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 50 | |
| 51 | Certificate::Certificate(const Data& data) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 52 | // Use the copy constructor. It clones the signature object. |
| 53 | : Data(data) |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 54 | { |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 55 | decode(); |
| 56 | } |
| 57 | |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 58 | Certificate::Certificate(const Block& block) |
| 59 | : Data(block) |
| 60 | { |
| 61 | decode(); |
| 62 | } |
| 63 | |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 64 | Certificate::~Certificate() |
| 65 | { |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void |
| 69 | Certificate::wireDecode(const Block& wire) |
| 70 | { |
| 71 | Data::wireDecode(wire); |
| 72 | decode(); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | bool |
| 76 | Certificate::isTooEarly() |
| 77 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 78 | if (time::system_clock::now() < m_notBefore) |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 79 | return true; |
| 80 | else |
| 81 | return false; |
| 82 | } |
| 83 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 84 | bool |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 85 | Certificate::isTooLate() |
| 86 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 87 | if (time::system_clock::now() > m_notAfter) |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 88 | return true; |
| 89 | else |
| 90 | return false; |
| 91 | } |
| 92 | |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 93 | void |
| 94 | Certificate::encode() |
| 95 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 96 | // Name |
| 97 | // <key_name>/ID-CERT/<id#> |
| 98 | // Content |
| 99 | // DER encoded idCert: |
| 100 | // |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 101 | // idCert ::= SEQUENCE { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 102 | // validity Validity, |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 103 | // subject Name, |
| 104 | // subjectPubKeyInfo SubjectPublicKeyInfo, |
| 105 | // extension Extensions OPTIONAL } |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 106 | // |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 107 | // Validity ::= SEQUENCE { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 108 | // notBefore Time, |
| 109 | // notAfter Time } |
| 110 | // |
| 111 | // Name ::= CHOICE { |
| 112 | // RDNSequence } |
| 113 | // |
| 114 | // RDNSequence ::= SEQUENCE OF RelativeDistinguishedName |
| 115 | // |
| 116 | // RelativeDistinguishedName ::= |
| 117 | // SET OF AttributeTypeAndValue |
| 118 | // |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 119 | // SubjectPublicKeyInfo ::= SEQUENCE { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 120 | // algorithm AlgorithmIdentifier |
| 121 | // keybits BIT STRING } |
| 122 | // |
| 123 | // Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension |
| 124 | // |
| 125 | // (see http://www.ietf.org/rfc/rfc3280.txt for more detail) |
| 126 | // |
| 127 | // KeyLocator |
| 128 | // issuer’s certificate name |
| 129 | // Signature |
| 130 | |
| 131 | using namespace CryptoPP; |
| 132 | |
| 133 | OBufferStream os; |
| 134 | CryptoPP::FileSink sink(os); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 136 | // idCert ::= SEQUENCE { |
| 137 | // validity Validity, |
| 138 | // subject Name, |
| 139 | // subjectPubKeyInfo SubjectPublicKeyInfo, |
| 140 | // extension Extensions OPTIONAL } |
| 141 | DERSequenceEncoder idCert(sink); |
| 142 | { |
| 143 | // Validity ::= SEQUENCE { |
| 144 | // notBefore Time, |
| 145 | // notAfter Time } |
| 146 | DERSequenceEncoder validity(idCert); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 147 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 148 | DEREncodeGeneralTime(validity, m_notBefore); |
| 149 | DEREncodeGeneralTime(validity, m_notAfter); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 150 | } |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 151 | validity.MessageEnd(); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 152 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 153 | // Name ::= CHOICE { |
| 154 | // RDNSequence } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 155 | // |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 156 | // RDNSequence ::= SEQUENCE OF RelativeDistinguishedName |
| 157 | DERSequenceEncoder name(idCert); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 158 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 159 | for (SubjectDescriptionList::iterator it = m_subjectDescriptionList.begin(); |
| 160 | it != m_subjectDescriptionList.end(); ++it) |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 161 | { |
| 162 | it->encode(name); |
| 163 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 164 | } |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 165 | name.MessageEnd(); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 166 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 167 | // SubjectPublicKeyInfo |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 168 | m_key.encode(idCert); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 169 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 170 | // Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension |
| 171 | // |
| 172 | // Extension ::= SEQUENCE { |
| 173 | // extnID OBJECT IDENTIFIER, |
| 174 | // critical BOOLEAN DEFAULT FALSE, |
| 175 | // extnValue OCTET STRING } |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 176 | if (!m_extensionList.empty()) |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 177 | { |
| 178 | DERSequenceEncoder extensions(idCert); |
| 179 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 180 | for (ExtensionList::iterator it = m_extensionList.begin(); |
| 181 | it != m_extensionList.end(); ++it) |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 182 | { |
| 183 | it->encode(extensions); |
| 184 | } |
| 185 | } |
| 186 | extensions.MessageEnd(); |
| 187 | } |
| 188 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 189 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 190 | idCert.MessageEnd(); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 191 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 192 | setContent(os.buf()); |
Junxiao Shi | a464b92 | 2014-11-12 21:13:06 -0700 | [diff] [blame] | 193 | setContentType(tlv::ContentType_Key); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 194 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 195 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 196 | void |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 197 | Certificate::decode() |
| 198 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 199 | using namespace CryptoPP; |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 200 | |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 201 | try { |
| 202 | OBufferStream os; |
| 203 | StringSource source(getContent().value(), getContent().value_size(), true); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 204 | |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 205 | // idCert ::= SEQUENCE { |
| 206 | // validity Validity, |
| 207 | // subject Name, |
| 208 | // subjectPubKeyInfo SubjectPublicKeyInfo, |
| 209 | // extension Extensions OPTIONAL } |
| 210 | BERSequenceDecoder idCert(source); |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 211 | { |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 212 | // Validity ::= SEQUENCE { |
| 213 | // notBefore Time, |
| 214 | // notAfter Time } |
| 215 | BERSequenceDecoder validity(idCert); |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 216 | { |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 217 | BERDecodeTime(validity, m_notBefore); |
| 218 | BERDecodeTime(validity, m_notAfter); |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 219 | } |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 220 | validity.MessageEnd(); |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 221 | |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 222 | // Name ::= CHOICE { |
| 223 | // RDNSequence } |
| 224 | // |
| 225 | // RDNSequence ::= SEQUENCE OF RelativeDistinguishedName |
| 226 | m_subjectDescriptionList.clear(); |
| 227 | BERSequenceDecoder name(idCert); |
| 228 | { |
| 229 | while (!name.EndReached()) |
| 230 | { |
| 231 | m_subjectDescriptionList.push_back(CertificateSubjectDescription(name)); |
| 232 | } |
| 233 | } |
| 234 | name.MessageEnd(); |
| 235 | |
| 236 | // SubjectPublicKeyInfo ::= SEQUENCE { |
| 237 | // algorithm AlgorithmIdentifier |
| 238 | // keybits BIT STRING } |
| 239 | m_key.decode(idCert); |
| 240 | |
| 241 | // Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension |
| 242 | // |
| 243 | // Extension ::= SEQUENCE { |
| 244 | // extnID OBJECT IDENTIFIER, |
| 245 | // critical BOOLEAN DEFAULT FALSE, |
| 246 | // extnValue OCTET STRING } |
| 247 | m_extensionList.clear(); |
| 248 | if (!idCert.EndReached()) |
| 249 | { |
| 250 | BERSequenceDecoder extensions(idCert); |
| 251 | { |
| 252 | while (!extensions.EndReached()) |
| 253 | { |
| 254 | m_extensionList.push_back(CertificateExtension(extensions)); |
| 255 | } |
| 256 | } |
| 257 | extensions.MessageEnd(); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | idCert.MessageEnd(); |
| 262 | } |
| 263 | catch (CryptoPP::BERDecodeErr&) { |
| 264 | throw Error("Certificate Decoding Error"); |
| 265 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 268 | void |
| 269 | Certificate::printCertificate(std::ostream& oss, const std::string& indent) const |
| 270 | { |
Alexander Afanasyev | bbb31f9 | 2014-12-01 13:15:59 -0800 | [diff] [blame] | 271 | util::IndentedStream os(oss, indent); |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 272 | |
| 273 | os << "Certificate name:\n"; |
| 274 | os << " " << getName() << "\n"; |
| 275 | os << "Validity:\n"; |
| 276 | { |
| 277 | os << " NotBefore: " << time::toIsoString(m_notBefore) << "\n"; |
| 278 | os << " NotAfter: " << time::toIsoString(m_notAfter) << "\n"; |
| 279 | } |
| 280 | |
| 281 | os << "Subject Description:\n"; |
| 282 | for (const auto& description : m_subjectDescriptionList) |
| 283 | os << " " << description.getOidString() << ": " << description.getValue() << "\n"; |
| 284 | |
Yingdi Yu | 3b4c314 | 2014-11-18 10:30:45 -0800 | [diff] [blame] | 285 | os << "Public key bits: "; |
| 286 | switch (m_key.getKeyType()) { |
| 287 | case KEY_TYPE_RSA: |
| 288 | os << "(RSA)"; |
| 289 | break; |
| 290 | case KEY_TYPE_ECDSA: |
| 291 | os << "(ECDSA)"; |
| 292 | break; |
| 293 | default: |
| 294 | os << "(Unknown key type)"; |
| 295 | break; |
| 296 | } |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 297 | os << "\n"; |
Yingdi Yu | 3b4c314 | 2014-11-18 10:30:45 -0800 | [diff] [blame] | 298 | |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 299 | { |
Alexander Afanasyev | bbb31f9 | 2014-12-01 13:15:59 -0800 | [diff] [blame] | 300 | util::IndentedStream os2(os, " "); |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 301 | CryptoPP::Base64Encoder encoder(new CryptoPP::FileSink(os2), true, 64); |
| 302 | m_key.encode(encoder); |
| 303 | } |
| 304 | |
| 305 | os << "Signature Information:\n"; |
Yingdi Yu | 3b4c314 | 2014-11-18 10:30:45 -0800 | [diff] [blame] | 306 | { |
| 307 | os << " Signature Type: "; |
| 308 | switch (getSignature().getType()) { |
| 309 | case tlv::SignatureTypeValue::DigestSha256: |
| 310 | os << "DigestSha256"; |
| 311 | break; |
| 312 | case tlv::SignatureTypeValue::SignatureSha256WithRsa: |
| 313 | os << "SignatureSha256WithRsa"; |
| 314 | break; |
| 315 | case tlv::SignatureTypeValue::SignatureSha256WithEcdsa: |
| 316 | os << "SignatureSha256WithEcdsa"; |
| 317 | break; |
| 318 | default: |
| 319 | os << "Unknown Signature Type"; |
| 320 | } |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 321 | os << "\n"; |
Yingdi Yu | 3b4c314 | 2014-11-18 10:30:45 -0800 | [diff] [blame] | 322 | |
| 323 | if (getSignature().hasKeyLocator()) { |
| 324 | const KeyLocator& keyLocator = getSignature().getKeyLocator(); |
| 325 | os << " Key Locator: "; |
| 326 | switch (keyLocator.getType()) { |
| 327 | case KeyLocator::KeyLocator_Name: |
| 328 | { |
| 329 | const Name& signerName = keyLocator.getName(); |
| 330 | if (signerName.isPrefixOf(getName())) |
| 331 | os << "(Self-Signed) " << keyLocator.getName(); |
| 332 | else |
| 333 | os << "(Name) " << keyLocator.getName(); |
| 334 | break; |
| 335 | } |
| 336 | case KeyLocator::KeyLocator_KeyDigest: |
| 337 | os << "(KeyDigest)"; |
| 338 | break; |
| 339 | case KeyLocator::KeyLocator_None: |
| 340 | os << "None"; |
| 341 | break; |
| 342 | default: |
| 343 | os << "Unknown"; |
| 344 | } |
Yingdi Yu | 3e8b52e | 2014-11-26 22:05:00 -0800 | [diff] [blame] | 345 | os << "\n"; |
Yingdi Yu | 3b4c314 | 2014-11-18 10:30:45 -0800 | [diff] [blame] | 346 | } |
| 347 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 348 | } |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 349 | |
Yingdi Yu | 80979ba | 2014-11-25 14:38:36 -0800 | [diff] [blame] | 350 | std::ostream& |
| 351 | operator<<(std::ostream& os, const Certificate& cert) |
| 352 | { |
| 353 | cert.printCertificate(os); |
| 354 | return os; |
| 355 | } |
| 356 | |
| 357 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 358 | } // namespace ndn |