diff --git a/ccsrc/Helpers/helpers_externals.cc b/ccsrc/Helpers/helpers_externals.cc index c9f2ec731b5bf40b31c86c043814cd397d9f4c97..37d1f3e62e5096219539d0b6e8ac4573edf85b84 100644 --- a/ccsrc/Helpers/helpers_externals.cc +++ b/ccsrc/Helpers/helpers_externals.cc @@ -121,7 +121,27 @@ namespace LibHelpers__Functions { * @brief Retrieve the current local date/time formatted as yyyy-mm-ddThh:mm:ss.lll+nn:00 * @return The the current date/time on success, a null string otherwise */ - CHARSTRING fx__get__current__date__time() { //2018-01-18T13:19:35.367+01:00 + CHARSTRING fx__get__current__date__time(const INTEGER& p__shift__time) { //2018-01-18T13:19:35.367+01:00 + loggers::get_instance().log(">>> fx__get__current__date__time"); + + time_t t = std::time(nullptr); + if (p__shift__time != 0) { + t += static_cast<int>(p__shift__time); + } + auto tm = *std::localtime(&t); + std::ostringstream oss; + oss << std::put_time(&tm, "%FT%TZ");//%FT%T%Z + + CHARSTRING dt(oss.str().c_str()); + loggers::get_instance().log_msg("fx__get__current__date__time: ", dt); + return dt; + } + + /** + * @brief Retrieve the local date/time in the past formatted as yyyy-mm-ddThh:mm:ss.lll+nn:00 + * @return The the current date/time on success, a null string otherwise + */ + CHARSTRING fx__get__current__date__time__past() { //2018-01-18T13:19:35.367+01:00 loggers::get_instance().log(">>> fx__get__current__date__time"); time_t t = std::time(nullptr); diff --git a/ccsrc/security/src/certs_cache.cc b/ccsrc/security/src/certs_cache.cc index a6b8184faf75c92c41cf71aa980019c81a95dc9e..1d7bcf7fd066357456d83c5e480a6fb447cbba87 100644 --- a/ccsrc/security/src/certs_cache.cc +++ b/ccsrc/security/src/certs_cache.cc @@ -183,9 +183,13 @@ int certs_cache::store_certificate(const std::string& p_certificate_name, const loggers::get_instance().log(">>> certs_cache::store_certificate: '%s'", p_certificate_name.c_str()); if (certs_loader::get_instance().store_certificate(p_certificate_name, p_certificate_pem, p_certificate_id, _certificates) == -1) { - loggers::get_instance().warning("certs_cache::store_certificate: Failed to load certificate"); - return -1; - } + loggers::get_instance().warning("certs_cache::store_certificate: Failed to load certificate"); + return -1; + } + + loggers::get_instance().log("certs_cache::store_certificate: Dump of current certificates: "); + dump(); + // Certificate is on the DB, load it std::map<std::string, std::unique_ptr<const certs_db_record>>::const_iterator it = _certificates.find(p_certificate_id); *p_record = it->second.get(); @@ -194,17 +198,18 @@ int certs_cache::store_certificate(const std::string& p_certificate_name, const std::string sn(256, (char)0x00); const X509_NAME* subject = (*p_record)->subject_name(); ::X509_NAME_oneline(subject, sn.data(), sn.length()); - loggers::get_instance().log("certs_cache::store_certificate: sn: '%s'", sn.c_str()); + loggers::get_instance().log("certs_cache::store_certificate: sn: '%s'", sn.c_str()); _certificates_subject.insert(std::pair<std::string, const std::string>(sn, p_certificate_id)); return 0; } void certs_cache::dump() const { - loggers::get_instance().log("certs_cache::dump_certificates: # items = %d", _certificates.size()); + loggers::get_instance().log(">>> certs_cache::dump_certificates: # items = %d", _certificates.size()); for (std::map<std::string, std::unique_ptr<const certs_db_record>>::const_iterator it = _certificates.cbegin(); it != _certificates.cend(); ++it) { const certs_db_record *p = it->second.get(); + loggers::get_instance().log("certs_cache::dump_certificates: certificate_id: '%s'", p->certificate_id().c_str()); } // End of 'for' statement } // End of method dump diff --git a/ccsrc/security/src/certs_loader.cc b/ccsrc/security/src/certs_loader.cc index 91bd87b51dae9353cc1ebd6c5942fabb336b085f..306e6a5417dee83d7388f6a4e2055f3a87509e61 100644 --- a/ccsrc/security/src/certs_loader.cc +++ b/ccsrc/security/src/certs_loader.cc @@ -210,6 +210,10 @@ int certs_loader::store_certificate(const std::string& p_certificate_name, const loggers::get_instance().log("certs_loader::store_certificate: p_certificate_id: '%s'", p_certificate_id.c_str()); loggers::get_instance().log("certs_loader::store_certificate: cert: '%p'", cert); + + // FIXME Dump certificate + + // Create new record certs_db_record *r = new certs_db_record(p_certificate_name, cert, nullptr, p_certificate_pem); std::pair<std::map<std::string, std::unique_ptr<const certs_db_record>>::iterator, bool> result = p_certificates.insert(std::pair<std::string, std::unique_ptr<const certs_db_record>>(p_certificate_id, std::unique_ptr<const certs_db_record>(r))); @@ -221,4 +225,3 @@ int certs_loader::store_certificate(const std::string& p_certificate_name, const return 0; } // End of method store_certificate - diff --git a/ttcn/LibHelpers/ttcn/LibHelpers_Functions.ttcn b/ttcn/LibHelpers/ttcn/LibHelpers_Functions.ttcn index f7edf9619881c752eee169fadceff511fca7848c..1f93d1c6c33543d8628402d1a804a684b5a81f5a 100644 --- a/ttcn/LibHelpers/ttcn/LibHelpers_Functions.ttcn +++ b/ttcn/LibHelpers/ttcn/LibHelpers_Functions.ttcn @@ -178,7 +178,7 @@ module LibHelpers_Functions { */ external function fx_generate_uuid() return charstring; - external function fx_get_current_date_time() return charstring; + external function fx_get_current_date_time(in integer p_shift_time) return charstring; } // End of externals