Skip to content
Snippets Groups Projects
Commit 4e4b88ae authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

key parameters: active/inactive timestamp

refs #2413

Change-Id: I44e0e6b9058781d58c54ee8521e294836ee4e183
parent 630b5f81
No related branches found
No related tags found
No related merge requests found
......@@ -14,16 +14,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <arpa/inet.h>
#include <assert.h>
#include <config.h>
#include <ctype.h>
#include <netinet/in.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include "binary.h"
#include "common.h"
......@@ -224,6 +225,21 @@ static int key_param_int(const void *save_to, char *value)
return KNOT_EOK;
}
/*!
* \brief Handle storing of key lifetime parameter.
*/
static int key_param_time(const void *save_to, char *value)
{
time_t *parameter = (time_t *)save_to;
struct tm parsed = { 0 };
if (!strptime(value, "%Y%m%d%H%M%S", &parsed))
return KNOT_EINVAL;
*parameter = timegm(&parsed);
return KNOT_EOK;
}
/*!
* \brief Describes private key parameter used in key_parameters.
*/
......@@ -255,6 +271,8 @@ static const struct key_parameter key_parameters[] = {
{ "Private_value(x)",key_offset(private_value), key_param_base64 },
{ "Public_value(y)", key_offset(public_value), key_param_base64 },
{ "PrivateKey", key_offset(private_key), key_param_base64 },
{ "Activate", key_offset(time_activate), key_param_time },
{ "Inactive", key_offset(time_inactive), key_param_time },
{ NULL }
};
......
......@@ -28,6 +28,7 @@
#define _KNOT_SIGN_KEY_H_
#include <stdint.h>
#include <time.h>
#include "dname.h"
#include "binary.h"
#include "tsig.h"
......@@ -65,6 +66,14 @@ struct knot_key_params {
// EC
knot_binary_t private_key;
// key lifetime
//time_t time_created;
//time_t time_publish;
time_t time_activate;
//time_t time_revoke;
time_t time_inactive;
//time_t time_delete;
};
typedef struct knot_key_params knot_key_params_t;
......
......@@ -30,7 +30,7 @@ unit_api sign_tests_api = {
static int sign_tests_count(int argc, char *argv[])
{
return 24;
return 25;
}
static int sign_tests_run(int argc, char *argv[])
......@@ -163,7 +163,7 @@ static int sign_tests_run(int argc, char *argv[])
"key_param_int(), number and text");
}
// 17-20. - parse_keyfile_line()
// 17-21. - parse_keyfile_line()
{
knot_key_params_t key = { 0 };
int result;
......@@ -188,9 +188,15 @@ static int sign_tests_run(int argc, char *argv[])
ok(result == KNOT_EOK,
"parse_keyfile_line(), unknown parameter");
free(line);
line = strdup("Activate: 20130521144259\n");
result = parse_keyfile_line(&key, line, strlen(line));
ok(result == KNOT_EOK && key.time_activate == 1369147379,
"parse_keyfile_line(), timestamp parsing");
free(line);
}
// 21. - knot_free_key_params()
// 22. - knot_free_key_params()
{
int result;
knot_key_params_t params = { 0 };
......@@ -205,7 +211,7 @@ static int sign_tests_run(int argc, char *argv[])
"knot_free_key_params(), regular free");
}
// 22-24. - knot_tsig_key_from_params()
// 23-25. - knot_tsig_key_from_params()
{
int result;
knot_key_params_t params = { 0 };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment