aws_cf_signer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/README.rdoc +66 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/aws_cf_signer.gemspec +60 -0
- data/lib/aws_cf_signer.rb +70 -0
- data/test/fixtures/README +5 -0
- data/test/fixtures/custom_policy1 +9 -0
- data/test/fixtures/custom_policy2 +10 -0
- data/test/fixtures/pk-PK123456789754.pem +15 -0
- data/test/fixtures/rsa-PK123456789754.pem +6 -0
- data/test/helper.rb +10 -0
- data/test/test_aws_cf_signer.rb +65 -0
- metadata +108 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= aws_cf_signer
|
2
|
+
|
3
|
+
Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here:
|
4
|
+
|
5
|
+
* http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
# Pass in path to the private CloudFront key from AWS
|
10
|
+
signer = AwsCfSigner.new('/path/to/my/pk-1234567890.pem')
|
11
|
+
|
12
|
+
# If the key filename doesn't contain the key_pair_id (as it usually does from AWS), pass that in as the second arg
|
13
|
+
signer = AwsCfSigner.new('/path/to/my/private-key.pem', '1234567890')
|
14
|
+
|
15
|
+
# expiration date is required
|
16
|
+
# See Example Canned Policy at above AWS doc link
|
17
|
+
url = signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => 'Sat, 14 Nov 2009 22:20:00 GMT')
|
18
|
+
|
19
|
+
# You can also use a Time object
|
20
|
+
url = signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => Time.now + 3600)
|
21
|
+
|
22
|
+
# Custom Policies
|
23
|
+
|
24
|
+
# See Example Custom Policy 1 at above AWS doc link
|
25
|
+
url = signer.sign('http://d604721fxaaqy9.cloudfront.net/training/orientation.avi',
|
26
|
+
:ending => 'Sat, 14 Nov 2009 22:20:00 GMT',
|
27
|
+
:resource => 'http://d604721fxaaqy9.cloudfront.net/training/*',
|
28
|
+
:ip_range => '145.168.143.0/24'
|
29
|
+
)
|
30
|
+
|
31
|
+
# See Example Custom Policy 2 at above AWS doc link
|
32
|
+
url = signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz',
|
33
|
+
:starting => 'Thu, 30 Apr 2009 06:43:10 GMT',
|
34
|
+
:ending => 'Fri, 16 Oct 2009 06:31:56 GMT',
|
35
|
+
:resource => 'http://*',
|
36
|
+
:ip_range => '216.98.35.1/32'
|
37
|
+
)
|
38
|
+
|
39
|
+
# You can also pass in a path to a policy file
|
40
|
+
# This will supersede any other policy options
|
41
|
+
url = signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz', :policy_file => '/path/to/policy/file.txt')
|
42
|
+
|
43
|
+
See the test/test_aws_cf_signer.rb file for more examples.
|
44
|
+
|
45
|
+
== Note on Patches/Pull Requests
|
46
|
+
|
47
|
+
* Fork the project.
|
48
|
+
* Make your feature addition or bug fix.
|
49
|
+
* Add tests for it. This is important so I don't break it in a
|
50
|
+
future version unintentionally.
|
51
|
+
* Commit, do not mess with rakefile, version, or history.
|
52
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
53
|
+
* Send me a pull request. Bonus points for topic branches.
|
54
|
+
|
55
|
+
== Attributions
|
56
|
+
|
57
|
+
Parts of signing code taken from a question on Stack Overflow asked by Ben Wiseley, and answered by Blaz Lipuscek and Manual M:
|
58
|
+
|
59
|
+
* http://stackoverflow.com/questions/2632457/create-signed-urls-for-cloudfront-with-ruby
|
60
|
+
* http://stackoverflow.com/users/315829/ben-wiseley
|
61
|
+
* http://stackoverflow.com/users/267804/blaz-lipuscek
|
62
|
+
* http://stackoverflow.com/users/327914/manuel-m
|
63
|
+
|
64
|
+
== License
|
65
|
+
|
66
|
+
aws_cf_signer is distributed under the MIT License, copyright © 2010 STL
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "aws_cf_signer"
|
8
|
+
gem.summary = %Q{Ruby gem for signing AWS Cloudfront URLs for serving private content}
|
9
|
+
gem.description = %Q{Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here: http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html}
|
10
|
+
gem.email = "dylan.vaughn@stlondemand.com"
|
11
|
+
gem.homepage = "http://github.com/stlondemand/aws_cf_signer"
|
12
|
+
gem.authors = ["Dylan Vaughn"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "yard", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
begin
|
47
|
+
require 'yard'
|
48
|
+
YARD::Rake::YardocTask.new
|
49
|
+
rescue LoadError
|
50
|
+
task :yardoc do
|
51
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
52
|
+
end
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{aws_cf_signer}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dylan Vaughn"]
|
12
|
+
s.date = %q{2010-11-17}
|
13
|
+
s.description = %q{Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here: http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html}
|
14
|
+
s.email = %q{dylan.vaughn@stlondemand.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"aws_cf_signer.gemspec",
|
25
|
+
"lib/aws_cf_signer.rb",
|
26
|
+
"test/fixtures/README",
|
27
|
+
"test/fixtures/custom_policy1",
|
28
|
+
"test/fixtures/custom_policy2",
|
29
|
+
"test/fixtures/pk-PK123456789754.pem",
|
30
|
+
"test/fixtures/rsa-PK123456789754.pem",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_aws_cf_signer.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/stlondemand/aws_cf_signer}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Ruby gem for signing AWS Cloudfront URLs for serving private content}
|
39
|
+
s.test_files = [
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/test_aws_cf_signer.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'time'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
class AwsCfSigner
|
6
|
+
|
7
|
+
attr_reader :key_pair_id
|
8
|
+
|
9
|
+
def initialize(pem_path, key_pair_id = nil)
|
10
|
+
@pem_path = pem_path
|
11
|
+
@key = OpenSSL::PKey::RSA.new(File.readlines(@pem_path).join(""))
|
12
|
+
@key_pair_id = key_pair_id ? key_pair_id : extract_key_pair_id(@pem_path)
|
13
|
+
unless @key_pair_id
|
14
|
+
raise ArgumentError.new("key_pair_id couldn't be inferred from #{@pem_path} - please pass in explicitly")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def sign(url_to_sign, policy_options = {})
|
19
|
+
separator = url_to_sign =~ /\?/ ? '&' : '?'
|
20
|
+
if policy_options[:policy_file]
|
21
|
+
policy = IO.read(policy_options[:policy_file])
|
22
|
+
"#{url_to_sign}#{separator}Policy=#{encode_policy(policy)}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
|
23
|
+
else
|
24
|
+
raise ArgumentError.new("'ending' argument is required") if policy_options[:ending].nil?
|
25
|
+
if policy_options.keys.size == 1
|
26
|
+
# Canned Policy - shorter URL
|
27
|
+
expires_at = epoch_time(policy_options[:ending])
|
28
|
+
policy = %({"Statement":[{"Resource":"#{url_to_sign}","Condition":{"DateLessThan":{"AWS:EpochTime":#{expires_at}}}}]})
|
29
|
+
"#{url_to_sign}#{separator}Expires=#{expires_at}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
|
30
|
+
else
|
31
|
+
# Custom Policy
|
32
|
+
resource = policy_options[:resource] || url_to_sign
|
33
|
+
policy = generate_custom_policy(resource, policy_options)
|
34
|
+
"#{url_to_sign}#{separator}Policy=#{encode_policy(policy)}&Signature=#{create_signature(policy)}&Key-Pair-Id=#{@key_pair_id}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_custom_policy(resource, options)
|
40
|
+
conditions = ["\"DateLessThan\":{\"AWS:EpochTime\":#{epoch_time(options[:ending])}}"]
|
41
|
+
conditions << "\"DateGreaterThan\":{\"AWS:EpochTime\":#{epoch_time(options[:starting])}}" if options[:starting]
|
42
|
+
conditions << "\"IpAddress\":{\"AWS:SourceIp\":#{options[:ip_range]}" if options[:ip_range]
|
43
|
+
%({"Statement":[{"Resource":"#{resource}","Condition":{#{conditions.join(',')}}}]})
|
44
|
+
end
|
45
|
+
|
46
|
+
def epoch_time(timelike)
|
47
|
+
case timelike
|
48
|
+
when String then Time.parse(timelike).to_i
|
49
|
+
when Time then timelike.to_i
|
50
|
+
else raise ArgumentError.new("Invalid argument - String or Time required - #{timelike.class} passed.")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def encode_policy(policy)
|
55
|
+
url_safe(Base64.encode64(policy))
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_signature(policy)
|
59
|
+
url_safe(Base64.encode64(@key.sign(OpenSSL::Digest::SHA1.new, (policy))))
|
60
|
+
end
|
61
|
+
|
62
|
+
def extract_key_pair_id(key_path)
|
63
|
+
File.basename(key_path) =~ /^pk-(.*).pem$/ ? $1 : nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def url_safe(s)
|
67
|
+
s.gsub('+','-').gsub('=','_').gsub('/','~').gsub(/\n/,'').gsub(' ','')
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIICXQIBAAKBgQDA7ki9gI/lRygIoOjV1yymgx6FYFlzJ+z1ATMaLo57nL57AavW
|
3
|
+
hb68HYY8EA0GJU9xQdMVaHBogF3eiCWYXSUZCWM/+M5+ZcdQraRRScucmn6g4EvY
|
4
|
+
2K4W2pxbqH8vmUikPxir41EeBPLjMOzKvbzzQy9e/zzIQVREKSp/7y1mywIDAQAB
|
5
|
+
AoGABc7mp7XYHynuPZxChjWNJZIq+A73gm0ASDv6At7F8Vi9r0xUlQe/v0AQS3yc
|
6
|
+
N8QlyR4XMbzMLYk3yjxFDXo4ZKQtOGzLGteCU2srANiLv26/imXA8FVidZftTAtL
|
7
|
+
viWQZBVPTeYIA69ATUYPEq0a5u5wjGyUOij9OWyuy01mbPkCQQDluYoNpPOekQ0Z
|
8
|
+
WrPgJ5rxc8f6zG37ZVoDBiexqtVShIF5W3xYuWhW5kYb0hliYfkq15cS7t9m95h3
|
9
|
+
1QJf/xI/AkEA1v9l/WN1a1N3rOK4VGoCokx7kR2SyTMSbZgF9IWJNOugR/WZw7HT
|
10
|
+
njipO3c9dy1Ms9pUKwUF46d7049ck8HwdQJARgrSKuLWXMyBH+/l1Dx/I4tXuAJI
|
11
|
+
rlPyo+VmiOc7b5NzHptkSHEPfR9s1OK0VqjknclqCJ3Ig86OMEtEFBzjZQJBAKYz
|
12
|
+
470hcPkaGk7tKYAgP48FvxRsnzeooptURW5E+M+PQ2W9iDPPOX9739+Xi02hGEWF
|
13
|
+
B0IGbQoTRFdE4VVcPK0CQQCeS84lODlC0Y2BZv2JxW3Osv/WkUQ4dslfAQl1T303
|
14
|
+
7uwwr7XTroMv8dIFQIPreoPhRKmd/SbJzbiKfS/4QDhU
|
15
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,6 @@
|
|
1
|
+
-----BEGIN PUBLIC KEY-----
|
2
|
+
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDA7ki9gI/lRygIoOjV1yymgx6F
|
3
|
+
YFlzJ+z1ATMaLo57nL57AavWhb68HYY8EA0GJU9xQdMVaHBogF3eiCWYXSUZCWM/
|
4
|
+
+M5+ZcdQraRRScucmn6g4EvY2K4W2pxbqH8vmUikPxir41EeBPLjMOzKvbzzQy9e
|
5
|
+
/zzIQVREKSp/7y1mywIDAQAB
|
6
|
+
-----END PUBLIC KEY-----
|
data/test/helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestAwsCfSigner < Test::Unit::TestCase
|
5
|
+
context "CloudFront Signing" do
|
6
|
+
setup do
|
7
|
+
@cf_signer = AwsCfSigner.new(File.join(File.dirname(__FILE__), 'fixtures', 'pk-PK123456789754.pem'))
|
8
|
+
end
|
9
|
+
|
10
|
+
context "Initialization and Error Checking" do
|
11
|
+
should "be able to extract the key pair id from the filename of a key straight from AWS" do
|
12
|
+
assert_equal @cf_signer.extract_key_pair_id('/path/to/my/key/pk-THEKEYID.pem'), 'THEKEYID'
|
13
|
+
end
|
14
|
+
|
15
|
+
should "be able to tell you the key pair id" do
|
16
|
+
assert_equal @cf_signer.key_pair_id, 'PK123456789754'
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be able to make a string 'Url-Safe'" do
|
20
|
+
assert_equal(
|
21
|
+
@cf_signer.url_safe("Test+String_~ =Something/Weird"),
|
22
|
+
"Test-String_~_Something~Weird"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "Example Canned Policy" do
|
28
|
+
should "generate the correct signature" do
|
29
|
+
assert_equal(
|
30
|
+
@cf_signer.sign('http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes', :ending => 'Sat, 14 Nov 2009 22:20:00 GMT'),
|
31
|
+
'http://d604721fxaaqy9.cloudfront.net/horizon.jpg?large=yes&license=yes&Expires=1258237200&Signature=Nql641NHEUkUaXQHZINK1FZ~SYeUSoBJMxjdgqrzIdzV2gyEXPDNv0pYdWJkflDKJ3xIu7lbwRpSkG98NBlgPi4ZJpRRnVX4kXAJK6tdNx6FucDB7OVqzcxkxHsGFd8VCG1BkC-Afh9~lOCMIYHIaiOB6~5jt9w2EOwi6sIIqrg_&Key-Pair-Id=PK123456789754'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "Custom Policies from files" do
|
37
|
+
should "generate custom policy 1 correctly" do
|
38
|
+
assert_equal(
|
39
|
+
@cf_signer.sign('http://d604721fxaaqy9.cloudfront.net/training/orientation.avi', :policy_file => File.join(File.dirname(__FILE__), 'fixtures', 'custom_policy1')),
|
40
|
+
'http://d604721fxaaqy9.cloudfront.net/training/orientation.avi?Policy=eyAKICAgIlN0YXRlbWVudCI6IFt7IAogICAgICAiUmVzb3VyY2UiOiJodHRwOi8vZDYwNDcyMWZ4YWFxeTkuY2xvdWRmcm9udC5uZXQvdHJhaW5pbmcvKiIsIAogICAgICAiQ29uZGl0aW9uIjp7IAogICAgICAgICAiSXBBZGRyZXNzIjp7IkFXUzpTb3VyY2VJcCI6IjE0NS4xNjguMTQzLjAvMjQifSwgCiAgICAgICAgICJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI1ODIzNzIwMH0gICAgICAKICAgICAgfSAKICAgfV0gCn0K&Signature=cPFtRKvUfYNYmxek6ZNs6vgKEZP6G3Cb4cyVt~FjqbHOnMdxdT7eT6pYmhHYzuDsFH4Jpsctke2Ux6PCXcKxUcTIm8SO4b29~1QvhMl-CIojki3Hd3~Unxjw7Cpo1qRjtvrimW0DPZBZYHFZtiZXsaPt87yBP9GWnTQoaVysMxQ_&Key-Pair-Id=PK123456789754'
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "generate custom policy 2 correctly" do
|
45
|
+
assert_equal(
|
46
|
+
@cf_signer.sign('http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz', :policy_file => File.join(File.dirname(__FILE__), 'fixtures', 'custom_policy2')),
|
47
|
+
'http://d84l721fxaaqy9.cloudfront.net/downloads/pictures.tgz?Policy=eyAKICAgIlN0YXRlbWVudCI6IFt7IAogICAgICAiUmVzb3VyY2UiOiJodHRwOi8vKiIsIAogICAgICAiQ29uZGl0aW9uIjp7IAogICAgICAgICAiSXBBZGRyZXNzIjp7IkFXUzpTb3VyY2VJcCI6IjIxNi45OC4zNS4xLzMyIn0sCiAgICAgICAgICJEYXRlR3JlYXRlclRoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI0MTA3Mzc5MH0sCiAgICAgICAgICJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTI1NTY3NDcxNn0KICAgICAgfSAKICAgfV0gCn0K&Signature=rc~5Qbbm8EJXjUTQ6Cn0LAxR72g1DOPrTmdtfbWVVgQNw0q~KHUAmBa2Zv1Wjj8dDET4XSL~Myh44CLQdu4dOH~N9huH7QfPSR~O4tIOS1WWcP~2JmtVPoQyLlEc8YHRCuN3nVNZJ0m4EZcXXNAS-0x6Zco2SYx~hywTRxWR~5Q_&Key-Pair-Id=PK123456789754'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "Custom Policy Generation" do
|
53
|
+
should "correctly generate custom policy" do
|
54
|
+
starting = Time.now
|
55
|
+
ending = Time.now + 3600
|
56
|
+
ip_range = '216.98.35.1/32'
|
57
|
+
assert_equal(
|
58
|
+
@cf_signer.generate_custom_policy('http://d84l721fxaaqy9.cloudfront.net/downloads/*', :starting => starting, :ending => ending, :ip_range => ip_range),
|
59
|
+
%({"Statement":[{"Resource":"http://d84l721fxaaqy9.cloudfront.net/downloads/*","Condition":{"DateLessThan":{"AWS:EpochTime":#{ending.to_i}},"DateGreaterThan":{"AWS:EpochTime":#{starting.to_i}},"IpAddress":{"AWS:SourceIp":#{ip_range}}}]})
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_cf_signer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dylan Vaughn
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-17 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: yard
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: "Small gem for signing AWS CloudFront URLs given a AWS key_pair_id and pem file. Read more here: http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?PrivateContent.html"
|
50
|
+
email: dylan.vaughn@stlondemand.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- .document
|
59
|
+
- .gitignore
|
60
|
+
- README.rdoc
|
61
|
+
- Rakefile
|
62
|
+
- VERSION
|
63
|
+
- aws_cf_signer.gemspec
|
64
|
+
- lib/aws_cf_signer.rb
|
65
|
+
- test/fixtures/README
|
66
|
+
- test/fixtures/custom_policy1
|
67
|
+
- test/fixtures/custom_policy2
|
68
|
+
- test/fixtures/pk-PK123456789754.pem
|
69
|
+
- test/fixtures/rsa-PK123456789754.pem
|
70
|
+
- test/helper.rb
|
71
|
+
- test/test_aws_cf_signer.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/stlondemand/aws_cf_signer
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --charset=UTF-8
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.3.7
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Ruby gem for signing AWS Cloudfront URLs for serving private content
|
106
|
+
test_files:
|
107
|
+
- test/helper.rb
|
108
|
+
- test/test_aws_cf_signer.rb
|