Update CaConfig and ClientCaItem. Add INFO packet encoding and decoding.
Change-Id: I2118bfee05640ddbf20643fa07bf4c91eb7ebd06
diff --git a/src/ca-config.hpp b/src/ca-config.hpp
index 091c327..5bf4f44 100644
--- a/src/ca-config.hpp
+++ b/src/ca-config.hpp
@@ -21,85 +21,159 @@
#ifndef NDNCERT_CA_CONFIG_HPP
#define NDNCERT_CA_CONFIG_HPP
+#include <ndn-cxx/security/v2/certificate.hpp>
+
#include "certificate-request.hpp"
#include "client-config.hpp"
+<<<<<<< HEAD
#include <ndn-cxx/security/certificate.hpp>
+=======
+>>>>>>> Update CaConfig and ClientCaItem. Add INFO packet encoding and decoding.
namespace ndn {
namespace ndncert {
/**
- * @brief The function should be able to convert a probe info string to an identity name
+ * @brief The name assignment function provided by the CA operator to generate available
+ * namecomponents.
+ * The function does not guarantee that all the returned names are available. Therefore the
+ * CA should further check the availability of each returned name and remove unavailable results.
*
- * The function should throw exceptions when there is an unexpected input.
+ * @p vector, input, a list of parameter key-value pair used for name assignment.
+ * @return a vector containing the possible namespaces derived from the parameters.
*/
-using ProbeHandler = function<std::string/*identity name*/ (const JsonSection& json/*requester input*/)>;
+using ProbeHandler = function<std::string /*identity name*/ (const JsonSection& json /*requester input*/)>;
+using NameAssignmentFunc = function<std::vector<std::string>(const std::vector<std::tuple<std::string, std::string>>)>;
/**
- * @brief The function would be invoked whenever the certificate request status gets update
- *
+ * @brief The function would be invoked whenever the certificate request status is updated.
* The callback is used to notice the CA application or CA command line tool. The callback is
* fired whenever a request instance is created, challenge status is updated, and when certificate
* is issued.
+ *
+ * @p CertificateRequest, input, the state of the certificate request whose status is updated.
*/
-using StatusUpdateCallback = function<void (const CertificateRequest&/*the latest request info*/)>;
+using StatusUpdateCallback = function<void(const CertificateRequest&)>;
/**
- * @brief Represents a CA configuration instance
- *
+ * @brief CA's configuration on NDNCERT.
* For CA configuration format, please refer to:
- * https://github.com/named-data/ndncert/wiki/Ca-Configuration-Sample
+ * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
*
- * @note Changes made to CaConfig won't be written back to the config
+ * The format of CA configuration in JSON
+ * {
+ * "ca-prefix": "",
+ * "ca-info": "",
+ * "max-validity-period": "",
+ * "probe-parameters":
+ * [
+ * {"probe-parameter-key": ""},
+ * {"probe-parameter-key": ""}
+ * ]
+ * "supported-challenges":
+ * [
+ * {"challenge": ""},
+ * {"challenge": ""}
+ * ]
+ * }
*/
-class CaConfig
-{
+class CaConfig {
public:
/**
* @brief Error that can be thrown from CaConfig
*/
- class Error : public std::runtime_error
- {
+ class Error : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
public:
/**
- * @throw CaConfig::Error when config file does not exist
- * @throw CaConfig::Error when the JSON text in the file cannot be parsed correctly
- * @throw CaConfig::Error when the ca-prefix attribute in JSON text is empty
- * @throw CaConfig::Error when the challenge is not specified or is not supported
+ * Load CA configuration from the file.
+ *
+ * @param fileName, the configuration file name.
+ * @throw CaConfig::Error when config file does not exist or the configuration
+ * in the file cannot be parsed correctly.
+ * @throw CaConfig::Error when the ca-prefix attribute in JSON text is empty.
+ * @throw CaConfig::Error when the challenge is not specified or is not supported.
*/
void
load(const std::string& fileName);
+ /**
+ * Set the NameAssignmentFunction.
+ */
+ void
+ setNameAssignmentFunc(const NameAssignmentFunc& nameAssignmentFunc) {
+ m_nameAssignmentFunc = nameAssignmentFunc;
+ }
+
+ /**
+ * Set the StatusUpdateCallback.
+ */
+ void
+ setStatusUpdateCallback(const StatusUpdateCallback& statusUpdateCallback) {
+ m_statusUpdateCallback = statusUpdateCallback;
+ }
+
private:
void
parse(const JsonSection& configJson);
- std::list<std::string>
+ void
+ parseProbeParameters(const JsonSection& section);
+
+ void
parseChallengeList(const JsonSection& configSection);
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;
+ /**
+ * A list of supported challenges.
+ */
+ std::list<std::string> m_supportedChallenges;
+ /**
+ * NameAssignmentFunc Callback function
+ */
+ NameAssignmentFunc m_nameAssignmentFunc;
+ /**
+ * StatusUpdate Callback function
+ */
+ StatusUpdateCallback m_statusUpdateCallback;
+
+ //====================old
+
// basic info
Name m_caName;
// essential config
time::seconds m_freshnessPeriod;
time::days m_validityPeriod;
- std::list<std::string> m_supportedChallenges;
// optional parameters
std::string m_probe;
- std::string m_caInfo;
// callbacks
ProbeHandler m_probeHandler;
- StatusUpdateCallback m_statusUpdateCallback;
};
-} // namespace ndncert
-} // namespace ndn
+} // namespace ndncert
+} // namespace ndn
-#endif // NDNCERT_CA_CONFIG_HPP
+#endif // NDNCERT_CA_CONFIG_HPP