diff options
author | elijah <elijah@riseup.net> | 2014-08-05 15:11:33 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2014-08-05 15:11:33 -0700 |
commit | b76d1bcc4d135f0d46a1f5daa54a0faa939cfd20 (patch) | |
tree | eaf766b279a5fd69899b665adea0ca433b37d9d5 | |
parent | 4af55c774c0d47462fffe0600c8204bbc23224ed (diff) |
added kkp_ca_file config option
-rw-r--r-- | config/default.yml | 2 | ||||
-rw-r--r-- | config/sks-keyservers.netCA.pem | 32 | ||||
-rw-r--r-- | lib/nickserver/config.rb | 18 | ||||
-rw-r--r-- | test/files/autistici-ca.pem | 40 | ||||
-rw-r--r-- | test/files/mayfirst-ca.pem | 22 | ||||
-rw-r--r-- | test/test_helper.rb | 13 | ||||
-rw-r--r-- | test/unit/hkp_test.rb | 46 |
7 files changed, 160 insertions, 13 deletions
diff --git a/config/default.yml b/config/default.yml index 8ddadce..898b91b 100644 --- a/config/default.yml +++ b/config/default.yml @@ -21,4 +21,4 @@ couch_password: ~ # HKP # hkp_url: 'https://hkps.pool.sks-keyservers.net:/pks/lookup' - +hkp_ca_file: 'config/sks-keyservers.netCA.pem' diff --git a/config/sks-keyservers.netCA.pem b/config/sks-keyservers.netCA.pem new file mode 100644 index 0000000..24a2ad2 --- /dev/null +++ b/config/sks-keyservers.netCA.pem @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFizCCA3OgAwIBAgIJAK9zyLTPn4CPMA0GCSqGSIb3DQEBBQUAMFwxCzAJBgNV +BAYTAk5PMQ0wCwYDVQQIDARPc2xvMR4wHAYDVQQKDBVza3Mta2V5c2VydmVycy5u +ZXQgQ0ExHjAcBgNVBAMMFXNrcy1rZXlzZXJ2ZXJzLm5ldCBDQTAeFw0xMjEwMDkw +MDMzMzdaFw0yMjEwMDcwMDMzMzdaMFwxCzAJBgNVBAYTAk5PMQ0wCwYDVQQIDARP +c2xvMR4wHAYDVQQKDBVza3Mta2V5c2VydmVycy5uZXQgQ0ExHj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H8uPrnSlqoPBcKC9PrgUzQYfSZJkLmB+3jEa3HKruy1abJP5 +gAdQvwvcPpvYRnIzUc9fZODsVmlHVFBCl2dlu/iHh2h4GmL4Da2rRkUMlbVTdioB +UYIvMycdOkpH5wJftzw7cpjsudGas0PARDXCFfGyKhwBRFY7Xp7lbjtU5Rz0Gc04 +lPrhDf0pFE98Aw4jJRpFeWMjpXUEaG1cq7D641RpgcMfPFvOHY47rvDTS7XJOaUT +BwRjmDt896s6vMDcaG/uXJbQjuzmmx3W2Idyh3s5SI0GTHb0IwMKYb4eBUIpQOnB +cE77VnCYqKvN1NVYAqhWjXbY7XasZvszCRcOG+W3FqNaHOK/n/0ueb0uijdLan+U +f4p1bjbAox8eAOQS/8a3bzkJzdyBNUKGx1BIK2IBL9bn/HravSDOiNRSnZ/R3l9G +ZauX0tu7IIDlRCILXSyeazu0aj/vdT3YFQXPcvt5Fkf5wiNTo53f72/jYEJd6qph +WrpoKqrwGwTpRUCMhYIUt65hsTxCiJJ5nKe39h46sg== +-----END CERTIFICATE----- diff --git a/lib/nickserver/config.rb b/lib/nickserver/config.rb index 31fbfea..0f44b79 100644 --- a/lib/nickserver/config.rb +++ b/lib/nickserver/config.rb @@ -9,6 +9,7 @@ module Nickserver class << self attr_accessor :hkp_url + attr_accessor :hkp_ca_file attr_accessor :couch_port attr_accessor :couch_host attr_accessor :couch_database @@ -32,10 +33,27 @@ module Nickserver end true end + self.validate end private + def self.validate + if @hkp_ca_file + # look for the hkp_ca_file either by absolute path or relative to nickserver gem root + [@hkp_ca_file, File.expand_path(@hkp_ca_file, "#{__FILE__}/../../../")].each do |file| + if File.exists?(file) + @hkp_ca_file = file + break + end + end + unless File.exists?(@hkp_ca_file) + STDERR.puts "ERROR in configuration: cannot find hkp_ca_file `#{@hkp_ca_file}`" + exit(1) + end + end + end + def self.load_config(file_path) begin YAML.load(File.read(file_path)).each do |key, value| diff --git a/test/files/autistici-ca.pem b/test/files/autistici-ca.pem new file mode 100644 index 0000000..f7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EXg4DIelRTbCuqMwglSDFO95R0uCUG +meI6GQ/N1+8VVY4+3yMxSmua7kQ1A00J839qqduqcMfE5/KlnZ1IDY+kBP39jBa1 +JHgpRLc3zi8Rn0GRuxuMX3L4bYAWhqcNdlodgCvh1HU2JqWRdCv0xamy2XRk99m1 +zyTYZh5ZkthQJTCJcnKm/C91jLwzm0Jxze/xftBzTQopdZ2zrr4JFGei9MHNpLZ7 +kBXXeobvgkl0bq4TLHP0wE6A9QgA39b8KQ/7LlCSHjpNxtQKv4y54Yz9Lsdj7eUh +ZIRZTLZuwNzIlT0TGXaqQnLCmqKiP2AJKGAhUyAT4P3QXGheExdpcSyQ3X0kaVaS +kWSqyylqMmL7oO1p7RVnSApnoVToqaTZXEj8DtmztgWUe7s2n/x8jYKR0qCtx84= +-----END CERTIFICATE----- diff --git a/test/files/mayfirst-ca.pem b/test/files/mayfirst-ca.pem new file mode 100644 index 0000000..471f532 --- /dev/null +++ b/test/files/mayfirst-ca.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDjTCCAvagAwIBAgIJANhg2/WVrETtMA0GCSqGSIb3DQEBBQUAMIGMMR4wHAYD +VQQKExVNYXkgRmlyc3QvUGVvcGxlIExpbmsxIDAeBgkqhkiG9w0BCQEWEWluZm9A +bWF5Zmlyc3Qub3JnMREwDwYDVQQHEwhOZXcgWW9yazERMA8GA1UECBMITmV3IFlv +cmsxCzAJBgNVBAYTAlVTMRUwEwYDVQQDEwxNRlBMIFJvb3QgQ0EwHhcNMDkwMTEy +MTYyNjU3WhcNMTkwMTEwMTYyNjU3WjCBjDEeMBwGA1UEChMVTWF5IEZpcnN0L1Bl +b3BsZSBMaW5rMSAwHgYJKoZIhvcNAQkBFhFpbmZvQG1heWZpcnN0Lm9yZzERMA8G +A1UEBxMITmV3IFlvcmsxETAPBgNVBAgTCE5ldyBZb3JrMQswCQYDVQQGEwJVUzEV +MBMGA1UEAxMMTUZQTCBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB +gQDQgYTGNjAJADudHV2MZ1QJQdf3YAMB1g/buR9ADsoTzM3vKWzXBvgoC6CFrojw +RNbVtgU3A9aetLxaWJuBSqqREub+HyZvzD14tP90hq10YthtXoCtjhs6C/mEqckk +LCGdTZ/lsIiM8tSdoE/OFQNRqk81A4lHgyumHlw3wnVICQIDAQABo4H0MIHxMAwG +A1UdEwQFMAMBAf8wHQYDVR0OBBYEFHzhAs1Q0Pu6lbptL6VlnVVTDni0MIHBBgNV +HSMEgbkwgbaAFHzhAs1Q0Pu6lbptL6VlnVVTDni0oYGSpIGPMIGMMR4wHAYDVQQK +ExVNYXkgRmlyc3QvUGVvcGxlIExpbmsxIDAeBgkqhkiG9w0BCQEWEWluZm9AbWF5 +Zmlyc3Qub3JnMREwDwYDVQQHEwhOZXcgWW9yazERMA8GA1UECBMITmV3IFlvcmsx +CzAJBgNVBAYTAlVTMRUwEwYDVQQDEwxNRlBMIFJvb3QgQ0GCCQDYYNv1laxE7TAN +BgkqhkiG9w0BAQUFAAOBgQA8kagGZR+Tp6GRyQWYlcNW9xVYza/xPZhPY4dVYUtv +Czcw5N1mB0R444c4jhVLIrPWUjcpz46akXXHMGpcIsX/rNetbLCtcE9/AuB+Xg1K +Fwr/SXkZXVK1vIppXmV0ZBaIB/tRV/SozcGRN/D9ETYX4JhBZU6OXPxNVjp5dvlH +vQ== +-----END CERTIFICATE----- diff --git a/test/test_helper.rb b/test/test_helper.rb index d6eabe5..7fbe400 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,7 +19,11 @@ class Minitest::Test end def file_content(filename) - (@file_contents ||= {})[filename] ||= File.read("%s/files/%s" % [File.dirname(__FILE__), filename]) + (@file_contents ||= {})[filename] ||= File.read(file_path(filename)) + end + + def file_path(filename) + "%s/files/%s" % [File.dirname(__FILE__), filename] end def real_network @@ -54,4 +58,11 @@ class Minitest::Test end end + # + # temporarily stubs the config property for the duration of the given block + # + def stub_config(property, value, &block) + Nickserver::Config.stub(property, value, &block) + end + end diff --git a/test/unit/hkp_test.rb b/test/unit/hkp_test.rb index 0ac4728..9c10aab 100644 --- a/test/unit/hkp_test.rb +++ b/test/unit/hkp_test.rb @@ -34,16 +34,6 @@ class HkpTest < Minitest::Test end end - def test_key_info_real_network - real_network do - uid = 'elijah@riseup.net' - test_em_callback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |keys| - assert_equal 1, keys.size - assert keys.first.keyid =~ /00440025$/ - end - end - end - def test_fetch_key uid = 'cloudadmin@leap.se' key_id = 'E818C478D3141282F7590D29D041EB11B1647490' @@ -77,6 +67,39 @@ class HkpTest < Minitest::Test end end + # + # real network tests + # remember: must be run with REAL_NET=true + # + + def test_key_info_real_network + real_network do + uid = 'elijah@riseup.net' + test_em_callback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |keys| + assert_equal 1, keys.size + assert keys.first.keyid =~ /00440025$/ + end + end + end + + def test_tls_validation_with_real_network + hkp_url = 'https://keys.mayfirst.org/pks/lookup' + ca_file = file_path('mayfirst-ca.pem') + + real_network do + stub_config(:hkp_url, hkp_url) do + stub_config(:hkp_ca_file, ca_file) do + #stub_config(:hkp_ca_file, file_path('autistici-ca.pem')) do + assert File.exists?(Nickserver::Config.hkp_ca_file) + uid = 'elijah@riseup.net' + test_em_callback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |keys| + assert_equal 1, keys.size + assert keys.first.keyid =~ /00440025$/ + end + end + end + end + end protected @@ -97,7 +120,8 @@ class HkpTest < Minitest::Test } deferrable.errback {|response, msg| EM.stop - flunk "Expecting callback, but errback invoked with response: #{response} #{msg}" + puts caller.join("\n") + flunk "Expecting callback, but errback invoked with response: #{response} #{msg}\n\n#{caller.join("\n")}" } end assert false, 'should not get here' |