Commit 98d6aa21 authored by marcus-tun's avatar marcus-tun
Browse files

Blowfish CBC encryption of assertion, tested with serverside python

parent 012f7219
......@@ -26,9 +26,10 @@ use Term::ReadKey;
use Term::ReadLine;
use MIME::Base64 qw( encode_base64 );
use Crypt::GeneratePassword qw(word chars);
use Crypt::Twofish;
use Crypt::Blowfish;
#use Crypt::Twofish;
#use Crypt::Blowfish;
use Crypt::CBC;
use Crypt::ECB;
# Handle <Ctrl>+C to reset the terminal to non-bold text
$SIG{INT} = \&resetTerm;
......@@ -287,20 +288,35 @@ my $assertion=$response_content;
################
my $restrict='!@#$%^&*()_-=+/' ;
my $symmetric_key =chars(5,32,0,$restrict,0);
my $iv='12333123';
print "key: ".$symmetric_key."\n";
# encryption
my $cipher = new Crypt::CBC ($symmetric_key, 'Twofish');
#my $cipher = new Crypt::CBC ($symmetric_key, 'Blowfish');
#my $encryption_algorithm='Twofish';
my $encryption_algorithm='Blowfish';
my $cipher = new Crypt::CBC ($symmetric_key, $encryption_algorithm, -iv=>$iv, -header=>'none');
print ("length(assertion):". length($assertion)."\n");
my $encrypted_assertion= $cipher->encrypt($assertion);
undef $assertion;
# decrypt
#$cipher = new Crypt::CBC ($symmetric_key, 'Twofish');
#my $plaintext = $cipher->decrypt($ciphertext);
#print $plaintext;
# extract actual password and initialisation vector
my $perl_pass = unpack('H*', $cipher->key());
my $perl_iv = $cipher->iv();
## log to file
#open (FILE, ">", 'log.perl');
#print FILE "pass: ".$perl_pass."\n";
#print FILE "iv: ".$perl_iv."\n";
#print FILE $encrypted_assertion."\n";
#close (FILE);
## decrypt
#my $de_cipher = new Crypt::CBC ($symmetric_key, $encryption_algorithm, -iv=>'asdlsdff', -header=>'asdf');
##$cipher = new Crypt::ECB ($symmetric_key, $encryption_algorithm);
#my $plaintext = $de_cipher->decrypt($encrypted_assertion);
#print ("\n".$plaintext."\n");
# base64 encoding
my $b64_encrypted_assertion=encode_base64($encrypted_assertion);
......@@ -308,15 +324,26 @@ undef $encrypted_assertion;
# upload encrypted assertion
$response=$ua->post(CREDENTIAL_UPLOAD_URL,
[encrypted_assertion =>$b64_encrypted_assertion]);
[encrypted_assertion =>$b64_encrypted_assertion,
#key => $perl_pass,
perl_iv => $perl_iv,
crypto_algo => $encryption_algorithm,
client => "perl",
client_verion => VERSION]);
#print Dumper($response);
$response_content = $response->decoded_content;
use Data::Dumper;
print Dumper($response_content);
# Store the returned URL
(undef, $url_to_assertion) = split("url=", $response_content);
my $url_to_assertion_with_key = $url_to_assertion."&k=".$symmetric_key;
open (FILE, ">", $urlfile) or die $!;
print FILE $url_to_assertion_with_key."\n";
print FILE $url_to_assertion;
close (FILE);
print "This is your temprary password: ".$url_to_assertion_with_key."\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment