| 1 | package DJabberd::DialbackParams; | ||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 20 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 20 | ▶ | use Digest::HMAC_SHA1 qw(hmac_sha1_hex); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 20 | ▶ | use DJabberd::Log; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 20 | our $logger = DJabberd::Log->get_logger(); | |||||||||
| 8 | |||||||||||
| 9 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 10 | 0 | my ($class, %opts) = @_; | |||||||||
| 11 | |||||||||||
| 12 | 0 | my $self = bless {}, $class; | |||||||||
| 13 | 0 | foreach my $f (qw(id recv orig vhost)) { | |||||||||
| 14 | 0 | ▶ | $self->{$f} = delete $opts{$f} or croak "No '$f' field"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | } | ||||||||||
| 16 | 0 | ▶ | croak "Unknown params" if %opts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 0 | return $self; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub concat_params { | ||||||||
|
Subroutine
concat_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my $self = shift; | |||||||||
| 22 | 0 | return join("|", map { $self->{$_} } qw(id recv orig)); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub generate_dialback_result { | ||||||||
|
Subroutine
generate_dialback_result: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | 0 | my ($self, $cb) = @_; | |||||||||
| 27 | 0 | my $vhost = $self->{vhost}; | |||||||||
| 28 | 0 | $logger->info("Generating dialback result for vhost $vhost->{server_name} from $self->{recv}"); | |||||||||
| 29 | 0 | ▶ | $vhost->get_secret_key(sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 30 | 0 | my ($shandle, $secret) = @_; | |||||||||
| 31 | 0 | my $params = $self->concat_params; | |||||||||
| 32 | 0 | my $res = join("-", $shandle, hmac_sha1_hex($params, $secret)); | |||||||||
| 33 | 0 | $logger->debug("Generated dialback result '$res' using secret(of handle '$shandle')='$secret', params='$params'"); | |||||||||
| 34 | 0 | $cb->($res); | |||||||||
| 35 | 0 | }); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub verify_callback { | ||||||||
|
Subroutine
verify_callback: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 39 | 0 | my ($self, %args) = @_; | |||||||||
| 40 | 0 | my $vhost = $self->{vhost}; | |||||||||
| 41 | |||||||||||
| 42 | 0 | my $restext = delete $args{'result_text'}; | |||||||||
| 43 | 0 | my $on_success = delete $args{'on_success'}; | |||||||||
| 44 | 0 | my $on_failure = delete $args{'on_failure'}; | |||||||||
| 45 | 0 | ▶ | Carp::croak("args") if %args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 0 | my ($handle, $digest) = split(/-/, $restext); | |||||||||
| 48 | 0 | $logger->debug("verify callback, restext=[$restext], stream_id = $self->{id}"); | |||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | $vhost->get_secret_key_by_handle($handle, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 51 | 0 | my $secret = shift; | |||||||||
| 52 | 0 | $logger->debug("Secret(of handle '$handle') is '$secret'"); | |||||||||
| 53 | |||||||||||
| 54 | # bogus handle if no secret | ||||||||||
| 55 | 0 | ▶ | unless ($secret) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | $on_failure->(); | |||||||||
| 57 | 0 | return; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | my $params = $self->concat_params; | |||||||||
| 61 | 0 | $logger->debug("concat params = [$params]"); | |||||||||
| 62 | 0 | my $proper_digest = hmac_sha1_hex($params, $secret); | |||||||||
| 63 | 0 | ▶ | if ($digest eq $proper_digest) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | $on_success->(); | |||||||||
| 65 | } else { | ||||||||||
| 66 | 0 | $on_failure->(); | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | }); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 20 | 1; | |||||||||
| 72 | |||||||||||