diff --git a/Makefile b/Makefile deleted file mode 100644 index e0e3d3b..0000000 --- a/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -NAME := redoctober -VERSION := 0.1 -ITERATION := $(shell date +%s) -REVISION := $(shell git log -n1 --pretty=format:%h) - -export GOPATH := $(PWD) - -BUILD_DEPS := go mercurial - -.PHONY: external -external: - @go get code.google.com/p/go.crypto/scrypt - -.PHONY: all -all: external $(NAME) - -.PHONY: test -test: - @go test $(NAME)/... - -.PHONY: print-builddeps -print-builddeps: - @echo $(BUILD_DEPS) - -.PHONY: $(NAME) -$(NAME): bin/$(NAME) - -SRC := $(shell find src/$(NAME) -type f) -bin/$(NAME): $(SRC) - @go fmt $(NAME) - @go install -tags "$(TAGS)" -ldflags "$(LDFLAGS)" $(NAME) - -BUILD_PATH := build -INSTALL_PREFIX := usr/local -REDOCTOBER_BUILD_PATH := $(BUILD_PATH)/$(INSTALL_PREFIX)/$(NAME) - -FPM := fakeroot fpm -C $(BUILD_PATH) \ - -s dir \ - -t deb \ - --deb-compression bzip2 \ - -v $(VERSION) \ - --iteration $(ITERATION) - -DEB_PACKAGE := $(NAME)_$(VERSION)-$(ITERATION)_amd64.deb -$(DEB_PACKAGE): TAGS := release -$(DEB_PACKAGE): LDFLAGS := -X main.version $(VERSION) -X main.revision $(REVISION) -$(DEB_PACKAGE): clean all - mkdir -p $(REDOCTOBER_BUILD_PATH) - cp bin/$(NAME) $(REDOCTOBER_BUILD_PATH) - $(FPM) -n $(NAME) . - -register-%.deb: ; $(PACKAGE_REGISTER_BIN) $*.deb - -.PHONY: cf-package -cf-package: $(DEB_PACKAGE) - -.PHONY: clean-package -clean-package: - $(RM) -r $(BUILD_PATH) - $(RM) $(DEB_PACKAGE) - -.PHONY: clean -clean: clean-package - @go clean -i $(NAME)/... - @$(RM) -r pkg - -print-%: ; @echo $*=$($*) diff --git a/src/redoctober/core/core.go b/core/core.go similarity index 95% rename from src/redoctober/core/core.go rename to core/core.go index 0c09034..caa8df2 100644 --- a/src/redoctober/core/core.go +++ b/core/core.go @@ -8,10 +8,10 @@ import ( "encoding/json" "errors" "fmt" + "github.com/cloudflare/redoctober/cryptor" + "github.com/cloudflare/redoctober/keycache" + "github.com/cloudflare/redoctober/passvault" "log" - "redoctober/cryptor" - "redoctober/keycache" - "redoctober/passvault" ) // Each of these structures corresponds to the JSON expected on the @@ -33,8 +33,8 @@ type delegate struct { Name string Password string - Uses int - Time string + Uses int + Time string } type password struct { @@ -48,16 +48,16 @@ type encrypt struct { Name string Password string - Minimum int - Owners []string - Data []byte + Minimum int + Owners []string + Data []byte } type decrypt struct { Name string Password string - Data []byte + Data []byte } type modify struct { @@ -94,7 +94,7 @@ func jsonStatusError(err error) ([]byte, error) { return json.Marshal(status{Status: err.Error()}) } func jsonSummary() ([]byte, error) { - return json.Marshal(summaryData{Status: "ok",Live: keycache.GetSummary(), All: passvault.GetSummary()}) + return json.Marshal(summaryData{Status: "ok", Live: keycache.GetSummary(), All: passvault.GetSummary()}) } func jsonResponse(resp []byte) ([]byte, error) { return json.Marshal(responseData{Status: "ok", Response: resp}) @@ -139,7 +139,7 @@ func Create(jsonIn []byte) ([]byte, error) { if passvault.NumRecords() != 0 { return jsonStatusError(errors.New("Vault is already created")) } - + if _, err := passvault.AddNewRecord(s.Name, s.Password, true); err != nil { log.Printf("Error adding record for %s: %s\n", s.Name, err) return jsonStatusError(err) diff --git a/src/redoctober/core/core_test.go b/core/core_test.go similarity index 99% rename from src/redoctober/core/core_test.go rename to core/core_test.go index f883822..a86a98d 100644 --- a/src/redoctober/core/core_test.go +++ b/core/core_test.go @@ -5,12 +5,12 @@ package core import ( - "encoding/json" - "testing" "bytes" + "encoding/json" "os" - "redoctober/passvault" - "redoctober/keycache" + "github.com/cloudflare/redoctober/keycache" + "github.com/cloudflare/redoctober/passvault" + "testing" ) func TestCreate(t *testing.T) { @@ -378,7 +378,7 @@ func TestEncryptDecrypt(t *testing.T) { } // decrypt file - decryptJson, err := json.Marshal(decrypt{Name:"Alice", Password:"Hello", Data:s.Response}) + decryptJson, err := json.Marshal(decrypt{Name: "Alice", Password: "Hello", Data: s.Response}) if err != nil { t.Fatalf("Error in marshalling decryption,", err) } @@ -668,7 +668,6 @@ func TestStatic(t *testing.T) { Init("/tmp/db1.json") - // check for summary of initialized vault with new member var s responseData respJson, err := Delegate(delegateJson2) @@ -709,7 +708,7 @@ func TestStatic(t *testing.T) { } if bytes.Compare(expected, r.Response) != 0 { - t.Fatalf("Error in summary, ", expected, r.Response ) + t.Fatalf("Error in summary, ", expected, r.Response) } keycache.FlushCache() diff --git a/src/redoctober/cryptor/cryptor.go b/cryptor/cryptor.go similarity index 98% rename from src/redoctober/cryptor/cryptor.go rename to cryptor/cryptor.go index 00f327d..3a5558e 100644 --- a/src/redoctober/cryptor/cryptor.go +++ b/cryptor/cryptor.go @@ -12,12 +12,12 @@ import ( "crypto/rand" "crypto/sha1" "encoding/json" - "strconv" - "sort" "errors" - "redoctober/keycache" - "redoctober/padding" - "redoctober/passvault" + "github.com/cloudflare/redoctober/keycache" + "github.com/cloudflare/redoctober/padding" + "github.com/cloudflare/redoctober/passvault" + "sort" + "strconv" ) const ( @@ -187,7 +187,7 @@ func (s *mwkSorter) Less(i, j int) bool { // swkSorter joins a slice of names with SingleWrappedKeys to be sorted. type pair struct { name string - key []byte + key []byte } type swkSorter []pair @@ -207,7 +207,6 @@ func (s swkSorter) Less(i, j int) bool { return s[i].name < s[j].name } - // computeHmac computes the signature of the encrypted data structure // the signature takes into account every element of the EncryptedData // structure, with all keys sorted alphabetically by name @@ -240,7 +239,7 @@ func computeHmac(key []byte, encrypted EncryptedData) []byte { } // hash the single-wrapped keys - for index, _ := range swks { + for index := range swks { mac.Write([]byte(swks[index].name)) mac.Write(swks[index].key) } @@ -404,4 +403,3 @@ func Decrypt(in []byte) (resp []byte, err error) { return padding.RemovePadding(clearData) } - diff --git a/src/redoctober/cryptor/cryptor_test.go b/cryptor/cryptor_test.go similarity index 89% rename from src/redoctober/cryptor/cryptor_test.go rename to cryptor/cryptor_test.go index 4184e00..60578a3 100644 --- a/src/redoctober/cryptor/cryptor_test.go +++ b/cryptor/cryptor_test.go @@ -5,9 +5,9 @@ package cryptor import ( + "bytes" "encoding/base64" "encoding/json" - "bytes" "testing" ) @@ -16,16 +16,16 @@ func TestHash(t *testing.T) { var encrypted EncryptedData if err := json.Unmarshal(decryptJson, &encrypted); err != nil { - t.Fatalf("Error unmarshalling json,", err) + t.Fatalf("Error unmarshalling json,", err) } - + var hmacKey, _ = base64.StdEncoding.DecodeString("Qugc5ZQ0vC7KQSgmDHTVgQ==") var signature = append([]byte{}, encrypted.Signature...) expectedSig := computeHmac(hmacKey, encrypted) if diff := bytes.Compare(signature, expectedSig); diff != 0 { - t.Fatalf("Error comparing signature", base64.StdEncoding.EncodeToString(expectedSig)) + t.Fatalf("Error comparing signature", base64.StdEncoding.EncodeToString(expectedSig)) } // change version and check hmac @@ -33,7 +33,7 @@ func TestHash(t *testing.T) { unexpectedSig := computeHmac(hmacKey, encrypted) if diff := bytes.Compare(signature, unexpectedSig); diff == 0 { - t.Fatalf("Error comparing signature") + t.Fatalf("Error comparing signature") } encrypted.Version = 1 @@ -42,7 +42,7 @@ func TestHash(t *testing.T) { unexpectedSig = computeHmac(hmacKey, encrypted) if diff := bytes.Compare(signature, unexpectedSig); diff != 0 { - t.Fatalf("Error comparing signature", base64.StdEncoding.EncodeToString(expectedSig)) + t.Fatalf("Error comparing signature", base64.StdEncoding.EncodeToString(expectedSig)) } // delete RSA key and check hmac @@ -51,7 +51,7 @@ func TestHash(t *testing.T) { unexpectedSig = computeHmac(hmacKey, encrypted) if diff := bytes.Compare(signature, unexpectedSig); diff == 0 { - t.Fatalf("Error comparing signature") + t.Fatalf("Error comparing signature") } } diff --git a/src/redoctober/keycache/keycache.go b/keycache/keycache.go similarity index 98% rename from src/redoctober/keycache/keycache.go rename to keycache/keycache.go index a23dec3..39c842a 100644 --- a/src/redoctober/keycache/keycache.go +++ b/keycache/keycache.go @@ -11,8 +11,8 @@ import ( "crypto/rsa" "crypto/sha1" "errors" + "github.com/cloudflare/redoctober/passvault" "log" - "redoctober/passvault" "time" ) @@ -58,7 +58,7 @@ func GetSummary() map[string]ActiveUser { // FlushCache removes all delegated keys. func FlushCache() { - for name, _ := range UserKeys { + for name := range UserKeys { delete(UserKeys, name) } } diff --git a/src/redoctober/keycache/keycache_test.go b/keycache/keycache_test.go similarity index 96% rename from src/redoctober/keycache/keycache_test.go rename to keycache/keycache_test.go index 3d978f2..1e331d7 100644 --- a/src/redoctober/keycache/keycache_test.go +++ b/keycache/keycache_test.go @@ -4,7 +4,7 @@ package keycache import ( - "redoctober/passvault" + "github.com/cloudflare/redoctober/passvault" "testing" "time" ) diff --git a/src/redoctober/padding/padding.go b/padding/padding.go similarity index 99% rename from src/redoctober/padding/padding.go rename to padding/padding.go index bcbc6a3..65a65c0 100644 --- a/src/redoctober/padding/padding.go +++ b/padding/padding.go @@ -22,7 +22,7 @@ import "errors" // 3. Data to be padded has a length with remainder 2 when divided by // 16. 14 bytes will be added. The first 13 will be 0x00 and then final // byte will be 0x0e. -// +// // Removing padding is trivial: the number of bytes specified by the // final byte are removed. diff --git a/src/redoctober/padding/padding_test.go b/padding/padding_test.go similarity index 99% rename from src/redoctober/padding/padding_test.go rename to padding/padding_test.go index ee39209..5bd2651 100644 --- a/src/redoctober/padding/padding_test.go +++ b/padding/padding_test.go @@ -70,4 +70,3 @@ func TestDetectBadPadding(t *testing.T) { assert(t, err != nil) assert(t, d == nil) } - diff --git a/src/redoctober/passvault/passvault.go b/passvault/passvault.go similarity index 99% rename from src/redoctober/passvault/passvault.go rename to passvault/passvault.go index f88b8fa..18e33b1 100644 --- a/src/redoctober/passvault/passvault.go +++ b/passvault/passvault.go @@ -17,11 +17,11 @@ import ( "encoding/binary" "encoding/json" "errors" + "github.com/cloudflare/redoctober/padding" "io/ioutil" "math/big" mrand "math/rand" "os" - "redoctober/padding" ) // Constants for record type @@ -341,7 +341,7 @@ func WriteRecordsToDisk() error { func AddNewRecord(name, password string, admin bool) (PasswordRecord, error) { if pr, err := createPasswordRec(password, admin); err == nil { SetRecord(pr, name) - return pr, WriteRecordsToDisk() + return pr, WriteRecordsToDisk() } else { return pr, err } diff --git a/src/redoctober/passvault/passvault_test.go b/passvault/passvault_test.go similarity index 99% rename from src/redoctober/passvault/passvault_test.go rename to passvault/passvault_test.go index 8ddd961..6ceba9b 100644 --- a/src/redoctober/passvault/passvault_test.go +++ b/passvault/passvault_test.go @@ -34,4 +34,3 @@ func TestRSAEncryptDecrypt(t *testing.T) { t.Fatalf("Error validating RSA key") } } - diff --git a/src/redoctober/redoctober.go b/redoctober.go similarity index 99% rename from src/redoctober/redoctober.go rename to redoctober.go index 31543f5..fe7c84f 100644 --- a/src/redoctober/redoctober.go +++ b/redoctober.go @@ -11,12 +11,12 @@ import ( "encoding/pem" "flag" "fmt" + "github.com/cloudflare/redoctober/core" "io/ioutil" "log" "net" "net/http" "os" - "redoctober/core" "runtime" )