27 #include "../../util/time.hpp" 29 #include "../../encoding/cryptopp/asn_ext.hpp" 30 #include "../../encoding/buffer-stream.hpp" 31 #include "../../util/concepts.hpp" 32 #include "../../util/indented-stream.hpp" 34 #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) 2013-2017 Regents of the University of California.
time::system_clock::TimePoint m_notBefore
void wireDecode(const Block &wire)
Decode from the wire format.
Copyright (c) 2013-2017 Regents of the University of California.
size_t DEREncodeGeneralTime(CryptoPP::BufferedTransformation &bt, const time::system_clock::TimePoint &time)
std::ostream & operator<<(std::ostream &os, const Certificate &cert)
Certificate()
The default constructor.
Data & setContent(const Block &block)
Set Content from a block.
const Signature & getSignature() const
Get Signature.
const KeyLocator & getKeyLocator() const
Get KeyLocator.
SubjectDescriptionList m_subjectDescriptionList
Represents a TLV element of NDN packet format.
void encode(CryptoPP::BufferedTransformation &out) const
indicates KeyLocator contains a Name
BOOST_CONCEPT_ASSERT((WireEncodable< Certificate >))
static time_point now() noexcept
const Name & getName() const
get Name element
KeyType getKeyType() const
bool isTooEarly()
Check if the certificate is valid.
void BERDecodeTime(CryptoPP::BufferedTransformation &bt, time::system_clock::TimePoint &time)
indicates KeyLocator is empty (internal use only)
A CertificateSubjectDescription represents the SubjectDescription entry in a Certificate.
void encode()
encode certificate info into content
Represents an absolute name.
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)
indicates KeyLocator contains a KeyDigest
const Name & getName() const
Get name.
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
const Block & getContent() const
Get Content.
void printCertificate(std::ostream &os, const std::string &indent="") const
indicates content is a public key
bool isTooLate()
Check if the certificate is valid.
implements an output stream that constructs ndn::Buffer
void decode(CryptoPP::BufferedTransformation &in)
A CertificateExtension represents the Extension entry in a certificate.
time::system_clock::TimePoint m_notAfter
ExtensionList m_extensionList
Represents a Data packet.
void wireDecode(const Block &wire)
Output to stream with specified indent or prefix.