keen 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/keen/aes_helper.rb +25 -32
- data/lib/keen/aes_helper_old.rb +50 -0
- data/lib/keen/scoped_key.rb +11 -8
- data/lib/keen/version.rb +1 -1
- data/spec/keen/scoped_key_old_spec.rb +57 -0
- data/spec/keen/scoped_key_spec.rb +2 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1699510fc2d24980d980c0fc72cd2a8b95db715
|
4
|
+
data.tar.gz: a50d16fe6edff311e4482217a96a89f812b81988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d4e6b05301f89eaf477bc95f4b9297ac22ca96706e3133458cccdff0bd2a2a0d0a6f6c377273e5358bee1924a0a52376068e8d34f4fcc875ec20d959a816ec3
|
7
|
+
data.tar.gz: eea17f8068313eefcb15f2c23460f23fccf212e1464e12050ee18f2069980d344581cb39228c38838a02f8363ab6bc0988b62b39cb488e019f9a70b1a092d5f5
|
data/README.md
CHANGED
@@ -412,6 +412,9 @@ If you want some bot protection, check out the [Voight-Kampff](https://github.co
|
|
412
412
|
|
413
413
|
### Changelog
|
414
414
|
|
415
|
+
##### 0.9.5
|
416
|
+
+ Fix bug with scoped key generation not working with newer Keen projects.
|
417
|
+
|
415
418
|
##### 0.9.4
|
416
419
|
+ Add SDK support for Saved Queries
|
417
420
|
+ Removed support for Ruby MRI 1.8.7
|
data/lib/keen/aes_helper.rb
CHANGED
@@ -3,42 +3,35 @@ require 'digest'
|
|
3
3
|
require 'base64'
|
4
4
|
|
5
5
|
module Keen
|
6
|
-
|
6
|
+
class AESHelper
|
7
7
|
|
8
|
-
|
8
|
+
class << self
|
9
|
+
def aes256_decrypt(key, iv_plus_encrypted)
|
10
|
+
aes = OpenSSL::Cipher::AES.new(256, :CBC)
|
11
|
+
iv = iv_plus_encrypted[0, aes.key_len]
|
12
|
+
encrypted = iv_plus_encrypted[aes.key_len, iv_plus_encrypted.length]
|
13
|
+
aes.decrypt
|
14
|
+
aes.key = unhexlify(key)
|
15
|
+
aes.iv = unhexlify(iv)
|
16
|
+
aes.update(unhexlify(encrypted)) + aes.final
|
17
|
+
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def aes256_decrypt(key, iv_plus_encrypted)
|
20
|
-
iv = iv_plus_encrypted[0, 16]
|
21
|
-
encrypted = iv_plus_encrypted[16, iv_plus_encrypted.length]
|
22
|
-
aes = OpenSSL::Cipher::AES.new(256, :CBC)
|
23
|
-
aes.decrypt
|
24
|
-
aes.key = key
|
25
|
-
aes.iv = iv
|
26
|
-
aes.update(encrypted) + aes.final
|
27
|
-
end
|
19
|
+
def aes256_encrypt(key, plaintext, iv = nil)
|
20
|
+
aes = OpenSSL::Cipher::AES.new(256, :CBC)
|
21
|
+
aes.encrypt
|
22
|
+
aes.key = unhexlify(key)
|
23
|
+
aes.iv = iv unless iv.nil?
|
24
|
+
iv ||= aes.random_iv
|
25
|
+
hexlify(iv) + hexlify(aes.update(plaintext) + aes.final)
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def unhexlify(msg)
|
34
|
-
[msg].pack('H*')
|
35
|
-
end
|
28
|
+
def hexlify(msg)
|
29
|
+
msg.unpack('H*')[0]
|
30
|
+
end
|
36
31
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
padded = msg + padding
|
41
|
-
padded
|
32
|
+
def unhexlify(msg)
|
33
|
+
[msg].pack('H*')
|
34
|
+
end
|
42
35
|
end
|
43
36
|
end
|
44
37
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'digest'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Keen
|
6
|
+
class AESHelperOld
|
7
|
+
|
8
|
+
BLOCK_SIZE = 32
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def aes256_decrypt(key, iv_plus_encrypted)
|
12
|
+
padded_key = pad(key)
|
13
|
+
unhexed_iv_plus_encrypted = unhexlify(iv_plus_encrypted)
|
14
|
+
iv = unhexed_iv_plus_encrypted[0, 16]
|
15
|
+
encrypted = unhexed_iv_plus_encrypted[16, unhexed_iv_plus_encrypted.length]
|
16
|
+
aes = OpenSSL::Cipher::AES.new(256, :CBC)
|
17
|
+
aes.decrypt
|
18
|
+
aes.key = padded_key
|
19
|
+
aes.iv = iv
|
20
|
+
aes.update(encrypted) + aes.final
|
21
|
+
end
|
22
|
+
|
23
|
+
def aes256_encrypt(key, plaintext, iv = nil)
|
24
|
+
padded_key = pad(key)
|
25
|
+
aes = OpenSSL::Cipher::AES.new(256, :CBC)
|
26
|
+
aes.encrypt
|
27
|
+
aes.key = padded_key
|
28
|
+
aes.iv = iv unless iv.nil?
|
29
|
+
iv ||= aes.random_iv
|
30
|
+
encrypted = aes.update(plaintext) + aes.final
|
31
|
+
hexlify(iv) + hexlify(encrypted)
|
32
|
+
end
|
33
|
+
|
34
|
+
def hexlify(msg)
|
35
|
+
msg.unpack('H*')[0]
|
36
|
+
end
|
37
|
+
|
38
|
+
def unhexlify(msg)
|
39
|
+
[msg].pack('H*')
|
40
|
+
end
|
41
|
+
|
42
|
+
def pad(msg)
|
43
|
+
pad_len = BLOCK_SIZE - (msg.length % BLOCK_SIZE)
|
44
|
+
padding = pad_len.chr * pad_len
|
45
|
+
padded = msg + padding
|
46
|
+
padded
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/keen/scoped_key.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'multi_json'
|
2
2
|
require 'keen/aes_helper'
|
3
|
+
require 'keen/aes_helper_old'
|
3
4
|
|
4
5
|
module Keen
|
5
6
|
class ScopedKey
|
6
|
-
include AESHelper
|
7
|
-
extend AESHelper
|
8
7
|
|
9
8
|
attr_accessor :api_key
|
10
9
|
attr_accessor :data
|
11
10
|
|
12
11
|
class << self
|
13
12
|
def decrypt!(api_key, scoped_key)
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
if api_key.length == 64
|
14
|
+
decrypted = Keen::AESHelper.aes256_decrypt(api_key, scoped_key)
|
15
|
+
else
|
16
|
+
decrypted = Keen::AESHelperOld.aes256_decrypt(api_key, scoped_key)
|
17
|
+
end
|
17
18
|
data = MultiJson.load(decrypted)
|
18
19
|
self.new(api_key, data)
|
19
20
|
end
|
@@ -26,9 +27,11 @@ module Keen
|
|
26
27
|
|
27
28
|
def encrypt!(iv = nil)
|
28
29
|
json_str = MultiJson.dump(self.data)
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
if self.api_key.length == 64
|
31
|
+
Keen::AESHelper.aes256_encrypt(self.api_key, json_str, iv)
|
32
|
+
else
|
33
|
+
Keen::AESHelperOld.aes256_encrypt(self.api_key, json_str, iv)
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
data/lib/keen/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Keen::ScopedKey do
|
4
|
+
let(:api_key) { "ab428324dbdbcfe744" }
|
5
|
+
let(:bad_api_key) { "badbadbadbad" }
|
6
|
+
let(:data) { {
|
7
|
+
"filters" => [{
|
8
|
+
"property_name" => "accountId",
|
9
|
+
"operator" => "eq",
|
10
|
+
"property_value" => "123456"
|
11
|
+
}]
|
12
|
+
}}
|
13
|
+
let(:new_scoped_key) { Keen::ScopedKey.new(api_key, data) }
|
14
|
+
|
15
|
+
describe "constructor" do
|
16
|
+
it "should retain the api_key" do
|
17
|
+
new_scoped_key.api_key.should == api_key
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should retain the data" do
|
21
|
+
new_scoped_key.data.should == data
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "encrypt! and decrypt!" do
|
26
|
+
it "should encrypt and hex encode the data using the api key" do
|
27
|
+
encrypted_str = new_scoped_key.encrypt!
|
28
|
+
other_api_key = Keen::ScopedKey.decrypt!(api_key, encrypted_str)
|
29
|
+
other_api_key.data.should == data
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when an IV is not provided" do
|
33
|
+
it "should not produce the same encrypted key text" do
|
34
|
+
new_scoped_key.encrypt!.should_not == (new_scoped_key.encrypt!)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "when an IV is provided" do
|
39
|
+
it "should produce the same encrypted key text for a " do
|
40
|
+
iv = "\0" * 32
|
41
|
+
new_scoped_key.encrypt!(iv).should == (new_scoped_key.encrypt!(iv))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should raise error when an invalid IV is supplied" do
|
45
|
+
iv = "fakeiv"
|
46
|
+
expect { new_scoped_key.encrypt!(iv) }.to raise_error(OpenSSL::Cipher::CipherError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not decrypt the scoped key with a bad api key" do
|
51
|
+
encrypted_str = new_scoped_key.encrypt!
|
52
|
+
expect {
|
53
|
+
other_api_key = Keen::ScopedKey.decrypt!(bad_api_key, encrypted_str)
|
54
|
+
}.to raise_error(OpenSSL::Cipher::CipherError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Keen::ScopedKey do
|
4
|
-
let(:api_key) {
|
5
|
-
let(:bad_api_key) { "
|
4
|
+
let(:api_key) { "24077ACBCB198BAAA2110EDDB673282F8E34909FD823A15C55A6253A664BE368" }
|
5
|
+
let(:bad_api_key) { "24077ACBCB198BAAA2110EDDB673282F8E34909FD823A15C55A6253A664BE369" }
|
6
6
|
let(:data) { {
|
7
7
|
"filters" => [{
|
8
8
|
"property_name" => "accountId",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kleissner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- keen.gemspec
|
156
156
|
- lib/keen.rb
|
157
157
|
- lib/keen/aes_helper.rb
|
158
|
+
- lib/keen/aes_helper_old.rb
|
158
159
|
- lib/keen/client.rb
|
159
160
|
- lib/keen/client/maintenance_methods.rb
|
160
161
|
- lib/keen/client/publishing_methods.rb
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- spec/keen/client_spec.rb
|
173
174
|
- spec/keen/keen_spec.rb
|
174
175
|
- spec/keen/saved_query_spec.rb
|
176
|
+
- spec/keen/scoped_key_old_spec.rb
|
175
177
|
- spec/keen/scoped_key_spec.rb
|
176
178
|
- spec/keen/spec_helper.rb
|
177
179
|
- spec/spec_helper.rb
|
@@ -197,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
199
|
version: '0'
|
198
200
|
requirements: []
|
199
201
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.4.
|
202
|
+
rubygems_version: 2.4.5
|
201
203
|
signing_key:
|
202
204
|
specification_version: 4
|
203
205
|
summary: Keen IO API Client
|
@@ -211,6 +213,7 @@ test_files:
|
|
211
213
|
- spec/keen/client_spec.rb
|
212
214
|
- spec/keen/keen_spec.rb
|
213
215
|
- spec/keen/saved_query_spec.rb
|
216
|
+
- spec/keen/scoped_key_old_spec.rb
|
214
217
|
- spec/keen/scoped_key_spec.rb
|
215
218
|
- spec/keen/spec_helper.rb
|
216
219
|
- spec/spec_helper.rb
|