tencentcloud-simple-sign 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4160751fc4885ac1b8d4235af4a2a3ca2cc7f3365380bf1807693e52dc93af10
4
+ data.tar.gz: 9210cfd39a66135f4def0365c02ec9b89073d827398caf026bbe134d47de419b
5
+ SHA512:
6
+ metadata.gz: 12af7f15a53fbe9f0cab3c55fa082e1fc782a5c5e0484239c32f2e93338441e11b12f4b40171e63908cf006594e50821b726357031975d4b893645168c2fff9c
7
+ data.tar.gz: a53d3cd9edb344c956871a400817bfb926d74bc1a639a012dd25cfb27cefac12b7311bbae0701dbac0cc8a4e1e4fc6e8fcbfbdc0da4432bf1de51afb8f5d9e23
data/lib/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module TencentCloud
7
+ class Sign
8
+ class << self
9
+ def sign_v3(secret_id, secret_key, host, timestamp, expire_timestamp)
10
+ service = 'clbia'
11
+ method = 'POST'
12
+ content_type = 'application/json'
13
+ uri = '/'
14
+ query = ""
15
+ canonical_headers = "content-type:#{content_type}\nhost:#{host}\n"
16
+ signed_headers = 'content-type;host'
17
+ payload = Digest::SHA256.hexdigest('')
18
+ canonical_request = [
19
+ method,
20
+ uri,
21
+ query,
22
+ canonical_headers,
23
+ signed_headers,
24
+ payload,
25
+ ].join("\n")
26
+
27
+ date = Time.at(timestamp).utc.strftime('%Y-%m-%d')
28
+ credential_scope = date + '/' + service + '/' + 'tc3_request'
29
+ algorithm = 'TC3-HMAC-SHA256'
30
+ hashed_request_payload = Digest::SHA256.hexdigest(canonical_request)
31
+ string_to_sign = [
32
+ algorithm,
33
+ timestamp,
34
+ credential_scope,
35
+ hashed_request_payload,
36
+ ].join("\n")
37
+
38
+ digest = OpenSSL::Digest.new('sha256')
39
+ secret_date = OpenSSL::HMAC.digest(digest, 'TC3' + secret_key, date)
40
+ secret_service = OpenSSL::HMAC.digest(digest, secret_date, service)
41
+ secret_signing = OpenSSL::HMAC.digest(digest, secret_service, 'tc3_request')
42
+ signature = OpenSSL::HMAC.hexdigest(digest, secret_signing, string_to_sign)
43
+ "#{algorithm} Credential=#{secret_id}/#{credential_scope}, SignedHeaders=#{signed_headers}, SignTime=#{timestamp}, ExpireTime=#{expire_timestamp}, Signature=#{signature}"
44
+ end
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tencentcloud-simple-sign
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tencent Cloud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Tencent Cloud Simple Sign SDK for Ruby
14
+ email:
15
+ - tencentcloudapi@tencent.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/VERSION
21
+ - lib/tencentcloud-simple-sign.rb
22
+ homepage: https://github.com/TencentCloud/simple-auth-sign-ruby
23
+ licenses:
24
+ - Apache-2.0
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.0.3.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Tencent Cloud Simple Sign SDK for Ruby
45
+ test_files: []