diff mbox

[01/15] uefirtauthvar: add the test for creating authenticated variable

Message ID 1413970598-26976-1-git-send-email-ivan.hu@canonical.com
State Rejected
Headers show

Commit Message

Ivan Hu Oct. 22, 2014, 9:36 a.m. UTC
This test checks the setvariable with the new authenticated variable which
created with TIME_BASED_AUTHENTICATED, i.e. EFI_VARIABLE_AUTHENTICATION_2
descriptor(UEFI spec. 7.2.1.). It also checks the data content after variable
was successfully created.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/Makefile.am                        |    3 +-
 src/uefi/uefirtauthvar/authvardefs.h   |  148 +++++++++++++++++++++
 src/uefi/uefirtauthvar/uefirtauthvar.c |  223 ++++++++++++++++++++++++++++++++
 3 files changed, 373 insertions(+), 1 deletion(-)
 create mode 100644 src/uefi/uefirtauthvar/authvardefs.h
 create mode 100644 src/uefi/uefirtauthvar/uefirtauthvar.c

Comments

Colin Ian King Oct. 22, 2014, 3:59 p.m. UTC | #1
On 22/10/14 10:36, Ivan Hu wrote:
> This test checks the setvariable with the new authenticated variable which
> created with TIME_BASED_AUTHENTICATED, i.e. EFI_VARIABLE_AUTHENTICATION_2
> descriptor(UEFI spec. 7.2.1.). It also checks the data content after variable
> was successfully created.
> 
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/Makefile.am                        |    3 +-
>  src/uefi/uefirtauthvar/authvardefs.h   |  148 +++++++++++++++++++++
>  src/uefi/uefirtauthvar/uefirtauthvar.c |  223 ++++++++++++++++++++++++++++++++
>  3 files changed, 373 insertions(+), 1 deletion(-)
>  create mode 100644 src/uefi/uefirtauthvar/authvardefs.h
>  create mode 100644 src/uefi/uefirtauthvar/uefirtauthvar.c
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index d472d5c..db367a0 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -91,7 +91,8 @@ fwts_SOURCES = main.c 				\
>  	uefi/uefirtmisc/uefirtmisc.c		\
>  	uefi/securebootcert/securebootcert.c	\
>  	uefi/uefivarinfo/uefivarinfo.c		\
> -	uefi/uefibootpath/uefibootpath.c
> +	uefi/uefibootpath/uefibootpath.c	\
> +	uefi/uefirtauthvar/uefirtauthvar.c
>  
>  fwts_LDFLAGS = -lm `pkg-config --libs glib-2.0 gio-2.0`
>  
> diff --git a/src/uefi/uefirtauthvar/authvardefs.h b/src/uefi/uefirtauthvar/authvardefs.h
> new file mode 100644
> index 0000000..d74a018
> --- /dev/null
> +++ b/src/uefi/uefirtauthvar/authvardefs.h
> @@ -0,0 +1,148 @@
> +/*
> + * Copyright (C) 2014 Canonical
> + *
> + * 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.
> + *
> + */
> +
> +#ifndef __AUTH_VAR_DEF_H__
> +#define __AUTH_VAR_DEF_H__
> +
> +/*
> + * AuthVarCreate,
> + * timestamp: 2014.09.08:03:41:15
> + * GUID: 7f5c5d52-2f14-4f12-967cdb60db05a0fd
> + * attributes = UEFI_VAR_NON_VOLATILE, UEFI_VAR_BOOTSERVICE_ACCESS,
> + *		UEFI_VAR_RUNTIME_ACCESS, UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
> + * Variable name: AuthVarTest
> + * data content: 1234567890abcdef
> + */
> +static uint8_t AuthVarCreate[] = {
> +	0xde, 0x07, 0x09, 0x08, 0x03, 0x29, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
> +	0x00, 0x00, 0x00, 0x00, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x02, 0xf1, 0x0e,
> +	0x9d, 0xd2, 0xaf, 0x4a, 0xdf, 0x68, 0xee, 0x49, 0x8a, 0xa9, 0x34, 0x7d,
> +	0x37, 0x56, 0x65, 0xa7, 0x30, 0x82, 0x04, 0xef, 0x06, 0x09, 0x2a, 0x86,
> +	0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x04, 0xe0, 0x30,
> +	0x82, 0x04, 0xdc, 0x02, 0x01, 0x01, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x09,
> +	0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x30,
> +	0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01,
> +	0xa0, 0x82, 0x02, 0xfd, 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1,
> +	0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xbb, 0x94, 0x92, 0x5f,
> +	0x3b, 0x5e, 0xd3, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
> +	0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x13, 0x31, 0x11, 0x30,
> +	0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x74, 0x65, 0x73, 0x74,
> +	0x2d, 0x6b, 0x65, 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x38,
> +	0x31, 0x32, 0x31, 0x30, 0x32, 0x31, 0x33, 0x30, 0x5a, 0x17, 0x0d, 0x31,
> +	0x34, 0x30, 0x39, 0x31, 0x31, 0x31, 0x30, 0x32, 0x31, 0x33, 0x30, 0x5a,
> +	0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
> +	0x08, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x6b, 0x65, 0x79, 0x30, 0x82, 0x01,
> +	0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
> +	0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01,
> +	0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe5, 0xbf, 0x24, 0xb1, 0x10, 0x46,
> +	0x55, 0xad, 0x70, 0x77, 0x14, 0xc3, 0x1b, 0x55, 0xa0, 0x72, 0xfa, 0x3c,
> +	0x3c, 0x44, 0x3e, 0xc3, 0xd7, 0xfa, 0x05, 0x94, 0xeb, 0x70, 0x6a, 0xe3,
> +	0x47, 0x58, 0xb5, 0xab, 0x83, 0x6e, 0x7a, 0x43, 0xdd, 0x51, 0x9a, 0x31,
> +	0x4a, 0x4a, 0x4f, 0xf0, 0x65, 0xfe, 0xae, 0x10, 0x30, 0xf8, 0xaa, 0x69,
> +	0x54, 0xaf, 0xff, 0x4b, 0x3d, 0x48, 0x5d, 0x09, 0x9c, 0x94, 0x87, 0x3a,
> +	0xf6, 0x56, 0xeb, 0xb6, 0x80, 0x07, 0x77, 0x1e, 0x92, 0x8b, 0x19, 0xc3,
> +	0xa6, 0x8b, 0x4b, 0x0f, 0x60, 0x8f, 0x88, 0xca, 0x89, 0x41, 0x1d, 0x18,
> +	0xb6, 0xde, 0x16, 0x75, 0xaa, 0xaa, 0xa7, 0xba, 0x88, 0xbd, 0x0f, 0x62,
> +	0x27, 0x7e, 0xe1, 0x11, 0x67, 0x6a, 0xf2, 0x8a, 0xd9, 0xf0, 0xc2, 0x56,
> +	0x60, 0x7f, 0xfd, 0xd7, 0x62, 0x71, 0x75, 0x8f, 0x09, 0xf8, 0x52, 0x37,
> +	0xc9, 0xf2, 0xef, 0x56, 0xd5, 0x81, 0x95, 0xb3, 0x7f, 0xd9, 0xcc, 0xf4,
> +	0xbc, 0xd0, 0x5e, 0x8c, 0x8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0d, 0x61, 0xf2, 0x62, 0x8e, 0xc6, 0xe7, 0xd5, 0xb6, 0x4e, 0x30,
> +	0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01,
> +	0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
> +	0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xb2, 0x28, 0xe3,
> +	0x94, 0x02, 0x6f, 0xe5, 0x2a, 0xdc, 0x29, 0x7d, 0xcf, 0x2b, 0x88, 0x09,
> +	0x4f, 0x73, 0x8a, 0xc3, 0x54, 0xfc, 0xa3, 0x40, 0x84, 0x82, 0xce, 0x32,
> +	0x8d, 0x75, 0x51, 0xa2, 0xc3, 0x3f, 0x01, 0x0f, 0xde, 0x1b, 0x1f, 0x48,
> +	0xdb, 0x8f, 0xf9, 0xe0, 0xf3, 0x23, 0x78, 0x17, 0x4a, 0x84, 0xbc, 0xf4,
> +	0x84, 0xb5, 0xe5, 0x8c, 0x17, 0x36, 0x7f, 0x4f, 0x6f, 0x54, 0x47, 0xbd,
> +	0xe6, 0x40, 0xb0, 0x8a, 0x73, 0x74, 0x65, 0x57, 0x98, 0xf6, 0x77, 0x58,
> +	0x0e, 0x5f, 0x82, 0x77, 0xb3, 0xd9, 0x87, 0xf8, 0xe9, 0x21, 0x11, 0x37,
> +	0x4c, 0x6e, 0x5f, 0xda, 0x1e, 0x81, 0xa6, 0xa3, 0x45, 0x09, 0x81, 0x26,
> +	0xd0, 0xb6, 0xe1, 0x27, 0xa5, 0xc3, 0x6e, 0xed, 0x86, 0xb7, 0x4f, 0xf3,
> +	0x7e, 0x34, 0xa5, 0x0b, 0x8a, 0xd1, 0x56, 0x65, 0x04, 0xe2, 0x16, 0x71,
> +	0x11, 0xdc, 0xa8, 0xa6, 0xe0, 0x57, 0x91, 0x63, 0xe2, 0x9d, 0xe7, 0x86,
> +	0x00, 0xa6, 0xb4, 0x75, 0xf3, 0x37, 0x63, 0x48, 0x41, 0xcd, 0x97, 0x12,
> +	0x2e, 0x5c, 0xc0, 0xf0, 0x13, 0x62, 0x71, 0xc1, 0x8e, 0x65, 0x28, 0x52,
> +	0x09, 0x71, 0x87, 0x33, 0x27, 0x77, 0x84, 0x2f, 0xb4, 0x9a, 0x0a, 0x62,
> +	0xe6, 0x69, 0x05, 0xd7, 0x94, 0x70, 0x8a, 0xb9, 0x61, 0x68, 0xdb, 0xbd,
> +	0x4b, 0x58, 0xd3, 0x74, 0x0e, 0x3e, 0x00, 0x6c, 0x64, 0x02, 0x22, 0x4f,
> +	0x62, 0xbe, 0xe1, 0x53, 0x96, 0xa5, 0x6a, 0x7d, 0xf7, 0x8c, 0x77, 0x42,
> +	0x49, 0xb3, 0xb0, 0x44, 0xf1, 0xa9, 0xd5, 0x64, 0xdf, 0xcc, 0x8b, 0x90,
> +	0x03, 0x05, 0xb8, 0x07, 0x5f, 0x6e, 0x88, 0x11, 0x7e, 0x93, 0x85, 0xe6,
> +	0x3c, 0x87, 0x92, 0x74, 0xbb, 0xfe, 0x01, 0x32, 0xe8, 0x0b, 0xa9, 0xab,
> +	0x15, 0xd4, 0x8a, 0x4f, 0xd7, 0x40, 0x12, 0xe1, 0xde, 0x8a, 0xa8, 0x7c,
> +	0xf5, 0x31, 0x82, 0x01, 0xb6, 0x30, 0x82, 0x01, 0xb2, 0x02, 0x01, 0x01,
> +	0x30, 0x20, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04,
> +	0x03, 0x0c, 0x08, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x6b, 0x65, 0x79, 0x02,
> +	0x09, 0x00, 0xbb, 0x94, 0x92, 0x5f, 0x3b, 0x5e, 0xd3, 0x2d, 0x30, 0x0d,
> +	0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
> +	0x00, 0xa0, 0x69, 0x30, 0x18, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
> +	0x0d, 0x01, 0x09, 0x03, 0x31, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
> +	0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x09, 0x2a, 0x86, 0x48,
> +	0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05, 0x31, 0x0f, 0x17, 0x0d, 0x31, 0x34,
> +	0x31, 0x30, 0x30, 0x38, 0x30, 0x33, 0x34, 0x31, 0x31, 0x35, 0x5a, 0x30,
> +	0x2f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04,
> +	0x31, 0x22, 0x04, 0x20, 0x7d, 0x9f, 0x1b, 0x65, 0x76, 0x70, 0x66, 0xe3,
> +	0xa0, 0x6a, 0x53, 0x01, 0xd9, 0xde, 0x6f, 0x6a, 0x88, 0xcb, 0x76, 0xb3,
> +	0xf8, 0xd6, 0xc4, 0x45, 0x3a, 0x8f, 0x7b, 0x9d, 0x06, 0x50, 0xc6, 0x12,
> +	0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
> +	0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0xb5, 0x61, 0x49, 0xea, 0xfc,
> +	0xfe, 0x13, 0xfc, 0xd5, 0x92, 0x5a, 0xf5, 0x11, 0x88, 0x2a, 0xba, 0x0f,
> +	0x3d, 0x3d, 0x56, 0x8a, 0x69, 0x2b, 0xcc, 0x3a, 0x95, 0x09, 0xb6, 0x06,
> +	0xd9, 0x36, 0x17, 0x63, 0x40, 0xd7, 0xc8, 0x5a, 0xb3, 0xca, 0x2d, 0xd2,
> +	0xea, 0xa0, 0x9a, 0x82, 0x04, 0x75, 0x66, 0xeb, 0x41, 0x9b, 0x1a, 0x23,
> +	0x70, 0xf0, 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0x15, 0x18, 0x54,
> +	0xbd, 0x51, 0xc1, 0x84, 0x62, 0x0f, 0x72, 0x8d, 0x67, 0xce, 0xe6, 0xbd,
> +	0x6e, 0x21, 0x58, 0x1f, 0x77, 0xf4, 0xfc, 0x36, 0xf9, 0x0c, 0x1d, 0x31,
> +	0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63,
> +	0x64, 0x65, 0x66
> +};
> +
> +static uint8_t AuthVarCreateData[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66};
> +
> +#endif

Normally I don't like static data being #included as this can end up
being included multiple times and end up bloating the code. However,
since this is just isolated to this test, I'll let this through.


> diff --git a/src/uefi/uefirtauthvar/uefirtauthvar.c b/src/uefi/uefirtauthvar/uefirtauthvar.c
> new file mode 100644
> index 0000000..bde760f
> --- /dev/null
> +++ b/src/uefi/uefirtauthvar/uefirtauthvar.c
> @@ -0,0 +1,223 @@
> +/*
> + * Copyright (C) 2014 Canonical
> + *
> + * 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 <inttypes.h>
> +#include <stdio.h>
> +#include <stddef.h>
> +#include <sys/ioctl.h>
> +#include <fcntl.h>
> +
> +#include "fwts.h"
> +#include "fwts_uefi.h"
> +#include "efi_runtime.h"
> +#include "fwts_efi_module.h"
> +#include "authvardefs.h"
> +
> +static int fd;
> +
> +#define TEST_GUID {0x7f5c5d52, 0x2f14, 0x4f12, {0x96, 0x7c, 0xdb, 0x60, 0xdb, 0x05, 0xa0, 0xfd} }
> +
> +#define getvar_buf_size 100
> +
> +static EFI_GUID gtestguid = TEST_GUID;
> +
> +static uint32_t attributes =

You could make that static const uint32_t attributes

> +	FWTS_UEFI_VAR_NON_VOLATILE |
> +	FWTS_UEFI_VAR_BOOTSERVICE_ACCESS |
> +	FWTS_UEFI_VAR_RUNTIME_ACCESS |
> +	FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
> +
> +static uint16_t variablenametest[] = {'A', 'u', 't', 'h', 'V', 'a', 'r', 'T', 'e', 's', 't', '\0'};
> +
> +static long setvar(
> +	EFI_GUID *guid,
> +	uint32_t attributes,
> +	uint64_t datasize,
> +	void *data,
> +	uint64_t *status)
> +{
> +	long ioret;
> +	struct efi_setvariable setvariable;
> +
> +	setvariable.VariableName = variablenametest;
> +	setvariable.VendorGuid = guid;
> +	setvariable.Attributes = attributes;
> +	setvariable.DataSize = datasize;
> +	setvariable.Data = data;
> +	setvariable.status = status;
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	return ioret;
> +}
> +
> +static long getvar(
> +	EFI_GUID *guid,
> +	uint32_t *attributestest,
> +	uint64_t *getdatasize,
> +	void *data,
> +	uint64_t *status)
> +{
> +	long ioret;
> +	struct efi_getvariable getvariable;
> +
> +	getvariable.VariableName = variablenametest;
> +	getvariable.VendorGuid = guid;
> +	getvariable.Attributes = attributestest;
> +	getvariable.DataSize = getdatasize;
> +	getvariable.Data = data;
> +	getvariable.status = status;
> +	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
> +
> +	return ioret;
> +}
> +
> +static int uefirtauthvar_init(fwts_framework *fw)
> +{
> +	if (fwts_firmware_detect() != FWTS_FIRMWARE_UEFI) {
> +		fwts_log_info(fw, "Cannot detect any UEFI firmware. Aborted.");
> +		return FWTS_ABORTED;
> +	}
> +
> +	if (fwts_lib_efi_runtime_load_module(fw) != FWTS_OK) {
> +		fwts_log_info(fw, "Cannot load efi_runtime module. Aborted.");
> +		return FWTS_ABORTED;
> +	}
> +
> +	fd = open("/dev/efi_runtime", O_RDONLY);

I guess since we're just doing ioctl() calls on this fd O_RDONLY is
fine.  Using O_WRONLY | O_RDWR may be preferred since it allows just
ioctl() calls and NO accidental read or writes to the device.

http://smackerelofopinion.blogspot.co.uk/2012/01/open-using-owronly-ordwr.html

> +	if (fd == -1) {
> +		fwts_log_info(fw, "Cannot open efi_runtime driver. Aborted.");
> +		return FWTS_ABORTED;
> +	}
> +
> +	return FWTS_OK;
> +}
> +
> +static int uefirtauthvar_deinit(fwts_framework *fw)
> +{
> +	close(fd);
> +	fwts_lib_efi_runtime_unload_module(fw);
> +
> +	return FWTS_OK;
> +}
> +
> +static int check_fw_support(fwts_framework *fw, uint64_t status)
> +{
> +	if ((status == EFI_INVALID_PARAMETER) &&
> +		((attributes & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ||
> +		(attributes & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) ||
> +		(attributes & FWTS_UEFI_VARIABLE_APPEND_WRITE))) {
> +		fwts_uefi_print_status_info(fw, status);
> +		fwts_skipped(fw,
> +			"EFI_INVALID_PARAMETER shall be returned, "
> +			"when firmware doesn't support these operations "
> +			"with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, "
> +			"EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS "
> +			"or EFI_VARIABLE_APPEND_WRITE attributes is set.");
> +		return FWTS_SKIP;
> +	}
> +	if (status == EFI_OUT_OF_RESOURCES) {
> +		fwts_uefi_print_status_info(fw, status);
> +		fwts_skipped(fw,
> +			"Run out of resources for SetVariable "
> +			"UEFI runtime interface: cannot test.");
> +		fwts_advice(fw,
> +			"Firmware may reclaim some resources "
> +			"after rebooting. Reboot and test "
> +			"again may be helpful to continue "
> +			"the test.");
> +		return FWTS_SKIP;
> +	}
> +	return FWTS_OK;
> +}
> +
> +/*
> + * Set the created authenticated variable, AuthVarCreate,
> + * and checking the data size and data.
> + * expect EFI_SUCCESS returned.
> + */
> +static int uefirtauthvar_test1(fwts_framework *fw)
> +{
> +	long ioret;
> +
> +	uint8_t data[getvar_buf_size];
> +	uint64_t getdatasize = sizeof(data);
> +	uint64_t status;
> +	uint32_t attributestest;
> +	size_t i;
> +	int supcheck;
> +
> +	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);
> +
> +	if (ioret == -1) {
> +		supcheck = check_fw_support(fw, status);
> +		if (supcheck != FWTS_OK)
> +			return supcheck;
> +
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"UEFICreateAuthVar",
> +			"Failed to create authenticated variable with UEFI "
> +			"runtime service.");
> +
> +		fwts_uefi_print_status_info(fw, status);
> +		return FWTS_ERROR;
> +	}
> +
> +	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"UEFICreateAuthVar",
> +			"Failed to get authenticated variable with UEFI "
> +			"runtime service.");
> +		fwts_uefi_print_status_info(fw, status);
> +		return FWTS_ERROR;
> +	}
> +	if (getdatasize != sizeof(AuthVarCreateData)) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"UEFICreateAuthVar",
> +			"Get authenticated variable data size is not the "
> +			"same as it set.");
> +	}
> +	for (i = 0; i < sizeof(AuthVarCreateData); i++) {
> +		if (data[i] != AuthVarCreateData[i]) {
> +			fwts_failed(fw, LOG_LEVEL_HIGH,
> +			"UEFICreateAuthVar",
> +			"Get authenticated variable data are not the "
> +			"same as it set.");
> +			return FWTS_ERROR;
> +		}
> +	}
> +
> +	fwts_passed(fw, "Create authenticated variable test passed.");
> +
> +	return FWTS_OK;
> +}
> +
> +static fwts_framework_minor_test uefirtauthvar_tests[] = {
> +	{ uefirtauthvar_test1, "Create authenticated variable test." },
> +	{ NULL, NULL }
> +};
> +
> +static fwts_framework_ops uefirtauthvar_ops = {
> +	.description     = "Authenticated variable tests.",
> +	.init            = uefirtauthvar_init,
> +	.deinit          = uefirtauthvar_deinit,
> +	.minor_tests     = uefirtauthvar_tests,
> +};
> +
> +FWTS_REGISTER("uefirtauthvar", &uefirtauthvar_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_TEST_UEFI | FWTS_FLAG_UNSAFE | FWTS_FLAG_ROOT_PRIV)
>
Ivan Hu Oct. 23, 2014, 5:39 a.m. UTC | #2
On 10/22/2014 11:59 PM, Colin Ian King wrote:
> On 22/10/14 10:36, Ivan Hu wrote:
>> This test checks the setvariable with the new authenticated variable which
>> created with TIME_BASED_AUTHENTICATED, i.e. EFI_VARIABLE_AUTHENTICATION_2
>> descriptor(UEFI spec. 7.2.1.). It also checks the data content after variable
>> was successfully created.
>>
>> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
>> ---
>>   src/Makefile.am                        |    3 +-
>>   src/uefi/uefirtauthvar/authvardefs.h   |  148 +++++++++++++++++++++
>>   src/uefi/uefirtauthvar/uefirtauthvar.c |  223 ++++++++++++++++++++++++++++++++
>>   3 files changed, 373 insertions(+), 1 deletion(-)
>>   create mode 100644 src/uefi/uefirtauthvar/authvardefs.h
>>   create mode 100644 src/uefi/uefirtauthvar/uefirtauthvar.c
>>
>> diff --git a/src/Makefile.am b/src/Makefile.am
>> index d472d5c..db367a0 100644
>> --- a/src/Makefile.am
>> +++ b/src/Makefile.am
>> @@ -91,7 +91,8 @@ fwts_SOURCES = main.c 				\
>>   	uefi/uefirtmisc/uefirtmisc.c		\
>>   	uefi/securebootcert/securebootcert.c	\
>>   	uefi/uefivarinfo/uefivarinfo.c		\
>> -	uefi/uefibootpath/uefibootpath.c
>> +	uefi/uefibootpath/uefibootpath.c	\
>> +	uefi/uefirtauthvar/uefirtauthvar.c
>>
>>   fwts_LDFLAGS = -lm `pkg-config --libs glib-2.0 gio-2.0`
>>
>> diff --git a/src/uefi/uefirtauthvar/authvardefs.h b/src/uefi/uefirtauthvar/authvardefs.h
>> new file mode 100644
>> index 0000000..d74a018
>> --- /dev/null
>> +++ b/src/uefi/uefirtauthvar/authvardefs.h
>> @@ -0,0 +1,148 @@
>> +/*
>> + * Copyright (C) 2014 Canonical
>> + *
>> + * 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.
>> + *
>> + */
>> +
>> +#ifndef __AUTH_VAR_DEF_H__
>> +#define __AUTH_VAR_DEF_H__
>> +
>> +/*
>> + * AuthVarCreate,
>> + * timestamp: 2014.09.08:03:41:15
>> + * GUID: 7f5c5d52-2f14-4f12-967cdb60db05a0fd
>> + * attributes = UEFI_VAR_NON_VOLATILE, UEFI_VAR_BOOTSERVICE_ACCESS,
>> + *		UEFI_VAR_RUNTIME_ACCESS, UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
>> + * Variable name: AuthVarTest
>> + * data content: 1234567890abcdef
>> + */
>> +static uint8_t AuthVarCreate[] = {
>> +	0xde, 0x07, 0x09, 0x08, 0x03, 0x29, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
>> +	0x00, 0x00, 0x00, 0x00, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x02, 0xf1, 0x0e,
>> +	0x9d, 0xd2, 0xaf, 0x4a, 0xdf, 0x68, 0xee, 0x49, 0x8a, 0xa9, 0x34, 0x7d,
>> +	0x37, 0x56, 0x65, 0xa7, 0x30, 0x82, 0x04, 0xef, 0x06, 0x09, 0x2a, 0x86,
>> +	0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x04, 0xe0, 0x30,
>> +	0x82, 0x04, 0xdc, 0x02, 0x01, 0x01, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x09,
>> +	0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x30,
>> +	0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01,
>> +	0xa0, 0x82, 0x02, 0xfd, 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1,
>> +	0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xbb, 0x94, 0x92, 0x5f,
>> +	0x3b, 0x5e, 0xd3, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
>> +	0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x13, 0x31, 0x11, 0x30,
>> +	0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x74, 0x65, 0x73, 0x74,
>> +	0x2d, 0x6b, 0x65, 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x38,
>> +	0x31, 0x32, 0x31, 0x30, 0x32, 0x31, 0x33, 0x30, 0x5a, 0x17, 0x0d, 0x31,
>> +	0x34, 0x30, 0x39, 0x31, 0x31, 0x31, 0x30, 0x32, 0x31, 0x33, 0x30, 0x5a,
>> +	0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
>> +	0x08, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x6b, 0x65, 0x79, 0x30, 0x82, 0x01,
>> +	0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
>> +	0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01,
>> +	0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe5, 0xbf, 0x24, 0xb1, 0x10, 0x46,
>> +	0x55, 0xad, 0x70, 0x77, 0x14, 0xc3, 0x1b, 0x55, 0xa0, 0x72, 0xfa, 0x3c,
>> +	0x3c, 0x44, 0x3e, 0xc3, 0xd7, 0xfa, 0x05, 0x94, 0xeb, 0x70, 0x6a, 0xe3,
>> +	0x47, 0x58, 0xb5, 0xab, 0x83, 0x6e, 0x7a, 0x43, 0xdd, 0x51, 0x9a, 0x31,
>> +	0x4a, 0x4a, 0x4f, 0xf0, 0x65, 0xfe, 0xae, 0x10, 0x30, 0xf8, 0xaa, 0x69,
>> +	0x54, 0xaf, 0xff, 0x4b, 0x3d, 0x48, 0x5d, 0x09, 0x9c, 0x94, 0x87, 0x3a,
>> +	0xf6, 0x56, 0xeb, 0xb6, 0x80, 0x07, 0x77, 0x1e, 0x92, 0x8b, 0x19, 0xc3,
>> +	0xa6, 0x8b, 0x4b, 0x0f, 0x60, 0x8f, 0x88, 0xca, 0x89, 0x41, 0x1d, 0x18,
>> +	0xb6, 0xde, 0x16, 0x75, 0xaa, 0xaa, 0xa7, 0xba, 0x88, 0xbd, 0x0f, 0x62,
>> +	0x27, 0x7e, 0xe1, 0x11, 0x67, 0x6a, 0xf2, 0x8a, 0xd9, 0xf0, 0xc2, 0x56,
>> +	0x60, 0x7f, 0xfd, 0xd7, 0x62, 0x71, 0x75, 0x8f, 0x09, 0xf8, 0x52, 0x37,
>> +	0xc9, 0xf2, 0xef, 0x56, 0xd5, 0x81, 0x95, 0xb3, 0x7f, 0xd9, 0xcc, 0xf4,
>> +	0xbc, 0xd0, 0x5e, 0x8c, 0x8b, 0x78, 0x14, 0x2a, 0xe0, 0x3d, 0xc5, 0xd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 0xc6, 0xe7, 0xd5, 0xb6, 0x4e, 0x30,
>> +	0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01,
>> +	0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
>> +	0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xb2, 0x28, 0xe3,
>> +	0x94, 0x02, 0x6f, 0xe5, 0x2a, 0xdc, 0x29, 0x7d, 0xcf, 0x2b, 0x88, 0x09,
>> +	0x4f, 0x73, 0x8a, 0xc3, 0x54, 0xfc, 0xa3, 0x40, 0x84, 0x82, 0xce, 0x32,
>> +	0x8d, 0x75, 0x51, 0xa2, 0xc3, 0x3f, 0x01, 0x0f, 0xde, 0x1b, 0x1f, 0x48,
>> +	0xdb, 0x8f, 0xf9, 0xe0, 0xf3, 0x23, 0x78, 0x17, 0x4a, 0x84, 0xbc, 0xf4,
>> +	0x84, 0xb5, 0xe5, 0x8c, 0x17, 0x36, 0x7f, 0x4f, 0x6f, 0x54, 0x47, 0xbd,
>> +	0xe6, 0x40, 0xb0, 0x8a, 0x73, 0x74, 0x65, 0x57, 0x98, 0xf6, 0x77, 0x58,
>> +	0x0e, 0x5f, 0x82, 0x77, 0xb3, 0xd9, 0x87, 0xf8, 0xe9, 0x21, 0x11, 0x37,
>> +	0x4c, 0x6e, 0x5f, 0xda, 0x1e, 0x81, 0xa6, 0xa3, 0x45, 0x09, 0x81, 0x26,
>> +	0xd0, 0xb6, 0xe1, 0x27, 0xa5, 0xc3, 0x6e, 0xed, 0x86, 0xb7, 0x4f, 0xf3,
>> +	0x7e, 0x34, 0xa5, 0x0b, 0x8a, 0xd1, 0x56, 0x65, 0x04, 0xe2, 0x16, 0x71,
>> +	0x11, 0xdc, 0xa8, 0xa6, 0xe0, 0x57, 0x91, 0x63, 0xe2, 0x9d, 0xe7, 0x86,
>> +	0x00, 0xa6, 0xb4, 0x75, 0xf3, 0x37, 0x63, 0x48, 0x41, 0xcd, 0x97, 0x12,
>> +	0x2e, 0x5c, 0xc0, 0xf0, 0x13, 0x62, 0x71, 0xc1, 0x8e, 0x65, 0x28, 0x52,
>> +	0x09, 0x71, 0x87, 0x33, 0x27, 0x77, 0x84, 0x2f, 0xb4, 0x9a, 0x0a, 0x62,
>> +	0xe6, 0x69, 0x05, 0xd7, 0x94, 0x70, 0x8a, 0xb9, 0x61, 0x68, 0xdb, 0xbd,
>> +	0x4b, 0x58, 0xd3, 0x74, 0x0e, 0x3e, 0x00, 0x6c, 0x64, 0x02, 0x22, 0x4f,
>> +	0x62, 0xbe, 0xe1, 0x53, 0x96, 0xa5, 0x6a, 0x7d, 0xf7, 0x8c, 0x77, 0x42,
>> +	0x49, 0xb3, 0xb0, 0x44, 0xf1, 0xa9, 0xd5, 0x64, 0xdf, 0xcc, 0x8b, 0x90,
>> +	0x03, 0x05, 0xb8, 0x07, 0x5f, 0x6e, 0x88, 0x11, 0x7e, 0x93, 0x85, 0xe6,
>> +	0x3c, 0x87, 0x92, 0x74, 0xbb, 0xfe, 0x01, 0x32, 0xe8, 0x0b, 0xa9, 0xab,
>> +	0x15, 0xd4, 0x8a, 0x4f, 0xd7, 0x40, 0x12, 0xe1, 0xde, 0x8a, 0xa8, 0x7c,
>> +	0xf5, 0x31, 0x82, 0x01, 0xb6, 0x30, 0x82, 0x01, 0xb2, 0x02, 0x01, 0x01,
>> +	0x30, 0x20, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04,
>> +	0x03, 0x0c, 0x08, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x6b, 0x65, 0x79, 0x02,
>> +	0x09, 0x00, 0xbb, 0x94, 0x92, 0x5f, 0x3b, 0x5e, 0xd3, 0x2d, 0x30, 0x0d,
>> +	0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
>> +	0x00, 0xa0, 0x69, 0x30, 0x18, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
>> +	0x0d, 0x01, 0x09, 0x03, 0x31, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
>> +	0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x09, 0x2a, 0x86, 0x48,
>> +	0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05, 0x31, 0x0f, 0x17, 0x0d, 0x31, 0x34,
>> +	0x31, 0x30, 0x30, 0x38, 0x30, 0x33, 0x34, 0x31, 0x31, 0x35, 0x5a, 0x30,
>> +	0x2f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04,
>> +	0x31, 0x22, 0x04, 0x20, 0x7d, 0x9f, 0x1b, 0x65, 0x76, 0x70, 0x66, 0xe3,
>> +	0xa0, 0x6a, 0x53, 0x01, 0xd9, 0xde, 0x6f, 0x6a, 0x88, 0xcb, 0x76, 0xb3,
>> +	0xf8, 0xd6, 0xc4, 0x45, 0x3a, 0x8f, 0x7b, 0x9d, 0x06, 0x50, 0xc6, 0x12,
>> +	0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
>> +	0x01, 0x05, 0x00, 0x04, 0x82, 0x01, 0x00, 0xb5, 0x61, 0x49, 0xea, 0xfc,
>> +	0xfe, 0x13, 0xfc, 0xd5, 0x92, 0x5a, 0xf5, 0x11, 0x88, 0x2a, 0xba, 0x0f,
>> +	0x3d, 0x3d, 0x56, 0x8a, 0x69, 0x2b, 0xcc, 0x3a, 0x95, 0x09, 0xb6, 0x06,
>> +	0xd9, 0x36, 0x17, 0x63, 0x40, 0xd7, 0xc8, 0x5a, 0xb3, 0xca, 0x2d, 0xd2,
>> +	0xea, 0xa0, 0x9a, 0x82, 0x04, 0x75, 0x66, 0xeb, 0x41, 0x9b, 0x1a, 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x3a, 0x25, 0xdf, 0xa2, 0xc6, 0xb2, 0x15, 0x18, 0x54,
>> +	0xbd, 0x51, 0xc1, 0x84, 0x62, 0x0f, 0x72, 0x8d, 0x67, 0xce, 0xe6, 0xbd,
>> +	0x6e, 0x21, 0x58, 0x1f, 0x77, 0xf4, 0xfc, 0x36, 0xf9, 0x0c, 0x1d, 0x31,
>> +	0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63,
>> +	0x64, 0x65, 0x66
>> +};
>> +
>> +static uint8_t AuthVarCreateData[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66};
>> +
>> +#endif
>
> Normally I don't like static data being #included as this can end up
> being included multiple times and end up bloating the code. However,
> since this is just isolated to this test, I'll let this through.
>
>
>> diff --git a/src/uefi/uefirtauthvar/uefirtauthvar.c b/src/uefi/uefirtauthvar/uefirtauthvar.c
>> new file mode 100644
>> index 0000000..bde760f
>> --- /dev/null
>> +++ b/src/uefi/uefirtauthvar/uefirtauthvar.c
>> @@ -0,0 +1,223 @@
>> +/*
>> + * Copyright (C) 2014 Canonical
>> + *
>> + * 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 <inttypes.h>
>> +#include <stdio.h>
>> +#include <stddef.h>
>> +#include <sys/ioctl.h>
>> +#include <fcntl.h>
>> +
>> +#include "fwts.h"
>> +#include "fwts_uefi.h"
>> +#include "efi_runtime.h"
>> +#include "fwts_efi_module.h"
>> +#include "authvardefs.h"
>> +
>> +static int fd;
>> +
>> +#define TEST_GUID {0x7f5c5d52, 0x2f14, 0x4f12, {0x96, 0x7c, 0xdb, 0x60, 0xdb, 0x05, 0xa0, 0xfd} }
>> +
>> +#define getvar_buf_size 100
>> +
>> +static EFI_GUID gtestguid = TEST_GUID;
>> +
>> +static uint32_t attributes =
>
> You could make that static const uint32_t attributes
>
>> +	FWTS_UEFI_VAR_NON_VOLATILE |
>> +	FWTS_UEFI_VAR_BOOTSERVICE_ACCESS |
>> +	FWTS_UEFI_VAR_RUNTIME_ACCESS |
>> +	FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
>> +
>> +static uint16_t variablenametest[] = {'A', 'u', 't', 'h', 'V', 'a', 'r', 'T', 'e', 's', 't', '\0'};
>> +
>> +static long setvar(
>> +	EFI_GUID *guid,
>> +	uint32_t attributes,
>> +	uint64_t datasize,
>> +	void *data,
>> +	uint64_t *status)
>> +{
>> +	long ioret;
>> +	struct efi_setvariable setvariable;
>> +
>> +	setvariable.VariableName = variablenametest;
>> +	setvariable.VendorGuid = guid;
>> +	setvariable.Attributes = attributes;
>> +	setvariable.DataSize = datasize;
>> +	setvariable.Data = data;
>> +	setvariable.status = status;
>> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
>> +
>> +	return ioret;
>> +}
>> +
>> +static long getvar(
>> +	EFI_GUID *guid,
>> +	uint32_t *attributestest,
>> +	uint64_t *getdatasize,
>> +	void *data,
>> +	uint64_t *status)
>> +{
>> +	long ioret;
>> +	struct efi_getvariable getvariable;
>> +
>> +	getvariable.VariableName = variablenametest;
>> +	getvariable.VendorGuid = guid;
>> +	getvariable.Attributes = attributestest;
>> +	getvariable.DataSize = getdatasize;
>> +	getvariable.Data = data;
>> +	getvariable.status = status;
>> +	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
>> +
>> +	return ioret;
>> +}
>> +
>> +static int uefirtauthvar_init(fwts_framework *fw)
>> +{
>> +	if (fwts_firmware_detect() != FWTS_FIRMWARE_UEFI) {
>> +		fwts_log_info(fw, "Cannot detect any UEFI firmware. Aborted.");
>> +		return FWTS_ABORTED;
>> +	}
>> +
>> +	if (fwts_lib_efi_runtime_load_module(fw) != FWTS_OK) {
>> +		fwts_log_info(fw, "Cannot load efi_runtime module. Aborted.");
>> +		return FWTS_ABORTED;
>> +	}
>> +
>> +	fd = open("/dev/efi_runtime", O_RDONLY);
>
> I guess since we're just doing ioctl() calls on this fd O_RDONLY is
> fine.  Using O_WRONLY | O_RDWR may be preferred since it allows just
> ioctl() calls and NO accidental read or writes to the device.
>
> http://smackerelofopinion.blogspot.co.uk/2012/01/open-using-owronly-ordwr.html
>
Thanks for the info! Colin,
I'll send out a new patch for this. And I will also send out a fix patch 
for the other UEFI tests.

Ivan

>> +	if (fd == -1) {
>> +		fwts_log_info(fw, "Cannot open efi_runtime driver. Aborted.");
>> +		return FWTS_ABORTED;
>> +	}
>> +
>> +	return FWTS_OK;
>> +}
>> +
>> +static int uefirtauthvar_deinit(fwts_framework *fw)
>> +{
>> +	close(fd);
>> +	fwts_lib_efi_runtime_unload_module(fw);
>> +
>> +	return FWTS_OK;
>> +}
>> +
>> +static int check_fw_support(fwts_framework *fw, uint64_t status)
>> +{
>> +	if ((status == EFI_INVALID_PARAMETER) &&
>> +		((attributes & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ||
>> +		(attributes & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) ||
>> +		(attributes & FWTS_UEFI_VARIABLE_APPEND_WRITE))) {
>> +		fwts_uefi_print_status_info(fw, status);
>> +		fwts_skipped(fw,
>> +			"EFI_INVALID_PARAMETER shall be returned, "
>> +			"when firmware doesn't support these operations "
>> +			"with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, "
>> +			"EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS "
>> +			"or EFI_VARIABLE_APPEND_WRITE attributes is set.");
>> +		return FWTS_SKIP;
>> +	}
>> +	if (status == EFI_OUT_OF_RESOURCES) {
>> +		fwts_uefi_print_status_info(fw, status);
>> +		fwts_skipped(fw,
>> +			"Run out of resources for SetVariable "
>> +			"UEFI runtime interface: cannot test.");
>> +		fwts_advice(fw,
>> +			"Firmware may reclaim some resources "
>> +			"after rebooting. Reboot and test "
>> +			"again may be helpful to continue "
>> +			"the test.");
>> +		return FWTS_SKIP;
>> +	}
>> +	return FWTS_OK;
>> +}
>> +
>> +/*
>> + * Set the created authenticated variable, AuthVarCreate,
>> + * and checking the data size and data.
>> + * expect EFI_SUCCESS returned.
>> + */
>> +static int uefirtauthvar_test1(fwts_framework *fw)
>> +{
>> +	long ioret;
>> +
>> +	uint8_t data[getvar_buf_size];
>> +	uint64_t getdatasize = sizeof(data);
>> +	uint64_t status;
>> +	uint32_t attributestest;
>> +	size_t i;
>> +	int supcheck;
>> +
>> +	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);
>> +
>> +	if (ioret == -1) {
>> +		supcheck = check_fw_support(fw, status);
>> +		if (supcheck != FWTS_OK)
>> +			return supcheck;
>> +
>> +		fwts_failed(fw, LOG_LEVEL_HIGH,
>> +			"UEFICreateAuthVar",
>> +			"Failed to create authenticated variable with UEFI "
>> +			"runtime service.");
>> +
>> +		fwts_uefi_print_status_info(fw, status);
>> +		return FWTS_ERROR;
>> +	}
>> +
>> +	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
>> +	if (ioret == -1) {
>> +		fwts_failed(fw, LOG_LEVEL_HIGH,
>> +			"UEFICreateAuthVar",
>> +			"Failed to get authenticated variable with UEFI "
>> +			"runtime service.");
>> +		fwts_uefi_print_status_info(fw, status);
>> +		return FWTS_ERROR;
>> +	}
>> +	if (getdatasize != sizeof(AuthVarCreateData)) {
>> +		fwts_failed(fw, LOG_LEVEL_HIGH,
>> +			"UEFICreateAuthVar",
>> +			"Get authenticated variable data size is not the "
>> +			"same as it set.");
>> +	}
>> +	for (i = 0; i < sizeof(AuthVarCreateData); i++) {
>> +		if (data[i] != AuthVarCreateData[i]) {
>> +			fwts_failed(fw, LOG_LEVEL_HIGH,
>> +			"UEFICreateAuthVar",
>> +			"Get authenticated variable data are not the "
>> +			"same as it set.");
>> +			return FWTS_ERROR;
>> +		}
>> +	}
>> +
>> +	fwts_passed(fw, "Create authenticated variable test passed.");
>> +
>> +	return FWTS_OK;
>> +}
>> +
>> +static fwts_framework_minor_test uefirtauthvar_tests[] = {
>> +	{ uefirtauthvar_test1, "Create authenticated variable test." },
>> +	{ NULL, NULL }
>> +};
>> +
>> +static fwts_framework_ops uefirtauthvar_ops = {
>> +	.description     = "Authenticated variable tests.",
>> +	.init            = uefirtauthvar_init,
>> +	.deinit          = uefirtauthvar_deinit,
>> +	.minor_tests     = uefirtauthvar_tests,
>> +};
>> +
>> +FWTS_REGISTER("uefirtauthvar", &uefirtauthvar_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_TEST_UEFI | FWTS_FLAG_UNSAFE | FWTS_FLAG_ROOT_PRIV)
>>
>
>
diff mbox

Patch

diff --git a/src/Makefile.am b/src/Makefile.am
index d472d5c..db367a0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -91,7 +91,8 @@  fwts_SOURCES = main.c 				\
 	uefi/uefirtmisc/uefirtmisc.c		\
 	uefi/securebootcert/securebootcert.c	\
 	uefi/uefivarinfo/uefivarinfo.c		\
-	uefi/uefibootpath/uefibootpath.c
+	uefi/uefibootpath/uefibootpath.c	\
+	uefi/uefirtauthvar/uefirtauthvar.c
 
 fwts_LDFLAGS = -lm `pkg-config --libs glib-2.0 gio-2.0`
 
diff --git a/src/uefi/uefirtauthvar/authvardefs.h b/src/uefi/uefirtauthvar/authvardefs.h
new file mode 100644
index 0000000..d74a018
--- /dev/null
+++ b/src/uefi/uefirtauthvar/authvardefs.h
@@ -0,0 +1,148 @@ 
+/*
+ * Copyright (C) 2014 Canonical
+ *
+ * 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.
+ *
+ */
+
+#ifndef __AUTH_VAR_DEF_H__
+#define __AUTH_VAR_DEF_H__
+
+/*
+ * AuthVarCreate,
+ * timestamp: 2014.09.08:03:41:15
+ * GUID: 7f5c5d52-2f14-4f12-967cdb60db05a0fd
+ * attributes = UEFI_VAR_NON_VOLATILE, UEFI_VAR_BOOTSERVICE_ACCESS,
+ *		UEFI_VAR_RUNTIME_ACCESS, UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
+ * Variable name: AuthVarTest
+ * data content: 1234567890abcdef
+ */
+static uint8_t AuthVarCreate[] = {
+	0xde, 0x07, 0x09, 0x08, 0x03, 0x29, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x0b, 0x05, 0x00, 0x00, 0x00, 0x02, 0xf1, 0x0e,
+	0x9d, 0xd2, 0xaf, 0x4a, 0xdf, 0x68, 0xee, 0x49, 0x8a, 0xa9, 0x34, 0x7d,
+	0x37, 0x56, 0x65, 0xa7, 0x30, 0x82, 0x04, 0xef, 0x06, 0x09, 0x2a, 0x86,
+	0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x82, 0x04, 0xe0, 0x30,
+	0x82, 0x04, 0xdc, 0x02, 0x01, 0x01, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x09,
+	0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x30,
+	0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01,
+	0xa0, 0x82, 0x02, 0xfd, 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1,
+	0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xbb, 0x94, 0x92, 0x5f,
+	0x3b, 0x5e, 0xd3, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+	0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x13, 0x31, 0x11, 0x30,
+	0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x74, 0x65, 0x73, 0x74,
+	0x2d, 0x6b, 0x65, 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x38,
+	0x31, 0x32, 0x31, 0x30, 0x32, 0x31, 0x33, 0x30, 0x5a, 0x17, 0x0d, 0x31,
+	0x34, 0x30, 0x39, 0x31, 0x31, 0x31, 0x30, 0x32, 0x31, 0x33, 0x30, 0x5a,
+	0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
+	0x08, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x6b, 0x65, 0x79, 0x30, 0x82, 0x01,
+	0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
+	0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01,
+	0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe5, 0xbf, 0x24, 0xb1, 0x10, 0x46,
+	0x55, 0xad, 0x70, 0x77, 0x14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 0x3e, 0x00, 0x6c, 0x64, 0x02, 0x22, 0x4f,
+	0x62, 0xbe, 0xe1, 0x53, 0x96, 0xa5, 0x6a, 0x7d, 0xf7, 0x8c, 0x77, 0x42,
+	0x49, 0xb3, 0xb0, 0x44, 0xf1, 0xa9, 0xd5, 0x64, 0xdf, 0xcc, 0x8b, 0x90,
+	0x03, 0x05, 0xb8, 0x07, 0x5f, 0x6e, 0x88, 0x11, 0x7e, 0x93, 0x85, 0xe6,
+	0x3c, 0x87, 0x92, 0x74, 0xbb, 0xfe, 0x01, 0x32, 0xe8, 0x0b, 0xa9, 0xab,
+	0x15, 0xd4, 0x8a, 0x4f, 0xd7, 0x40, 0x12, 0xe1, 0xde, 0x8a, 0xa8, 0x7c,
+	0xf5, 0x31, 0x82, 0x01, 0xb6, 0x30, 0x82, 0x01, 0xb2, 0x02, 0x01, 0x01,
+	0x30, 0x20, 0x30, 0x13, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04,
+	0x03, 0x0c, 0x08, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x6b, 0x65, 0x79, 0x02,
+	0x09, 0x00, 0xbb, 0x94, 0x92, 0x5f, 0x3b, 0x5e, 0xd3, 0x2d, 0x30, 0x0d,
+	0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
+	0x00, 0xa0, 0x69, 0x30, 0x18, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
+	0x0d, 0x01, 0x09, 0x03, 0x31, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+	0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x09, 0x2a, 0x86, 0x48,
+	0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05, 0x31, 0x0f, 0x17, 0x0d, 0x31, 0x34,
+	0x31, 0x30, 0x30, 0x38, 0x30, 0x33, 0x34, 0x31, 0x31, 0x35, 0x5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c0,
+	0x79, 0x61, 0xfb, 0xa2, 0xf4, 0xf7, 0x3c, 0xa1, 0xb7, 0x1b, 0x68, 0x56,
+	0x5c, 0x04, 0x74, 0x97, 0xdc, 0xf5, 0x3e, 0x07, 0x93, 0xd5, 0x43, 0xb7,
+	0x36, 0xb9, 0xc9, 0xc8, 0x65, 0x4c, 0x24, 0xce, 0x58, 0x6d, 0x9e, 0x60,
+	0x54, 0x10, 0x6c, 0xb5, 0x4e, 0xbe, 0x47, 0x9b, 0xef, 0x31, 0xa1, 0xdc,
+	0x0c, 0x84, 0xe5, 0xff, 0xd2, 0xdd, 0x2d, 0x8e, 0xa1, 0x7e, 0x9f, 0x02,
+	0x98, 0x46, 0x1a, 0x7f, 0x6e, 0x4f, 0x70, 0x68, 0x4a, 0x1d, 0xa7, 0x9c,
+	0x0e, 0x1d, 0x42, 0xaf, 0x6f, 0x0f, 0x6d, 0x8f, 0x91, 0x69, 0x6a, 0xff,
+	0x73, 0x86, 0xc6, 0xc3, 0x24, 0x7d, 0x60, 0x67, 0xb4, 0xae, 0xa8, 0xb4,
+	0x19, 0xba, 0x7a, 0x61, 0xc9, 0xad, 0xcc, 0xcf, 0x9f, 0xfe, 0x13, 0x1e,
+	0xc3, 0x2c, 0xfd, 0x3a, 0x25, 0xdf, 0xa2, 0xc6, 0xb2, 0x15, 0x18, 0x54,
+	0xbd, 0x51, 0xc1, 0x84, 0x62, 0x0f, 0x72, 0x8d, 0x67, 0xce, 0xe6, 0xbd,
+	0x6e, 0x21, 0x58, 0x1f, 0x77, 0xf4, 0xfc, 0x36, 0xf9, 0x0c, 0x1d, 0x31,
+	0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63,
+	0x64, 0x65, 0x66
+};
+
+static uint8_t AuthVarCreateData[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66};
+
+#endif
diff --git a/src/uefi/uefirtauthvar/uefirtauthvar.c b/src/uefi/uefirtauthvar/uefirtauthvar.c
new file mode 100644
index 0000000..bde760f
--- /dev/null
+++ b/src/uefi/uefirtauthvar/uefirtauthvar.c
@@ -0,0 +1,223 @@ 
+/*
+ * Copyright (C) 2014 Canonical
+ *
+ * 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 <inttypes.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+
+#include "fwts.h"
+#include "fwts_uefi.h"
+#include "efi_runtime.h"
+#include "fwts_efi_module.h"
+#include "authvardefs.h"
+
+static int fd;
+
+#define TEST_GUID {0x7f5c5d52, 0x2f14, 0x4f12, {0x96, 0x7c, 0xdb, 0x60, 0xdb, 0x05, 0xa0, 0xfd} }
+
+#define getvar_buf_size 100
+
+static EFI_GUID gtestguid = TEST_GUID;
+
+static uint32_t attributes =
+	FWTS_UEFI_VAR_NON_VOLATILE |
+	FWTS_UEFI_VAR_BOOTSERVICE_ACCESS |
+	FWTS_UEFI_VAR_RUNTIME_ACCESS |
+	FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
+
+static uint16_t variablenametest[] = {'A', 'u', 't', 'h', 'V', 'a', 'r', 'T', 'e', 's', 't', '\0'};
+
+static long setvar(
+	EFI_GUID *guid,
+	uint32_t attributes,
+	uint64_t datasize,
+	void *data,
+	uint64_t *status)
+{
+	long ioret;
+	struct efi_setvariable setvariable;
+
+	setvariable.VariableName = variablenametest;
+	setvariable.VendorGuid = guid;
+	setvariable.Attributes = attributes;
+	setvariable.DataSize = datasize;
+	setvariable.Data = data;
+	setvariable.status = status;
+	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	return ioret;
+}
+
+static long getvar(
+	EFI_GUID *guid,
+	uint32_t *attributestest,
+	uint64_t *getdatasize,
+	void *data,
+	uint64_t *status)
+{
+	long ioret;
+	struct efi_getvariable getvariable;
+
+	getvariable.VariableName = variablenametest;
+	getvariable.VendorGuid = guid;
+	getvariable.Attributes = attributestest;
+	getvariable.DataSize = getdatasize;
+	getvariable.Data = data;
+	getvariable.status = status;
+	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
+
+	return ioret;
+}
+
+static int uefirtauthvar_init(fwts_framework *fw)
+{
+	if (fwts_firmware_detect() != FWTS_FIRMWARE_UEFI) {
+		fwts_log_info(fw, "Cannot detect any UEFI firmware. Aborted.");
+		return FWTS_ABORTED;
+	}
+
+	if (fwts_lib_efi_runtime_load_module(fw) != FWTS_OK) {
+		fwts_log_info(fw, "Cannot load efi_runtime module. Aborted.");
+		return FWTS_ABORTED;
+	}
+
+	fd = open("/dev/efi_runtime", O_RDONLY);
+	if (fd == -1) {
+		fwts_log_info(fw, "Cannot open efi_runtime driver. Aborted.");
+		return FWTS_ABORTED;
+	}
+
+	return FWTS_OK;
+}
+
+static int uefirtauthvar_deinit(fwts_framework *fw)
+{
+	close(fd);
+	fwts_lib_efi_runtime_unload_module(fw);
+
+	return FWTS_OK;
+}
+
+static int check_fw_support(fwts_framework *fw, uint64_t status)
+{
+	if ((status == EFI_INVALID_PARAMETER) &&
+		((attributes & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) ||
+		(attributes & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) ||
+		(attributes & FWTS_UEFI_VARIABLE_APPEND_WRITE))) {
+		fwts_uefi_print_status_info(fw, status);
+		fwts_skipped(fw,
+			"EFI_INVALID_PARAMETER shall be returned, "
+			"when firmware doesn't support these operations "
+			"with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, "
+			"EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS "
+			"or EFI_VARIABLE_APPEND_WRITE attributes is set.");
+		return FWTS_SKIP;
+	}
+	if (status == EFI_OUT_OF_RESOURCES) {
+		fwts_uefi_print_status_info(fw, status);
+		fwts_skipped(fw,
+			"Run out of resources for SetVariable "
+			"UEFI runtime interface: cannot test.");
+		fwts_advice(fw,
+			"Firmware may reclaim some resources "
+			"after rebooting. Reboot and test "
+			"again may be helpful to continue "
+			"the test.");
+		return FWTS_SKIP;
+	}
+	return FWTS_OK;
+}
+
+/*
+ * Set the created authenticated variable, AuthVarCreate,
+ * and checking the data size and data.
+ * expect EFI_SUCCESS returned.
+ */
+static int uefirtauthvar_test1(fwts_framework *fw)
+{
+	long ioret;
+
+	uint8_t data[getvar_buf_size];
+	uint64_t getdatasize = sizeof(data);
+	uint64_t status;
+	uint32_t attributestest;
+	size_t i;
+	int supcheck;
+
+	ioret = setvar(&gtestguid, attributes, sizeof(AuthVarCreate), AuthVarCreate, &status);
+
+	if (ioret == -1) {
+		supcheck = check_fw_support(fw, status);
+		if (supcheck != FWTS_OK)
+			return supcheck;
+
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			"UEFICreateAuthVar",
+			"Failed to create authenticated variable with UEFI "
+			"runtime service.");
+
+		fwts_uefi_print_status_info(fw, status);
+		return FWTS_ERROR;
+	}
+
+	ioret = getvar(&gtestguid, &attributestest, &getdatasize, data, &status);
+	if (ioret == -1) {
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			"UEFICreateAuthVar",
+			"Failed to get authenticated variable with UEFI "
+			"runtime service.");
+		fwts_uefi_print_status_info(fw, status);
+		return FWTS_ERROR;
+	}
+	if (getdatasize != sizeof(AuthVarCreateData)) {
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			"UEFICreateAuthVar",
+			"Get authenticated variable data size is not the "
+			"same as it set.");
+	}
+	for (i = 0; i < sizeof(AuthVarCreateData); i++) {
+		if (data[i] != AuthVarCreateData[i]) {
+			fwts_failed(fw, LOG_LEVEL_HIGH,
+			"UEFICreateAuthVar",
+			"Get authenticated variable data are not the "
+			"same as it set.");
+			return FWTS_ERROR;
+		}
+	}
+
+	fwts_passed(fw, "Create authenticated variable test passed.");
+
+	return FWTS_OK;
+}
+
+static fwts_framework_minor_test uefirtauthvar_tests[] = {
+	{ uefirtauthvar_test1, "Create authenticated variable test." },
+	{ NULL, NULL }
+};
+
+static fwts_framework_ops uefirtauthvar_ops = {
+	.description     = "Authenticated variable tests.",
+	.init            = uefirtauthvar_init,
+	.deinit          = uefirtauthvar_deinit,
+	.minor_tests     = uefirtauthvar_tests,
+};
+
+FWTS_REGISTER("uefirtauthvar", &uefirtauthvar_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_TEST_UEFI | FWTS_FLAG_UNSAFE | FWTS_FLAG_ROOT_PRIV)