flores 0.0.5 → 0.0.6

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: 753a3d8f3f074aa4abec9b5a50782da024e4c7d9
4
- data.tar.gz: b0680aa3d4ff01572d386edf6d3909c851a5df3b
3
+ metadata.gz: 2e913b4627dc9ac067842992242889c14e47d760
4
+ data.tar.gz: 4102c950d2497218313c0126a77c853800fc6c65
5
5
  SHA512:
6
- metadata.gz: 038c0c32048a720f228e0acd243d9ca9ca71d92e8b81ed4a80d70634b6788d34ca7325e926db02422d7dfbce3ebd4b1c46ffc521d139467d69b1f789f0d0a28e
7
- data.tar.gz: 61a9bbc371ff597856663a6e35f31f7b8c5d6e0547b9b1d584d4d59e7ec9d46f9185d062ac868ed9fbe9f2c05ddca13d36efa2be09942ac6cca30fe26da261b0
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"
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
- # Generate a random serial number for a certificate.
25
- def self.random_serial
26
- # RFC5280 (X509) says:
27
- # > 4.1.2.2. Serial Number
28
- # > Certificate users MUST be able to handle serialNumber values up to 20 octets
29
- Flores::Random.integer(1..9).to_s + Flores::Random.iterations(0..19).collect { Flores::Random.integer(0..9) }.join
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.
@@ -64,11 +64,19 @@ describe Flores::PKI::CertificateSigningRequest do
64
64
  end
65
65
 
66
66
  describe Flores::PKI do
67
- context "#random_serial" do
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.5
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-29 00:00:00.000000000 Z
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.