sus-fixtures-openssl 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 36794229edbdabba437a99a67421f8f986bb6492000697855047556b26bc400e
4
+ data.tar.gz: e8af0f9ca4310e18780457220b11ad5618b9d898de6680bd48efcdca9aa9ef45
5
+ SHA512:
6
+ metadata.gz: 543d9dcdc89a4ce34788a6d3db553957382dd4b1c48b759379d8176025af57d7e0a8e4fbfc8ef4b6e8da2b3a5dc2c23d7a870781f5270a855bc417111109e2c0
7
+ data.tar.gz: ccb5dd75795f33098acc61115ff99487184b69d3f44e4bd2226f38bff28fbd4030acf4519c1f291ae770d9b8764da0e1c908a35af26eb77a7f8f92f73b0f70d8
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require 'openssl'
7
+
8
+ module Sus
9
+ module Fixtures
10
+ module OpenSSL
11
+ module CertificateAuthorityContext
12
+ # This key size is generally considered insecure, but it's fine for testing.
13
+ def certificate_authority_key
14
+ @certificate_authority_key ||= ::OpenSSL::PKey::RSA.new(2048)
15
+ end
16
+
17
+ def certificate_authority_name
18
+ @certificate_authority_name ||= ::OpenSSL::X509::Name.parse("O=TestCA/CN=localhost")
19
+ end
20
+
21
+ # The certificate authority is used for signing and validating the certificate which is used for communciation:
22
+ def certificate_authority_certificate
23
+ @certificate_authority_certificate ||= ::OpenSSL::X509::Certificate.new.tap do |certificate|
24
+ certificate.subject = certificate_authority_name
25
+ # We use the same issuer as the subject, which makes this certificate self-signed:
26
+ certificate.issuer = certificate_authority_name
27
+
28
+ certificate.public_key = certificate_authority_key.public_key
29
+
30
+ certificate.serial = 1
31
+ certificate.version = 2
32
+
33
+ certificate.not_before = Time.now
34
+ certificate.not_after = Time.now + 3600
35
+
36
+ extension_factory = ::OpenSSL::X509::ExtensionFactory.new
37
+ extension_factory.subject_certificate = certificate
38
+ extension_factory.issuer_certificate = certificate
39
+ certificate.add_extension extension_factory.create_extension("basicConstraints", "CA:TRUE", true)
40
+ certificate.add_extension extension_factory.create_extension("keyUsage", "keyCertSign, cRLSign", true)
41
+ certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
42
+ certificate.add_extension extension_factory.create_extension("authorityKeyIdentifier", "keyid:always", false)
43
+
44
+ certificate.sign certificate_authority_key, ::OpenSSL::Digest::SHA256.new
45
+ end
46
+ end
47
+
48
+ def certificate_store
49
+ @certificate_store ||= ::OpenSSL::X509::Store.new.tap do |certificates|
50
+ certificates.add_cert(certificate_authority_certificate)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require_relative 'certificate_authority_context'
7
+
8
+ module Sus
9
+ module Fixtures
10
+ module OpenSSL
11
+ module HostCertificatesContext
12
+ include CertificateAuthorityContext
13
+
14
+ def keys
15
+ @keys ||= Hash[
16
+ hosts.collect{|name| [name, ::OpenSSL::PKey::RSA.new(2048)]}
17
+ ]
18
+ end
19
+
20
+ # The certificate used for actual communication:
21
+ def certificates
22
+ @certificates ||= Hash[
23
+ hosts.collect do |name|
24
+ certificate_name = ::OpenSSL::X509::Name.parse("O=Test/CN=#{name}")
25
+
26
+ certificate = ::OpenSSL::X509::Certificate.new
27
+ certificate.subject = certificate_name
28
+ certificate.issuer = certificate_authority_certificate.subject
29
+
30
+ certificate.public_key = keys[name].public_key
31
+
32
+ certificate.serial = 2
33
+ certificate.version = 2
34
+
35
+ certificate.not_before = Time.now
36
+ certificate.not_after = Time.now + 3600
37
+
38
+ extension_factory = ::OpenSSL::X509::ExtensionFactory.new
39
+ extension_factory.subject_certificate = certificate
40
+ extension_factory.issuer_certificate = certificate_authority_certificate
41
+ certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true)
42
+ certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
43
+
44
+ certificate.sign certificate_authority_key, ::OpenSSL::Digest::SHA256.new
45
+
46
+ [name, certificate]
47
+ end
48
+ ]
49
+ end
50
+
51
+ def server_context
52
+ @server_context ||= ::OpenSSL::SSL::SSLContext.new.tap do |context|
53
+ context.servername_cb = Proc.new do |socket, name|
54
+ if hosts.include? name
55
+ socket.hostname = name
56
+
57
+ ::OpenSSL::SSL::SSLContext.new.tap do |context|
58
+ context.cert = certificates[name]
59
+ context.key = keys[name]
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def client_context
67
+ @client_context ||= ::OpenSSL::SSL::SSLContext.new.tap do |context|
68
+ context.cert_store = certificate_store
69
+ context.verify_mode = ::OpenSSL::SSL::VERIFY_PEER
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require_relative 'valid_certificate_context'
7
+
8
+ module Sus
9
+ module Fixtures
10
+ module OpenSSL
11
+ module InvalidCertificateContext
12
+ include ValidCertificateContext
13
+
14
+ def invalid_key
15
+ @invalid_key ||= ::OpenSSL::PKey::RSA.new(2048)
16
+ end
17
+
18
+ # The certificate used for actual communication:
19
+ def certificate
20
+ @certificate ||= ::OpenSSL::X509::Certificate.new.tap do |certificate|
21
+ certificate.subject = certificate_name
22
+ certificate.issuer = certificate_authority_certificate.subject
23
+
24
+ certificate.public_key = key.public_key
25
+
26
+ certificate.serial = 2
27
+ certificate.version = 2
28
+
29
+ # We set the validity period to the past, so the certificate is invalid:
30
+ certificate.not_before = Time.now - 3600
31
+ certificate.not_after = Time.now
32
+
33
+ extension_factory = ::OpenSSL::X509::ExtensionFactory.new()
34
+ extension_factory.subject_certificate = certificate
35
+ extension_factory.issuer_certificate = certificate_authority_certificate
36
+ certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true)
37
+ certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
38
+
39
+ certificate.sign invalid_key, ::OpenSSL::Digest::SHA256.new
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require_relative 'certificate_authority_context'
7
+
8
+ module Sus
9
+ module Fixtures
10
+ module OpenSSL
11
+ module ValidCertificateContext
12
+ include CertificateAuthorityContext
13
+
14
+ # The private key to use on the server side:
15
+ def key
16
+ @key ||= ::OpenSSL::PKey::RSA.new(2048)
17
+ end
18
+
19
+ def certificate_name
20
+ ::OpenSSL::X509::Name.parse("O=Test/CN=localhost")
21
+ end
22
+
23
+ # The certificate used for actual communication:
24
+ def certificate
25
+ @certificate ||= ::OpenSSL::X509::Certificate.new.tap do |certificate|
26
+ certificate.subject = certificate_name
27
+ certificate.issuer = certificate_authority_certificate.subject
28
+
29
+ certificate.public_key = key.public_key
30
+
31
+ certificate.serial = 2
32
+ certificate.version = 2
33
+
34
+ # The certificate is valid for one hour:
35
+ certificate.not_before = Time.now
36
+ certificate.not_after = Time.now + 3600
37
+
38
+ extension_factory = ::OpenSSL::X509::ExtensionFactory.new()
39
+ extension_factory.subject_certificate = certificate
40
+ extension_factory.issuer_certificate = certificate_authority_certificate
41
+ certificate.add_extension extension_factory.create_extension("keyUsage", "digitalSignature", true)
42
+ certificate.add_extension extension_factory.create_extension("subjectKeyIdentifier", "hash")
43
+
44
+ certificate.sign certificate_authority_key, ::OpenSSL::Digest::SHA256.new
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require_relative 'certificate_authority_context'
7
+
8
+ module Sus
9
+ module Fixtures
10
+ module OpenSSL
11
+ module VerifiedCertificateContext
12
+ def server_context
13
+ ::OpenSSL::SSL::SSLContext.new.tap do |context|
14
+ context.cert = certificate
15
+ context.key = key
16
+ end
17
+ end
18
+
19
+ def client_context
20
+ ::OpenSSL::SSL::SSLContext.new.tap do |context|
21
+ context.cert_store = certificate_store
22
+ context.verify_mode = ::OpenSSL::SSL::VERIFY_PEER
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ module Sus
7
+ module Fixtures
8
+ module OpenSSL
9
+ VERSION = "0.1.0"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Samuel Williams.
5
+
6
+ require_relative 'openssl/version'
7
+
8
+ require_relative 'openssl/certificate_authority_context'
9
+ require_relative 'openssl/host_certificates_context'
10
+ require_relative 'openssl/valid_certificate_context'
11
+ require_relative 'openssl/invalid_certificate_context'
12
+ require_relative 'openssl/verified_certificate_context'
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright, 2023, by Samuel Williams.
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.
data/readme.md ADDED
@@ -0,0 +1,43 @@
1
+ # Sus::Fixtures::OpenSSL
2
+
3
+ Provides a convenient fixture for setting up client and server SSL sockets.
4
+
5
+ [![Development Status](https://github.com/ioquatix/sus-fixtures-openssl/workflows/Test/badge.svg)](https://github.com/ioquatix/sus-fixtures-openssl/actions?workflow=Test)
6
+
7
+ ## Installation
8
+
9
+ ``` bash
10
+ $ bundle add sus-fixtures-openssl
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ``` ruby
16
+ include Sus::Fixtures::OpenSSL::HostCertificatesContext
17
+
18
+ it 'can create a secure connection' do
19
+ # Use `server_context` to create a server socket:
20
+ server_socket = OpenSSL::SSL::SSLSocket.new(socket, server_context)
21
+
22
+ # Use `client_context` to create a client socket:
23
+ client_socket = OpenSSL::SSL::SSLSocket.new(socket, client_context)
24
+ end
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ We welcome contributions to this project.
30
+
31
+ 1. Fork it.
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
34
+ 4. Push to the branch (`git push origin my-new-feature`).
35
+ 5. Create new Pull Request.
36
+
37
+ ### Developer Certificate of Origin
38
+
39
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
40
+
41
+ ### Contributor Covenant
42
+
43
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ %m�U*la�5#6f���\c��"v傯GO賆7�,{ě���
2
+ or�-϶4*�D�9�r��k���f��l����Sz��7�l6��� ��E������:�/.�'���3���y��ۉŃǤ9D�nH�{�,m�t #��ߴ(7HbO�N����ݫ ��w���d�id�P�UT��<�,�
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sus-fixtures-openssl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
14
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
15
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
16
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
17
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
18
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
19
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
20
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
21
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
22
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
23
+ XibYXP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1XiAXL7lyYUyOq24KHgQ2Csg=
39
+ -----END CERTIFICATE-----
40
+ date: 2023-08-26 00:00:00.000000000 Z
41
+ dependencies:
42
+ - !ruby/object:Gem::Dependency
43
+ name: openssl
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: sus
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.10'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.10'
70
+ description:
71
+ email:
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/sus/fixtures/openssl.rb
77
+ - lib/sus/fixtures/openssl/certificate_authority_context.rb
78
+ - lib/sus/fixtures/openssl/host_certificates_context.rb
79
+ - lib/sus/fixtures/openssl/invalid_certificate_context.rb
80
+ - lib/sus/fixtures/openssl/valid_certificate_context.rb
81
+ - lib/sus/fixtures/openssl/verified_certificate_context.rb
82
+ - lib/sus/fixtures/openssl/version.rb
83
+ - license.md
84
+ - readme.md
85
+ homepage: https://github.com/ioquatix/sus-fixtures-openssl
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ funding_uri: https://github.com/sponsors/ioquatix/
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '3.0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.4.10
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Test fixtures for running with OpenSSL.
109
+ test_files: []
metadata.gz.sig ADDED
Binary file