huawei_cloud_sass 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 980e6938947ab6b18ffa039575ea2d3b6b52a01131532d2e589f20d7f6814e7f
4
+ data.tar.gz: 1cf0ef5683575fb067cb0d1529512f7333788a5215fd64a8fb601b94e6b8be6a
5
+ SHA512:
6
+ metadata.gz: d4d019cc2143a203e79b0328adc236fb1bfff6995a6e7fd907aa39cc2165ccf2e0c8fadb3048be1769ad7905ff2e5d6a9ffbc253301d0253455cfe04cbe54a8b
7
+ data.tar.gz: 3438c406ea20a07ba710a2e4f027d0265f96c88d3498e95dd21df91fa14cb730b3bb3bcd6000756cda4ff00e525a374fed5c72c6ca7d06fdcd9122a9d609d02a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 anke1460
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.
@@ -0,0 +1,24 @@
1
+ # huawei_cloud_sass
2
+
3
+ This gem provide the core encryption, decryption and signature methods that response to the request of huawei cloud market for sass category products
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'huawei_cloud_sass'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install huawei_cloud_sass
20
+
21
+ ## Usage
22
+
23
+ Support Api responsed for huawei sass.
24
+ More details https://support.huaweicloud.com/accessg-marketplace/zh-cn_topic_0070649067.html
@@ -0,0 +1,3 @@
1
+ require "huawei_cloud_sass/version"
2
+ require "huawei_cloud_sass/auth"
3
+ require "huawei_cloud_sass/parse"
@@ -0,0 +1,24 @@
1
+ require 'openssl'
2
+ require "base64"
3
+
4
+ module HuaweiCloudSass
5
+ class Auth
6
+
7
+ def initialize(key)
8
+ @key = key
9
+ end
10
+
11
+ def is_valid_request?(params)
12
+ params[:authToken] == generate_auth_token(params)
13
+ end
14
+
15
+ def generate_auth_token(params)
16
+ params.delete(:authToken)
17
+ data = params.keys.sort.map { |k| "#{k}=#{params[k]}" }.join("&")
18
+ digest = OpenSSL::Digest.new('sha256')
19
+ body = OpenSSL::HMAC.digest(digest, "#{@key}#{params[:timeStamp]}", data)
20
+ Base64.strict_encode64 body
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ module HuaweiCloudSass
2
+ class Parse < Auth
3
+
4
+ def decode(data)
5
+ cipher = OpenSSL::Cipher::AES.new(128, :CBC)
6
+ cipher.decrypt
7
+ cipher.key = sha1prng
8
+ cipher.iv = data[0..15]
9
+ cipher.update(Base64.decode64(data[16..-1])) << cipher.final
10
+ end
11
+
12
+ def encode(data)
13
+ cipher = OpenSSL::Cipher::AES.new(128, :CBC)
14
+ cipher.encrypt
15
+ cipher.key = sha1prng
16
+ iv = SecureRandom.hex(8)
17
+ cipher.iv = iv
18
+ content = cipher.update(data) << cipher.final
19
+ iv + Base64.strict_encode64(content)
20
+ end
21
+
22
+ def sha1prng
23
+ key = OpenSSL::Digest.digest("SHA1", @key)
24
+ key_bytes = OpenSSL::Digest.digest("SHA1", key).bytes[0..15]
25
+
26
+ for i in 0...key_bytes.size
27
+ if key_bytes[i] > 128
28
+ key_bytes[i] = key_bytes[i] - 256
29
+ end
30
+ end
31
+
32
+ key_bytes.pack('c*').force_encoding("UTF-8")
33
+ end
34
+
35
+ def sign_body(body)
36
+ digest = OpenSSL::Digest.new('sha256')
37
+ Base64.strict_encode64 OpenSSL::HMAC.digest(digest, @key, body.to_json)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module HuaweiCloudSass
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huawei_cloud_sass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - anke1460
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ This gem provide the core encryption, decryption and signature methods that response to the request of huawei cloud market for sass category products
15
+ .
16
+ email:
17
+ - zuosjob@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - README.md
24
+ - lib/huawei_cloud_sass.rb
25
+ - lib/huawei_cloud_sass/auth.rb
26
+ - lib/huawei_cloud_sass/parse.rb
27
+ - lib/huawei_cloud_sass/version.rb
28
+ homepage: https://github.com/anke1460/huawei_cloud_sass
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.7.7
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Support for huawei cloud sass market api.
52
+ test_files: []