fling 0.0.4 → 0.0.5

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: e0c35e2e75fc50c7e36b7f39db74ba04321ce966
4
- data.tar.gz: 660ff1f26c8262383c2706e84f06d6e23ce858e6
3
+ metadata.gz: 671be432ce1ac827abe07d0d965bd73edc7d7cad
4
+ data.tar.gz: 4b3d2acc5db6e37afac2e4035351ae038fdca986
5
5
  SHA512:
6
- metadata.gz: a85101e0c8b75968d81bbe66e5155ea509a5181f941d448fc38504bb3404e7f4cce1cd6bd029f793e1ccc46333a70288b3a95c5ff6faafed6e8f566c12deba94
7
- data.tar.gz: cdd34537276aa1a3f4ae03a81ae4f0a051cc81a390e79d6fda0ebe583dcc922196fcb6f1b633d2beec75a5e0f69dc43ee00dddc0f7440fa4d48fa4193ae006b2
6
+ metadata.gz: 6c6d2ecdca3f68d3706e19a8fb9ef0519f27ce412bc1e11b6975f5bb043f240ad58a73eeecca0629f136d21be82f277bc6989e32e560a2f7a4d44b2d65fafea8
7
+ data.tar.gz: 5500c71c4744eebd5bfa02e531dd9f0f916c8f58f8c519e573a7280587c8e708c9d8f13d78bf4f069bd6b897651ff9744f76dd6b1a380bebeaaa611be9c10865
data/.rubocop.yml CHANGED
@@ -7,6 +7,9 @@ Style/StringLiterals:
7
7
  Style/AlignParameters:
8
8
  Enabled: false
9
9
 
10
+ Style/MultilineOperationIndentation:
11
+ Enabled: false
12
+
10
13
  Metrics/MethodLength:
11
14
  CountComments: false
12
15
  Max: 20
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.0.5 (2015-06-13)
2
+ ------------------
3
+ * Fling::Config.decrypt
4
+
1
5
  0.0.4 (2015-06-13)
2
6
  ------------------
3
7
  * Initial 'fling provision' support
data/lib/fling/cli.rb CHANGED
@@ -20,7 +20,7 @@ module Fling
20
20
 
21
21
  say "\nGenerating encrypted config, please wait..."
22
22
 
23
- config = Config.generate_encrypted(
23
+ config = Config.encrypt(
24
24
  password,
25
25
  "introducer" => introducer,
26
26
  "dropcap" => dropcap,
data/lib/fling/config.rb CHANGED
@@ -6,6 +6,9 @@ require "rbnacl"
6
6
  module Fling
7
7
  # Configuration for the local Tahoe cluster
8
8
  class Config
9
+ BEGIN_MARKER = "-----BEGIN ENCRYPTED FLING CONFIGURATION-----\n"
10
+ END_MARKER = "------END ENCRYPTED FLING CONFIGURATION------\n"
11
+
9
12
  CONFIG_KEYS = %w(introducer convergence salt dropcap)
10
13
  attr_reader(*CONFIG_KEYS)
11
14
 
@@ -20,12 +23,17 @@ module Fling
20
23
  end
21
24
 
22
25
  # Generate an encrypted configuration
23
- def self.generate_encrypted(password, config)
26
+ def self.encrypt(password, config)
24
27
  ciphertext = Box.encrypt(password, generate_json(config))
28
+ BEGIN_MARKER + Base64.encode64(ciphertext) + END_MARKER
29
+ end
30
+
31
+ # Decrypt an encrypted configuration
32
+ def self.decrypt(password, ciphertext)
33
+ matches = ciphertext.match(/#{BEGIN_MARKER}(.*)#{END_MARKER}/m)
34
+ fail ConfigError, "couldn't find fling configuration" unless matches
25
35
 
26
- "-----BEGIN ENCRYPTED FLING CONFIGURATION-----\n" +
27
- Base64.encode64(ciphertext) +
28
- "------END ENCRYPTED FLING CONFIGURATION------\n"
36
+ new(Box.decrypt(password, Base64.decode64(matches[1])))
29
37
  end
30
38
 
31
39
  # Generate a JSON configuration
data/lib/fling/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Simple secret sharing over Tahoe-LAFS
2
2
  module Fling
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
@@ -5,6 +5,7 @@ RSpec.describe Fling::Config do
5
5
  let(:convergence) { "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }
6
6
  let(:salt) { "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }
7
7
  let(:dropcap) { "URI:DIR2:#{'x' * 26}:#{'x' * 52}" }
8
+ let(:password) { "squeamish ossifrage" }
8
9
 
9
10
  it "parses JSON" do
10
11
  config = described_class.from_json fixture("fling.json")
@@ -19,6 +20,18 @@ RSpec.describe Fling::Config do
19
20
  expect { described_class.new("bogus" => "true") }.to raise_error(ArgumentError)
20
21
  end
21
22
 
23
+ it "encrypts and decrypts configurations" do
24
+ json = JSON.parse(fixture("fling.json"))
25
+
26
+ ciphertext = described_class.encrypt(password, json)
27
+ config = described_class.decrypt(password, ciphertext)
28
+
29
+ expect(config.introducer).to eq introducer
30
+ expect(config.convergence).to eq convergence
31
+ expect(config.salt).to eq salt
32
+ expect(config.dropcap).to eq dropcap
33
+ end
34
+
22
35
  context "ConfigError" do
23
36
  let(:config_json) { JSON.parse(fixture("fling.json")) }
24
37
  it "raises for malformed introducer URL" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri