m2m_keygen 0.3.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -646,7 +646,7 @@
646
646
  <pre class="code"><span class="info file"># File 'lib/m2m_keygen/signature.rb', line 46</span>
647
647
 
648
648
  <span class='kw'>def</span> <span class='id identifier rubyid_validate'>validate</span><span class='lparen'>(</span><span class='label'>params:</span><span class='comma'>,</span> <span class='label'>verb:</span><span class='comma'>,</span> <span class='label'>path:</span><span class='comma'>,</span> <span class='label'>signature:</span><span class='rparen'>)</span>
649
- <span class='kw'>if</span> <span class='const'>OpenSSL</span><span class='period'>.</span><span class='id identifier rubyid_method_defined?'>method_defined?</span><span class='lparen'>(</span><span class='symbol'>:fixed_length_secure_compare</span><span class='rparen'>)</span>
649
+ <span class='kw'>if</span> <span class='const'>OpenSSL</span><span class='period'>.</span><span class='id identifier rubyid_methods'>methods</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:fixed_length_secure_compare</span><span class='rparen'>)</span>
650
650
  <span class='const'>OpenSSL</span><span class='period'>.</span><span class='id identifier rubyid_fixed_length_secure_compare'>fixed_length_secure_compare</span><span class='lparen'>(</span>
651
651
  <span class='id identifier rubyid_sign'>sign</span><span class='lparen'>(</span><span class='label'>params:</span> <span class='id identifier rubyid_params'>params</span><span class='comma'>,</span> <span class='label'>verb:</span> <span class='id identifier rubyid_verb'>verb</span><span class='comma'>,</span> <span class='label'>path:</span> <span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span><span class='comma'>,</span>
652
652
  <span class='id identifier rubyid_signature'>signature</span>
@@ -670,7 +670,7 @@
670
670
  </div>
671
671
 
672
672
  <div id="footer">
673
- Generated on Tue Aug 30 11:26:10 2022 by
673
+ Generated on Mon Sep 5 14:55:58 2022 by
674
674
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
675
675
  0.9.28 (ruby-3.1.2).
676
676
  </div>
@@ -137,7 +137,7 @@
137
137
  </div>
138
138
 
139
139
  <div id="footer">
140
- Generated on Tue Aug 30 11:26:10 2022 by
140
+ Generated on Mon Sep 5 14:55:58 2022 by
141
141
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
142
142
  0.9.28 (ruby-3.1.2).
143
143
  </div>
data/docs/M2mKeygen.html CHANGED
@@ -79,7 +79,7 @@
79
79
  <dl>
80
80
  <dt>Defined in:</dt>
81
81
  <dd>lib/m2m_keygen.rb<span class="defines">,<br />
82
- lib/m2m_keygen/version.rb,<br /> lib/m2m_keygen/signature.rb,<br /> lib/m2m_keygen/params_encoder.rb,<br /> lib/m2m_keygen/types/params_type.rb</span>
82
+ lib/m2m_keygen/version.rb,<br /> lib/m2m_keygen/signature.rb,<br /> lib/m2m_keygen/params_encoder.rb,<br /> lib/m2m_keygen/rack_validator.rb,<br /> lib/m2m_keygen/types/params_type.rb</span>
83
83
  </dd>
84
84
  </dl>
85
85
 
@@ -104,7 +104,7 @@
104
104
 
105
105
 
106
106
 
107
- <strong class="classes">Classes:</strong> <span class='object_link'><a href="M2mKeygen/Error.html" title="M2mKeygen::Error (class)">Error</a></span>, <span class='object_link'><a href="M2mKeygen/ParamsEncoder.html" title="M2mKeygen::ParamsEncoder (class)">ParamsEncoder</a></span>, <span class='object_link'><a href="M2mKeygen/Signature.html" title="M2mKeygen::Signature (class)">Signature</a></span>
107
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="M2mKeygen/Error.html" title="M2mKeygen::Error (class)">Error</a></span>, <span class='object_link'><a href="M2mKeygen/ParamsEncoder.html" title="M2mKeygen::ParamsEncoder (class)">ParamsEncoder</a></span>, <span class='object_link'><a href="M2mKeygen/RackValidator.html" title="M2mKeygen::RackValidator (class)">RackValidator</a></span>, <span class='object_link'><a href="M2mKeygen/Signature.html" title="M2mKeygen::Signature (class)">Signature</a></span>
108
108
 
109
109
 
110
110
  </p>
@@ -131,7 +131,7 @@
131
131
 
132
132
  </div>
133
133
  </dt>
134
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.3.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
134
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.4.2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
135
135
 
136
136
  </dl>
137
137
 
@@ -147,7 +147,7 @@
147
147
  </div>
148
148
 
149
149
  <div id="footer">
150
- Generated on Tue Aug 30 11:26:10 2022 by
150
+ Generated on Mon Sep 5 14:55:58 2022 by
151
151
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
152
152
  0.9.28 (ruby-3.1.2).
153
153
  </div>
data/docs/_index.html CHANGED
@@ -119,6 +119,21 @@
119
119
  </ul>
120
120
 
121
121
 
122
+ <ul id="alpha_R" class="alpha">
123
+ <li class="letter">R</li>
124
+ <ul>
125
+
126
+ <li>
127
+ <span class='object_link'><a href="M2mKeygen/RackValidator.html" title="M2mKeygen::RackValidator (class)">RackValidator</a></span>
128
+
129
+ <small>(M2mKeygen)</small>
130
+
131
+ </li>
132
+
133
+ </ul>
134
+ </ul>
135
+
136
+
122
137
  <ul id="alpha_S" class="alpha">
123
138
  <li class="letter">S</li>
124
139
  <ul>
@@ -157,7 +172,7 @@
157
172
  </div>
158
173
 
159
174
  <div id="footer">
160
- Generated on Tue Aug 30 11:26:10 2022 by
175
+ Generated on Mon Sep 5 14:55:58 2022 by
161
176
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
162
177
  0.9.28 (ruby-3.1.2).
163
178
  </div>
data/docs/class_list.html CHANGED
@@ -43,7 +43,7 @@
43
43
 
44
44
  <ul id="full_list" class="class">
45
45
  <li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
46
- <li id='object_M2mKeygen' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="M2mKeygen.html" title="M2mKeygen (module)">M2mKeygen</a></span><small class='search_info'>Top Level Namespace</small></div><ul><li id='object_M2mKeygen::Error' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/Error.html" title="M2mKeygen::Error (class)">Error</a></span> &lt; StandardError<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::ParamsEncoder' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/ParamsEncoder.html" title="M2mKeygen::ParamsEncoder (class)">ParamsEncoder</a></span> &lt; Object<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::Signature' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/Signature.html" title="M2mKeygen::Signature (class)">Signature</a></span> &lt; Object<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::Types' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/Types.html" title="M2mKeygen::Types (module)">Types</a></span><small class='search_info'>M2mKeygen</small></div></li></ul></li>
46
+ <li id='object_M2mKeygen' class='even'><div class='item' style='padding-left:30px'><a class='toggle'></a> <span class='object_link'><a href="M2mKeygen.html" title="M2mKeygen (module)">M2mKeygen</a></span><small class='search_info'>Top Level Namespace</small></div><ul><li id='object_M2mKeygen::Error' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/Error.html" title="M2mKeygen::Error (class)">Error</a></span> &lt; StandardError<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::ParamsEncoder' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/ParamsEncoder.html" title="M2mKeygen::ParamsEncoder (class)">ParamsEncoder</a></span> &lt; Object<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::RackValidator' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/RackValidator.html" title="M2mKeygen::RackValidator (class)">RackValidator</a></span> &lt; Object<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::Signature' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/Signature.html" title="M2mKeygen::Signature (class)">Signature</a></span> &lt; Object<small class='search_info'>M2mKeygen</small></div></li><li id='object_M2mKeygen::Types' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="M2mKeygen/Types.html" title="M2mKeygen::Types (module)">Types</a></span><small class='search_info'>M2mKeygen</small></div></li></ul></li>
47
47
 
48
48
  </ul>
49
49
  </div>
@@ -146,6 +146,38 @@ AuthSignature.validate(
146
146
 
147
147
  <p>If the validation is true, the request was signed with the same algorithm and same secret key.</p>
148
148
 
149
+ <h3 id="rackvalidator">RackValidator</h3>
150
+
151
+ <p>This module is here for directly validate Rack requests.</p>
152
+
153
+ <p>It will validate :</p>
154
+
155
+ <ul>
156
+ <li>Signature matching</li>
157
+ <li>That the <code>expiry</code> parameter is present and between now and in 2 minutes.</li>
158
+ </ul>
159
+
160
+ <h4 id="initialization-1">Initialization</h4>
161
+
162
+ <p>You should initialize the <code>RackValidator</code> once (in an initializer for example) with your secret key, eventually an encryption algorithm and a header name for the signature.</p>
163
+
164
+ <p><code>ruby
165
+ RackSignatureValidator =
166
+ M2mKeygen::RackValidator.new(
167
+ "secret",
168
+ algorithm: "sha512", # Default value
169
+ header_name: "X-Signature" # Default value
170
+ )
171
+ </code></p>
172
+
173
+ <h4 id="validation">Validation</h4>
174
+
175
+ <p>You can then validate a Rack::Request or a Rails Request directly:</p>
176
+
177
+ <p><code>ruby
178
+ RackSignatureValidator.validate(request) # =&gt; true or false
179
+ </code></p>
180
+
149
181
  <h2 id="how-does-it-works">How does it works</h2>
150
182
 
151
183
  <p>This is intended for a secure discussion between 2 servers and not something in a browser as the secret key must be stored and used both side (and you don’t want to send the secret key in the browser).</p>
@@ -188,7 +220,7 @@ The receiver will generate the same signature from the HTTP request it has recei
188
220
  </div></div>
189
221
 
190
222
  <div id="footer">
191
- Generated on Tue Aug 30 11:26:10 2022 by
223
+ Generated on Mon Sep 5 14:55:58 2022 by
192
224
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
193
225
  0.9.28 (ruby-3.1.2).
194
226
  </div>
data/docs/index.html CHANGED
@@ -146,6 +146,38 @@ AuthSignature.validate(
146
146
 
147
147
  <p>If the validation is true, the request was signed with the same algorithm and same secret key.</p>
148
148
 
149
+ <h3 id="rackvalidator">RackValidator</h3>
150
+
151
+ <p>This module is here for directly validate Rack requests.</p>
152
+
153
+ <p>It will validate :</p>
154
+
155
+ <ul>
156
+ <li>Signature matching</li>
157
+ <li>That the <code>expiry</code> parameter is present and between now and in 2 minutes.</li>
158
+ </ul>
159
+
160
+ <h4 id="initialization-1">Initialization</h4>
161
+
162
+ <p>You should initialize the <code>RackValidator</code> once (in an initializer for example) with your secret key, eventually an encryption algorithm and a header name for the signature.</p>
163
+
164
+ <p><code>ruby
165
+ RackSignatureValidator =
166
+ M2mKeygen::RackValidator.new(
167
+ "secret",
168
+ algorithm: "sha512", # Default value
169
+ header_name: "X-Signature" # Default value
170
+ )
171
+ </code></p>
172
+
173
+ <h4 id="validation">Validation</h4>
174
+
175
+ <p>You can then validate a Rack::Request or a Rails Request directly:</p>
176
+
177
+ <p><code>ruby
178
+ RackSignatureValidator.validate(request) # =&gt; true or false
179
+ </code></p>
180
+
149
181
  <h2 id="how-does-it-works">How does it works</h2>
150
182
 
151
183
  <p>This is intended for a secure discussion between 2 servers and not something in a browser as the secret key must be stored and used both side (and you don’t want to send the secret key in the browser).</p>
@@ -188,7 +220,7 @@ The receiver will generate the same signature from the HTTP request it has recei
188
220
  </div></div>
189
221
 
190
222
  <div id="footer">
191
- Generated on Tue Aug 30 11:26:10 2022 by
223
+ Generated on Mon Sep 5 14:55:58 2022 by
192
224
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
193
225
  0.9.28 (ruby-3.1.2).
194
226
  </div>
@@ -61,6 +61,14 @@
61
61
 
62
62
 
63
63
  <li class="odd ">
64
+ <div class="item">
65
+ <span class='object_link'><a href="M2mKeygen/RackValidator.html#header_name-instance_method" title="M2mKeygen::RackValidator#header_name (method)">#header_name</a></span>
66
+ <small>M2mKeygen::RackValidator</small>
67
+ </div>
68
+ </li>
69
+
70
+
71
+ <li class="even ">
64
72
  <div class="item">
65
73
  <span class='object_link'><a href="M2mKeygen/Signature.html#initialize-instance_method" title="M2mKeygen::Signature#initialize (method)">#initialize</a></span>
66
74
  <small>M2mKeygen::Signature</small>
@@ -68,6 +76,14 @@
68
76
  </li>
69
77
 
70
78
 
79
+ <li class="odd ">
80
+ <div class="item">
81
+ <span class='object_link'><a href="M2mKeygen/RackValidator.html#initialize-instance_method" title="M2mKeygen::RackValidator#initialize (method)">#initialize</a></span>
82
+ <small>M2mKeygen::RackValidator</small>
83
+ </div>
84
+ </li>
85
+
86
+
71
87
  <li class="even ">
72
88
  <div class="item">
73
89
  <span class='object_link'><a href="M2mKeygen/ParamsEncoder.html#initialize-instance_method" title="M2mKeygen::ParamsEncoder#initialize (method)">#initialize</a></span>
@@ -93,6 +109,14 @@
93
109
 
94
110
 
95
111
  <li class="odd ">
112
+ <div class="item">
113
+ <span class='object_link'><a href="M2mKeygen/RackValidator.html#signature-instance_method" title="M2mKeygen::RackValidator#signature (method)">#signature</a></span>
114
+ <small>M2mKeygen::RackValidator</small>
115
+ </div>
116
+ </li>
117
+
118
+
119
+ <li class="even ">
96
120
  <div class="item">
97
121
  <span class='object_link'><a href="M2mKeygen/Signature.html#validate-instance_method" title="M2mKeygen::Signature#validate (method)">#validate</a></span>
98
122
  <small>M2mKeygen::Signature</small>
@@ -100,6 +124,14 @@
100
124
  </li>
101
125
 
102
126
 
127
+ <li class="odd ">
128
+ <div class="item">
129
+ <span class='object_link'><a href="M2mKeygen/RackValidator.html#validate-instance_method" title="M2mKeygen::RackValidator#validate (method)">#validate</a></span>
130
+ <small>M2mKeygen::RackValidator</small>
131
+ </div>
132
+ </li>
133
+
134
+
103
135
 
104
136
  </ul>
105
137
  </div>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Tue Aug 30 11:26:10 2022 by
103
+ Generated on Mon Sep 5 14:55:58 2022 by
104
104
  <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.28 (ruby-3.1.2).
106
106
  </div>
@@ -0,0 +1,34 @@
1
+ # typed: strict
2
+
3
+ require "rack"
4
+
5
+ module M2mKeygen
6
+ class RackValidator
7
+ extend T::Sig
8
+
9
+ sig { returns(Signature) }
10
+ attr_reader :signature
11
+
12
+ sig { returns(String) }
13
+ attr_reader :header_name
14
+
15
+ sig { params(secret: String, algorithm: String, header_name: String).void }
16
+ def initialize(secret, algorithm: "sha512", header_name: "X-Signature")
17
+ @header_name = T.let("HTTP_#{header_name.tr("-", "_").upcase}", String)
18
+ @signature = T.let(Signature.new(secret, algorithm: algorithm), Signature)
19
+ end
20
+
21
+ sig { params(req: T.untyped).returns(T::Boolean) }
22
+ def validate(req)
23
+ # This will cover the case when Rails is used.
24
+ req = Rack::Request.new(req.env)
25
+ @signature.validate(
26
+ params: req.params || {},
27
+ verb: req.request_method || "get",
28
+ path: req.path || "/",
29
+ signature: req.env["HTTP_X_SIGNATURE"] || ""
30
+ ) && req.params["expiry"] && req.params["expiry"].to_i > Time.now.to_i &&
31
+ req.params["expiry"].to_i < Time.now.to_i + 120
32
+ end
33
+ end
34
+ end
@@ -44,7 +44,7 @@ module M2mKeygen
44
44
  ).returns(T::Boolean)
45
45
  end
46
46
  def validate(params:, verb:, path:, signature:)
47
- if OpenSSL.method_defined?(:fixed_length_secure_compare)
47
+ if OpenSSL.methods.include?(:fixed_length_secure_compare)
48
48
  OpenSSL.fixed_length_secure_compare(
49
49
  sign(params: params, verb: verb, path: path),
50
50
  signature
@@ -3,5 +3,5 @@
3
3
 
4
4
  module M2mKeygen
5
5
  # Gem version
6
- VERSION = "0.3.0"
6
+ VERSION = "0.4.2"
7
7
  end
data/m2m_keygen.gemspec CHANGED
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
42
42
  spec.require_paths = ["lib"]
43
43
 
44
+ spec.add_dependency "rack"
44
45
  spec.add_dependency "sorbet-runtime"
45
46
  spec.add_dependency "zeitwerk", "~> 2.6"
46
47
  end
@@ -1534,6 +1534,30 @@ class ActiveSupport::Cache::Strategy::LocalCache::LocalStore
1534
1534
  def write_entry(key, entry); end
1535
1535
  end
1536
1536
 
1537
+ # --
1538
+ # This class wraps up local storage for middlewares. Only the middleware method should
1539
+ # construct them.
1540
+ #
1541
+ # source://activesupport-7.0.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:13
1542
+ class ActiveSupport::Cache::Strategy::LocalCache::Middleware
1543
+ # @return [Middleware] a new instance of Middleware
1544
+ #
1545
+ # source://activesupport-7.0.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:16
1546
+ def initialize(name, local_cache_key); end
1547
+
1548
+ # source://activesupport-7.0.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:27
1549
+ def call(env); end
1550
+
1551
+ # source://activesupport-7.0.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:14
1552
+ def local_cache_key; end
1553
+
1554
+ # source://activesupport-7.0.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:14
1555
+ def name; end
1556
+
1557
+ # source://activesupport-7.0.3.1/lib/active_support/cache/strategy/local_cache_middleware.rb:22
1558
+ def new(app); end
1559
+ end
1560
+
1537
1561
  # These options mean something to all cache implementations. Individual cache
1538
1562
  # implementations may support additional options.
1539
1563
  #