onnistuu_fi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/onnistuu_fi/form.rb +48 -0
- data/lib/onnistuu_fi/response.rb +17 -0
- data/lib/onnistuu_fi/signer.rb +31 -0
- data/lib/onnistuu_fi/version.rb +3 -0
- data/lib/onnistuu_fi.rb +34 -0
- data/onnistuu_fi.gemspec +36 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d8c750ed0ddbe0401d908a47a5dc306b1ee07b5
|
4
|
+
data.tar.gz: bb7a70479ed65d1c3a98ee28062275dbb0dc27ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76377b3df828ce8b4affe483d69158c0fa7759b3beba5afeb0ea09e7a4791803d67b5d1d7e3c1cc13cb30c1ae4d476cbfd28f0722eae3c3f81009e369a2bd9f4
|
7
|
+
data.tar.gz: 2d63342c6558ed73b7707f90db5480cc2ac978ee5db1728c85a33da06be2f1926551ef3ee30f6cc0a2f7636d8d856c5b91e917b859b666855e3ab26928912a3a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# OnnistuuFi
|
2
|
+
|
3
|
+
This gem implements Onnistuu.fi API version 0.20.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'onnistuu_fi'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install onnistuu_fi
|
20
|
+
|
21
|
+
## Dependencies
|
22
|
+
|
23
|
+
Mcrypt needs to be installed for the library to work.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Generating the form
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Outputs the form HTML
|
31
|
+
|
32
|
+
OnnistuuFi.generate_form(
|
33
|
+
client_identifier: ENV["ONNISTUU_FI_CLIENT_ID"],
|
34
|
+
encryption_key: ENV["ONNISTUU_FI_ENCRYPTION_KEY"],
|
35
|
+
fields: {
|
36
|
+
return_failure: "https://example.com/failure",
|
37
|
+
return_success: "https://example.com/success",
|
38
|
+
document: "https://example.com/document.pdf",
|
39
|
+
button_text: "Sign the document",
|
40
|
+
requirements: [
|
41
|
+
{"type": "person", "identifier": "110761-635Y"}
|
42
|
+
]
|
43
|
+
}
|
44
|
+
)
|
45
|
+
```
|
46
|
+
|
47
|
+
If you want to customize the button & other form content, pass a block to `generate_form`:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
OnnistuuFi.generate_form(options) {
|
51
|
+
"<button type="submit">Sign document</button>"
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
55
|
+
### Processing the response
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
|
59
|
+
# Returns the data from Onnistuu.fi or raises OnnistuuFi::DecodeError
|
60
|
+
|
61
|
+
OnnistuuFi.decode_response(
|
62
|
+
client_identifier: ENV["ONNISTUU_FI_CLIENT_ID"],
|
63
|
+
encryption_key: ENV["ONNISTUU_FI_ENCRYPTION_KEY"],
|
64
|
+
encrypted_data: params[:data],
|
65
|
+
iv: params[:iv])
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## TODO
|
77
|
+
|
78
|
+
- A class for verifying a document
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kiskolabs/onnistuu_fi.
|
83
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "onnistuu_fi"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module OnnistuuFi
|
2
|
+
class Form
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
def initialize(signer, options = {})
|
6
|
+
@signer = signer
|
7
|
+
@options = options
|
8
|
+
|
9
|
+
data = {
|
10
|
+
stamp: @options.delete(:stamp) || Time.now,
|
11
|
+
return_success: @options.delete(:return_success),
|
12
|
+
document: @options.delete(:document),
|
13
|
+
requirements: @options.delete(:requirements)
|
14
|
+
}
|
15
|
+
iv, signed_data = signer.encrypt(data)
|
16
|
+
|
17
|
+
options[:iv] = iv
|
18
|
+
options[:data] = signed_data
|
19
|
+
validate_options!
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_html
|
23
|
+
"<form action='#{API_ENDPOINT}' method='post'>
|
24
|
+
#{fields.compact.join("\n")}
|
25
|
+
<input type='hidden' name='padding' value='pkcs5' />
|
26
|
+
#{@options[:button]}
|
27
|
+
</form>"
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def validate_options!
|
33
|
+
# TODO
|
34
|
+
end
|
35
|
+
|
36
|
+
def fields
|
37
|
+
[:customer, :return_failure, :return_success, :data, :iv].map {|field_name|
|
38
|
+
if options[field_name]
|
39
|
+
hidden_field(field_name, options[field_name])
|
40
|
+
end
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def hidden_field(name, value)
|
45
|
+
"<input type='hidden' name='#{name.to_s}' value='#{value.to_s}' />"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module OnnistuuFi
|
4
|
+
class Response
|
5
|
+
attr_reader :signer
|
6
|
+
|
7
|
+
def initialize(encrypted, iv, signer)
|
8
|
+
@encrypted = encrypted
|
9
|
+
@iv = iv
|
10
|
+
@signer = signer
|
11
|
+
end
|
12
|
+
|
13
|
+
def data
|
14
|
+
signer.decrypt(@encrypted, @iv)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "mcrypt"
|
2
|
+
require "base64"
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
module OnnistuuFi
|
6
|
+
class Signer
|
7
|
+
def initialize(client_identifier, encryption_key)
|
8
|
+
@client_identifier = client_identifier
|
9
|
+
@encryption_key = Base64.decode64(encryption_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns [base64_iv, base64_encrypted_data]
|
13
|
+
def encrypt(data)
|
14
|
+
iv = OpenSSL::Cipher::Cipher.new("AES-256-CBC").random_iv.unpack("H*").first
|
15
|
+
mcrypt = Mcrypt.new(:rijndael_256, :cbc, @encryption_key, iv, :pkcs)
|
16
|
+
|
17
|
+
[Base64.encode64(iv), Base64.encode64(mcrypt.encrypt(JSON.dump(data)))]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parameters:
|
21
|
+
# - encrypted data in base64
|
22
|
+
# - iv in base64
|
23
|
+
#
|
24
|
+
# Returns decrypted data
|
25
|
+
def decrypt(encrypted, iv)
|
26
|
+
mcrypt = Mcrypt.new(:rijndael_256, :cbc, @encryption_key, Base64.decode64(iv), :pkcs)
|
27
|
+
|
28
|
+
JSON.load(mcrypt.decrypt(Base64.decode64(encrypted)))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/onnistuu_fi.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "onnistuu_fi/version"
|
2
|
+
require "onnistuu_fi/signer"
|
3
|
+
require "onnistuu_fi/form"
|
4
|
+
require "onnistuu_fi/response"
|
5
|
+
|
6
|
+
module OnnistuuFi
|
7
|
+
API_ENDPOINT = "https://www.onnistuu.fi/external/entry/"
|
8
|
+
|
9
|
+
def self.generate_form(options = {})
|
10
|
+
@client_identifier = options.fetch(:client_identifier) { raise(ArgumentError, "missing client_identifier from the passed arguments") }
|
11
|
+
@encryption_key = options.fetch(:encryption_key) { raise(ArgumentError, "missing encryption_key from the passed arguments") }
|
12
|
+
|
13
|
+
signer = OnnistuuFi::Signer.new(@client_identifier, @encryption_key)
|
14
|
+
fields = options.fetch(:fields)
|
15
|
+
fields = fields.merge(customer: @client_identifier)
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
fields[:button] = yield
|
19
|
+
else
|
20
|
+
fields[:button] = "<button type='submit'>#{fields.fetch(:button_text, 'Sign')}</button>"
|
21
|
+
end
|
22
|
+
|
23
|
+
OnnistuuFi::Form.new(signer, fields).generate_html
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.decode_response(options = {})
|
27
|
+
@client_identifier = options.fetch(:client_identifier) { raise(ArgumentError, "missing client_identifier from the passed arguments") }
|
28
|
+
@encryption_key = options.fetch(:encryption_key) { raise(ArgumentError, "missing encryption_key from the passed arguments") }
|
29
|
+
|
30
|
+
signer = OnnistuuFi::Signer.new(@client_identifier, @encryption_key)
|
31
|
+
|
32
|
+
OnnistuuFi::Response.new(options.fetch(:encrypted_data), options.fetch(:iv), signer).data
|
33
|
+
end
|
34
|
+
end
|
data/onnistuu_fi.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onnistuu_fi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "onnistuu_fi"
|
8
|
+
spec.version = OnnistuuFi::VERSION
|
9
|
+
spec.authors = ["Vesa Vänskä"]
|
10
|
+
spec.email = ["vesa@vesavanska.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Implements Onnistuu.fi interface.}
|
13
|
+
spec.description = %q{Implements Onnistuu.fi interface}
|
14
|
+
spec.homepage = "https://github.com/kiskolabs/onnistuu_fi"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "rspec-html-matchers", "~> 0.8.0"
|
33
|
+
spec.add_development_dependency "byebug"
|
34
|
+
spec.add_dependency "aes", "~> 0.5.0"
|
35
|
+
spec.add_dependency "ruby-mcrypt", "~> 0.2.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onnistuu_fi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vesa Vänskä
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-html-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aes
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby-mcrypt
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.0
|
111
|
+
description: Implements Onnistuu.fi interface
|
112
|
+
email:
|
113
|
+
- vesa@vesavanska.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/console
|
125
|
+
- bin/setup
|
126
|
+
- lib/onnistuu_fi.rb
|
127
|
+
- lib/onnistuu_fi/form.rb
|
128
|
+
- lib/onnistuu_fi/response.rb
|
129
|
+
- lib/onnistuu_fi/signer.rb
|
130
|
+
- lib/onnistuu_fi/version.rb
|
131
|
+
- onnistuu_fi.gemspec
|
132
|
+
homepage: https://github.com/kiskolabs/onnistuu_fi
|
133
|
+
licenses: []
|
134
|
+
metadata:
|
135
|
+
allowed_push_host: https://rubygems.org
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.4.5.1
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Implements Onnistuu.fi interface.
|
156
|
+
test_files: []
|