ndnboost::any
PublicKeyVisitor::visit(DerSequence& derSeq)
{
  DerNodePtrList& children = derSeq.getChildren();

  SimpleVisitor simpleVisitor;
  ptr_lib::shared_ptr<DerSequence> algoSeq = ptr_lib::dynamic_pointer_cast<DerSequence>(children[0]);
  Blob raw = derSeq.getRaw();
  // TODO: Determine and pass the correct KeyType.
  return ndnboost::any(ptr_lib::shared_ptr<PublicKey>(new PublicKey(KEY_TYPE_RSA, raw)));
}
Beispiel #2
0
void 
PrintVisitor::visit(DerSequence& derSequence, ndnboost::any param)
{
  const string& indent = ndnboost::any_cast<const string&>(param);
  
  printData(derSequence.getHeader(), indent);

  const DerNodePtrList& children = derSequence.getChildren();
  DerNodePtrList::const_iterator it = children.begin();
  for(; it != children.end(); it++)
  (*it)->accept(*this, indent + " | ");
}
Beispiel #3
0
Blob
FilePrivateKeyStorage::encodeSubjectPublicKeyInfo
  (const OID& oid, const ptr_lib::shared_ptr<DerNode>& parameters,
   const ptr_lib::shared_ptr<DerNode>& bitString)
{
  ptr_lib::shared_ptr<DerSequence> algorithmIdentifier(new DerSequence());
  algorithmIdentifier->addChild(ptr_lib::make_shared<DerNode::DerOid>(oid));
  algorithmIdentifier->addChild(parameters);

  DerSequence result;
  result.addChild(algorithmIdentifier);
  result.addChild(bitString);

  return result.encode();
}
Beispiel #4
0
Blob
FilePrivateKeyStorage::encodePkcs8PrivateKey
  (const vector<uint8_t>& privateKeyDer, const OID& oid,
   const ptr_lib::shared_ptr<DerNode>& parameters)
{
  ptr_lib::shared_ptr<DerSequence> algorithmIdentifier(new DerSequence());
  algorithmIdentifier->addChild(ptr_lib::make_shared<DerNode::DerOid>(oid));
  algorithmIdentifier->addChild(parameters);

  DerSequence result;
  result.addChild(ptr_lib::make_shared<DerNode::DerInteger>(0));
  result.addChild(algorithmIdentifier);
  result.addChild(ptr_lib::make_shared<DerNode::DerOctetString>
    (&privateKeyDer[0], privateKeyDer.size()));

  return result.encode();
}
/*
 * CertExtensionVisitor
 */
void 
CertificateExtensionVisitor::visit(DerSequence& derSeq, ndnboost::any param)
{
  const DerNodePtrList& children = derSeq.getChildren();
  
  CertificateExtensionEntryVisitor extnEntryVisitor;

  DerNodePtrList::const_iterator it = children.begin();

  while(it != children.end()) {
    (*it)->accept(extnEntryVisitor, param);
    it++;
  }
}
/*
 * CertSubjectVisitor
 */
void 
CertificateSubjectVisitor::visit(DerSequence& derSeq, ndnboost::any param)
{
  // _LOG_DEBUG("CertSubjectVisitor::visit");

  const DerNodePtrList& children = derSeq.getChildren();
  
  CertificateSubjectDescriptionVisitor descryptVisitor;

  DerNodePtrList::const_iterator it = children.begin();

  while(it != children.end()) {
    (*it)->accept(descryptVisitor, param);
    it++;
  }
}
/*
 * CertSubDescryptVisitor
 */
void
CertificateSubjectDescriptionVisitor::visit(DerSequence& derSeq, ndnboost::any param)
{
  Certificate* certData = ndnboost::any_cast<Certificate*>(param); 
  
  const DerNodePtrList& children = derSeq.getChildren();
  
  SimpleVisitor simpleVisitor;

  OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
  string value = ndnboost::any_cast<string>(children[1]->accept(simpleVisitor));

  CertificateSubjectDescription subDescrypt(oid, value);

  certData->addSubjectDescription(subDescrypt);
}
/*
 * CertExtnEntryVisitor
 */
void 
CertificateExtensionEntryVisitor::visit(DerSequence& derSeq, ndnboost::any param)
{
  Certificate* certData = ndnboost::any_cast<Certificate*>(param); 
  
  const DerNodePtrList& children = derSeq.getChildren();
  
  SimpleVisitor simpleVisitor;

  OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
  bool critical = ndnboost::any_cast<bool>(children[1]->accept(simpleVisitor));
  const Blob& value = ndnboost::any_cast<const Blob&>(children[2]->accept(simpleVisitor));

  CertificateExtension extension(oid, critical, value);

  certData->addExtension(extension);
}
/*
 * CertValidityVisitor
 */
void 
CertificateValidityVisitor::visit(DerSequence& derSeq, ndnboost::any param)
{
  // _LOG_DEBUG("CertValidityVisitor::visit");
  
  Certificate* certData = ndnboost::any_cast<Certificate*>(param); 

  const DerNodePtrList& children = derSeq.getChildren();
  
  SimpleVisitor simpleVisitor;

  MillisecondsSince1970 notBefore = ndnboost::any_cast<MillisecondsSince1970>(children[0]->accept(simpleVisitor));
  MillisecondsSince1970 notAfter = ndnboost::any_cast<MillisecondsSince1970>(children[1]->accept(simpleVisitor));

  // _LOG_DEBUG("parsed notBefore: " << notBefore);
  // _LOG_DEBUG("parsed notAfter: " << notAfter);

  certData->setNotBefore(notBefore);
  certData->setNotAfter(notAfter);
}
/*
 * CertificateDataVisitor
 */
void 
CertificateDataVisitor::visit(DerSequence& derSeq, ndnboost::any param)
{
  // _LOG_DEBUG("CertificateDataVisitor::visit");

  const DerNodePtrList& children = derSeq.getChildren();
  CertificateValidityVisitor validityVisitor;
  children[0]->accept(validityVisitor, param);
  CertificateSubjectVisitor subjectVisitor;
  children[1]->accept(subjectVisitor, param);
  PublicKeyVisitor pubkeyVisitor;
  Certificate* certData = ndnboost::any_cast<Certificate*>(param);
  certData->setPublicKeyInfo(*ndnboost::any_cast<shared_ptr<PublicKey> >(children[2]->accept(pubkeyVisitor)));
      
  if(children.size() > 3)
    {
      CertificateExtensionVisitor extnVisitor;
      children[3]->accept(extnVisitor, param);
    }
}