fwupd/src/fu-keyring-result.c
Richard Hughes f69a4810fa Return the authority and timestamp as part of the signing validation
This means we return an error when encountering a rollback attack. This can
currently be performed by providing the old metadata and old signature when
calling into UpdateMetadata.
2017-08-17 16:15:47 +01:00

126 lines
3.3 KiB
C

/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "fwupd-error.h"
#include "fu-keyring-result.h"
struct _FuKeyringResult
{
GObject parent_instance;
gint64 timestamp;
gchar *authority;
};
G_DEFINE_TYPE (FuKeyringResult, fu_keyring_result, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_TIMESTAMP,
PROP_AUTHORITY,
PROP_LAST
};
gint64
fu_keyring_result_get_timestamp (FuKeyringResult *self)
{
g_return_val_if_fail (FU_IS_KEYRING_RESULT (self), 0);
return self->timestamp;
}
const gchar *
fu_keyring_result_get_authority (FuKeyringResult *self)
{
g_return_val_if_fail (FU_IS_KEYRING_RESULT (self), NULL);
return self->authority;
}
static void
fu_keyring_result_finalize (GObject *object)
{
FuKeyringResult *self = FU_KEYRING_RESULT (object);
g_free (self->authority);
G_OBJECT_CLASS (fu_keyring_result_parent_class)->finalize (object);
}
static void
fu_keyring_result_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
FuKeyringResult *self = FU_KEYRING_RESULT (object);
switch (prop_id) {
case PROP_TIMESTAMP:
g_value_set_int64 (value, self->timestamp);
break;
case PROP_AUTHORITY:
g_value_set_string (value, self->authority);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
fu_keyring_result_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
FuKeyringResult *self = FU_KEYRING_RESULT (object);
switch (prop_id) {
case PROP_TIMESTAMP:
self->timestamp = g_value_get_int64 (value);
break;
case PROP_AUTHORITY:
self->authority = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
fu_keyring_result_class_init (FuKeyringResultClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
object_class->get_property = fu_keyring_result_get_property;
object_class->set_property = fu_keyring_result_set_property;
object_class->finalize = fu_keyring_result_finalize;
pspec = g_param_spec_int64 ("timestamp", NULL, NULL,
0, G_MAXINT64, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_TIMESTAMP, pspec);
pspec = g_param_spec_string ("authority", NULL, NULL, NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_AUTHORITY, pspec);
}
static void
fu_keyring_result_init (FuKeyringResult *self)
{
}