flores 0.0.5 → 0.0.6
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 +4 -4
- data/flores.gemspec +1 -1
- data/lib/flores/pki.rb +43 -6
- data/spec/flores/pki_spec.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e913b4627dc9ac067842992242889c14e47d760
|
4
|
+
data.tar.gz: 4102c950d2497218313c0126a77c853800fc6c65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af96bea45346f686ee75242aa2b09f7d9906b5fd6a85b3710ea1e8be4622c33da75bb007b13eaea19ce3e16afbb355ad26ebf23dbe1c0fa7b33610655fedc986
|
7
|
+
data.tar.gz: 2a2612427e400a93ac1ad7910c1b2d2d9637a9f42c3e8a4c7c96ac1042fb4cbda6df50d060283de7c3c0122d6c8ecfdc84de68bb515b6d5f7ce5a0e34dfc0b0a
|
data/flores.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |spec|
|
|
2
2
|
files = %x(git ls-files).split("\n")
|
3
3
|
|
4
4
|
spec.name = "flores"
|
5
|
-
spec.version = "0.0.
|
5
|
+
spec.version = "0.0.6"
|
6
6
|
spec.summary = "Fuzz, randomize, and stress your tests"
|
7
7
|
spec.description = <<-DESCRIPTION
|
8
8
|
Add fuzzing, randomization, and stress to your tests.
|
data/lib/flores/pki.rb
CHANGED
@@ -21,12 +21,49 @@ require "English"
|
|
21
21
|
require "openssl"
|
22
22
|
|
23
23
|
module Flores::PKI
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
GENERATE_DEFAULT_KEY_SIZE = 1024
|
25
|
+
GENERATE_DEFAULT_EXPONENT = 65537
|
26
|
+
GENERATE_DEFAULT_DURATION_RANGE = 1..86400
|
27
|
+
|
28
|
+
class << self
|
29
|
+
# Generate a random serial number for a certificate.
|
30
|
+
def random_serial
|
31
|
+
# RFC5280 (X509) says:
|
32
|
+
# > 4.1.2.2. Serial Number
|
33
|
+
# > Certificate users MUST be able to handle serialNumber values up to 20 octets
|
34
|
+
Flores::Random.integer(1..9).to_s + Flores::Random.iterations(0..19).collect { Flores::Random.integer(0..9) }.join
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generate a valid certificate with sane random values.
|
38
|
+
#
|
39
|
+
# By default this method use `CN=localhost` as the default subject and a 1024 bits encryption
|
40
|
+
# key for the certificate, you can override the defaults by specifying a subject and the
|
41
|
+
# key size in the options hash.
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
#
|
45
|
+
# Flores::PKI.generate("CN=localhost", { :key_size => 2048 }
|
46
|
+
#
|
47
|
+
# @params subject [String] Certificate subject
|
48
|
+
# @params opts [Hash] Options
|
49
|
+
# @return [OpenSSL::X509::Certificate, OpenSSL::Pkey::RSA]
|
50
|
+
def generate(subject = "CN=localhost", opts = {})
|
51
|
+
key_size = opts.fetch(:key_size, GENERATE_DEFAULT_KEY_SIZE)
|
52
|
+
key = OpenSSL::PKey::RSA.generate(key_size, GENERATE_DEFAULT_EXPONENT)
|
53
|
+
|
54
|
+
certificate_duration = Flores::Random.number(GENERATE_DEFAULT_DURATION_RANGE)
|
55
|
+
|
56
|
+
csr = Flores::PKI::CertificateSigningRequest.new
|
57
|
+
csr.subject = subject
|
58
|
+
csr.public_key = key.public_key
|
59
|
+
csr.start_time = Time.now
|
60
|
+
csr.expire_time = csr.start_time + certificate_duration
|
61
|
+
csr.signing_key = key
|
62
|
+
csr.want_signature_ability = true
|
63
|
+
certificate = csr.create
|
64
|
+
|
65
|
+
return [certificate, key]
|
66
|
+
end
|
30
67
|
end
|
31
68
|
|
32
69
|
# A certificate signing request.
|
data/spec/flores/pki_spec.rb
CHANGED
@@ -64,11 +64,19 @@ describe Flores::PKI::CertificateSigningRequest do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
describe Flores::PKI do
|
67
|
-
context "
|
67
|
+
context ".random_serial" do
|
68
68
|
let(:serial) { Flores::PKI.random_serial }
|
69
69
|
stress_it "generates a valid OpenSSL::BN value" do
|
70
70
|
OpenSSL::BN.new(serial)
|
71
71
|
Integer(serial)
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
context ".generate" do
|
76
|
+
it "returns a certificate and a key" do
|
77
|
+
certificate, key = Flores::PKI.generate
|
78
|
+
expect(certificate).to(be_a(OpenSSL::X509::Certificate))
|
79
|
+
expect(key).to(be_a(OpenSSL::PKey::RSA))
|
80
|
+
end
|
81
|
+
end
|
74
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flores
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Sissel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Add fuzzing, randomization, and stress to your tests.
|