| 1 | # | ||
| 2 | # This file is part of Net-Amazon-Signature-V3 | ||
| 3 | # | ||
| 4 | # This software is Copyright (c) 2012 by Chris Weyl. | ||
| 5 | # | ||
| 6 | # This is free software, licensed under: | ||
| 7 | # | ||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||
| 9 | # | ||
| 10 | package Net::Amazon::Signature::V3; | ||
| 11 | { | ||
| 12 | 2 | $Net::Amazon::Signature::V3::VERSION = '0.001'; | |
| 13 | } | ||
| 14 | |||
| 15 | # ABSTRACT: Sign AWS requests -- V3 | ||
| 16 | |||
| 17 | 2 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 2 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 2 | ▶ | use MooseX::Types::Common::String ':all'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 2 | ▶ | use HTTP::Date; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 2 | ▶ | use Digest::HMAC_SHA1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 2 | ▶ | use MIME::Base64; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | has $_ => (is => 'ro', isa => NonEmptySimpleStr, required => 1) | ||
| 28 | 2 | for qw{ id key }; | |
| 29 | |||
| 30 | # see route53-dg-20120229.pdf, page 98 | ||
| 31 | 0 | ▶ | sub _time_string { time2str time } |
|
Subroutine
_time_string: not called CC=1 SCAR=6.9
| |||
| 32 | |||
| 33 | |||
| 34 | sub signed_headers { | ||
| 35 | 0 | ▶ | my $self = shift @_; |
|
Subroutine
signed_headers: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 36 | |||
| 37 | 0 | my $hmac = Digest::HMAC_SHA1->new($self->key); | |
| 38 | 0 | my $date = $self->_time_string; | |
| 39 | |||
| 40 | 0 | $hmac->add($date); | |
| 41 | 0 | my $signature = encode_base64($hmac->digest, ''); | |
| 42 | |||
| 43 | 0 | my $auth_string | |
| 44 | = 'AWS3-HTTPS ' | ||
| 45 | . 'AWSAccessKeyId=' . $self->id . ',' | ||
| 46 | . 'Algorithm=HmacSHA1,' | ||
| 47 | . 'Signature=' . $signature | ||
| 48 | ; | ||
| 49 | |||
| 50 | 0 | my %options = ( | |
| 51 | 'x-amz-date' => $date, | ||
| 52 | 'X-Amzn-Authorization' => $auth_string, | ||
| 53 | ); | ||
| 54 | |||
| 55 | ### %options | ||
| 56 | 0 | return %options; | |
| 57 | } | ||
| 58 | |||
| 59 | 2 | __PACKAGE__->meta->make_immutable; | |
| 60 | 2 | !!42; | |
| 61 | |||
| 62 | __END__ | ||
| 63 | |||
| 64 | =pod | ||
| 65 | |||
| 66 | =encoding utf-8 | ||
| 67 | |||
| 68 | =for :stopwords Chris Weyl AWS | ||
| 69 | |||
| 70 | =head1 NAME | ||
| 71 | |||
| 72 | Net::Amazon::Signature::V3 - Sign AWS requests -- V3 | ||
| 73 | |||
| 74 | =head1 VERSION | ||
| 75 | |||
| 76 | This document describes version 0.001 of Net::Amazon::Signature::V3 - released October 29, 2012 as part of Net-Amazon-Signature-V3. | ||
| 77 | |||
| 78 | =head1 SYNOPSIS | ||
| 79 | |||
| 80 | # somewhere inside the depths of your code... | ||
| 81 | my $signer = Net::Amazon::Signature::V3->new(id => $id, key => $key); | ||
| 82 | my $req = HTTP::Request->new('GET', $uri, [ $signer->signed_headers ]); | ||
| 83 | |||
| 84 | # profit! | ||
| 85 | |||
| 86 | =head1 DESCRIPTION | ||
| 87 | |||
| 88 | Amazon requires authentication when interfacing with its web services; this | ||
| 89 | package implements V3 of Amazon's authentication schemes. | ||
| 90 | |||
| 91 | =head1 METHODS | ||
| 92 | |||
| 93 | =head2 signed_headers | ||
| 94 | |||
| 95 | Returns a list of several key-value pairs suitable for including directly as | ||
| 96 | headers. These headers will authenticate the request to Amazon. | ||
| 97 | |||
| 98 | Note that these headers are only good when used within 5 minutes of the time | ||
| 99 | that Amazon thinks it is. | ||
| 100 | |||
| 101 | This routine is largely based off code extracted from | ||
| 102 | L<Net::Amazon::Route53/request>. | ||
| 103 | |||
| 104 | =head1 SEE ALSO | ||
| 105 | |||
| 106 | Please see those modules/websites for more information related to this module. | ||
| 107 | |||
| 108 | =over 4 | ||
| 109 | |||
| 110 | =item * | ||
| 111 | |||
| 112 | L<L<Net::Amazon::Route53> -- signed_headers() is largely based off of the code|L<Net::Amazon::Route53> -- signed_headers() is largely based off of the code> | ||
| 113 | |||
| 114 | =item * | ||
| 115 | |||
| 116 | L<inside L<Net::Amazon::Route53/request>.|inside L<Net::Amazon::Route53/request>.> | ||
| 117 | |||
| 118 | =back | ||
| 119 | |||
| 120 | =head1 SOURCE | ||
| 121 | |||
| 122 | The development version is on github at L<http://github.com/RsrchBoy/net-amazon-signature-v3> | ||
| 123 | and may be cloned from L<git://github.com/RsrchBoy/net-amazon-signature-v3.git> | ||
| 124 | |||
| 125 | =head1 BUGS | ||
| 126 | |||
| 127 | Please report any bugs or feature requests on the bugtracker website | ||
| 128 | https://github.com/RsrchBoy/net-amazon-signature-v3/issues | ||
| 129 | |||
| 130 | When submitting a bug or request, please include a test-file or a | ||
| 131 | patch to an existing test-file that illustrates the bug or desired | ||
| 132 | feature. | ||
| 133 | |||
| 134 | =head1 AUTHOR | ||
| 135 | |||
| 136 | Chris Weyl <cweyl@alumni.drew.edu> | ||
| 137 | |||
| 138 | =head1 COPYRIGHT AND LICENSE | ||
| 139 | |||
| 140 | This software is Copyright (c) 2012 by Chris Weyl. | ||
| 141 | |||
| 142 | This is free software, licensed under: | ||
| 143 | |||
| 144 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||
| 145 | |||
| 146 | =cut | ||