Skip to content

Commit

Permalink
Merge pull request #8 from sylvek/feature/share-password-with-anonymo…
Browse files Browse the repository at this point in the history
…us-support

share a secret with someone
  • Loading branch information
sylvek authored Dec 7, 2019
2 parents 99fc614 + a8b3fe3 commit f392f2b
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 91 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ $> leeloo keystore
|private|/Users/sylvek/.leeloo/private |* |
+-------+------------------------------+-------+
$> leeloo keystore add test ~/Desktop/test
# will add test's keystore
$> leeloo keystore add test ~/test
# will add test keystore
+-------+------------------------------+-------+
|Name |Path |Default|
+-------+------------------------------+-------+
|private|/Users/sylvek/.leeloo/private |* |
|test |/Users/sylvek/Desktop/test | |
|test |/Users/sylvek/test | |
+-------+------------------------------+-------+
$> leeloo keystore default test
Expand All @@ -66,7 +66,7 @@ $> leeloo keystore default test
|Name |Path |Default|
+-------+------------------------------+-------+
|private|/Users/sylvek/.leeloo/private | |
|test |/Users/sylvek/Desktop/test |* |
|test |/Users/sylvek/test |* |
+-------+------------------------------+-------+
$> leeloo write my_secret
Expand All @@ -89,13 +89,22 @@ $> leeloo sync
$> leeloo translate < file.in > file.out
# will replace ${my_secret} by the current secret and will return file translated
$> leeloo share my_secret
# will generate an url with an access token allowing to retrieve the secret
$> leeloo token my_secret
# will generate an access token for accessing my_secret
$> leeloo server
# will launch a server instance allowing to retrieve a secret by a given access token
```

## How to share a keystore ?

Each action is commited on Git. To share your keystore, [create a remote repository and share it](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes).
Each action is commited in Git. To share your keystore, [create a remote repository and share it](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes).

By default, a new created keystore comes with all registered public keys on your system. So each owner should read your "shared" secret. To manage this list, you could remove or add new public GPG keys. It allows to share secret with someone who don't know you yet.
By default, a new created keystore comes with *all registered public keys on your system*. So each owner should read your "shared" secret. To manage this list, you could remove or add new public GPG keys _(by adding/removing it in the keys folder by yourself for now)_. It allows to share secret with someone who don't know you yet.


## ZSH completion support !
Expand Down
2 changes: 2 additions & 0 deletions leeloo/lib/leeloo.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'leeloo/version'
require 'leeloo/controller'
require 'leeloo/command'
require 'leeloo/preferences'
require 'leeloo/keystore'
require 'leeloo/secret'
require 'leeloo/output'
require 'leeloo/server'

module Leeloo
def self.start
Expand Down
144 changes: 76 additions & 68 deletions leeloo/lib/leeloo/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,9 @@ def truncate(max)

module Leeloo

class OutputFactory
def self.create options
output = nil
if options.ascii
output = Ascii.new
else
output = Terminal.new
end
if options.clipboard
ClipboardOutputDecorator.new output
else
output
end
end
end

class Command
include Commander::Methods

def initialize
@preferences = PrivateLocalFileSystemPreferences.new.load
end

def run
program :name, 'leeloo'
program :version, Leeloo::VERSION
Expand All @@ -52,8 +32,7 @@ def run
c.option '--keystore STRING', String, 'a selected keystore'

c.action do |args, options|
keystore = @preferences.keystore(options.keystore)
OutputFactory.create(options).render_secrets keystore.secrets
SecretsController.new(options).display
end
end

Expand All @@ -66,10 +45,9 @@ def run
c.action do |args, options|
abort "name is missing" unless args.length == 1
name = args.first

keystore = @preferences.keystore(options.keystore)
secrets = keystore.secrets.select { |secret| secret.name.downcase.include? name.downcase } || []
OutputFactory.create(options).render_secrets secrets
ctl = SecretsController.new(options)
ctl.search(name)
ctl.display
end
end

Expand All @@ -79,18 +57,20 @@ def run
c.option '--ascii', nil, 'display secrets without unicode tree'

c.action do |args, options|
OutputFactory.create(options).render_preferences @preferences
KeystoreController.new(options).display
end
end

command "keystore remove" do |c|
c.syntax = 'leeloo keystore remove <name>'
c.description = "remove a keystore (path/to/keystore is not destroyed)"

c.action do |args, options|
c.action do |args, options|args
abort "name is missing" unless args.length == 1
@preferences.remove_keystore args.first
OutputFactory.create(options).render_preferences @preferences
name = args.first
ctl = KeystoreController.new(options)
ctl.remove(name)
ctl.display
end
end

Expand All @@ -100,10 +80,11 @@ def run

c.action do |args, options|
abort "name or path is missing" unless args.length == 2

@preferences.add_keystore({"name" => args.first, "path" => args.last, "cypher" => "gpg", "vc" => "git"})
@preferences.keystore(args.first).init
OutputFactory.create(options).render_preferences @preferences
name = args.first
path = args.last
ctl = KeystoreController.new(options)
ctl.add(name, path)
ctl.display
end
end

Expand All @@ -113,9 +94,10 @@ def run

c.action do |args, options|
abort "name is missing" unless args.length == 1

@preferences.set_default_keystore args.first
OutputFactory.create(options).render_preferences @preferences
name = args.first
ctl = KeystoreController.new(options)
ctl.set_default(name)
ctl.display
end
end

Expand All @@ -129,10 +111,9 @@ def run
c.action do |args, options|
abort "name is missing" unless args.length == 1
name = args.first

keystore = @preferences.keystore(options.keystore)
secret = keystore.secret_from_name(name)
OutputFactory.create(options).render_secret secret
ctl = SecretController.new(options)
ctl.read(name)
ctl.display
end
end

Expand All @@ -147,22 +128,9 @@ def run
c.action do |args, options|
abort "name is missing" unless args.length == 1
name = args.first
phrase = nil

phrase = STDIN.read if options.stdin
phrase = SecureRandom.base64(32).truncate(options.generate.to_i) if options.generate

unless phrase
phrase = password "secret"
confirm = password "confirm it"
abort "not the same secret" unless phrase == confirm
end

keystore = @preferences.keystore(options.keystore)
secret = keystore.secret_from_name(name)
secret.write(phrase)

OutputFactory.create(options).render_secret secret
ctl = SecretController.new(options)
ctl.write(name)
ctl.display
end
end

Expand All @@ -172,9 +140,9 @@ def run
c.option '--keystore STRING', String, 'a selected keystore'

c.action do |args, options|
keystore = @preferences.keystore(options.keystore)
text = STDIN.read
OutputFactory.create(options).render_translate keystore, text
ctl = TranslateController.new(options)
ctl.translate
ctl.display
end
end

Expand All @@ -186,10 +154,9 @@ def run
c.action do |args, options|
abort "name is missing" unless args.length == 1
name = args.first

keystore = @preferences.keystore(options.keystore)
secret = keystore.secret_from_name(name)
secret.erase
ctl = SecretController.new(options)
ctl.remove(name)
ctl.display
end
end

Expand All @@ -199,8 +166,9 @@ def run
c.option '--keystore STRING', String, 'a selected keystore'

c.action do |args, options|
keystore = @preferences.keystore(options.keystore)
keystore.sync
ctl = KeystoreController.new(options)
ctl.sync
ctl.display
end
end

Expand All @@ -210,8 +178,48 @@ def run
c.option '--keystore STRING', String, 'a selected keystore'

c.action do |args, options|
keystore = @preferences.keystore(options.keystore)
keystore.init
ctl = KeystoreController.new(options)
ctl.init
ctl.display
end
end

command :share do |c|
c.syntax = 'leeloo share <name>'
c.description = "share a secret with someone"
c.option '--keystore STRING', String, 'a selected keystore'

c.action do |args, options|
abort "name is missing" unless args.length == 1
name = args.first
ctl = ShareController.new(options)
ctl.token(name)
ctl.display
ctl.start_server
end
end

command :token do |c|
c.syntax = 'leeloo token <name>'
c.description = "generate an access token for a given secret"
c.option '--keystore STRING', String, 'a selected keystore'

c.action do |args, options|
abort "name is missing" unless args.length == 1
name = args.first
ctl = ShareController.new(options)
ctl.token(name)
ctl.display
end
end

command :server do |c|
c.syntax = 'leeloo server'
c.description = "start a server access token"

c.action do |args, options|
ctl = ShareController.new(options)
ctl.start_server
end
end

Expand Down
Loading

0 comments on commit f392f2b

Please sign in to comment.