-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/cryptoballot/cryptoballot/cryptoballot" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func actionAdminCreate(c *cli.Context) error { | ||
filename := c.Args().First() | ||
|
||
if filename == "" { | ||
log.Fatal("Please specify an election file to PUT to the ballotclerk server") | ||
} | ||
|
||
if PrivateKey == nil { | ||
log.Fatal("Please specify a private key pem file with --key (eg: `--key=path/to/mykey.pem`)") | ||
} | ||
|
||
content, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
election, err := cryptoballot.NewElection(content) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Sign election if needed | ||
if !election.HasSignature() { | ||
election.Signature, err = PrivateKey.SignString(election.String()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// Verify the election was signed correctly | ||
err = election.VerifySignature() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// PUT the election to the Election Clerk server | ||
err = BallotClerkClient.PutElection(election, PrivateKey) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
|
||
"github.com/cryptoballot/cryptoballot/cryptoballot" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func actionVoterVote(c *cli.Context) error { | ||
filename := c.Args().First() | ||
|
||
if filename == "" { | ||
log.Fatal("Please specify an balliot file to PUT to the ballotbox server") | ||
} | ||
|
||
if PrivateKey == nil { | ||
log.Fatal("Please specify a private key pem file with --key (eg: `--key=path/to/mykey.pem`)") | ||
} | ||
|
||
content, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ballot, err := cryptoballot.NewBallot(content) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Get public key from ballotclerk server | ||
clerkPublicKey, err := BallotClerkClient.GetPublicKey() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Blind the ballot | ||
blindBallot, unblinder, err := ballot.Blind(clerkPublicKey) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a signature request | ||
signatureRequest := &cryptoballot.SignatureRequest{ | ||
ElectionID: ballot.ElectionID, | ||
RequestID: PublicKey.GetSHA256(), | ||
PublicKey: PublicKey.Bytes(), | ||
BlindBallot: blindBallot, | ||
} | ||
signatureRequest.Signature, err = PrivateKey.SignString(signatureRequest.String()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Do the signature request | ||
fulfilled, err := BallotClerkClient.PostSignatureRequest(signatureRequest, PrivateKey) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Unblind the ballot using the FulfilledSignatureRequest | ||
err = ballot.Unblind(clerkPublicKey, fulfilled.BallotSignature, unblinder) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// PUT the ballot | ||
err = BallotBoxClient.PutBallot(ballot) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return nil | ||
} |