From 9b5cc7220709cccd1c124785bae769f1153503b2 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Thu, 10 Dec 2020 19:08:46 +0100 Subject: New password algo and handling strings better - Text strings are now regrouped in an hash, less insane than an array. - I searched a bit in terms of password saving methods and Argon2 seemed pretty good. So now we use it. --- gpigeon-template.cgi | 161 +++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 81 deletions(-) (limited to 'gpigeon-template.cgi') diff --git a/gpigeon-template.cgi b/gpigeon-template.cgi index 7f82857..d16bf3b 100755 --- a/gpigeon-template.cgi +++ b/gpigeon-template.cgi @@ -2,7 +2,7 @@ use warnings; use strict; -use Digest::SHA qw(sha256_hex); +use Crypt::Argon2 qw(argon2id_verify); use Email::Valid; use String::Random; use CGI qw(param); @@ -35,6 +35,8 @@ sub notif_if_defined{ if (defined $notif){ return $notif; } + else{ + return ''; } delete @ENV{qw(IFS PATH CDPATH BASH_ENV)}; @@ -54,51 +56,49 @@ my $mymail_gpgid = q{gpgid_goes_here}; #0xlong keyid form my $PASSWD_HASH = q{password_hash_goes_here}; my $mymailaddr_escaped = escape_arobase($mymailaddr); my $msg_form_char_limit = 3000; -my @text_strings = ('Successful removal !', - 'Address', - 'is valid!', - 'is not valid !', - 'Unknown', # displays on main page table when supposed sender isn't identified - 'Message length must be under$msg_form_char_limit chars.', - 'One time GPG messaging form', # title for generated links - 'Type your message below, ', - 'Send to me', - 'Generated a link for', #displays if link gen is successful - 'Link to your one time GPG messaging form', # mail subject when clicking a mailto: link in table - 'Your link is ', # message body when clicking a mailto: link in table - 'Delete', # text on button for deleting links - 'Damn! I cannot open ', # message when file opening fails - 'GPIGEON.CGI: generate one time GPG messaging links !', # main page title! - 'Hi and welcome.', # a greeting at the top of the main page. - 'Disconnect', # disconnect button text on main page - 'Refresh', # refresh button text - 'Generate link', #link generation button text - "Generated links by you, $mymailaddr:", # label above links table - 'Delete all links', # delete all links button text - 'Link', # first table header, 'Link' - 'For', # second table header, 'For' - 'Deletion', # third table header, 'Delete' - 'Deletion failed and here is why : ', - 'Cannot send message : message length must be under ' .$msg_form_char_limit . ' characters.', - 'Cannot send message : message is empty. You can type up to ' . $msg_form_char_limit . ' characters.' -); +my %text_strings = (link_del_ok => 'Successful removal !', + addr => 'Address', + addr_ok => 'is valid!', + addr_nok => 'is not valid !', + addr_unknown => 'Unknown', + link_web_title => 'One time GPG messaging form', + link_legend_textarea =>'Type your message below :', + link_send_btn => 'Send', + link_generated_ok => 'Generated a link for', + mailto_body => 'Your link is ', + mailto_subject => 'Link to your one time GPG messaging form', + delete_link_btn_text => 'Delete', + delete_links_btn_text => 'Delete all links', + create_link_btn => 'Generate link', + web_title => 'GPIGEON.CGI: generate one time GPG messaging links !', + web_greet_msg => 'Hi and welcome.', + disconnect_btn_text => 'Disconnect', + refresh_btn_text => 'Refresh', + theader_link => 'Link', + theader_for => 'For', + theader_deletion => 'Deletion', + link_del_failed => 'Deletion failed and here is why : ', + msg_too_long => 'Cannot send message : message length must be under ' .$msg_form_char_limit . ' characters.', + msg_empty => 'Cannot send message : message is empty. You can type up to ' . $msg_form_char_limit . ' characters.', + notif_login_failure => 'Cannot login. Check if your username and password match.' + ); my $cgi_query_get = CGI->new; my $PASSWD = $cgi_query_get->param('password'); -my $psswd_formfield = ''; my ($notif_de_creation, $notif_mail_valide, $notif_suppression) = undef; my @created_links = (); -if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ +if (argon2id_verify($PASSWD,$PASSWD_HASH)){ + my $psswd_formfield = ''; if (defined $cgi_query_get->param('supprlien')){ my $pending_deletion = $cgi_query_get->param('supprlien'); my $gpg_form_fn = "./l/$pending_deletion"; if (unlink untaint_cgi_filename($gpg_form_fn)){ - $notif_suppression=''.$text_strings[0].''; + $notif_suppression=qq{$text_strings{link_del_ok}}; } else { - $notif_suppression=''. $text_strings[24] . $gpg_form_fn.':'. $! .''; + $notif_suppression=qq{$text_strings{link_del_failed} $gpg_form_fn : $!}; } } @@ -109,7 +109,7 @@ if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ if ($_ ne '.' and $_ ne '..'){ my $gpg_form_fn = "./l/$_"; unlink untaint_cgi_filename($gpg_form_fn) or die "$!"; - $notif_suppression=''. $text_strings[0] .''; + $notif_suppression=qq{$text_strings{link_del_ok}}; } } closedir $link_dir_handle; @@ -119,7 +119,7 @@ if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ my $non_gpguser = scalar $cgi_query_get->param('mail'); if ( Email::Valid->address($non_gpguser) ){ - $notif_mail_valide = ''. $text_strings[1] . ' '. $non_gpguser.' '. $text_strings[2] . ''; + $notif_mail_valide = qq{$text_strings{addr} $non_gpguser $text_strings{addr_ok}}; my $escaped_non_gpguser = escape_arobase($non_gpguser); my $random_mailform_fn_str = String::Random->new; my @mailform_fn_str_buffer = (); @@ -150,9 +150,9 @@ if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ 'my $length_msg_form = length $msg_form;', "\n", 'if (defined $length_msg_form and $length_msg_form > $msg_form_char_limit){', "\n", - ' $error_processing_msg = q{'. $text_strings[25] .'.};', "\n", + ' $error_processing_msg = q{'. $text_strings{msg_too_long} .'.};', "\n", '} elsif (defined $length_msg_form and $length_msg_form eq 0 ){', "\n", - ' $error_processing_msg = q{'. $text_strings[26] . '.};', "\n", + ' $error_processing_msg = q{'. $text_strings{msg_empty} . '.};', "\n", '} else {', "\n", ' if (defined $length_msg_form and $ENV{\'REQUEST_METHOD\'} eq \'POST\'){',"\n", ' $msg_form =~ tr/\r//d;', "\n", @@ -208,20 +208,19 @@ if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ '};', "\n", 'if (defined $error_processing_msg){printf $error_processing_msg;}', "\n", 'printf qq{
- ', "\n", + ', "\n", ' ', "\n", ' ', "\n", ' };'; close $gpg_form_fh; chmod(0755,$MAILFORM_RELPATH); - $notif_de_creation=''. $text_strings[9] . $non_gpguser .'
'. $MAILFORM_LINK .''; - } + $notif_de_creation=qq{$text_strings{link_generated_ok} $non_gpguser:
$MAILFORM_LINK}; } else{ close $gpg_form_fh and die "Can't open $MAILFORM_RELPATH: $!"; } } else{ - $notif_mail_valide = "$text_strings[1] $non_gpguser $text_strings[3]."; + $notif_mail_valide = qq{$text_strings{addr} $non_gpguser $text_strings{addr_nok}.}; } } @@ -246,75 +245,75 @@ if ( sha256_hex($PASSWD) eq $PASSWD_HASH and $ENV{'REQUEST_METHOD'} eq 'POST'){ #create links table html push @created_links, - ' - ici - '.$non_gpguser.' + qq{ + ici + $non_gpguser
- - - + + +
- '; + }; } else { close $gpg_form_handle; - die 'Content-type: text/plain', "\n\n", "$text_strings[13] $gpg_form_fn: $!"; + die 'Content-type: text/plain', "\n\n", "Error: Can't open $gpg_form_fn: $!"; } } } closedir $link_dir_handle; print $HTML_CONTENT_TYPE_HEADER,"\n\n", - ' + qq{ - - ',"\n",' - '. $text_strings[14] .' + + + + $text_strings{web_title} -

'. $text_strings[15] .'

+

$text_strings{web_greet_msg}

- +
-
', - $psswd_formfield, - ' + + $psswd_formfield +


-
', - $psswd_formfield, - 'Mail de la personne:
+ + $psswd_formfield + Mail de la personne:
- -
'; - print notif_if_defined($notif_mail_valide); - print '
'; - print notif_if_defined($notif_de_creation); - print '
-

'. $text_strings[19] .'

', - '
', - $psswd_formfield, - ' - -
', + + }, + notif_if_defined($notif_mail_valide), + '
' + notif_if_defined($notif_de_creation), + qq{
+
+ $psswd_formfield + + +
}, notif_if_defined($notif_suppression), - ' + qq{
- ', - '', - '', - '', - "@created_links", - '
'. $text_strings[21] .''. $text_strings[22] .''. $text_strings[23] .'
+ $text_strings{theader_link} + $text_strings{theader_for} + $text_strings{theader_deletion} + + @created_links + - '; + }; } else { print 'Location: /index.html', "\n\n"; -- cgit v1.2.3-70-g09d2