Make repository work with go get

This commit is contained in:
Albert Strasheim
2013-11-21 12:01:25 -08:00
parent 5f328bb7a3
commit 9c5d08f665
12 changed files with 38 additions and 110 deletions

View File

@@ -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 $*=$($*)

View File

@@ -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)

View File

@@ -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()

View File

@@ -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)
}

View File

@@ -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")
}
}

View File

@@ -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)
}
}

View File

@@ -4,7 +4,7 @@
package keycache
import (
"redoctober/passvault"
"github.com/cloudflare/redoctober/passvault"
"testing"
"time"
)

View File

@@ -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.

View File

@@ -70,4 +70,3 @@ func TestDetectBadPadding(t *testing.T) {
assert(t, err != nil)
assert(t, d == nil)
}

View File

@@ -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
}

View File

@@ -34,4 +34,3 @@ func TestRSAEncryptDecrypt(t *testing.T) {
t.Fatalf("Error validating RSA key")
}
}

View File

@@ -11,12 +11,12 @@ import (
"encoding/pem"
"flag"
"fmt"
"github.com/cloudflare/redoctober/core"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"redoctober/core"
"runtime"
)