certmeister 1.0.1 → 1.1.0
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3a26696f474a3c8396726f7b84840b062172f86
|
4
|
+
data.tar.gz: 1e1e66376dda66c3a1a805b2f9335e516c8503a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 929dbfe79056c3e6150c69571f50a1ef4d46e4a2205790c9b1a0b248a7b6f371b64cab6312eb3853180ccdb99ad740057be4fb2cb1db5ba41f70ae5754ec1f0b
|
7
|
+
data.tar.gz: e3e1e03909bce76551b33b588cc4081e08d5274d7e5966b83545888f8f509b340d4c82fb2d082210a70fce6cdb7baae8c4d6295ca9f20c6b9153953eb09dce8b
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Certmeister
|
2
|
+
|
3
|
+
class SelfTest
|
4
|
+
|
5
|
+
# Pass in PEM-encoded key for fast tests that don't need lots of entropy.
|
6
|
+
def initialize(ca, key = nil)
|
7
|
+
@ca = ca
|
8
|
+
@key = key
|
9
|
+
end
|
10
|
+
|
11
|
+
def test(req = {cn: 'test', ip: '127.0.0.1'})
|
12
|
+
begin
|
13
|
+
res = @ca.remove(req)
|
14
|
+
res.hit? or res.miss? or raise "Test certificate remove failed: #{res.error}"
|
15
|
+
|
16
|
+
csr = get_csr("C=ZA, ST=Western Cape, L=Cape Town, O=Hetzner PTY Ltd, CN=#{req[:cn]}")
|
17
|
+
res = @ca.sign(cn: 'test', csr: csr.to_pem, ip: '127.0.0.1')
|
18
|
+
res.hit? or raise "Test certificate signing failed: #{res.error}"
|
19
|
+
|
20
|
+
res = @ca.fetch(cn: 'test', ip: '127.0.0.1')
|
21
|
+
res.hit? or raise "Test certificate fetch failed: #{res.error}"
|
22
|
+
|
23
|
+
cert = OpenSSL::X509::Certificate.new(res.pem)
|
24
|
+
cert.subject.to_s =~ /CN=#{req[:cn]}/ or raise "Test certificate common name mismatch"
|
25
|
+
|
26
|
+
Result.new(true, {message: "OK"})
|
27
|
+
rescue Exception => e
|
28
|
+
Result.new(false, {message: e.message})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get_csr(subject)
|
35
|
+
key = get_key
|
36
|
+
csr = OpenSSL::X509::Request.new
|
37
|
+
csr.version = 0
|
38
|
+
csr.subject = OpenSSL::X509::Name.parse(subject)
|
39
|
+
csr.public_key = key.public_key
|
40
|
+
csr.sign key, OpenSSL::Digest::SHA1.new
|
41
|
+
csr
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_key
|
45
|
+
OpenSSL::PKey::RSA.new(@key || 4096).tap do |key|
|
46
|
+
@key ||= key.to_pem
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Result
|
51
|
+
attr_reader :data
|
52
|
+
|
53
|
+
def initialize(ok, data)
|
54
|
+
@ok = !!ok
|
55
|
+
@data = data
|
56
|
+
end
|
57
|
+
|
58
|
+
def ok?
|
59
|
+
@ok
|
60
|
+
end
|
61
|
+
|
62
|
+
def message
|
63
|
+
@data.fetch(:message, nil) if @data.respond_to?(:fetch)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/lib/certmeister/version.rb
CHANGED
@@ -9,25 +9,25 @@ describe Certmeister::Policy::Fcrdns do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "refuses to authenticate a request with a missing cn" do
|
12
|
-
response = subject.authenticate({ip: '
|
12
|
+
response = subject.authenticate({ip: '8.8.8.8'})
|
13
13
|
expect(response).to_not be_authenticated
|
14
14
|
expect(response.error).to eql "missing cn"
|
15
15
|
end
|
16
16
|
|
17
17
|
it "refuses to authenticate a request with a missing ip" do
|
18
|
-
response = subject.authenticate({cn: '
|
18
|
+
response = subject.authenticate({cn: 'google-public-dns-a.google.com'})
|
19
19
|
expect(response).to_not be_authenticated
|
20
20
|
expect(response.error).to eql "missing ip"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "refuses to authenticate a request with an ip that does not have fcrdns that matches the cn" do
|
24
|
-
response = subject.authenticate({cn: '
|
24
|
+
response = subject.authenticate({cn: 'google-public-dns-a.google.com', ip: '127.0.0.1'})
|
25
25
|
expect(response).to_not be_authenticated
|
26
26
|
expect(response.error).to eql "cn does not match fcrdns"
|
27
27
|
end
|
28
28
|
|
29
|
-
it "authenticates any request with an ip that
|
30
|
-
response = subject.authenticate({cn: '
|
29
|
+
it "authenticates any request with an ip that has fcrdns that matches the cn" do
|
30
|
+
response = subject.authenticate({cn: 'google-public-dns-a.google.com', ip: '8.8.8.8'})
|
31
31
|
expect(response).to be_authenticated
|
32
32
|
end
|
33
33
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'helpers/certmeister_config_helper'
|
3
|
+
|
4
|
+
require 'certmeister'
|
5
|
+
|
6
|
+
describe Certmeister::SelfTest do
|
7
|
+
|
8
|
+
subject { Certmeister::SelfTest.new(ca, File.read('fixtures/client.key')) }
|
9
|
+
|
10
|
+
describe "#test(req = {cn: 'test', ip: '127.0.0.1'})" do
|
11
|
+
|
12
|
+
context "when the CA is functioning correctly" do
|
13
|
+
|
14
|
+
let(:ca) { Certmeister.new(CertmeisterConfigHelper::valid_config) }
|
15
|
+
|
16
|
+
it "returns success" do
|
17
|
+
res = subject.test(cn: 'test', ip: '127.0.0.1')
|
18
|
+
expect(res).to be_ok
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when the CA is malfunctioning" do
|
24
|
+
|
25
|
+
let(:store) { Certmeister::InMemoryStore.new.tap { |o| o.send(:break!) } }
|
26
|
+
let(:ca) { Certmeister.new(CertmeisterConfigHelper::custom_config(store: store)) }
|
27
|
+
|
28
|
+
it "returns an error" do
|
29
|
+
res = subject.test(cn: 'test', ip: '127.0.0.1')
|
30
|
+
expect(res).to_not be_ok
|
31
|
+
end
|
32
|
+
|
33
|
+
it "provides an error message in the response data" do
|
34
|
+
res = subject.test(cn: 'test', ip: '127.0.0.1')
|
35
|
+
expect(res.data[:message]).to match /in-memory store is broken/
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: certmeister
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Hearn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/certmeister/policy/psk.rb
|
103
103
|
- lib/certmeister/policy/response.rb
|
104
104
|
- lib/certmeister/response.rb
|
105
|
+
- lib/certmeister/self_test.rb
|
105
106
|
- lib/certmeister/store_error.rb
|
106
107
|
- lib/certmeister/test/memory_store_interface.rb
|
107
108
|
- lib/certmeister/version.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- spec/certmeister/policy/psk_spec.rb
|
120
121
|
- spec/certmeister/policy/response_spec.rb
|
121
122
|
- spec/certmeister/response_spec.rb
|
123
|
+
- spec/certmeister/self_test_spec.rb
|
122
124
|
- spec/helpers/certmeister_config_helper.rb
|
123
125
|
- spec/helpers/certmeister_fetching_request_helper.rb
|
124
126
|
- spec/helpers/certmeister_policy_helper.rb
|
@@ -164,6 +166,7 @@ test_files:
|
|
164
166
|
- spec/certmeister/policy/psk_spec.rb
|
165
167
|
- spec/certmeister/policy/response_spec.rb
|
166
168
|
- spec/certmeister/response_spec.rb
|
169
|
+
- spec/certmeister/self_test_spec.rb
|
167
170
|
- spec/helpers/certmeister_config_helper.rb
|
168
171
|
- spec/helpers/certmeister_fetching_request_helper.rb
|
169
172
|
- spec/helpers/certmeister_policy_helper.rb
|