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

add web interface to re-encrypt #68

Merged
merged 4 commits into from
Feb 14, 2024
Merged
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
File renamed without changes.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

gradle.properties

**/chaincli
**/smccli
chaincli
smccli

profile.cov
report.json
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go 1.21

require (
github.com/gorilla/mux v1.8.1
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.18.1
github.com/steinfletcher/apitest v1.5.15
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -42,7 +43,6 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand Down
15 changes: 6 additions & 9 deletions server/smc/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import (
"net/http"

"go.dedis.ch/hbt/server/smc/proxy/types"
"go.dedis.ch/kyber/v3/suites"
)

var suite = suites.MustFind("ed25519")

// NotFoundHandler defines a generic handler for 404
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
err := types.HTTPError{
Expand Down Expand Up @@ -59,7 +56,7 @@ func NotAllowedHandler(w http.ResponseWriter, r *http.Request) {

// InternalError sets an internal server error
func InternalError(w http.ResponseWriter, r *http.Request, err error, args map[string]interface{}) {
setHttpError(w, r, err, http.StatusInternalServerError, "Internal server error", args)
setHTTPError(w, r, err, http.StatusInternalServerError, "Internal server error", args)
}

// BadRequestError sets an bad request error
Expand All @@ -69,7 +66,7 @@ func BadRequestError(
err error,
args map[string]interface{},
) {
setHttpError(w, r, err, http.StatusBadRequest, "bad request", args)
setHTTPError(w, r, err, http.StatusBadRequest, "bad request", args)
}

// ForbiddenError sets a forbidden error error
Expand All @@ -79,15 +76,15 @@ func ForbiddenError(
err error,
args map[string]interface{},
) {
setHttpError(w, r, err, http.StatusForbidden, "not authorized / forbidden", args)
setHTTPError(w, r, err, http.StatusForbidden, "not authorized / forbidden", args)
}

// NotFoundErr sets a not found error
func NotFoundErr(w http.ResponseWriter, r *http.Request, err error, args map[string]interface{}) {
setHttpError(w, r, err, http.StatusNotFound, "not found", args)
setHTTPError(w, r, err, http.StatusNotFound, "not found", args)
}

func setHttpError(
func setHTTPError(
w http.ResponseWriter,
r *http.Request,
err error,
Expand Down Expand Up @@ -120,7 +117,7 @@ func setHttpError(

// AllowCORS defines a basic handler that adds wide Access Control Allow origin
// headers.
func AllowCORS(w http.ResponseWriter, r *http.Request) {
func AllowCORS(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
}
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
Loading
Loading