Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Identity generation will include a qr code for the public key
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun Chen committed Sep 4, 2018
1 parent fad7ec0 commit 16d8df5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
12 changes: 7 additions & 5 deletions prifi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,11 @@ case $1 in

read -p "Do you want to generate it for [r]elay, [c]lient, or [t]trustee ? " key

doOutputQR=true
path=""
case "$key" in
r|R)
pathSource="relay"
path="relay"
;;
t|T)
Expand Down Expand Up @@ -328,17 +330,17 @@ case $1 in
echo -e "Gonna generate ${highlightOn}identity.toml${highlightOff} in ${highlightOn}$pathReal${highlightOff}"

#generate identity.toml
DEBUG_COLOR="$colors" go run "$bin_file" --default_path "$pathReal" gen-id
DEBUG_COLOR="$colors" go run "$bin_file" --default_path "$pathReal" --qrcode="$doOutputQR" gen-id

if [ ! -f "${pathReal}group.toml" ]; then
#now group.toml
echo -n "Done ! now copying group.toml from identities_default/ to identity_real/..."
cp "${pathDefault}/group.toml" "${pathReal}group.toml"
echo -n "Now copying group.toml from identities_default/ to identity_real/..."
cp "${pathDefault}group.toml" "${pathReal}group.toml"
echo -e "$okMsg"

echo -e "Please edit ${highlightOn}$pathReal/group.toml${highlightOff} to the correct values."
echo -e "Please edit ${highlightOn}${pathReal}group.toml${highlightOff} to the correct values."
else
echo -e "Group file ${highlightOn}$pathReal/group.toml${highlightOff} already exists, not overwriting! you might want to check that the contents are correct."
echo -e "Group file ${highlightOn}${pathReal}group.toml${highlightOff} already exists, not overwriting! you might want to check that the contents are correct."
fi
;;

Expand Down
29 changes: 22 additions & 7 deletions sda/app/prifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/exec"
"strconv"
"time"
"github.com/skip2/go-qrcode"
)

// DefaultName is the name of the binary we produce and is used to create a directory
Expand Down Expand Up @@ -125,6 +126,10 @@ func main() {
Name: "nowait",
Usage: "Return immediately",
},
cli.BoolFlag{
Name: "qrcode",
Usage: "output the public key by qrcode",
},
}
app.Before = func(c *cli.Context) error {
log.SetDebugVisible(c.Int("debug"))
Expand Down Expand Up @@ -283,22 +288,24 @@ func checkOverwrite(file string) bool {

func createNewIdentityToml(c *cli.Context) error {

// -- Keys
log.Print("Generating public/private keys...")

suite := suites.MustFind("Ed25519") //TODO Nikko wants to change this
key := key.NewKeyPair(suite)
pubStr, err := encoding.PointToStringHex(suite, key.Public)
newKeyPair := key.NewKeyPair(suite)
pubStr, err := encoding.PointToStringHex(suite, newKeyPair.Public)
if err != nil {
panic(err)
}
privStr, err := encoding.ScalarToStringHex(suite, key.Private)
priStr, err := encoding.ScalarToStringHex(suite, newKeyPair.Private)
if err != nil {
panic(err)
}

addrPort := app.Inputf(":"+strconv.Itoa(DefaultPort)+"", "Which port do you want PriFi to use locally ?")
// -- Network
addrPort := ":" + app.Inputf(strconv.Itoa(DefaultPort), "Which port do you want PriFi to use locally ?")

//parse IP + Port
// parse IP + Port
var hostStr string
var portStr string

Expand All @@ -320,10 +327,11 @@ func createNewIdentityToml(c *cli.Context) error {

identity := &app.CothorityConfig{
Public: pubStr,
Private: privStr,
Private: priStr,
Address: serverBinding,
}

// -- File Creation
var configDone bool
var folderPath string
var identityFilePath string
Expand Down Expand Up @@ -353,7 +361,14 @@ func createNewIdentityToml(c *cli.Context) error {
}

if err := identity.Save(identityFilePath); err != nil {
log.Fatal("Unable to write the config to file:", err)
log.Fatal("Unable to write the config to file: ", err)
}

// QR Code for the public key
if c.GlobalBool("qrcode") {
if err := qrcode.WriteFile(pubStr, qrcode.Medium, 256, folderPath + "public_key_qr.png"); err != nil {
log.Fatal("Unable to generate the qr code for the public key: ", err)
}
}

log.Info("Identity file saved.")
Expand Down

0 comments on commit 16d8df5

Please sign in to comment.