mirror of
https://github.com/SunnyQjm/MIRCertificationManager.git
synced 2026-06-05 15:39:37 +08:00
fix: 测试并修复了查询证书剩余生存期,以及判断证书是否存在的接口
This commit is contained in:
@@ -73,6 +73,7 @@ void Server::onInterest(const InterestFilter &filter, const Interest &interest)
|
||||
case BaseRequestMessage::GET_CERTIFICATE_LIFETIME: // 获取证书的生存期
|
||||
getLifetimeRequestMessage.parse(params);
|
||||
longResult = ndnCertificationUtil.getCertLifetime(getLifetimeRequestMessage.getCertStr());
|
||||
std::cout << "longResult: " << longResult << std::endl;
|
||||
root["data"] = (long long int) longResult;
|
||||
if (longResult >= 0) {
|
||||
resCode = 0;
|
||||
|
||||
+6
-1
@@ -7,6 +7,9 @@
|
||||
#include <ndn-cxx/face.hpp>
|
||||
#include <ndn-cxx/data.hpp>
|
||||
#include "utils/FileUtils.h"
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace ndn;
|
||||
@@ -19,7 +22,9 @@ int main(int argc, char **argv) {
|
||||
Interest::setDefaultCanBePrefix(true);
|
||||
string jsonStr = FileUtils::readFile2String(argv[2]);;
|
||||
ndn::Face face;
|
||||
ndn::Interest interest("/localmanager/mircertification");
|
||||
boost::uuids::uuid a_uuid = boost::uuids::random_generator()();
|
||||
string uuid_string = boost::uuids::to_string(a_uuid);
|
||||
ndn::Interest interest("/localmanager/mircertification/" + uuid_string);
|
||||
interest.setMustBeFresh(true);
|
||||
interest.setApplicationParameters((uint8_t *) jsonStr.c_str(), jsonStr.size());
|
||||
face.expressInterest(interest, [=](const Interest &interest1, const Data &data) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"code":4,
|
||||
"data":{
|
||||
"certStr":"Bv0Cxwc1CANuZG4IA2VkdQgFcGt1c3oIAk9BCANLRVkICGPbD1xognqbCARzZWxm\nCAn9AAABcTrEzzwUCRgBAh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QEBAQUAA4IB\nDwAwggEKAoIBAQC5iB3MjTnzWUBlUryln80o9Y9WifC3KdF5xh9SazM90kVlTOqz\noLGfFvT6MIoFmMHyphU8D6HLuWuAK3hhcaamHi0ddiDYt7nNjvhkoZpzOQMAiXyv\n0P5LkbWzO1IK53MM1xga029rQJjPrRikoQJDe7K9NAzklRj9WBL6eYtevs6FKUhf\nhmoDgPLsiW5auhefv7cXwLfqee3BwaeugBw/77Z5/0/6X9bY9YXwFkcWl0JpGfGm\nXqZKD/V4TcK0/mNd6ho73aL3AdRnportgoo8RLGYQeG3VVXj8OAlOlJ/Ekh+Xel7\nC9sUQn2OuRw7bib52hode0WbTyxiaTsHlJX3AgMBAAEWVRsBARwmByQIA25kbggD\nZWR1CAVwa3VzeggCT0EIA0tFWQgIY9sPXGiCepv9AP0m/QD+DzE5NzAwMTAxVDAw\nMDAwMP0A/w8yMDQwMDMyOFQxMjAxNDgX/QEATFdz4SS3vHcA9twisNeqTi+3grxb\nisVJvH2LOOUxZhEP1H1NAP5EihLz91RqGnlcwl94svSNkZysuDm/0WI3bXtPTso7\nb+pS758CqMJ7SbvuAGFk9Q30it/Z3A2wUV2qxZbfp46u7JUByu2xU/0i3kzvWr4z\nw5EtWFoatNVsZDElKVsFSxo4k8Z1df3gXAWwF6ZIE12o7SM7O8EWtbiL1QydB30k\nA8zB9mJ9P//pAojI+u57WyCdRwa316cu2Q9ucFf22lPhtJxXzV8yf/sYW3bJeSPW\nD20fxxX3KrPNwSTI8oPl4ajvI4fexy4LXJ4F9GJ8VGBmc+A9HftxfHXVRw=="
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "NDNCertificationUtil.h"
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* 验证一个包含证书的字符串是不是一个合法的NDN证书
|
||||
@@ -154,16 +155,30 @@ bool NDNCertificationUtil::verifyData(const ndn::Data &data) {
|
||||
* 获取证书剩余存活时间,单位为毫秒;
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param certStr
|
||||
* @return
|
||||
* -2 => 返回-2表示key对应的条目不存在(可能是本来就没有这个条目,或者本来有一个条目,但是因为设置了存活期,其存活期已到,被移除了)
|
||||
* -1 => 返回-1表示key对应的条目存在,但是没有设置过存活期,是持久保存的
|
||||
* >= 0 => 返回大于等于0的值表示key对应的条目存在,且其剩余的存活时间为返回的值,单位为毫秒
|
||||
*/
|
||||
long NDNCertificationUtil::getCertLifetime(const std::string &key) {
|
||||
return redisUtil.getRemainingTime(key);
|
||||
long NDNCertificationUtil::getCertLifetime(const std::string &certStr) {
|
||||
// 首先验证证书是否有效
|
||||
if (!isValidBlock(certStr))
|
||||
return -1;
|
||||
// 接着构造证书
|
||||
std::stringstream ss(certStr);
|
||||
ndn::security::v2::Certificate cert =
|
||||
*(ndn::io::load<ndn::security::v2::Certificate>(ss));
|
||||
return redisUtil.getRemainingTime(cert.getName().toUri());
|
||||
}
|
||||
|
||||
bool NDNCertificationUtil::exists(const std::string &key) {
|
||||
return redisUtil.exist(key) > 0;
|
||||
bool NDNCertificationUtil::exists(const std::string &certStr) {
|
||||
// 首先验证证书是否有效
|
||||
if (!isValidBlock(certStr))
|
||||
return -1;
|
||||
// 接着构造证书
|
||||
std::stringstream ss(certStr);
|
||||
ndn::security::v2::Certificate cert =
|
||||
*(ndn::io::load<ndn::security::v2::Certificate>(ss));
|
||||
return redisUtil.exist(cert.getName().toUri()) > 0;
|
||||
}
|
||||
|
||||
@@ -72,20 +72,20 @@ public:
|
||||
* 获取证书剩余存活时间,单位为毫秒;
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param certStr
|
||||
* @return
|
||||
* -2 => 返回-2表示key对应的条目不存在(可能是本来就没有这个条目,或者本来有一个条目,但是因为设置了存活期,其存活期已到,被移除了)
|
||||
* -1 => 返回-1表示key对应的条目存在,但是没有设置过存活期,是持久保存的
|
||||
* >= 0 => 返回大于等于0的值表示key对应的条目存在,且其剩余的存活时间为返回的值,单位为毫秒
|
||||
*/
|
||||
long getCertLifetime(const std::string &key);
|
||||
long getCertLifetime(const std::string &certStr);
|
||||
|
||||
/**
|
||||
* 判断某个证书是否存在
|
||||
* @param key
|
||||
* @param certStr
|
||||
* @return 如果存在则返回大于0的值,典型值为1
|
||||
*/
|
||||
bool exists(const std::string &key);
|
||||
bool exists(const std::string &certStr);
|
||||
|
||||
/**
|
||||
* 验证兴趣包签名是否有效
|
||||
|
||||
Reference in New Issue
Block a user