From a29cc3b54367eea65223b143a189324bba4abe04 Mon Sep 17 00:00:00 2001 From: PartialVolume <22084881+PartialVolume@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:13:56 +0000 Subject: [PATCH] PDFGen6 - further work on PDF certificate 1. Fix @param in pdfgen.h, committed and accepted upstream 2. Added size of disk in bytes 3. When NVME drive show message "Not applicable" for HPA, DCO 4. Highlight status ERASED, FAILED etc with coloured ellipse 5. Added function help for nwipe_log (shows in hints in IDE) --- src/PDFGen/pdfgen.h | 2 +- src/create_pdf.c | 58 +++++++++++++++++++++++++++++++++++++++++---- src/create_pdf.h | 5 ++++ src/logging.h | 15 ++++++++++++ 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/PDFGen/pdfgen.h b/src/PDFGen/pdfgen.h index 50fd306..ca0ac6d 100644 --- a/src/PDFGen/pdfgen.h +++ b/src/PDFGen/pdfgen.h @@ -524,8 +524,8 @@ int pdf_add_custom_path(struct pdf_doc *pdf, struct pdf_object *page, * @param y Y offset of the center of the ellipse * @param xradius Radius of the ellipse in the X axis * @param yradius Radius of the ellipse in the Y axis - * @param colour Colour to draw the ellipse outline stroke * @param width Width of the ellipse outline stroke + * @param colour Colour to draw the ellipse outline stroke * @param fill_colour Colour to fill the ellipse * @return 0 on success, < 0 on failure */ diff --git a/src/create_pdf.c b/src/create_pdf.c index b1bdafb..eee679c 100644 --- a/src/create_pdf.c +++ b/src/create_pdf.c @@ -46,15 +46,18 @@ int create_pdf( nwipe_context_t* ptr ) c = ptr; char model_header[50] = ""; /* Model text in the header */ char serial_header[30] = ""; /* Serial number text in the header */ + char device_size[50] = ""; /* Device size in the form xMB (xxxx bytes) */ char barcode[100] = ""; /* Contents of the barcode, i.e model:serial */ - char dimm[50] = ""; /* Disk Information: Model */ char verify[20] = ""; /* Verify option text */ char blank[10] = ""; /* blanking pass, none, zeros, ones */ char rounds[10] = ""; /* rounds ASCII numeric */ char prng_type[20] = ""; /* type of prng, twister, isaac, isaac64 */ - char wipe_status[8] = ""; /* Erased or Failed */ char start_time_text[50] = ""; char end_time_text[50] = ""; + char HPA_pre_erase[50] = ""; + char HPA_post_erase[50] = ""; + char DCO_pre_erase[50] = ""; + char DCO_post_erase[50] = ""; struct pdf_info info = { .creator = "https://github.com/PartialVolume/shredos.x86_64", .producer = "https://github.com/martijnvanbrummelen/nwipe", @@ -117,11 +120,13 @@ int create_pdf( nwipe_context_t* ptr ) pdf_add_line( pdf, NULL, 50, 330, 550, 330, 1, PDF_GRAY ); pdf_add_text( pdf, NULL, "Disk Information", 12, 50, 430, PDF_BLUE ); + /* Make/model */ pdf_add_text( pdf, NULL, "Make/Model:", 12, 60, 410, PDF_GRAY ); pdf_set_font( pdf, "Helvetica-Bold" ); pdf_add_text( pdf, NULL, c->device_model, 12, 135, 410, PDF_BLACK ); pdf_set_font( pdf, "Helvetica" ); + /* Serial no. */ pdf_add_text( pdf, NULL, "Serial:", 12, 300, 410, PDF_GRAY ); if( c->device_serial_no[0] == 0 ) { @@ -131,9 +136,11 @@ int create_pdf( nwipe_context_t* ptr ) pdf_add_text( pdf, NULL, c->device_serial_no, 12, 340, 410, PDF_BLACK ); pdf_set_font( pdf, "Helvetica" ); + /* Capacity (Size) of disk */ pdf_add_text( pdf, NULL, "Size:", 12, 60, 390, PDF_GRAY ); pdf_set_font( pdf, "Helvetica-Bold" ); - pdf_add_text( pdf, NULL, c->device_size_text, 12, 85, 390, PDF_BLACK ); + snprintf( device_size, sizeof( device_size ), "%s, %lli bytes", c->device_size_text, c->device_size ); + pdf_add_text( pdf, NULL, device_size, 12, 85, 390, PDF_BLACK ); pdf_set_font( pdf, "Helvetica" ); pdf_add_text( pdf, NULL, "Bus:", 12, 300, 390, PDF_GRAY ); @@ -143,8 +150,23 @@ int create_pdf( nwipe_context_t* ptr ) pdf_add_text( pdf, NULL, "Health:", 12, 60, 370, PDF_GRAY ); pdf_add_text( pdf, NULL, "Remapped Sectors:", 12, 300, 370, PDF_GRAY ); + + /* HPA, DCO, pre-erase */ + if( !strcmp( c->device_type_str, "NVME" ) ) + { + snprintf( HPA_pre_erase, sizeof( HPA_pre_erase ), "Not applicable to NVME" ); + snprintf( HPA_post_erase, sizeof( HPA_post_erase ), "Not applicable to NVME" ); + snprintf( DCO_pre_erase, sizeof( DCO_pre_erase ), "Not applicable to NVME" ); + snprintf( DCO_post_erase, sizeof( DCO_post_erase ), "Not applicable to NVME" ); + } pdf_add_text( pdf, NULL, "HPA(pre-erase):", 12, 60, 350, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( pdf, NULL, HPA_pre_erase, 12, 150, 350, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); pdf_add_text( pdf, NULL, "DCO(pre-erase):", 12, 300, 350, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( pdf, NULL, DCO_pre_erase, 12, 393, 350, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); /* --------------- */ /* Erasure Details */ @@ -191,16 +213,28 @@ int create_pdf( nwipe_context_t* ptr ) /* Status */ pdf_add_text( pdf, NULL, "Status:", 12, 300, 270, PDF_GRAY ); pdf_set_font( pdf, "Helvetica-Bold" ); + if( !strcmp( c->wipe_status_txt, "ERASED" ) ) { - pdf_add_text( pdf, NULL, c->wipe_status_txt, 12, 345, 270, PDF_DARK_GREEN ); + pdf_add_text( pdf, NULL, c->wipe_status_txt, 12, 365, 270, PDF_DARK_GREEN ); + pdf_add_ellipse( pdf, NULL, 390, 275, 45, 10, 2, PDF_DARK_GREEN, PDF_TRANSPARENT ); } else { - pdf_add_text( pdf, NULL, c->wipe_status_txt, 12, 345, 270, PDF_RED ); + if( !strcmp( c->wipe_status_txt, "FAILED" ) ) + { + // text shifted left slightly in ellipse due to extra character + pdf_add_text( pdf, NULL, c->wipe_status_txt, 12, 370, 270, PDF_RED ); + } + else + { + pdf_add_text( pdf, NULL, c->wipe_status_txt, 12, 360, 270, PDF_RED ); + } + pdf_add_ellipse( pdf, NULL, 390, 275, 45, 10, 2, PDF_RED, PDF_TRANSPARENT ); } pdf_set_font( pdf, "Helvetica" ); + /* Method */ pdf_add_text( pdf, NULL, "Method:", 12, 60, 250, PDF_GRAY ); pdf_set_font( pdf, "Helvetica-Bold" ); pdf_add_text( pdf, NULL, nwipe_method_label( nwipe_options.method ), 12, 110, 250, PDF_BLACK ); @@ -268,14 +302,28 @@ int create_pdf( nwipe_context_t* ptr ) pdf_add_text( pdf, NULL, verify, 12, 450, 230, PDF_BLACK ); pdf_set_font( pdf, "Helvetica" ); + /* bytes erased */ + pdf_add_text( pdf, NULL, "Bytes Erased:", 12, 60, 210, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( pdf, NULL, "", 12, 60, 210, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); + + /* rounds */ pdf_add_text( pdf, NULL, "Rounds:", 12, 300, 210, PDF_GRAY ); snprintf( rounds, sizeof( rounds ), "%i", nwipe_options.rounds ); pdf_set_font( pdf, "Helvetica-Bold" ); pdf_add_text( pdf, NULL, rounds, 12, 350, 210, PDF_BLACK ); pdf_set_font( pdf, "Helvetica" ); + /* HPA, DCO, post erase */ pdf_add_text( pdf, NULL, "HPA(post-erase):", 12, 60, 190, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( pdf, NULL, HPA_post_erase, 12, 155, 190, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); pdf_add_text( pdf, NULL, "DCO(post-erase):", 12, 300, 190, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( pdf, NULL, DCO_post_erase, 12, 397, 190, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); pdf_add_text( pdf, NULL, "Information:", 12, 60, 170, PDF_GRAY ); /* ---------------------- */ diff --git a/src/create_pdf.h b/src/create_pdf.h index 3005382..f9d4c0b 100644 --- a/src/create_pdf.h +++ b/src/create_pdf.h @@ -31,6 +31,11 @@ /*! Utility macro to provide gray */ #define PDF_GRAY PDF_RGB( 0x5A, 0x5A, 0x5A ) +/** + * Create the disk erase report in PDF format + * @param pointer to a drive context + * @return returns 0 on success < 1 on error + */ int create_pdf( nwipe_context_t* ptr ); #endif /* CREATE_PDF_H_ */ diff --git a/src/logging.h b/src/logging.h index b2d4b75..d4b6db0 100644 --- a/src/logging.h +++ b/src/logging.h @@ -40,7 +40,22 @@ typedef enum nwipe_log_t_ { NWIPE_LOG_NOTIMESTAMP // logs the message without the timestamp } nwipe_log_t; +/** + * Writes a string to the log. nwipe_log timestamps the string + * @param level the tag to display: + * NWIPE_LOG_NONE Don't display a tag + * NWIPE_LOG_DEBUG, Very verbose logging. + * NWIPE_LOG_INFO, Verbose logging. + * NWIPE_LOG_NOTICE, Most logging happens at this level. + * NWIPE_LOG_WARNING, Things that the user should know about. + * NWIPE_LOG_ERROR, Non-fatal errors that result in failure. + * NWIPE_LOG_FATAL, Errors that cause the program to exit. + * NWIPE_LOG_SANITY, Programming errors. + * NWIPE_LOG_NOTIMESTAMP logs the message without the timestamp + * @param format the string to be logged + */ void nwipe_log( nwipe_log_t level, const char* format, ... ); + void nwipe_perror( int nwipe_errno, const char* f, const char* s ); void nwipe_log_OSinfo(); int nwipe_log_sysinfo();