ubiq-security 1.0.1 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7988726fc44204d81c5fd65b343c14d34ff24e2fc6883b6fed4acdfc71afb98
4
- data.tar.gz: c22cc110f282e5b93dd42fe49be499a1dff208d6fce0726329499a5b0b0fb93a
3
+ metadata.gz: eb202f29281352bd6b6054b8ee1593e063b34f5f4230b5f73e59fe3ce33544e1
4
+ data.tar.gz: 58f2192b4fad98886e30218925097539716107748de42d50c29fe83ef250cb0f
5
5
  SHA512:
6
- metadata.gz: 91e17a9b5b5d52dc2f107585884bdda8e3a12cf2e405329b5204835ac28a9dd416bd044fc0fb530e6b43382d1ec6ecc9b0b9771b4317744fcfef6ae7bd9b9757
7
- data.tar.gz: a428124dc92b6b956a8f5be93d19e00bc4541144894b73f3ee692f6db22bb8514e2be77f8977b140ed04f8f0ed3504d20523c5bec1d5f08399dda4654218afcc
6
+ metadata.gz: 1f5114fb90183ae27e4e706752e9d065cddbacf3230196ad8dce0949207bfc3db92502c607ce606b5ca73716676336514098342b6cb6ad61085467968fab2543
7
+ data.tar.gz: 6fd719b4f2c08b1bfcdfb4a33215002a85f51f2e7d03a24ff7a89e3b941044d470443241f9e447bcac049828548b1ffc9542a37ca9c50bc9b588182dff238d6c
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.0.6 - 2020-10-28
4
+ * Change to MIT license
5
+
6
+ ## 1.0.5 - 2020-09-23
7
+ * Remove dead code
8
+ * Pass client library name and version to server
9
+ * Added AAD information to ciphers for encrypt and decrypt
10
+
11
+ ## 1.0.1 - 2020-08-20
12
+ * Initial Version
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020- Ubiq Security, Inc. (https://ubiqsecurity.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -31,8 +31,11 @@ To build and install directly from a clone of the gitlab repository source:
31
31
  ```sh
32
32
  git clone https://gitlab.com/ubiqsecurity/ubiq-ruby.git
33
33
  cd ubiq-ruby
34
- rake install:local
34
+ bundle install
35
+ gem build ubiq-security.gemspec
36
+ gem install ./ubiq-security*.gem
35
37
  ```
38
+ You may need to run the `gem install` commands above using sudo.
36
39
 
37
40
 
38
41
  ## Usage
@@ -82,7 +85,7 @@ Pass credentials and data into the encryption function. The encrypted data will
82
85
 
83
86
 
84
87
  ```ruby
85
- require "ubiq-security"
88
+ require 'ubiq-security'
86
89
  include Ubiq
87
90
 
88
91
  encrypted_data = encrypt(credentials, plaintext_data)
@@ -94,7 +97,7 @@ encrypted_data = encrypt(credentials, plaintext_data)
94
97
  Pass credentials and encrypted data into the decryption function. The plaintext data will be returned.
95
98
 
96
99
  ```ruby
97
- require "ubiq-security"
100
+ require 'ubiq-security'
98
101
  include Ubiq
99
102
 
100
103
  plaintext_data = decrypt(credentials, encrypted_data)
@@ -111,7 +114,7 @@ plaintext_data = decrypt(credentials, encrypted_data)
111
114
 
112
115
 
113
116
  ```ruby
114
- require "ubiq-security"
117
+ require 'ubiq-security'
115
118
  include Ubiq
116
119
 
117
120
  # Process 1 MiB of plaintext data at a time
@@ -127,7 +130,7 @@ BLOCK_SIZE = 1024 * 1024
127
130
  # Loop until the end of the input file is reached
128
131
  until infile.eof?
129
132
  chunk = infile.read BLOCK_SIZE
130
- encrypted_data += encryption.update(chunk))
133
+ encrypted_data += encryption.update(chunk)
131
134
  end
132
135
  # Make sure any additional encrypted data is retrieved from encryption instance
133
136
  encrypted_data += encryption.end()
@@ -146,7 +149,7 @@ BLOCK_SIZE = 1024 * 1024
146
149
 
147
150
 
148
151
  ```ruby
149
- require "ubiq-security"
152
+ require 'ubiq-security'
150
153
  include Ubiq
151
154
 
152
155
  # Process 1 MiB of encrypted data at a time
@@ -158,7 +161,7 @@ BLOCK_SIZE = 1024 * 1024
158
161
  decryption = Decryption(credentials)
159
162
 
160
163
  # Start the decryption and get any header information
161
- plaintext_data = decryption.begin())
164
+ plaintext_data = decryption.begin()
162
165
 
163
166
  # Loop until the end of the input file is reached
164
167
  until infile.eof?
@@ -179,7 +182,7 @@ BLOCK_SIZE = 1024 * 1024
179
182
  [bundler]: https://bundler.io
180
183
  [rubygems]: https://rubygems.org
181
184
  [gem]: https://rubygems.org/gems/uniq-security
182
- [dashboard]:https://dev.ubiqsecurity.com/docs/dashboard
185
+ [dashboard]:https://dashboard.ubiqsecurity.com/
183
186
  [credentials]:https://dev.ubiqsecurity.com/docs/how-to-create-api-keys
184
187
  [apidocs]:https://dev.ubiqsecurity.com/docs/api
185
188
 
@@ -1,18 +1,3 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
-
16
1
  # frozen_string_literal: true
17
2
 
18
3
  require 'ubiq/version'
@@ -1,19 +1,3 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
16
-
17
1
  # frozen_string_literal: true
18
2
 
19
3
  require 'active_support/all'
@@ -23,7 +7,11 @@ module Ubiq
23
7
  # Class to provide some basic information mapping between an
24
8
  # encryption algorithm name and the cooresponding
25
9
  # key size, initialization vector length, and tag
10
+
26
11
  class Algo
12
+
13
+ UBIQ_HEADER_V0_FLAG_AAD = 0b00000001
14
+
27
15
  def set_algo
28
16
  @algorithm = {
29
17
  'aes-256-gcm' => {
@@ -33,10 +21,27 @@ module Ubiq
33
21
  key_length: 32,
34
22
  iv_length: 12,
35
23
  tag_length: 16
24
+ },
25
+ 'aes-128-gcm' => {
26
+ id: 1,
27
+ algorithm: OpenSSL::Cipher::AES128,
28
+ mode: OpenSSL::Cipher::AES128.new(:GCM),
29
+ key_length: 16,
30
+ iv_length: 12,
31
+ tag_length: 16
36
32
  }
37
33
  }
38
34
  end
39
35
 
36
+ def find_alg(id)
37
+ set_algo.each do |k,v|
38
+ if v[:id] == id
39
+ return k
40
+ end
41
+ end
42
+ "unknown"
43
+ end
44
+
40
45
  def get_algo(name)
41
46
  set_algo[name]
42
47
  end
@@ -1,19 +1,3 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
16
-
17
1
  # frozen_string_literal: true
18
2
 
19
3
  require 'active_support/all'
@@ -48,6 +32,7 @@ module Ubiq
48
32
 
49
33
  # Initialize the headers object to be returned via this method
50
34
  all_headers = {}
35
+ all_headers['user-agent'] = 'ubiq-ruby/' + Ubiq::VERSION
51
36
  # The content type of request
52
37
  all_headers['content-type'] = 'application/json'
53
38
  # The request target calculated above(reqt)
@@ -74,7 +59,7 @@ module Ubiq
74
59
  all_headers.delete('(created)')
75
60
  all_headers.delete('(request-target)')
76
61
  all_headers.delete('host')
77
-
62
+
78
63
  # Build the Signature header itself
79
64
  all_headers['signature'] = 'keyId="' + papi + '"'
80
65
  all_headers['signature'] += ', algorithm="hmac-sha512"'
@@ -87,9 +72,13 @@ module Ubiq
87
72
  return all_headers
88
73
  end
89
74
 
75
+ # Only want to return port in the URI if the
76
+ # host contained one, otherwise let gateway resolve it
90
77
  def self.get_host(host)
91
78
  uri = URI(host)
92
- return "#{uri.hostname}:#{uri.port}"
79
+ ret = uri.hostname.to_s
80
+ ret += ":#{uri.port}" if host.match(/:[0-9]+/)
81
+ ret
93
82
  end
94
83
 
95
84
  def self.get_date
@@ -1,24 +1,10 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
16
-
17
1
  # frozen_string_literal: true
18
2
 
19
3
  require 'configparser'
20
4
  require 'rb-readline'
21
5
  require 'byebug'
6
+ require_relative './host.rb'
7
+
22
8
 
23
9
  module Ubiq
24
10
  # Access Credentials used by the library to validate service calls
@@ -76,6 +62,10 @@ module Ubiq
76
62
  d = config['default']
77
63
  end
78
64
 
65
+ if !d.key?('SERVER')
66
+ d['SERVER'] = Ubiq::UBIQ_HOST
67
+ end
68
+
79
69
  # get the supplied profile if there is one
80
70
  if config[profile].present?
81
71
  p = config[profile]
@@ -1,19 +1,3 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
16
-
17
1
  # frozen_string_literal: true
18
2
 
19
3
  require 'rb-readline'
@@ -123,10 +107,10 @@ module Ubiq
123
107
  # and the key?
124
108
  if @data.length > struct_length
125
109
  # Unpack the values packed in encryption
126
- version, flag_for_later, algorithm_id, iv_length, key_length = packed_struct.unpack('CCCCn')
110
+ version, flags, algorithm_id, iv_length, key_length = packed_struct.unpack('CCCCn')
127
111
 
128
- # verify flag and version are 0
129
- raise 'invalid encryption header' if (version != 0) || (flag_for_later != 0)
112
+ # verify flag are correct and version is 0
113
+ raise 'invalid encryption header' if (version != 0 ) || ((flags & ~Algo::UBIQ_HEADER_V0_FLAG_AAD) != 0)
130
114
 
131
115
  # Does the buffer contain the entire header?
132
116
  if @data.length > struct_length + iv_length + key_length
@@ -165,7 +149,8 @@ module Ubiq
165
149
  @key['client_id'] = client_id
166
150
  @key['session'] = response['encryption_session']
167
151
 
168
- @key['algorithm'] = 'aes-256-gcm'
152
+ # Get the algorithm name from the internal algorithm id in the header
153
+ @key['algorithm'] = Algo.new.find_alg(algorithm_id)
169
154
 
170
155
  encrypted_private_key = response['encrypted_private_key']
171
156
  # Decrypt the encryped private key using SRSA
@@ -194,6 +179,15 @@ module Ubiq
194
179
  if @key.present?
195
180
  @algo = Algo.new.get_algo(@key['algorithm'])
196
181
  @key['dec'] = Algo.new.decryptor(@algo, @key['raw'], iv)
182
+ # Documentation indicates the auth_data has to be set AFTER auth_tag
183
+ # but we get an OpenSSL error when it is set AFTER an update call.
184
+ # Checking OpenSSL documentation, there is not a requirement to set
185
+ # auth_data before auth_tag so Ruby documentation seems to be
186
+ # wrong. This approach works and is compatible with the encrypted
187
+ # data produced by the other languages' client library
188
+ if (flags & Algo::UBIQ_HEADER_V0_FLAG_AAD) != 0
189
+ @key['dec'].auth_data = packed_struct + iv + encrypted_key
190
+ end
197
191
  @key['uses'] += 1
198
192
  end
199
193
  end
@@ -1,19 +1,3 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
16
-
17
1
  # frozen_string_literal: true
18
2
 
19
3
  require 'rb-readline'
@@ -128,7 +112,9 @@ module Ubiq
128
112
  @enc, @iv = Algo.new.encryptor(@algo, @key['raw'])
129
113
 
130
114
  # Pack the result into bytes to get a byte string
131
- struct = [0, 0, @algo[:id], @iv.length, @key['encrypted'].length].pack('CCCCn')
115
+ struct = [0, Algo::UBIQ_HEADER_V0_FLAG_AAD, @algo[:id], @iv.length, @key['encrypted'].length].pack('CCCCn')
116
+
117
+ @enc.auth_data = struct + @iv + @key['encrypted']
132
118
  @encryption_started = true
133
119
  return struct + @iv + @key['encrypted']
134
120
  end
@@ -1,18 +1,5 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
1
+ # frozen_string_literal: true
2
+
16
3
  module Ubiq
17
- UBIQ_HOST = 'api.ubiqsecurity.com:8811'
4
+ UBIQ_HOST = 'api.ubiqsecurity.com'
18
5
  end
@@ -1,21 +1,5 @@
1
- # Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
2
- #
3
- # NOTICE: All information contained herein is, and remains the property
4
- # of Ubiq Security, Inc. The intellectual and technical concepts contained
5
- # herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
6
- # covered by U.S. and Foreign Patents, patents in process, and are
7
- # protected by trade secret or copyright law. Dissemination of this
8
- # information or reproduction of this material is strictly forbidden
9
- # unless prior written permission is obtained from Ubiq Security, Inc.
10
- #
11
- # Your use of the software is expressly conditioned upon the terms
12
- # and conditions available at:
13
- #
14
- # https://ubiqsecurity.com/legal
15
- #
16
-
17
1
  # frozen_string_literal: true
18
2
 
19
3
  module Ubiq
20
- VERSION = '1.0.1'
4
+ VERSION = '1.0.6'
21
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "Provide data encryption to any application with a couple of API calls. " \
11
11
  "See https://www.ubiqsecurity.com for details."
12
12
  spec.homepage = "https://dev.ubiqsecurity.com/docs/ruby-library"
13
- spec.license = "Nonstandard"
13
+ spec.license = "MIT"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubiq-security
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ubiq Security, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-readline
@@ -58,9 +58,10 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
+ - CHANGELOG.md
61
62
  - CODE_OF_CONDUCT.md
62
63
  - Gemfile
63
- - LICENSE.txt
64
+ - LICENSE
64
65
  - README.md
65
66
  - Rakefile
66
67
  - lib/ubiq-security.rb
@@ -74,7 +75,7 @@ files:
74
75
  - ubiq-security.gemspec
75
76
  homepage: https://dev.ubiqsecurity.com/docs/ruby-library
76
77
  licenses:
77
- - Nonstandard
78
+ - MIT
78
79
  metadata:
79
80
  homepage_uri: https://dev.ubiqsecurity.com/docs/ruby-library
80
81
  source_code_uri: https://gitlab.com/ubiqsecurity/ubiq-ruby
@@ -1,17 +0,0 @@
1
-
2
- Copyright 2020 Ubiq Security, Inc., Proprietary and All Rights Reserved.
3
-
4
- NOTICE: All information contained herein is, and remains the property
5
- of Ubiq Security, Inc. The intellectual and technical concepts contained
6
- herein are proprietary to Ubiq Security, Inc. and its suppliers and may be
7
- covered by U.S. and Foreign Patents, patents in process, and are
8
- protected by trade secret or copyright law. Dissemination of this
9
- information or reproduction of this material is strictly forbidden
10
- unless prior written permission is obtained from Ubiq Security, Inc.
11
-
12
- Your use of the software is expressly conditioned upon the terms
13
- and conditions available at:
14
-
15
- https://ubiqsecurity.com/legal
16
-
17
-