secure_request 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/secure_request/version.rb +3 -0
- data/lib/secure_request.rb +51 -0
- data/secure_request.gemspec +17 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTVhYWIxYzg0NDFiZWVlNWVkNGU0YTZlNGZhN2I4NzYzYWQwN2QyZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTZhOWQ1M2M4Y2NkYTM4OWVhNjMyZjM5NjlmNWU1NGMzMjI0N2ZmYw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmI3Zjk5NmVlODViN2I3M2Y5NDQ0NjJhYWM3M2Y2YmRlNGYwNWE5MDM1OGJh
|
10
|
+
MGY1ZTVmYTMyN2M2NzAwNzdiNDQ3NmFhMTI5Nzk4ZWE2ZDRiNzMwMDFkZGRi
|
11
|
+
Yzc4NmZjZDEzMDk5YTQ0NGViNjQxMGQ3MDc5ZWZjOGIwNTI0ODc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWE0Y2M3MGY5MmU1Zjg4ZjE3YzdhYTA4MGE2NTY4NzZiMDllMGJiMzdiM2Ey
|
14
|
+
ZDg4Yzc1ZWYxZWNmNWI1YzhkYjkxNjY0OTIxOTMxZmRjZGVmYzg2NzBkM2Nm
|
15
|
+
NjY1OWZlMDJkNTU0YTkyODQyMmExN2I3NjVkNDg5NDUwZGVkMDc=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'signatron'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
module SecureRequest
|
5
|
+
def self.post(url, body, timeout = 60)
|
6
|
+
HTTParty.post url, body: body.strip, headers: make_httparty_headers(url.strip + body.strip, Time.now, timeout)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.put(url, body, timeout = 60)
|
10
|
+
HTTParty.put url, body: body.strip, headers: make_httparty_headers(url.strip + body.strip, Time.now, timeout)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.delete(url, timeout = 60)
|
14
|
+
HTTParty.delete url, headers: make_httparty_headers(url.strip, Time.now, timeout)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get(url, timeout = 60)
|
18
|
+
HTTParty.get url, headers: make_httparty_headers(url.strip, Time.now, timeout)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.verify(request)
|
22
|
+
http_s = request.env['HTTP_X_SECUREREQUEST_S']
|
23
|
+
http_ts = request.env['HTTP_X_SECUREREQUEST_TS']
|
24
|
+
http_to = request.env['HTTP_X_SECUREREQUEST_TO']
|
25
|
+
|
26
|
+
return false unless http_s and http_ts and http_to
|
27
|
+
|
28
|
+
signature = http_s.strip
|
29
|
+
timestamp = Time.at http_ts.to_i
|
30
|
+
timeout = http_to.to_i
|
31
|
+
|
32
|
+
data = request.url.strip
|
33
|
+
|
34
|
+
if request.body.size > 0
|
35
|
+
request.body.pos = 0
|
36
|
+
data += request.body.gets.strip
|
37
|
+
end
|
38
|
+
|
39
|
+
Signatron.verify data, timestamp, timeout, signature
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.make_httparty_headers(data, timestamp, timeout)
|
45
|
+
{
|
46
|
+
'X-SecureRequest-S' => Signatron.sign(data, timestamp, timeout),
|
47
|
+
'X-SecureRequest-TS' => timestamp.to_i.to_s,
|
48
|
+
'X-SecureRequest-TO' => timeout.to_i.to_s
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'secure_request/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'secure_request'
|
7
|
+
spec.version = SecureRequest::VERSION
|
8
|
+
spec.authors = ['Gabriel Kirkpatrick', 'James Billingham']
|
9
|
+
spec.email = ['g@be-k.biz', 'james@billingham.net']
|
10
|
+
spec.summary = 'Makes and verifies secure requests'
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.require_paths = ['lib']
|
14
|
+
|
15
|
+
spec.add_dependency 'httparty'
|
16
|
+
spec.add_dependency 'signatron', '>= 0.0.9'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secure_request
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Kirkpatrick
|
8
|
+
- James Billingham
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: signatron
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.0.9
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.0.9
|
42
|
+
description:
|
43
|
+
email:
|
44
|
+
- g@be-k.biz
|
45
|
+
- james@billingham.net
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- Rakefile
|
53
|
+
- lib/secure_request.rb
|
54
|
+
- lib/secure_request/version.rb
|
55
|
+
- secure_request.gemspec
|
56
|
+
homepage:
|
57
|
+
licenses: []
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Makes and verifies secure requests
|
79
|
+
test_files: []
|