blob: 2d74cf63fbd83caa874ab621143c24d0f7a435eb [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2017-2020, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
* ndncert is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received copies of the GNU General Public License along with
* ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
#ifndef NDNCERT_CLIENT_CONFIG_HPP
#define NDNCERT_CLIENT_CONFIG_HPP
#include "certificate-request.hpp"
#include <ndn-cxx/security/v2/certificate.hpp>
namespace ndn {
namespace ndncert {
/**
* @brief The configuration for a trusted CA from a requester's perspective
*/
class ClientCaItem {
public:
/**
* CA Name prefix (without /CA suffix).
*/
Name m_caPrefix;
/**
* CA Information.
*/
std::string m_caInfo;
/**
* A list of parameter-keys for PROBE.
*/
std::list<std::string> m_probeParameterKeys;
/**
* Maximum allowed validity period of the certificate being requested.
* The value is in the unit of second.
*/
time::seconds m_maxValidityPeriod;
/**
* CA's certificate.
*/
security::v2::Certificate m_anchor;
/**
* Maximum allowed suffix length of requested name.
* E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix.
*/
size_t m_maxSuffixLength;
//=======old
// The identity name of the CA. Extracted from config field "ca-prefix"
Name m_caName;
// An instruction for requesters to use _PROBE. Extracted from config field "probe"
std::string m_probe; // "email::uid::name"
};
/**
* @brief Represents Client configuration
*
* For Client configuration format, please refer to:
* https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
*/
class ClientConfig {
public:
class Error : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
public:
/**
* @throw ClientConfig::Error when config file does not exist
* @throw ClientConfig::Error when the JSON text in the file cannot be parsed correctly
* @throw ClientConfig::Error when the ca-prefix attribute in JSON text is empty
* @throw ClientConfig::Error when the certificate in JSON text cannot be parsed correctly
*/
void
load(const std::string& fileName);
void
load(const JsonSection& configSection);
void
save(const std::string& fileName);
void
addNewCaItem(const ClientCaItem& item);
void
removeCaItem(const Name& caName);
static ClientCaItem
extractCaItem(const JsonSection& configSection);
public:
std::list<ClientCaItem> m_caItems;
std::string m_localNdncertAnchor;
};
} // namespace ndncert
} // namespace ndn
#endif // NDNCERT_CLIENT_CONFIG_HPP