From 66b56f352827c3eba86d85e0dff795fefbf93e63 Mon Sep 17 00:00:00 2001 From: PartialVolume <22084881+PartialVolume@users.noreply.github.com> Date: Wed, 8 May 2024 23:06:10 +0100 Subject: [PATCH] Add additional error message for prng Prior to this update any error produced by the nwipe_random_verify() or nwipe_random_pass functions would be displayed in the GUI with a generic message "IOERROR", while the details of the error would be displayed in log file. With this patch the GUI now displayes "I/O ERROR" for any read/write errors, "PRNG ERROR" for all errors returned by the prng generators and "FAILURE" for any signal errors. The nwipe_random_verify() and nwipe_random_pass() functions previously only returned a -1 to indicate some failure. They now return -1 for read/write I/O errors and -2 for prng errors. Identifing a prng error will be particulary important for an upcoming commit related to the aes-ctr prng which calls external libraries. --- src/gui.c | 24 +++++++++++++++++++++--- src/pass.c | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/gui.c b/src/gui.c index 03776b66..490a4315 100644 --- a/src/gui.c +++ b/src/gui.c @@ -6598,9 +6598,27 @@ void* nwipe_gui_status( void* ptr ) } else { - wattron( main_window, COLOR_PAIR( 9 ) ); - mvwprintw( main_window, yy++, 4, "(>>> IOERROR! <<<, code %i) ", c[i]->result ); - wattroff( main_window, COLOR_PAIR( 9 ) ); + switch( c[i]->result ) + { + case -1: + wattron( main_window, COLOR_PAIR( 9 ) ); + mvwprintw( main_window, yy++, 4, "(>>> I/O ERROR! <<<, code %i) ", c[i]->result ); + wattroff( main_window, COLOR_PAIR( 9 ) ); + break; + + case -2: + wattron( main_window, COLOR_PAIR( 9 ) ); + mvwprintw( main_window, yy++, 4, "(>>> PRNG ERROR! <<<, code %i) ", c[i]->result ); + wattroff( main_window, COLOR_PAIR( 9 ) ); + break; + + default: + wattron( main_window, COLOR_PAIR( 9 ) ); + mvwprintw( + main_window, yy++, 4, "(>>> SANITY ERROR! <<<, code %i) ", c[i]->result ); + wattroff( main_window, COLOR_PAIR( 9 ) ); + break; + } } } /* child returned */ diff --git a/src/pass.c b/src/pass.c index fc48ac13..6a62f2a8 100644 --- a/src/pass.c +++ b/src/pass.c @@ -37,6 +37,10 @@ int nwipe_random_verify( nwipe_context_t* c ) /** * Verifies that a random pass was correctly written to the device. * + * returns: + * 0 = Success + * -1 = I/O error + * -2 = PRNG error */ /* The result holder. */ @@ -59,14 +63,14 @@ int nwipe_random_verify( nwipe_context_t* c ) if( c->prng_seed.s == NULL ) { - nwipe_log( NWIPE_LOG_SANITY, "Null seed pointer." ); - return -1; + nwipe_log( NWIPE_LOG_SANITY, "Null seed pointer on verification." ); + return -2; } if( c->prng_seed.length <= 0 ) { - nwipe_log( NWIPE_LOG_SANITY, "The entropy length member is %i.", c->prng_seed.length ); - return -1; + nwipe_log( NWIPE_LOG_SANITY, "On verification the entropy length member is %i.", c->prng_seed.length ); + return -2; } /* Create the input buffer. */ @@ -133,7 +137,11 @@ int nwipe_random_verify( nwipe_context_t* c ) } /* Reseed the PRNG. */ - c->prng->init( &c->prng_state, &c->prng_seed ); + if( c->prng->init( &c->prng_state, &c->prng_seed ) ) + { + nwipe_log( NWIPE_LOG_ERROR, "Initialising PRNG failed on verification" ); + return -2; + } while( z > 0 ) { @@ -154,7 +162,11 @@ int nwipe_random_verify( nwipe_context_t* c ) } /* Fill the output buffer with the random pattern. */ - c->prng->read( &c->prng_state, d, blocksize ); + if( c->prng->read( &c->prng_state, d, blocksize ) ) + { + nwipe_log( NWIPE_LOG_ERROR, "Reading PRNG failed on verification" ); + return -2; + } /* Read the buffer in from the device. */ r = read( c->device_fd, b, blocksize ); @@ -253,14 +265,14 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) if( c->prng_seed.s == NULL ) { - nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: Null seed pointer." ); - return -1; + nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: Null seed pointer on erasure" ); + return -2; } if( c->prng_seed.length <= 0 ) { - nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: The entropy length member is %i.", c->prng_seed.length ); - return -1; + nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: On erasure the entropy length member is %i.", c->prng_seed.length ); + return -2; } /* Create the initialised output buffer. Initialised because we don't want memory leaks @@ -276,7 +288,11 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) } /* Seed the PRNG. */ - c->prng->init( &c->prng_state, &c->prng_seed ); + if( c->prng->init( &c->prng_state, &c->prng_seed ) ) + { + nwipe_log( NWIPE_LOG_ERROR, "Initialising PRNG failed on erasure" ); + return -2; + } /* Reset the file pointer. */ offset = lseek( c->device_fd, 0, SEEK_SET ); @@ -319,7 +335,11 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) } /* Fill the output buffer with the random pattern. */ - c->prng->read( &c->prng_state, b, blocksize ); + if( c->prng->read( &c->prng_state, b, blocksize ) ) + { + nwipe_log( NWIPE_LOG_ERROR, "Reading PRNG failed during erasure" ); + return -2; + } /* For the first block only, check the prng actually wrote something to the buffer */ if( z == c->device_size )