Skip to content

Commit

Permalink
improve fix for GH #28 (measuring of compressed files)
Browse files Browse the repository at this point in the history
  • Loading branch information
neusdan committed Jan 1, 2016
1 parent 8b2b65b commit 422617f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 85 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ support to GRUB2.
* grub-core/kern/dl.c
* grub-core/kern/i386/pc/tpm/tpm_kern.c
* grub-core/kern/sha1.c
* grub-core/kern/file.c
* grub-core/disk/cryptodisk.c
* grub-core/disk/luks.c
* grub-core/loader/linux.c
Expand All @@ -276,7 +275,6 @@ support to GRUB2.
* include/grub/i386/pc/tpm.h
* include/grub/tpm.h
* include/grub/sha1.h
* include/grub/file.h
* util/mkimage.c

## 3. Thanks
Expand Down
72 changes: 0 additions & 72 deletions grub-core/kern/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,78 +143,6 @@ grub_file_open (const char *name)
return 0;
}


/* Begin TCG extension */
grub_file_t
grub_file_open_nofilter (const char *name)
{
grub_device_t device = 0;
grub_file_t file = 0;
char *device_name;
const char *file_name;

device_name = grub_file_get_device_name (name);
if (grub_errno)
goto fail;

/* Get the file part of NAME. */
file_name = (name[0] == '(') ? grub_strchr (name, ')') : NULL;
if (file_name)
file_name++;
else
file_name = name;

device = grub_device_open (device_name);
grub_free (device_name);
if (! device)
goto fail;

file = (grub_file_t) grub_zalloc (sizeof (*file));
if (! file)
goto fail;

file->device = device;

/* In case of relative pathnames and non-Unix systems (like Windows)
* name of host files may not start with `/'. Blocklists for host files
* are meaningless as well (for a start, host disk does not allow any direct
* access - it is just a marker). So skip host disk in this case.
*/
if (device->disk && file_name[0] != '/'
#if defined(GRUB_UTIL) || defined(GRUB_MACHINE_EMU)
&& grub_strcmp (device->disk->name, "host")
#endif
)
/* This is a block list. */
file->fs = &grub_fs_blocklist;
else
{
file->fs = grub_fs_probe (device);
if (! file->fs)
goto fail;
}

if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE)
goto fail;

file->name = grub_strdup (name);
grub_errno = GRUB_ERR_NONE;

return file;

fail:
if (device)
grub_device_close (device);

/* if (net) grub_net_close (net); */

grub_free (file);

return 0;
}
/* End TCG extension CUSTOM */


grub_disk_read_hook_t grub_file_progress_hook;

grub_ssize_t
Expand Down
6 changes: 4 additions & 2 deletions grub-core/kern/i386/pc/tpm/tpm_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ grub_TPM_measure_string( const char* string ) {
DEBUG_PRINT( ( "SHA1: " ) );
print_sha1( convertedResult );
DEBUG_PRINT( ( "\n" ) );
grub_sleep( 5 );
grub_sleep( 4 );
#endif

/* measure */
Expand All @@ -269,7 +269,9 @@ grub_TPM_measure_file( const char* filename, const unsigned long index ) {
CHECK_FOR_NULL_ARGUMENT( filename )

/* open file 'raw' (without any pre-processing filters) */
grub_file_t file = grub_file_open_nofilter( filename );
grub_file_filter_disable_compression ();
grub_file_t file = grub_file_open( filename );

if( ! file ) {
grub_print_error();
grub_fatal( "grub_TPM_measureFile: grub_file_open failed." );
Expand Down
9 changes: 0 additions & 9 deletions include/grub/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ char *EXPORT_FUNC(grub_file_get_device_name) (const char *name);

grub_file_t EXPORT_FUNC(grub_file_open) (const char *name);

/* Begin TCG extension */

/* Used for TPM file measurement */
/* grub_file_open is not suited for measurement because it does not necessarily return the same file that is stored on disk */
/* For example it decompresses compressed files automatically */
grub_file_t EXPORT_FUNC(grub_file_open_nofilter) (const char *name);

/* End TCG extension */

grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf,
grub_size_t len);
grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);
Expand Down

0 comments on commit 422617f

Please sign in to comment.