fling 0.0.4 → 0.0.5
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/.rubocop.yml +3 -0
- data/CHANGES.md +4 -0
- data/lib/fling/cli.rb +1 -1
- data/lib/fling/config.rb +12 -4
- data/lib/fling/version.rb +1 -1
- data/spec/fling/config_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 671be432ce1ac827abe07d0d965bd73edc7d7cad
|
4
|
+
data.tar.gz: 4b3d2acc5db6e37afac2e4035351ae038fdca986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c6d2ecdca3f68d3706e19a8fb9ef0519f27ce412bc1e11b6975f5bb043f240ad58a73eeecca0629f136d21be82f277bc6989e32e560a2f7a4d44b2d65fafea8
|
7
|
+
data.tar.gz: 5500c71c4744eebd5bfa02e531dd9f0f916c8f58f8c519e573a7280587c8e708c9d8f13d78bf4f069bd6b897651ff9744f76dd6b1a380bebeaaa611be9c10865
|
data/.rubocop.yml
CHANGED
data/CHANGES.md
CHANGED
data/lib/fling/cli.rb
CHANGED
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.
|
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
|
-
|
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
data/spec/fling/config_spec.rb
CHANGED
@@ -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
|