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

Added missing e4 commands #17

Merged
merged 9 commits into from
Mar 16, 2020
Merged

Added missing e4 commands #17

merged 9 commits into from
Mar 16, 2020

Conversation

daeMOn63
Copy link
Member

@daeMOn63 daeMOn63 commented Mar 6, 2020

Added missing E4 commands as C2 endpoints, along with commands on the c2cli client for:

  • RemovePubKey
  • ResetPubKeys
  • NewC2Key

Notes on NewC2Key

  • Have added an extra safety feature on NewC2Key, creating a backup copy of the C2 key file provided in configuration before modifying it (see https://github.com/teserakt-io/c2/blob/fb/missing-e4-commands/internal/crypto/c2key.go). Once everything is fine, the new key get written in the actual c2key file, allowing to restart or reload the config without reusing the initial key.
  • Any errors occurring while sending the new C2 key to clients will just skip the client, and keep going for the remaining ones. Only a log error is generated for tracking at the moment.

Fix #15

diagprov
diagprov previously approved these changes Mar 9, 2020
"testing"

"github.com/teserakt-io/c2/pkg/pb"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious line yet could be anchored with all the "github.com/*" imports down below.

"github.com/teserakt-io/c2/pkg/pb"

"github.com/golang/mock/gomock"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto about the spurious newline.

@@ -14,8 +12,8 @@ func TestE4Command(t *testing.T) {
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
if cmdType != e4.Command(0x01) {
t.Errorf("Expected type to be %v, got %v", e4.Command(0x01), cmdType)
if cmdType != 0x01 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if g, w := cmdType, 0x01; g != w {
}

but even better, let's make constants instead of using magic numbers.

func (f *factory) CreateRemoveTopicCommand(topic string) (Command, error) {
cmd, err := e4.CmdRemoveTopic(topic)
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the return e4Command(cmd), err anchored to the if, since they are now all part of the same logical block so:

func (f *factory) CreateRemoveTopicCommand(topic string) (Command, error) {
	cmd, err := e4.CmdRemoveTopic(topic)
	if err != nil {
		return nil, err
	}
	return e4Command(cmd), err
}

if err != nil {
return nil, err
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious newline.

func (f *factory) CreateSetTopicKeyCommand(topic string, key []byte) (Command, error) {
cmd, err := e4.CmdSetTopicKey(key, topic)
if err != nil {
return nil, err
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious newline.

if err != nil {
return nil, err
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious newline.

@daeMOn63 daeMOn63 merged commit 83f9776 into develop Mar 16, 2020
@diagprov diagprov deleted the fb/missing-e4-commands branch March 16, 2020 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PublicKey commands
3 participants