blob: cb22d65afcc2c27f8edde9077dce0561c7a5d7d7 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2013, Regents of the University of California
* Yingdi Yu
*
* BSD license, See the LICENSE file for more information
*
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
*/
#ifndef CHRONOS_VALIDATOR_INVITATION_H
#define CHRONOS_VALIDATOR_INVITATION_H
#include <ndn-cpp-dev/security/validator.hpp>
#include <ndn-cpp-dev/security/certificate-cache.hpp>
#include <ndn-cpp-dev/security/sec-rule-relative.hpp>
#include <map>
#include "endorse-certificate.h"
namespace chronos{
class ValidatorInvitation : public ndn::Validator
{
typedef ndn::function< void (const std::string&) > OnValidationFailed;
typedef ndn::function< void () > OnValidated;
public:
struct Error : public Validator::Error { Error(const std::string &what) : Validator::Error(what) {} };
static const ndn::shared_ptr<ndn::CertificateCache> DefaultCertificateCache;
ValidatorInvitation();
virtual
~ValidatorInvitation() {};
void
addTrustAnchor(const ndn::Name& keyName, const ndn::PublicKey& key)
{
m_trustAnchors[keyName] = key;
}
void
removeTrustAnchor(const ndn::Name& keyName)
{
m_trustAnchors.erase(keyName);
}
void
cleanTrustAnchor()
{
m_trustAnchors.clear();
}
protected:
void
checkPolicy(const ndn::Data& data,
int stepCount,
const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed,
std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
void
checkPolicy(const ndn::Interest& interest,
int stepCount,
const ndn::OnInterestValidated& onValidated,
const ndn::OnInterestValidationFailed& onValidationFailed,
std::vector<ndn::shared_ptr<ndn::ValidationRequest> >& nextSteps);
private:
void
internalCheck(const uint8_t* buf, size_t size,
const ndn::SignatureSha256WithRsa& sig,
const ndn::Data& innerData,
const OnValidated& onValidated,
const OnValidationFailed& onValidationFailed);
private:
typedef std::map<ndn::Name, ndn::PublicKey> TrustAnchors;
ndn::SecRuleRelative m_invitationReplyRule;
ndn::Regex m_invitationInterestRule;
ndn::Regex m_innerKeyRegex;
TrustAnchors m_trustAnchors;
};
}//chronos
#endif //CHRONOS_VALIDATOR_INVITATION_H