Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement blackbox in Golang #250

Merged
merged 76 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
ff792cf
vendor github.com/pkg/errors vendor/github.com/urfave/cli
tlimoncelli Apr 21, 2018
57702a1
New command: blackbox: Parses subcommands and calls bash scripts.
tlimoncelli Apr 21, 2018
3a5e4b6
Implement status and nlist commands
tlimoncelli Apr 22, 2018
5681903
Add "blackbox admin nlist" command.
tlimoncelli Apr 22, 2018
d393d7e
First draft of ndecrypt
tlimoncelli Apr 22, 2018
a6b9c17
Merge branch 'master' into golang
tlimoncelli Jul 3, 2018
3cc7e46
Partial commit
tlimoncelli Sep 10, 2018
e1e6dee
Merge branch 'master' into golang
tlimoncelli Sep 10, 2018
b62ec37
Merge branch 'master' into golang
tlimoncelli Dec 4, 2018
5671b71
Merge branch 'master' into golang
tlimoncelli Dec 9, 2018
ffde3ae
Restructure
tlimoncelli Dec 9, 2018
a5cd829
wip!
tlimoncelli Dec 18, 2018
a47f038
Merge branch 'master' into golang
tlimoncelli Mar 3, 2019
36e1774
Merge branch 'master' into golang
Apr 19, 2020
1fb5701
NEW: DESIGN.md
Apr 19, 2020
b3e052b
Merge branch 'master' into golang
tlimoncelli Jun 6, 2020
c9bd587
tmp
tlimoncelli Jun 6, 2020
a630c6b
flags.go and parse.go complete
tlimoncelli Jun 6, 2020
0bdffb3
Draft
tlimoncelli Jun 6, 2020
a6ec716
Box discovers admins and files.
tlimoncelli Jun 6, 2020
50fa2e5
Snapshot
tlimoncelli Jun 7, 2020
d7bdd49
Fixed the signature mismatch problem!!!
tlimoncelli Jun 7, 2020
ac8105c
linting
tlimoncelli Jun 7, 2020
4979113
Implement Discover()
tlimoncelli Jun 7, 2020
bc5dab7
Implement: files list
tlimoncelli Jun 7, 2020
2425c0f
"blackbox status" works.
tlimoncelli Jun 7, 2020
bf1f1e2
Unvendor
tlimoncelli Jun 7, 2020
148aa3d
Unvendor
tlimoncelli Jun 7, 2020
6c260d1
Cleanup
tlimoncelli Jun 7, 2020
126f60f
cleanup
tlimoncelli Jun 7, 2020
edad8a8
snapshot
tlimoncelli Jun 7, 2020
66eeea2
snapshot!
tlimoncelli Jun 7, 2020
9998758
Rename pkgs
tlimoncelli Jun 7, 2020
8c329b1
linting
tlimoncelli Jun 7, 2020
56665df
Implement decrypt --askagent and --umask
tlimoncelli Jun 8, 2020
f860c73
Random fixes
tlimoncelli Jun 8, 2020
b3aa045
snapshot
tlimoncelli Jun 8, 2020
df2bb78
integration test framework works
tlimoncelli Jun 9, 2020
164376f
Integration tests work all the way through "init".
tlimoncelli Jun 10, 2020
2c8400c
init completed
tlimoncelli Jun 11, 2020
b544a02
Mostly working
tlimoncelli Jun 12, 2020
e831a5a
logging works
tlimoncelli Jun 12, 2020
0a0068d
fix logging
tlimoncelli Jun 12, 2020
a189a4a
wip!
tlimoncelli Jun 14, 2020
e0e61f5
wip!
tlimoncelli Jun 15, 2020
7276fae
Now working: init, admin add, file add, encrypt, decrypt, shred
tlimoncelli Jun 15, 2020
b17a11a
Cat works!
tlimoncelli Jun 16, 2020
a47bc5d
cat and other commands now work. shell commands replaced
tlimoncelli Jun 16, 2020
fa2a643
create binv2
tlimoncelli Jun 19, 2020
0518006
integration tests working
tlimoncelli Jun 19, 2020
b963da0
Now works on CentOS 7
TomOnTime Jun 19, 2020
b3e9e52
aRough out Docs
tlimoncelli Jun 23, 2020
eccea8d
fix comment
tlimoncelli Jul 2, 2020
ac66afd
linting
tlimoncelli Jul 2, 2020
bea3af3
Refactor how NeedsCommit is done
tlimoncelli Jul 2, 2020
4f79084
add missing files
tlimoncelli Jul 3, 2020
56ecdc8
git commit messages are more pretty
tlimoncelli Jul 3, 2020
433b357
cleanup
tlimoncelli Jul 3, 2020
c0d1883
Fixing commits
tlimoncelli Jul 3, 2020
0eb9fd1
bx.* dirs are now relative
tlimoncelli Jul 4, 2020
afcec7d
linting
tlimoncelli Jul 4, 2020
6b8deb4
Clean up redact
tlimoncelli Jul 4, 2020
7ab79e0
Fix bug: filenames with spaces dont work
tlimoncelli Jul 4, 2020
6ff8d0d
macos doesn't need gpg-agent
tlimoncelli Jul 4, 2020
68a17b5
Fix umask display. All --all commands now work from any directory
tlimoncelli Jul 5, 2020
fdb2559
Fix --debug. Fix --group
tlimoncelli Jul 5, 2020
fa53022
Fix links
tlimoncelli Jul 5, 2020
b3b54fa
Refactor makesafe
tlimoncelli Jul 5, 2020
259ba65
cleanig up code
tlimoncelli Jul 6, 2020
b6d4fee
linting
tlimoncelli Jul 6, 2020
f886ea5
mDocs
tlimoncelli Jul 14, 2020
ccc2439
fix reencrypt commit messages
tlimoncelli Jul 17, 2020
92e791a
Fix
tlimoncelli Jul 18, 2020
9e088db
Rewrite shred detector
tlimoncelli Jul 18, 2020
4c47af8
do some integration tests from a funny subdir
tlimoncelli Jul 18, 2020
053b8a6
Rewrite shred detector
tlimoncelli Jul 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
snapshot!
  • Loading branch information
tlimoncelli committed Jun 7, 2020
commit 66eeea284096dc4235edba1f6a13b1e22cde3605
5 changes: 5 additions & 0 deletions crypters/_all/all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package all

import (
_ "github.com/StackExchange/blackbox/crypters/gnupg"
)
39 changes: 39 additions & 0 deletions crypters/crypters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package crypters

import (
"sort"

"github.com/StackExchange/blackbox/models"
)

// Crypter is the handle
type Crypter interface {
models.Crypter
}

// NewFnSig function signature needed by reg.
type NewFnSig func() (Crypter, error)

// Item stores one item
type Item struct {
Name string
New NewFnSig
Priority int
}

// Catalog is the list of registered vcs's.
var Catalog []*Item

// Register a new VCS.
func Register(name string, priority int, newfn NewFnSig) {
//fmt.Printf("CRYPTER registered: %v\n", name)
item := &Item{
Name: name,
New: newfn,
Priority: priority,
}
Catalog = append(Catalog, item)

// Keep the list sorted.
sort.Slice(Catalog, func(i, j int) bool { return Catalog[j].Priority < Catalog[i].Priority })
}
25 changes: 25 additions & 0 deletions crypters/gnupg/gnupg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gnupg

import (
"fmt"

"github.com/StackExchange/blackbox/crypters"
)

func init() {
crypters.Register("GnuPG", 100, registerNew)
}

// CrypterHandle is the handle
type CrypterHandle struct {
}

func registerNew() (crypters.Crypter, error) {
return &CrypterHandle{}, nil
}

// Decrypt decrypts a file, possibly overwriting the plaintext.
func (crypt CrypterHandle) Decrypt(name string, overwrite bool) error {
fmt.Printf("WOULD decrypt %v (overwrite=%v)\n", name, overwrite)
return nil
}
7 changes: 7 additions & 0 deletions models/crypters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models

// CryptoSystem is gpg binaries, go-opengpg, etc.
type Crypter interface {
// Decrypt name+".gpg", possibly overwriting name.
Decrypt(filename string, overwrite bool) error
}
116 changes: 116 additions & 0 deletions pkg/box/boxutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package box

import (
"fmt"
"os"
"os/user"
"strconv"
)

// FileStatus returns the status of a file.
func FileStatus(name string) (string, error) {
/*
DECRYPTED: File is decrypted and ready to edit (unknown if it has been edited).
ENCRYPTED: GPG file is newer than plaintext. Indicates recented edited then encrypted.
SHREDDED: Plaintext is missing.
GPGMISSING: The .gpg file is missing. Oops?
PLAINERROR: Can't access the plaintext file to determine status.
GPGERROR: Can't access .gpg file to determine status.
*/

p := name
e := p + ".gpg"
ps, perr := os.Stat(p)
es, eerr := os.Stat(e)
if perr == nil && eerr == nil {
if ps.ModTime().Before(es.ModTime()) {
return "ENCRYPTED", nil
}
return "DECRYPTED", nil
}

if eerr != nil {
if os.IsNotExist(eerr) {
return "GPGMISSING", nil
}
return "GPGERROR", eerr
}

if perr != nil {
if os.IsNotExist(perr) {
return "SHREDDED", nil
}
}
return "PLAINERROR", perr
}

// func isChanged(pname string) (bool, error) {
// // if .gpg exists but not plainfile: unchanged
// // if plaintext exists but not .gpg: changed
// // if plainfile < .gpg: unchanged
// // if plainfile > .gpg: don't know, need to try diff

// // Gather info about the files:

// pstat, perr := os.Stat(pname)
// if perr != nil && (!os.IsNotExist(perr)) {
// return false, fmt.Errorf("isChanged(%q) returned error: %w", pname, perr)
// }
// gname := pname + ".gpg"
// gstat, gerr := os.Stat(gname)
// if gerr != nil && (!os.IsNotExist(perr)) {
// return false, fmt.Errorf("isChanged(%q) returned error: %w", gname, gerr)
// }

// pexists := perr == nil
// gexists := gerr == nil

// // Use the above rules:

// // if .gpg exists but not plainfile: unchanged
// if gexists && !pexists {
// return false, nil
// }

// // if plaintext exists but not .gpg: changed
// if pexists && !gexists {
// return true, nil
// }

// // At this point we can conclude that both p and g exist.
// // Can't hurt to test that assertion.
// if (!pexists) && (!gexists) {
// return false, fmt.Errorf("Assertion failed. p and g should exist: pn=%q", pname)
// }

// pmodtime := pstat.ModTime()
// gmodtime := gstat.ModTime()
// // if plainfile < .gpg: unchanged
// if pmodtime.Before(gmodtime) {
// return false, nil
// }
// // if plainfile > .gpg: don't know, need to try diff
// return false, fmt.Errorf("Can not know for sure. Try git diff?")
// }

func parseGroup(userinput string) (int, error) {
if userinput == "" {
return -1, fmt.Errorf("group spec is empty string")
}

// If it is a valid number, use it.
i, err := strconv.Atoi(userinput)
if err == nil {
return i, nil
}

// If not a number, look it up by name.
g, err := user.LookupGroup(userinput)
if err != nil {
i, err = strconv.Atoi(g.Gid)
return i, nil
}

// Give up.
return -1, err
}