Skip to content

Commit

Permalink
add web interface to rencrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
jbsv committed Feb 13, 2024
1 parent 2976125 commit 1c41084
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
47 changes: 36 additions & 11 deletions server/smc/smccli/controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"strings"

"go.dedis.ch/dela"
"go.dedis.ch/dela/cli"
"go.dedis.ch/dela/cli/node"
"go.dedis.ch/dela/dkg"
"go.dedis.ch/kyber/v3/util/key"

"go.dedis.ch/kyber/v3"
Expand All @@ -22,7 +23,12 @@ const separator = ":"
const malformedEncoded = "malformed encoded: %s"
const keyFileName = "key.pair"

func createKeyPairAction(_ cli.Flags) error {
// createKeyPairAction is an action to create a key pair
//
// - implements node.ActionTemplate
type createKeyPairAction struct{}

func (c createKeyPairAction) Execute(_ node.Context) error {
kp := key.NewKeyPair(suites.MustFind("Ed25519"))

privk, err := kp.Private.MarshalBinary()
Expand Down Expand Up @@ -53,26 +59,45 @@ func createKeyPairAction(_ cli.Flags) error {
return nil
}

func revealAction(flags cli.Flags) error {
xhatString := flags.String("xhatenc")
// revealAction is an action to reveal a message
//
// - implements node.ActionTemplate
type revealAction struct{}

func (r revealAction) Execute(ctx node.Context) error {
xhatString := ctx.Flags.String("xhatenc")
xhatenc, err := decodePublicKey(xhatString)
if err != nil {
return xerrors.Errorf("failed to reencrypt: %v", err)
return xerrors.Errorf("failed to reveal: %v", err)
}

dkgpubString := flags.String("dkgpub")
dkgpubk, err := decodePublicKey(dkgpubString)
if err != nil {
return xerrors.Errorf("failed to decode public key str: %v", err)
dkgpubString := ctx.Flags.String("dkgpub")
var dkgpubk kyber.Point
if dkgpubString != "" {
dkgpubk, err = decodePublicKey(dkgpubString)
if err != nil {
return xerrors.Errorf("failed to decode public key str: %v", err)
}
} else {
var actor dkg.Actor
err := ctx.Injector.Resolve(&actor)
if err != nil {
return xerrors.Errorf("failed to resolve DKG actor: %v", err)
}

dkgpubk, err = actor.GetPublicKey()
if err != nil {
return xerrors.Errorf("failed retrieving DKG public key: %v", err)
}
}

privkString := flags.String("privk")
privkString := ctx.Flags.String("privk")
privateKey, err := decodePrivateKey(privkString)
if err != nil {
return xerrors.Errorf("failed to decode private key str: %v", err)
}

encrypted := flags.String("encrypted")
encrypted := ctx.Flags.String("encrypted")
_, cs, err := decodeEncrypted(encrypted)
if err != nil {
return xerrors.Errorf("failed to decode encrypted str: %v", err)
Expand Down
9 changes: 5 additions & 4 deletions server/smc/smccli/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (s smcctl) SetCommands(builder node.Builder) {

sub := cmd.SetSubCommand("createkeys")
sub.SetDescription("create key pair for reencryption")
sub.SetAction(createKeyPairAction)
sub.SetAction(builder.MakeAction(createKeyPairAction{}))

sub = cmd.SetSubCommand("reveal")
sub.SetDescription("reveal a reencrypted message")
Expand All @@ -30,8 +30,9 @@ func (s smcctl) SetCommands(builder node.Builder) {
Usage: "the reencrypted key as <hex(xhatenc)>",
},
cli.StringFlag{
Name: "dkgpub",
Usage: "the DKG public key as <hex(dkgpub)>",
Name: "dkgpub",
Usage: "the DKG public key as <hex(dkgpub)>",
Required: false,
},
cli.StringFlag{
Name: "encrypted",
Expand All @@ -42,7 +43,7 @@ func (s smcctl) SetCommands(builder node.Builder) {
Usage: "drop me if you can",
},
)
sub.SetAction(revealAction)
sub.SetAction(builder.MakeAction(revealAction{}))
}

// OnStart implements node.Initializer. It creates and registers a pedersen DKG.
Expand Down

0 comments on commit 1c41084

Please sign in to comment.