openssl-additions 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3af2a1bdc82b061267777ed93961fa411eaea3ddeeb4912a0be3772cadfacd48
4
- data.tar.gz: '0860f6fa16eb240a6d3408f91a3637f48900dc06d4f2fbe550684df60bccd3f8'
3
+ metadata.gz: 960c29488ad97c87c67fa2b6aa7a286a51b4678ab190ebc628a3d55efcb9125a
4
+ data.tar.gz: 284c3dc79c7325406e06567c7e2c34d6439b3050f8bf25202b088e5a1fe802f7
5
5
  SHA512:
6
- metadata.gz: d27ca892b2505c0fb88095936dd44e880f340d112b2df50e48deb2fc66c96aa8bf36a0ea3d4c599c621e36efa020045709783fb4c239e26a143bd3a08d8fc265
7
- data.tar.gz: 7bb76838e1bc1eee2af1b813e3406827dc0fe08ce32defe633be1da3f7037f7f9485a0e534e2fef0d16d99f10a8f4e317711639ab6363fd8796a8e0b6d1eb130
6
+ metadata.gz: 578c11f9214f96bb30aed6332fb8893fdd547a66b5d0c6c10fff5df39dbcc5d48d71966dce0f88b2e52344d7ac4cf126fd829939fbf75783b61ae801b93eebb7
7
+ data.tar.gz: 788e22b2e62c2d1573ce49d4c6de45f56af518f1bb0476e7a83856164480d81a9f3cfbd6cad41b4d801817078069c75d76c7b20d8603ba8f9720bc9d9184fd83
@@ -15,6 +15,65 @@ class OpenSSL::PKey::RSA
15
15
  OpenSSL::X509::SPKI.new(self.public_key.to_der)
16
16
  end
17
17
 
18
+ # Give our best guess as to whether the given RSA private key is valid.
19
+ #
20
+ # Applies a set of heuristics to the (private) key, with a view to deciding
21
+ # whether it is correctly formed.
22
+ #
23
+ # Based on the RSA_check_key OpenSSL function.
24
+ #
25
+ # @param extended [Boolean] specify whether to only check problems which
26
+ # cannot be corrected by re-calculating from the fundamental parameters of
27
+ # the key (the private factors `p` and `q`, and the public exponent `e`).
28
+ # The default is to consider any deviation from a completely correct key
29
+ # to render the key invalid.
30
+ #
31
+ # @return [Boolean]
32
+ #
33
+ def valid?(extended = true)
34
+ # Must have factors and public exponent
35
+ return false if p.nil? || q.nil? || e.nil?
36
+
37
+ # Public exponent must be odd and greater than one
38
+ return false if e == 1
39
+
40
+ return false if e % 2 == 0
41
+
42
+ # Factors must be prime
43
+ return false unless p.prime?
44
+ return false unless q.prime?
45
+
46
+ # All the remaining checks are things that could be fixed with some
47
+ # arithmetic
48
+ return true if !extended
49
+
50
+ # Must have private exponent and a modulus
51
+ return false if d.nil? || n.nil?
52
+
53
+ # Public modulus must be the product of the two prime factors
54
+ return false unless n == p * q
55
+
56
+ # d * e must equal 1 mod (lcm(p-1,q-1))
57
+ return false unless e * d % (p.to_i-1).lcm(q.to_i-1) == 1
58
+
59
+ # CRT parameters are optional, but if present must be correct
60
+ unless dmp1.nil?
61
+ return false unless dmp1 == d % (p-1)
62
+ end
63
+
64
+ unless dmq1.nil?
65
+ return false unless dmq1 == d % (q-1)
66
+ end
67
+
68
+ unless iqmp.nil?
69
+ t, _ = self.class.egcd(q.to_i, p.to_i)
70
+ t %= p if t < 0
71
+ return false unless iqmp == t
72
+ end
73
+
74
+ return true
75
+ end
76
+
18
77
  # Construct a fully-featured RSA private key from fundamental values.
19
78
  #
20
79
  # Many parts of an RSA key are, in fact, derived from the basic numbers that
@@ -296,7 +296,7 @@ module OpenSSL::PKey
296
296
  end
297
297
 
298
298
  def self.decode_public_ssh_key(s)
299
- if s =~ /\Assh-[a-z0-9-]+ /
299
+ if s =~ /\A(ssh|ecdsa)-[a-z0-9-]+ /
300
300
  # WHOOP WHOOP prefixed key detected.
301
301
  s = s.split(" ")[1]
302
302
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openssl-additions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
193
  requirements: []
194
- rubygems_version: 3.0.3
194
+ rubygems_version: 3.2.5
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Quality-of-life improvements to the core openssl ruby library