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

gofmt #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

gofmt #192

Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions cmd/ro/roagent/roagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"crypto/subtle"
"encoding/json"
"errors"
"log"
"io"
"log"

roclient "github.com/cloudflare/redoctober/client"
"github.com/cloudflare/redoctober/core"
"golang.org/x/crypto/ssh"
)

type ROAgent struct {
locked bool
keyring []*ROSigner
locked bool
keyring []*ROSigner

server *roclient.RemoteServer
username string
Expand Down Expand Up @@ -102,7 +102,7 @@ func (roagent *ROAgent) Remove(key ssh.PublicKey) error {
for i, rosigner := range roagent.keyring {
if bytes.Equal(rosigner.PublicKey().Marshal(), wanted) {
// Order is not preserved
roagent.keyring[i] = roagent.keyring[0]
roagent.keyring[i] = roagent.keyring[0]
roagent.keyring = roagent.keyring[1:]
log.Println("ro-ssh-agent: signer removed")
return nil
Expand Down
14 changes: 6 additions & 8 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type DelegateRequest struct {
}

type CreateUserRequest struct {
Name string
Name string
Password string
UserType string
HipchatName string
Expand Down Expand Up @@ -113,7 +113,7 @@ type SSHSignWithRequest struct {
type SSHSignatureWithDelegates struct {
SignatureFormat string
Signature []byte
Secure bool
Secure bool
Delegates []string
}

Expand All @@ -135,13 +135,13 @@ type ExportRequest struct {
}

type OrderRequest struct {
Name string
Name string
Password string
Duration string
Uses int
Users []string
Uses int
Users []string
EncryptedData []byte
Labels []string
Labels []string
}

type OrderInfoRequest struct {
Expand Down Expand Up @@ -723,7 +723,6 @@ func Decrypt(jsonIn []byte) ([]byte, error) {
}
}


resp := &DecryptWithDelegates{
Data: data,
Secure: secure,
Expand Down Expand Up @@ -819,7 +818,6 @@ func SSHSignWith(jsonIn []byte) ([]byte, error) {
return jsonResponse(out)
}


// Modify processes a modify request.
func Modify(jsonIn []byte) ([]byte, error) {
var s ModifyRequest
Expand Down
96 changes: 48 additions & 48 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,87 +677,87 @@ func TestEncryptDecrypt(t *testing.T) {
// Encrypt with "decrypt" usage
respJson, err = Encrypt(encryptJson4)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in encrypt, %v", s.Status)
t.Fatalf("Error in encrypt, %v", s.Status)
}

respJson, err = Delegate(delegateJson6)
if err != nil {
t.Fatalf("Error in delegating account, %v", err)
t.Fatalf("Error in delegating account, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in delegating account, %v", err)
t.Fatalf("Error in delegating account, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in delegating account, %v", s.Status)
t.Fatalf("Error in delegating account, %v", s.Status)
}

// decrypt file
decryptJson3, err := json.Marshal(DecryptRequest{Name: "Alice", Password: "Hello", Data: s.Response})
if err != nil {
t.Fatalf("Error in marshalling decryption, %v", err)
t.Fatalf("Error in marshalling decryption, %v", err)
}

respJson2, err = Decrypt(decryptJson3)
if err != nil {
t.Fatalf("Error in decrypt, %v", err)
t.Fatalf("Error in decrypt, %v", err)
}
err = json.Unmarshal(respJson2, &s)
if err != nil {
t.Fatalf("Error in decrypt, %v", err)
t.Fatalf("Error in decrypt, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in decrypt, %v", s.Status)
t.Fatalf("Error in decrypt, %v", s.Status)
}

// Encrypt with "unused" usage
respJson, err = Encrypt(encryptJson5)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in encrypt, %v", s.Status)
t.Fatalf("Error in encrypt, %v", s.Status)
}

respJson, err = Delegate(delegateJson6)
if err != nil {
t.Fatalf("Error in delegating account, %v", err)
t.Fatalf("Error in delegating account, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in delegating account, %v", err)
t.Fatalf("Error in delegating account, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in delegating account, %v", s.Status)
t.Fatalf("Error in delegating account, %v", s.Status)
}

// decrypt file
decryptJson4, err := json.Marshal(DecryptRequest{Name: "Alice", Password: "Hello", Data: s.Response})
if err != nil {
t.Fatalf("Error in marshalling decryption, %v", err)
t.Fatalf("Error in marshalling decryption, %v", err)
}

respJson2, err = Decrypt(decryptJson4)
if err != nil {
t.Fatalf("Error in decrypt, %v", err)
t.Fatalf("Error in decrypt, %v", err)
}
err = json.Unmarshal(respJson2, &s)
if err != nil {
t.Fatalf("Error in decrypt, %v", err)
t.Fatalf("Error in decrypt, %v", err)
}
if s.Status == "ok" {
t.Fatalf("Expected error decrypting blob without \"decrypt\" usage")
t.Fatalf("Expected error decrypting blob without \"decrypt\" usage")
}
}

Expand Down Expand Up @@ -1293,121 +1293,121 @@ func TestSSHSignWith(t *testing.T) {
var s ResponseData
respJson, err := Create(delegateJson)
if err != nil {
t.Fatalf("Error in creating account, %v", err)
t.Fatalf("Error in creating account, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in creating account, %v", err)
t.Fatalf("Error in creating account, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in creating account, %v", s.Status)
t.Fatalf("Error in creating account, %v", s.Status)
}

respJson, err = Delegate(delegateJson)
if err != nil {
t.Fatalf("Error in delegating account, %v", err)
t.Fatalf("Error in delegating account, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in delegating account, %v", err)
t.Fatalf("Error in delegating account, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in delegating account, %v", s.Status)
t.Fatalf("Error in delegating account, %v", s.Status)
}

sshKey, err := ioutil.ReadFile("../testdata/ssh_key")
if err != nil {
t.Fatalf("Error loading test SSH key, %v", err)
t.Fatalf("Error loading test SSH key, %v", err)
}

sshPubKeyBytes, err := ioutil.ReadFile("../testdata/ssh_key.pub")
if err != nil {
t.Fatalf("Error loading test SSH pubkey, %v", err)
t.Fatalf("Error loading test SSH pubkey, %v", err)
}

sshPubKey, _, _, _, err := ssh.ParseAuthorizedKey(sshPubKeyBytes)
if err != nil {
t.Fatalf("Error loading test SSH pubkey, %v", err)
t.Fatalf("Error loading test SSH pubkey, %v", err)
}

e := EncryptRequest{Name: "Alice", Password: "Hello",
Owners: []string{"Alice"}, Minimum: 1, Data: sshKey}
Owners: []string{"Alice"}, Minimum: 1, Data: sshKey}

encryptJson, err := json.Marshal(e)
if err != nil {
t.Fatalf("Error marshalling encrypt request, %v", err)
t.Fatalf("Error marshalling encrypt request, %v", err)
}

// Encrypt SSH key
respJson, err = Encrypt(encryptJson)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in encrypt, %v", s.Status)
t.Fatalf("Error in encrypt, %v", s.Status)
}

// try to generate a signature
sshSignWithJson, err := json.Marshal(SSHSignWithRequest{Name: "Alice", Password: "Hello", Data: s.Response, TBSData: []byte("signme")})
if err != nil {
t.Fatalf("Error marshalling ssh-sign-with request, %v", err)
t.Fatalf("Error marshalling ssh-sign-with request, %v", err)
}

respJson, err = SSHSignWith(sshSignWithJson)
if err != nil {
t.Fatalf("Error in ssh-sign-with, %v", err)
t.Fatalf("Error in ssh-sign-with, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in ssh-sign-with, %v", err)
t.Fatalf("Error in ssh-sign-with, %v", err)
}
if s.Status != "cannot sign with this file" {
t.Fatalf("Expected error using ssh-sign-with without 'ssh-sign-with' usage, got %v", s.Status)
t.Fatalf("Expected error using ssh-sign-with without 'ssh-sign-with' usage, got %v", s.Status)
}

e.Usages = []string{"ssh-sign-with"}
encryptJson, err = json.Marshal(e)
if err != nil {
t.Fatalf("Error marshalling encrypt request, %v", err)
t.Fatalf("Error marshalling encrypt request, %v", err)
}

respJson, err = Encrypt(encryptJson)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in encrypt, %v", err)
t.Fatalf("Error in encrypt, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in encrypt, %v", s.Status)
t.Fatalf("Error in encrypt, %v", s.Status)
}

sshSignWithJson, err = json.Marshal(SSHSignWithRequest{Name: "Alice", Password: "Hello", Data: s.Response, TBSData: []byte("signme")})
if err != nil {
t.Fatalf("Error marshalling ssh-sign-with request, %v", err)
t.Fatalf("Error marshalling ssh-sign-with request, %v", err)
}

respJson, err = SSHSignWith(sshSignWithJson)
if err != nil {
t.Fatalf("Error in ssh-sign-with, %v", err)
t.Fatalf("Error in ssh-sign-with, %v", err)
}
err = json.Unmarshal(respJson, &s)
if err != nil {
t.Fatalf("Error in ssh-sign-with, %v", err)
t.Fatalf("Error in ssh-sign-with, %v", err)
}
if s.Status != "ok" {
t.Fatalf("Error in ssh-sign-with, %v", s.Status)
t.Fatalf("Error in ssh-sign-with, %v", s.Status)
}

var sshSignWithResponse SSHSignatureWithDelegates
err = json.Unmarshal(s.Response, &sshSignWithResponse)
if err != nil {
t.Fatalf("Error unmarshalling ssh-sign-with response, %v", err)
t.Fatalf("Error unmarshalling ssh-sign-with response, %v", err)
}

sshSignature := ssh.Signature{
Expand All @@ -1416,7 +1416,7 @@ func TestSSHSignWith(t *testing.T) {
}
err = sshPubKey.Verify([]byte("signme"), &sshSignature)
if err != nil {
t.Fatalf("Error verifying ssh-sign-with signature, %v", err)
t.Fatalf("Error verifying ssh-sign-with signature, %v", err)
}
}

Expand Down
22 changes: 11 additions & 11 deletions cryptor/cryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ func New(records *passvault.Records, cache *keycache.Cache, config *config.Confi
// both, then he can decrypt it alone). If a predicate is present, it must be
// satisfied to decrypt.
type AccessStructure struct {
Minimum int
Names []string
Minimum int
Names []string

LeftNames []string
RightNames []string

Predicate string
Predicate string
}

// Implements msp.UserDatabase
type UserDatabase struct {
names *[]string
names *[]string

records *passvault.Records
cache *keycache.Cache
records *passvault.Records
cache *keycache.Cache

user string
labels []string
Expand Down Expand Up @@ -126,9 +126,9 @@ type SingleWrappedKey struct {
// EncryptedData is the format for encrypted data containing all the
// keys necessary to decrypt it when delegated.
type EncryptedData struct {
Version int
VaultId int `json:",omitempty"`
Labels []string `json:",omitempty"`
Version int
VaultId int `json:",omitempty"`
Labels []string `json:",omitempty"`
// Usages list the endpoints which may use this data
// If empty, only decryption in permitted
Usages []string `json:",omitempty"`
Expand All @@ -149,8 +149,8 @@ type pair struct {
type mwkSlice []MultiWrappedKey
type swkSlice []pair

func (s mwkSlice) Len() int { return len(s) }
func (s mwkSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s mwkSlice) Len() int { return len(s) }
func (s mwkSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s mwkSlice) Less(i, j int) bool { // Alphabetic order
var shorter = i
if len(s[i].Name) > len(s[j].Name) {
Expand Down