sign.go 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9
package main

import (
	"fmt"
	"os"

	"dfss/dfssc/sign"
)

Loïck Bonniot's avatar
Loïck Bonniot committed
10 11
func signContract(args []string) {
	filename := args[0]
12
	fmt.Println("You are going to sign the following contract:")
Loïck Bonniot's avatar
Loïck Bonniot committed
13 14
	showContract(args)

Loïck Bonniot's avatar
Loïck Bonniot committed
15
	contract := getContract(filename)
16 17 18 19 20 21 22 23 24 25 26 27 28
	if contract == nil {
		os.Exit(1)
	}

	var passphrase string
	_ = readPassword(&passphrase, false)

	// Preparation
	manager, err := sign.NewSignatureManager(fca, fcert, fkey, addrPort, passphrase, localPort, contract)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}
Loïck Bonniot's avatar
Loïck Bonniot committed
29 30

	manager.OnSignerStatusUpdate = signFeedbackFn
31 32 33 34 35 36 37 38 39 40 41 42 43 44
	err = manager.ConnectToPeers()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(3)
	}

	// Confirmation
	var ready string
	readStringParam("Do you REALLY want to sign "+contract.File.Name+"? Type 'yes' to confirm", "", &ready)
	if ready != "yes" {
		os.Exit(4)
	}

	// Ignition
Loïck Bonniot's avatar
Loïck Bonniot committed
45 46 47 48 49 50 51
	fmt.Println("Waiting for other signers to be ready...")
	signatureUUID, err := manager.SendReadySign()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(5)
	}

52
	// TODO Warning, integration tests are checking Stdout
Loïck Bonniot's avatar
Loïck Bonniot committed
53
	fmt.Println("Everybody is ready, starting the signature", signatureUUID)
54 55

	// Signature
Loïck Bonniot's avatar
Loïck Bonniot committed
56
	manager.OnProgressUpdate = signProgressFn
57 58 59 60 61
	err = manager.Sign()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(5)
	}
62

63
	// Persist evidencies, if any
64 65 66 67 68 69
	err = manager.PersistSignaturesToFile()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(5)
	}

70
	fmt.Println("Signature complete! See .proof file for evidences.")
71
}
Loïck Bonniot's avatar
Loïck Bonniot committed
72 73 74 75 76 77 78 79 80 81

func signFeedbackFn(mail string, status sign.SignerStatus, data string) {
	if status == sign.StatusConnecting {
		fmt.Println("- Trying to connect with", mail, "/", data)
	} else if status == sign.StatusConnected {
		fmt.Println("  Successfully connected!", "[", data, "]")
	}
}

func signProgressFn(current int, max int) {}