auric-vault-door 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +9 -0
- data/auric-vault-door.gemspec +26 -0
- data/lib/auric/vault/door/version.rb +7 -0
- data/lib/auric/vault/door.rb +134 -0
- metadata +119 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
vendor/*
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Carl Anderson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Auric::Vault::Door
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'auric-vault-door'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install auric-vault-door
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
@door = Auric::Vault::Door.new('shared_secret_goes_here', 'merchant_id', 'config_id', 'segment', @production_boolean?)
|
22
|
+
|
23
|
+
@door.encrypt('string_to_encrypt')
|
24
|
+
=> 'dpFAl7BY260IWzFxxxx'
|
25
|
+
|
26
|
+
@door.decrypt('dpFAl7BY260IWzFxxxx')
|
27
|
+
=> 'string_to_encrypt'
|
28
|
+
|
29
|
+
If either method fails, checking error should return a string about what went wrong:
|
30
|
+
|
31
|
+
@door.error
|
32
|
+
=> "VLT-112: This method is missing the following fields. Method: decrypt [token]"
|
33
|
+
|
34
|
+
TODO: Only encrypt and decrypt methods are currently implemented.
|
35
|
+
Better error error handling
|
36
|
+
Tests.
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/[my-github-username]/auric-vault-door/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'auric/vault/door/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "auric-vault-door"
|
8
|
+
spec.version = Auric::Vault::Door::VERSION
|
9
|
+
spec.authors = ["Carl Anderson"]
|
10
|
+
spec.email = ["carl@planetargon.com"]
|
11
|
+
spec.summary = %q{Provides access to the Auric Vault API.}
|
12
|
+
spec.description = %q{Provides access to API at https://www.auricsystems.com/products/paymentvault-tokenization/ for storing data using a token.}
|
13
|
+
spec.homepage = "https://github.com/nextekcarl/auric-vault-door"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'httparty', '~> 0.13.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require "auric/vault/door/version"
|
2
|
+
require 'openssl'
|
3
|
+
require 'HTTParty'
|
4
|
+
|
5
|
+
module Auric
|
6
|
+
module Vault
|
7
|
+
class Door
|
8
|
+
attr_accessor :secret, :mtid, :config_id, :production, :segment
|
9
|
+
attr_reader :error, :success
|
10
|
+
SANDBOXURLS = ['https://vault01-sb.auricsystems.com/vault/v2/', 'https://vault02-sb.auricsystems.com/vault/v2/']
|
11
|
+
PRODUCTIONURLS= ['https://vault01-sb.auricsystems.com/vault/v2/', 'https://vault02-sb.auricsystems.com/vault/v2/']
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
required_args = [:secret, :mtid, :config_id]
|
15
|
+
required_args.each do |arg|
|
16
|
+
raise ArgumentError, "Required argument: (#{arg}) not provided" unless args.include?(arg)
|
17
|
+
end
|
18
|
+
@secret = args[:secret]
|
19
|
+
@mtid = args[:mtid]
|
20
|
+
@config_id = args[:config_id]
|
21
|
+
@production = args[:production] || false
|
22
|
+
@segment = args[:segment]
|
23
|
+
@success = false
|
24
|
+
@error = nil
|
25
|
+
if @production
|
26
|
+
@url = PRODUCTIONURLS
|
27
|
+
else
|
28
|
+
@url = SANDBOXURLS
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def encrypt(data)
|
33
|
+
json = post_data('encrypt', data)
|
34
|
+
if @success
|
35
|
+
return json['result']['token']
|
36
|
+
else
|
37
|
+
@error = json['error']
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def decrypt(token)
|
43
|
+
json = get_data('decrypt', token)
|
44
|
+
if @success
|
45
|
+
return json['result']['plaintextValue']
|
46
|
+
else
|
47
|
+
@error = json['error']
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def build_post_message(method, plaintext_value)
|
55
|
+
{
|
56
|
+
'params'=>
|
57
|
+
[{
|
58
|
+
'mtid'=> @mtid,
|
59
|
+
'configurationId'=> @config_id,
|
60
|
+
'utcTimestamp'=> Time.now.to_i.to_s,
|
61
|
+
'retention'=> 'big-year',
|
62
|
+
'segment'=> @segment,
|
63
|
+
'last4'=> '',
|
64
|
+
'plaintextValue'=> plaintext_value
|
65
|
+
}],
|
66
|
+
'method'=> method
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_get_message(method, token)
|
71
|
+
{
|
72
|
+
'params'=>
|
73
|
+
[{
|
74
|
+
'mtid'=> @mtid,
|
75
|
+
'configurationId'=> @config_id,
|
76
|
+
'utcTimestamp'=> Time.now.to_i.to_s,
|
77
|
+
'token'=> token
|
78
|
+
}],
|
79
|
+
'method'=> method
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def figure_hexdigest_for_auth(message_body)
|
84
|
+
digest = OpenSSL::Digest.new('sha512')
|
85
|
+
OpenSSL::HMAC.hexdigest(digest, @secret, message_body.to_json)
|
86
|
+
end
|
87
|
+
|
88
|
+
def call_auric(method, data)
|
89
|
+
signature = figure_hexdigest_for_auth(data)
|
90
|
+
begin
|
91
|
+
HTTParty.post(
|
92
|
+
@url[0],
|
93
|
+
{
|
94
|
+
:body => data.to_json,
|
95
|
+
headers: { 'X-VAULT-HMAC' => signature }
|
96
|
+
}
|
97
|
+
)
|
98
|
+
rescue
|
99
|
+
HTTParty.post(
|
100
|
+
@url[1],
|
101
|
+
{
|
102
|
+
:body => data.to_json,
|
103
|
+
headers: { 'X-VAULT-HMAC' => signature }
|
104
|
+
}
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def post_data(method, data)
|
110
|
+
message_body = build_post_message(method, data)
|
111
|
+
response = call_auric(method, message_body)
|
112
|
+
json_response = JSON.parse(response.parsed_response)
|
113
|
+
if json_response['result']['lastActionSucceeded'] == 1
|
114
|
+
@success = true
|
115
|
+
else
|
116
|
+
@success = false
|
117
|
+
end
|
118
|
+
json_response
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_data(method, data)
|
122
|
+
message_body = build_get_message(method, data)
|
123
|
+
response = call_auric(method, message_body)
|
124
|
+
json_response = JSON.parse(response.parsed_response)
|
125
|
+
if json_response['result']['lastActionSucceeded'] == 1
|
126
|
+
@success = true
|
127
|
+
else
|
128
|
+
@success = false
|
129
|
+
end
|
130
|
+
json_response
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auric-vault-door
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Carl Anderson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.13.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.13.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.6'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.6'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Provides access to API at https://www.auricsystems.com/products/paymentvault-tokenization/
|
79
|
+
for storing data using a token.
|
80
|
+
email:
|
81
|
+
- carl@planetargon.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- auric-vault-door.gemspec
|
92
|
+
- lib/auric/vault/door.rb
|
93
|
+
- lib/auric/vault/door/version.rb
|
94
|
+
homepage: https://github.com/nextekcarl/auric-vault-door
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.23
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Provides access to the Auric Vault API.
|
119
|
+
test_files: []
|