Crypt::SRP - Secure Remote Protocol


NAME

Crypt::SRP - Secure Remote Protocol (SRP6a)


SYNOPSIS

Example 1 - SRP login handshake:

 ###CLIENT###
 my $I = '...'; # login entered by user
 my $P = '...'; # password entered by user
 my $cli = Crypt::SRP->new('RFC5054-1024bit', 'SHA1');
 my ($A, $a) = $cli->client_compute_A;
 #  request[1] to server:  ---> /auth/srp_step1 ($I, $A) --->
                           ###SERVER###
                           my %USERS;  # sort of "user database"
                           my %TOKENS; # sort of temporary "token database"
                           my $v = $USERS{$I}->{verifier};
                           my $s = $USERS{$I}->{salt};
                           my $srv = Crypt::SRP->new('RFC5054-1024bit', 'SHA1');
                           return unless $srv->server_verify_A($A);
                           $srv->server_init($I, $v, $s);
                           my ($B, $b) = $srv->server_compute_B;
                           my $token = $srv->random_bytes(32);
                           $TOKENS{$token} = [$I, $A, $B, $b];
 #  response[1] from server:  <--- ($B, $s, $token) <---
 ###CLIENT###
 return unless $cli->client_verify_B($B);
 $cli->client_init($I, $P, $s);
 my $M1 = $cli->client_compute_M1;
 #  request[2] to server:  ---> /auth/srp_step2 ($M1, $token) --->
                           ###SERVER###
                           my $M2 = '';
                           return unless $M1 && $token && $TOKENS{$token};
                           my ($I, $A, $B, $b) = @{delete $TOKENS{$token}};
                           return unless $I && $A && $B && $b && $USERS{$I};
                           my $s = $USERS{$I}->{salt};
                           my $v = $USERS{$I}->{verifier};
                           return unless $s && $v;
                           my $srv = Crypt::SRP->new('RFC5054-1024bit', 'SHA1');
                           $srv->server_init($I, $v, $s, $A, $B, $b);
                           return unless $srv->server_verify_M1($M1);
                           $M2 = $srv->server_compute_M2;
                           my $K = $srv->get_secret_K; # shared secret
 #  response[2] from server:  <--- ($M2) <---
 ###CLIENT###
 if ($M2 && $cli->client_verify_M2($M2)) {
   my $K = $srv->get_secret_K; # shared secret
   print "SUCCESS";
 }
 else {
   print "ERROR";
 }

Example 2 - creating a new user and his/her password verifier:

 ###CLIENT###
 my $I = '...'; # login entered by user
 my $P = '...'; # password entered by user
 my $cli = Crypt::SRP->new('RFC5054-1024bit', 'SHA1');
 my ($v, $s) = $cli->compute_verifier_and_salt($I, $P);
 #  request to server:  ---> /auth/create_user [$I, $s, $v] --->
                           ###SERVER###
                           my %USERS;  # sort of "user database"
                           die "user already exists" unless $USERS{$I};
                           $USERS{$I}->{salt} = $s;
                           $USERS{$I}->{verifier} = $v;

Working sample implementation of SRP authentication on client and server side is available in examples subdirectory: srp_server.pl, srp_client.pl.


DESCRIPTION

More info about SRP protocol:

This module implements SRP version 6a.

IMPORTANT: This module performs some big integer arithmetic via the Math::BigInt manpage. From performance reasons it is recommended to install the Math::BigInt::GMP manpage.

IMPORTANT: This module needs a cryptographically strong random number generator. It tries to use one of the following:


METHODS

Login and password ($I, $P) can be ASCII strings (without utf8 flag) or raw octets. If you want special characters in login and/or password then you have to encode them from Perl's internal from like this: $I = encode('utf8', $I) or $P = encode('utf8', $P)

All SRP related variables ($s, $v, $A, $a, $B, $b, $M1, $M2, $S, $K) are by defaults raw octets (no BigInts, no strings with utf8 flag). However if you set new's optional parameter $format to 'hex', 'base64' or 'base64url' SRP related input parameters (not $I or $P) are expected in given encoding and return values are converted into the same encoding as well.


LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


COPYRIGHT

Copyright (c) 2012 DCIT, a.s. http://www.dcit.cz / Karel Miko

 Crypt::SRP - Secure Remote Protocol