Skip to content

Commit e05faca

Browse files
committed
Set up linting
* Autofixed issues * Excluded Akami::WSSE::Signature
1 parent 94a908e commit e05faca

17 files changed

Lines changed: 207 additions & 215 deletions

.standard.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The WS-Security algorithm/type URIs are public constants named in CamelCase
2+
# since akami 1.1.0 (2012). They are part of Akami::WSSE::Signature's public
3+
# surface and are referenced elsewhere as e.g.
4+
# Akami::WSSE::Signature::ExclusiveXMLCanonicalizationAlgorithm. Renaming them to
5+
# SCREAMING_SNAKE_CASE would break any caller that references them, so the naming
6+
# cop is disabled for this one file rather than changing the API.
7+
ignore:
8+
- "lib/akami/wsse/signature.rb":
9+
- Naming/ConstantName

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22
gemspec
33

4-
4+
gem "standard", require: false

Rakefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
require 'bundler'
1+
require "bundler"
22
Bundler::GemHelper.install_tasks
33

44
require "rspec/core/rake_task"
55

66
RSpec::Core::RakeTask.new do |t|
7-
t.rspec_opts = %w(-c)
7+
t.rspec_opts = %w[-c]
88
end
99

10-
task :default => :spec
11-
task :test => :spec
10+
task default: :spec
11+
task test: :spec

akami.gemspec

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
# -*- encoding: utf-8 -*-
21
$:.push File.expand_path("../lib", __FILE__)
32
require "akami/version"
43

54
Gem::Specification.new do |s|
6-
s.name = "akami"
7-
s.version = Akami::VERSION
8-
s.authors = ["Daniel Harrington"]
9-
s.email = ["me@rubiii.com"]
10-
s.homepage = "https://github.com/savonrb/#{s.name}"
11-
s.summary = "Web Service Security"
5+
s.name = "akami"
6+
s.version = Akami::VERSION
7+
s.authors = ["Daniel Harrington"]
8+
s.email = ["me@rubiii.com"]
9+
s.homepage = "https://github.com/savonrb/#{s.name}"
10+
s.summary = "Web Service Security"
1211
s.description = "Building Web Service Security"
13-
s.required_ruby_version = '>= 3.0.0'
12+
s.required_ruby_version = ">= 3.0.0"
1413

1514
s.license = "MIT"
1615

1716
s.add_dependency "gyoku", ">= 0.4.0"
1817
s.add_dependency "nokogiri"
1918
s.add_dependency "base64"
2019

21-
s.add_development_dependency "rake", "~> 13.0"
22-
s.add_development_dependency "rspec", "~> 3.12"
20+
s.add_development_dependency "rake", "~> 13.0"
21+
s.add_development_dependency "rspec", "~> 3.12"
2322
s.add_development_dependency "timecop", "~> 0.5"
2423

25-
s.metadata = { "rubygems_mfa_required" => "true" }
24+
s.metadata = {"rubygems_mfa_required" => "true"}
2625

2726
s.files = Dir["lib/**/*"] + %w[CHANGELOG.md LICENSE README.md]
2827
s.require_paths = ["lib"]

lib/akami.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
require "akami/wsse"
33

44
module Akami
5-
65
# Returns a new <tt>Akami::WSSE</tt>.
76
def self.wsse
87
WSSE.new
98
end
10-
119
end

lib/akami/hash_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module HashHelper
33
# Returns a new Hash with +hash+ and +other_hash+ merged recursively.
44
# Modifies +hash+ in place.
55
def self.deep_merge!(hash, other_hash)
6-
other_hash.each_pair do |k,v|
6+
other_hash.each_pair do |k, v|
77
tv = hash[k]
8-
hash[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge!(tv.dup, v) : v
8+
hash[k] = (tv.is_a?(Hash) && v.is_a?(Hash)) ? deep_merge!(tv.dup, v) : v
99
end
1010
hash
1111
end

lib/akami/version.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module Akami
2-
3-
VERSION = '1.3.3'
4-
2+
VERSION = "1.3.3"
53
end

lib/akami/wsse.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
require "akami/wsse/signature"
1010

1111
module Akami
12-
1312
# = Akami::WSSE
1413
#
1514
# Building Web Service Security.
1615
class WSSE
17-
1816
# Namespace for WS Security Secext.
1917
WSE_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
2018

@@ -94,11 +92,11 @@ def to_xml
9492
h = merge_hashes_with_keys(h, wsu_timestamp) if timestamp?
9593
h = merge_hashes_with_keys(h, wsse_username_token) if username_token?
9694

97-
return '' unless h
95+
return "" unless h
9896
Gyoku.xml h
9997
end
10098

101-
private
99+
private
102100

103101
def merge_hashes_with_keys(hash_one, hash_two)
104102
return hash_two unless hash_one
@@ -116,14 +114,14 @@ def wsse_username_token
116114
"wsse:Nonce" => Base64.encode64(nonce).chomp,
117115
"wsu:Created" => timestamp,
118116
"wsse:Password" => digest_password,
119-
:attributes! => { "wsse:Password" => { "Type" => PASSWORD_DIGEST_URI }, "wsse:Nonce" => { "EncodingType" => BASE64_URI } }
117+
:attributes! => {"wsse:Password" => {"Type" => PASSWORD_DIGEST_URI}, "wsse:Nonce" => {"EncodingType" => BASE64_URI}}
120118
# clear the nonce after each use
121119
@nonce = nil
122120
else
123121
token = security_hash :wsse, "UsernameToken",
124122
"wsse:Username" => username,
125123
"wsse:Password" => password,
126-
:attributes! => { "wsse:Password" => { "Type" => PASSWORD_TEXT_URI } }
124+
:attributes! => {"wsse:Password" => {"Type" => PASSWORD_TEXT_URI}}
127125
end
128126
token
129127
end
@@ -146,23 +144,23 @@ def wsu_timestamp
146144

147145
# Returns a Hash containing wsse/wsu Security details for a given
148146
# +namespace+, +tag+ and +hash+.
149-
def security_hash(namespace, tag, hash, extra_info = {}, signature_request=false)
147+
def security_hash(namespace, tag, hash, extra_info = {}, signature_request = false)
150148
key = [namespace, tag].compact.join(":")
151149

152150
sec_hash = {
153151
"wsse:Security" => {
154152
key => hash,
155153
:order! => [key]
156154
},
157-
:attributes! => { "wsse:Security" => { "xmlns:wsse" => WSE_NAMESPACE } }
155+
:attributes! => {"wsse:Security" => {"xmlns:wsse" => WSE_NAMESPACE}}
158156
}
159157

160158
sec_hash["wsse:Security"].merge!(extra_info) unless extra_info.empty?
161159

162160
if signature_request
163-
sec_hash[:attributes!].merge!("soapenv:mustUnderstand" => "1")
161+
sec_hash[:attributes!]["soapenv:mustUnderstand"] = "1"
164162
else
165-
sec_hash["wsse:Security"].merge!(:attributes! => { key => { "wsu:Id" => "#{tag}-#{count}", "xmlns:wsu" => WSU_NAMESPACE } })
163+
sec_hash["wsse:Security"][:attributes!] = {key => {"wsu:Id" => "#{tag}-#{count}", "xmlns:wsu" => WSU_NAMESPACE}}
166164
end
167165

168166
sec_hash

lib/akami/wsse/certs.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ module Akami
22
class WSSE
33
# Contains certs for WSSE::Signature
44
class Certs
5-
65
def initialize(certs = {})
76
certs.each do |key, value|
8-
self.send :"#{key}=", value
7+
send :"#{key}=", value
98
end
109
end
1110

lib/akami/wsse/signature.rb

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def document=(document)
2323
@document = Nokogiri::XML(document)
2424
end
2525

26-
ExclusiveXMLCanonicalizationAlgorithm = 'http://www.w3.org/2001/10/xml-exc-c14n#'.freeze
27-
RSASHA1SignatureAlgorithm = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'.freeze
28-
SHA1DigestAlgorithm = 'http://www.w3.org/2000/09/xmldsig#sha1'.freeze
26+
ExclusiveXMLCanonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#".freeze
27+
RSASHA1SignatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1".freeze
28+
SHA1DigestAlgorithm = "http://www.w3.org/2000/09/xmldsig#sha1".freeze
2929

30-
X509v3ValueType = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3'.freeze
31-
Base64EncodingType = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'.freeze
30+
X509v3ValueType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3".freeze
31+
Base64EncodingType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary".freeze
3232

33-
SignatureNamespace = 'http://www.w3.org/2000/09/xmldsig#'.freeze
33+
SignatureNamespace = "http://www.w3.org/2000/09/xmldsig#".freeze
3434

3535
def initialize(certs = Certs.new)
3636
@certs = certs
@@ -57,28 +57,28 @@ def security_token_id
5757
def body_attributes
5858
{
5959
"xmlns:wsu" => Akami::WSSE::WSU_NAMESPACE,
60-
"wsu:Id" => body_id,
60+
"wsu:Id" => body_id
6161
}
6262
end
6363

6464
def to_token
6565
return {} unless have_document?
6666

6767
sig = signed_info.merge(key_info).merge(signature_value)
68-
sig.merge! :order! => []
69-
[ "SignedInfo", "SignatureValue", "KeyInfo" ].each do |key|
68+
sig[:order!] = []
69+
["SignedInfo", "SignatureValue", "KeyInfo"].each do |key|
7070
sig[:order!] << key if sig[key]
7171
end
7272

7373
token = {
7474
"Signature" => sig,
75-
:attributes! => { "Signature" => { "xmlns" => SignatureNamespace } },
75+
:attributes! => {"Signature" => {"xmlns" => SignatureNamespace}}
7676
}
7777

7878
Akami::HashHelper.deep_merge!(token, binary_security_token) if certs.cert
7979

80-
token.merge! :order! => []
81-
[ "wsse:BinarySecurityToken", "Signature" ].each do |key|
80+
token[:order!] = []
81+
["wsse:BinarySecurityToken", "Signature"].each do |key|
8282
token[:order!] << key if token[key]
8383
end
8484

@@ -89,13 +89,13 @@ def to_token
8989

9090
def binary_security_token
9191
{
92-
"wsse:BinarySecurityToken" => Base64.encode64(certs.cert.to_der).gsub("\n", ''),
93-
:attributes! => { "wsse:BinarySecurityToken" => {
92+
"wsse:BinarySecurityToken" => Base64.encode64(certs.cert.to_der).delete("\n"),
93+
:attributes! => {"wsse:BinarySecurityToken" => {
9494
"wsu:Id" => security_token_id,
95-
'EncodingType' => Base64EncodingType,
96-
'ValueType' => X509v3ValueType,
97-
"xmlns:wsu" => Akami::WSSE::WSU_NAMESPACE,
98-
} }
95+
"EncodingType" => Base64EncodingType,
96+
"ValueType" => X509v3ValueType,
97+
"xmlns:wsu" => Akami::WSSE::WSU_NAMESPACE
98+
}}
9999
}
100100
end
101101

@@ -104,18 +104,18 @@ def key_info
104104
"KeyInfo" => {
105105
"wsse:SecurityTokenReference" => {
106106
"wsse:Reference/" => nil,
107-
:attributes! => { "wsse:Reference/" => {
107+
:attributes! => {"wsse:Reference/" => {
108108
"ValueType" => X509v3ValueType,
109-
"URI" => "##{security_token_id}",
110-
} }
109+
"URI" => "##{security_token_id}"
110+
}}
111111
},
112-
:attributes! => { "wsse:SecurityTokenReference" => { "xmlns:wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" } },
113-
},
112+
:attributes! => {"wsse:SecurityTokenReference" => {"xmlns:wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"}}
113+
}
114114
}
115115
end
116116

117117
def signature_value
118-
{ "SignatureValue" => the_signature }
118+
{"SignatureValue" => the_signature}
119119
rescue MissingCertificate
120120
{}
121121
end
@@ -126,25 +126,25 @@ def signed_info
126126
"CanonicalizationMethod/" => nil,
127127
"SignatureMethod/" => nil,
128128
"Reference" => [
129-
#signed_info_transforms.merge(signed_info_digest_method).merge({ "DigestValue" => timestamp_digest }),
130-
signed_info_transforms.merge(signed_info_digest_method).merge({ "DigestValue" => body_digest }),
129+
# signed_info_transforms.merge(signed_info_digest_method).merge({ "DigestValue" => timestamp_digest }),
130+
signed_info_transforms.merge(signed_info_digest_method).merge({"DigestValue" => body_digest})
131131
],
132132
:attributes! => {
133-
"CanonicalizationMethod/" => { "Algorithm" => ExclusiveXMLCanonicalizationAlgorithm },
134-
"SignatureMethod/" => { "Algorithm" => RSASHA1SignatureAlgorithm },
135-
"Reference" => { "URI" => ["##{body_id}"] },
133+
"CanonicalizationMethod/" => {"Algorithm" => ExclusiveXMLCanonicalizationAlgorithm},
134+
"SignatureMethod/" => {"Algorithm" => RSASHA1SignatureAlgorithm},
135+
"Reference" => {"URI" => ["##{body_id}"]}
136136
},
137-
:order! => [ "CanonicalizationMethod/", "SignatureMethod/", "Reference" ],
138-
},
137+
:order! => ["CanonicalizationMethod/", "SignatureMethod/", "Reference"]
138+
}
139139
}
140140
end
141141

142142
def the_signature
143143
raise MissingCertificate, "Expected a private_key for signing" unless certs.private_key
144144
signed_info = at_xpath(@document, "//Envelope/Header/Security/Signature/SignedInfo")
145145
signed_info = signed_info ? canonicalize(signed_info) : ""
146-
signature = certs.private_key.sign(OpenSSL::Digest::SHA1.new, signed_info)
147-
Base64.encode64(signature).gsub("\n", '') # TODO: DRY calls to Base64.encode64(...).gsub("\n", '')
146+
signature = certs.private_key.sign(OpenSSL::Digest.new("SHA1"), signed_info)
147+
Base64.encode64(signature).delete("\n") # TODO: DRY calls to Base64.encode64(...).gsub("\n", '')
148148
end
149149

150150
def body_digest
@@ -153,15 +153,15 @@ def body_digest
153153
end
154154

155155
def signed_info_digest_method
156-
{ "DigestMethod/" => nil, :attributes! => { "DigestMethod/" => { "Algorithm" => SHA1DigestAlgorithm } } }
156+
{"DigestMethod/" => nil, :attributes! => {"DigestMethod/" => {"Algorithm" => SHA1DigestAlgorithm}}}
157157
end
158158

159159
def signed_info_transforms
160-
{ "Transforms" => { "Transform/" => nil, :attributes! => { "Transform/" => { "Algorithm" => ExclusiveXMLCanonicalizationAlgorithm } } } }
160+
{"Transforms" => {"Transform/" => nil, :attributes! => {"Transform/" => {"Algorithm" => ExclusiveXMLCanonicalizationAlgorithm}}}}
161161
end
162162

163163
def uid
164-
OpenSSL::Digest::SHA1.hexdigest([Time.now, rand].collect(&:to_s).join('/'))
164+
OpenSSL::Digest::SHA1.hexdigest([Time.now, rand].join("/"))
165165
end
166166
end
167167
end

0 commit comments

Comments
 (0)