| 1 | package Net::OAuth::SignatureMethod::RSA_SHA1; | ||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | # RFC 5849 3.4.3 mandates RSASSA-PKCS1-v1_5 with SHA-1. Crypt::OpenSSL::RSA | ||||||||||||||||||||
| 7 | # defaults have drifted (SHA-256 since 0.29_01, PSS padding since 0.35), so | ||||||||||||||||||||
| 8 | # pin both rather than inheriting whatever the installed version prefers. | ||||||||||||||||||||
| 9 | 2 | ▶ | sub _apply_rfc5849_defaults { | ||||||||||||||||||
|
Subroutine
_apply_rfc5849_defaults: called CC=4 SCAR=14.1
| |||||||||||||||||||||
| 10 | 2 | my $key = shift; | |||||||||||||||||||
| 11 | 2 | for my $method (qw(use_sha1_hash use_pkcs1_padding)) { | |||||||||||||||||||
| 12 | 4 | ▶ | next unless UNIVERSAL::can($key, $method); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 13 | 4 | ▶ | eval { $key->$method; 1 } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 14 | or die "Your Crypt::OpenSSL::RSA cannot do $method, which OAuth " | ||||||||||||||||||||
| 15 | . "RSA-SHA1 requires (RFC 5849 3.4.3): $@"; | ||||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | 2 | return $key; | |||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 1 | ▶ | sub sign { | ||||||||||||||||||
|
Subroutine
sign: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||
| 21 | 1 | my $self = shift; | |||||||||||||||||||
| 22 | 1 | my $request = shift; | |||||||||||||||||||
| 23 | 1 | ▶ | my $key = shift || $request->signature_key; | ||||||||||||||||||
|
Condition33%1/3
shift() || $request->signature_key
MC/DC0%0/2
shift() || $request->signature_key
shift()
$request->signature_key
Truth table33%1/3
A || B
A= shift()B= $request->signature_key
| |||||||||||||||||||||
| 24 | 1 | ▶ | die '$request->signature_key must be an RSA key object (e.g. Crypt::OpenSSL::RSA) that can sign($text)' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | unless UNIVERSAL::can($key, 'sign'); | ||||||||||||||||||||
| 26 | 1 | _apply_rfc5849_defaults($key); | |||||||||||||||||||
| 27 | 1 | return encode_base64($key->sign($request->signature_base_string), ""); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | sub verify { | ||||||||||||||||||
|
Subroutine
verify: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||
| 31 | 1 | my $self = shift; | |||||||||||||||||||
| 32 | 1 | my $request = shift; | |||||||||||||||||||
| 33 | 1 | ▶ | my $key = shift || $request->signature_key; | ||||||||||||||||||
|
Condition33%1/3
shift() || $request->signature_key
MC/DC0%0/2
shift() || $request->signature_key
shift()
$request->signature_key
Truth table33%1/3
A || B
A= shift()B= $request->signature_key
| |||||||||||||||||||||
| 34 | 1 | ▶ | die 'You must pass an RSA key object (e.g. Crypt::OpenSSL::RSA) that can verify($text,$sig)' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | unless UNIVERSAL::can($key, 'verify'); | ||||||||||||||||||||
| 36 | 1 | _apply_rfc5849_defaults($key); | |||||||||||||||||||
| 37 | 1 | return $key->verify($request->signature_base_string, decode_base64($request->signature)); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 NAME | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | Net::OAuth::SignatureMethod::RSA_SHA1 - RSA_SHA1 Signature Method for OAuth protocol | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =head1 SEE ALSO | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | L<Net::OAuth>, L<http://oauth.net> | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =head1 AUTHOR | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | Originally by Keith Grennan <foss@nearlyfree.org> | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Currently maintained by Robert Rothenberg <perl@rhizomnic.com> | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | Copyright 2007-2012, 2024-2026 Keith Grennan | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 59 | under the same terms as Perl itself. | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||