29 #include "../util/time.hpp" 31 #include "../encoding/cryptopp/asn_ext.hpp" 32 #include "../encoding/buffer-stream.hpp" 33 #include "../util/concepts.hpp" 34 #include "../util/indented-stream.hpp" 36 #include <boost/algorithm/string/split.hpp> 42 static_assert(std::is_base_of<tlv::Error, Certificate::Error>::value,
43 "Certificate::Error must inherit from tlv::Error");
46 : m_notBefore(
time::system_clock::TimePoint::max())
47 , m_notAfter(
time::system_clock::TimePoint::min())
134 CryptoPP::FileSink sink(os);
141 DERSequenceEncoder idCert(sink);
146 DERSequenceEncoder validity(idCert);
151 validity.MessageEnd();
157 DERSequenceEncoder
name(idCert);
178 DERSequenceEncoder extensions(idCert);
183 it->encode(extensions);
186 extensions.MessageEnd();
210 BERSequenceDecoder idCert(source);
215 BERSequenceDecoder validity(idCert);
220 validity.MessageEnd();
227 BERSequenceDecoder
name(idCert);
229 while (!name.EndReached())
248 if (!idCert.EndReached())
250 BERSequenceDecoder extensions(idCert);
252 while (!extensions.EndReached())
257 extensions.MessageEnd();
263 catch (CryptoPP::BERDecodeErr&) {
264 BOOST_THROW_EXCEPTION(
Error(
"Certificate Decoding Error"));
273 os <<
"Certificate name:\n";
274 os <<
" " <<
getName() <<
"\n";
281 os <<
"Subject Description:\n";
283 os <<
" " << description.getOidString() <<
": " << description.getValue() <<
"\n";
285 os <<
"Public key bits: ";
294 os <<
"(Unknown key type)";
301 CryptoPP::Base64Encoder encoder(
new CryptoPP::FileSink(os2),
true, 64);
305 os <<
"Signature Information:\n";
307 os <<
" Signature Type: ";
310 os <<
"DigestSha256";
313 os <<
"SignatureSha256WithRsa";
316 os <<
"SignatureSha256WithEcdsa";
319 os <<
"Unknown Signature Type";
325 os <<
" Key Locator: ";
326 switch (keyLocator.
getType()) {
331 os <<
"(Self-Signed) " << keyLocator.
getName();
333 os <<
"(Name) " << keyLocator.
getName();
Data & setContentType(uint32_t type)
Copyright (c) 2011-2015 Regents of the University of California.
ExtensionList m_extensionList
void wireDecode(const Block &wire)
Decode from the wire format.
Copyright (c) 2013-2014 Regents of the University of California.
size_t DEREncodeGeneralTime(CryptoPP::BufferedTransformation &bt, const time::system_clock::TimePoint &time)
A CertificateSubjectDescription represents the SubjectDescription entry in a Certificate.
std::ostream & operator<<(std::ostream &os, const Data &data)
void wireDecode(const Block &wire)
void encode(CryptoPP::BufferedTransformation &out) const
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Data & setContent(const uint8_t *buffer, size_t bufferSize)
Set the content from the buffer (buffer will be copied)
Class representing a wire element of NDN-TLV packet format.
Certificate()
The default constructor.
indicates KeyLocator contains a Name
static time_point now() noexcept
const Name & getName() const
Get name of the Data packet.
time::system_clock::TimePoint m_notAfter
Table::const_iterator iterator
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
const Name & getName() const
get Name element
void BERDecodeTime(CryptoPP::BufferedTransformation &bt, time::system_clock::TimePoint &time)
bool isTooLate()
Check if the certificate is valid.
void encode()
encode certificate info into content
indicates KeyLocator is empty (internal use only)
KeyType getKeyType() const
time::system_clock::TimePoint m_notBefore
Name abstraction to represent an absolute name.
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)
bool isTooEarly()
Check if the certificate is valid.
void decode(CryptoPP::BufferedTransformation &in)
const Signature & getSignature() const
indicates KeyLocator contains a KeyDigest
SubjectDescriptionList m_subjectDescriptionList
const Block & getContent() const
Get content Block.
void printCertificate(std::ostream &os, const std::string &indent="") const
indicates content is a public key
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
A CertificateExtension represents the Extension entry in a certificate.
a concept check for TLV abstraction with .wireEncode method
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Output to stream with specified indent or prefix.