-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2444 from matiaskorhonen/feature/gem-signature-ve…
…rification Gem signature verification
- Loading branch information
Showing
12 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddCertChainToVersions < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column :versions, :cert_chain, :text | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class CertificateChainSerializer | ||
PATTERN = /-----BEGIN CERTIFICATE-----(?:.|\n)+?-----END CERTIFICATE-----/.freeze | ||
|
||
def self.load(chain) | ||
return [] unless chain | ||
chain.scan(PATTERN).map do |cert| | ||
OpenSSL::X509::Certificate.new(cert) | ||
end | ||
end | ||
|
||
def self.dump(chain) | ||
return if chain.blank? | ||
normalised = chain.map do |cert| | ||
cert.respond_to?(:to_pem) ? cert : OpenSSL::X509::Certificate.new(cert) | ||
end | ||
normalised.map(&:to_pem).join | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIFKTCCBBGgAwIBAgISBFspP+tJfRaC6xprreB4Rp9KMA0GCSqGSIb3DQEBCwUA | ||
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD | ||
EwJSMzAeFw0yMTA0MTcwMjQzMTlaFw0yMTA3MTYwMjQzMTlaMBwxGjAYBgNVBAMT | ||
EXd3dy5jb2Rlb3Rha3UuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC | ||
AQEAx6h5vNPfkkrtYWxn1PWDDLRAwrGmZbkYPttjHBRSwTcd7rsIX4PcSzw9fWxm | ||
K4vIkAYoKAElIvsSE3xRUjyzMrACfdhK5J8rG25fq94iVyoYaNBQV0WMJkO6X47s | ||
hGeIKkK91ohR5b2tMw3/z9zELP0TVo2TPG7rYsBZm34myldqDA8yVEBEOa+Qdpda | ||
9xewPhkkdpAU55qgWTrD21m7vGq9WpsBz4wNKnwVsaugtkRH82VPIfaL4ZI9kox6 | ||
QoPWe/tHUBdlDkuT7ud77eLAWnC/5Clg28/9GU/Z8Nj8SrrKuXL6WUXmxxaAhWUR | ||
Qx4VblZeuIpwd0nHyP0hz4CWKQIDAQABo4ICTTCCAkkwDgYDVR0PAQH/BAQDAgWg | ||
MB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0G | ||
A1UdDgQWBBTKiSGZuLFSIG2JPbFSZa9TxMu5WTAfBgNVHSMEGDAWgBQULrMXt1hW | ||
y65QCUDmH6+dixTCxjBVBggrBgEFBQcBAQRJMEcwIQYIKwYBBQUHMAGGFWh0dHA6 | ||
Ly9yMy5vLmxlbmNyLm9yZzAiBggrBgEFBQcwAoYWaHR0cDovL3IzLmkubGVuY3Iu | ||
b3JnLzAcBgNVHREEFTATgh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52LFMLGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjANBgkqhkiG9w0B | ||
AQsFAAOCAQEA2UzgyfWEiDcx27sT4rP8i2tiEmxYt0l+PAK3qB8oYevO4C5z70kH | ||
ejWEHx2taPDY/laBL21/WKZuNTYQHHPD5b1tXgHXbnL7KqC401dk5VvCadTQsvd8 | ||
S8MXjohyc9z9/G2948kLjmE6Flh9dDYrVYA9x2O+hEPGOaEOa1eePynBgPayvUfL | ||
qjBstzLhWVQLGAkXXmNs+5ZnPBxzDJOLxhF2JIbeQAcH5H0tZrUlo5ZYyOqA7s9p | ||
O5b85o3AM/OJ+CktFBQtfvBhcJVd9wvlwPsk+uyOy2HI7mNxKKgsBTt375teA2Tw | ||
UdHkhVNcsAKX1H7GNNLOEADksd86wuoXvg== | ||
-----END CERTIFICATE----- |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "test_helper" | ||
|
||
class CertificateChainSerializerTest < ActiveSupport::TestCase | ||
context ".load" do | ||
setup do | ||
@cert_chain = File.read(File.expand_path("../certs/chain.pem", __dir__)) | ||
end | ||
|
||
should "return an empty array when no certificates are present" do | ||
assert_equal [], CertificateChainSerializer.load("") | ||
assert_equal [], CertificateChainSerializer.load(nil) | ||
end | ||
|
||
should "return an array of certificates when certificates are present" do | ||
certs = CertificateChainSerializer.load(@cert_chain) | ||
assert_equal 2, certs.size | ||
assert_equal "379469669351564281569116418161349711273802", certs[0].serial.to_s | ||
assert_equal "85078157426496920958827089468591623647", certs[1].serial.to_s | ||
end | ||
end | ||
|
||
context ".dump" do | ||
setup do | ||
@certs = Array.new(2) do | ||
key = OpenSSL::PKey::RSA.new(1024) | ||
public_key = key.public_key | ||
|
||
subject = "/C=FI/O=Test/OU=Test/CN=Test" | ||
|
||
cert = OpenSSL::X509::Certificate.new | ||
cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject) | ||
cert.not_before = Time.current | ||
cert.not_after = 1.year.from_now | ||
cert.public_key = public_key | ||
cert.serial = 0x0 | ||
cert.version = 2 | ||
cert.sign(key, OpenSSL::Digest.new("SHA256")) | ||
cert | ||
end | ||
end | ||
|
||
should "return an nil when no certificates are present" do | ||
assert_nil CertificateChainSerializer.dump([]) | ||
assert_nil CertificateChainSerializer.dump(nil) | ||
end | ||
|
||
should "return a certificate chain string when certificates are present" do | ||
assert_equal @certs.map(&:to_pem).join, CertificateChainSerializer.dump(@certs) | ||
end | ||
|
||
should "return a certificate chain when the chain certificates are in PEMs" do | ||
pems = @certs.map(&:to_pem) | ||
assert_equal pems.join, CertificateChainSerializer.dump(pems) | ||
end | ||
|
||
should "strip out excessive newlines from the certificate PEMs" do | ||
pems = @certs.map { |cert| "#{cert.to_pem}\n\n\n" } | ||
assert_equal @certs.map(&:to_pem).join, CertificateChainSerializer.dump(pems) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters