Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions web/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev": "./node_modules/.bin/nodemon",
"eslint": "./node_modules/.bin/eslint .",
"eslint-fix": "./node_modules/.bin/eslint . --fix",
"keygen": "ts-node src/cli.ts keygen",
"prettier": "./node_modules/.bin/prettier --write .",
"prettier-check": "./node_modules/.bin/prettier --check .",
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
23 changes: 18 additions & 5 deletions web/backend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,31 @@ Copy the database credentials from `config.env.template` to `/d-voting/bachend/s

## Generate a keypair

Here is a small piece of code to help generating the keys:
Here is a small piece of code in go to generate the keypair for the backend:

```go
func GenerateKey() {
privK := suite.Scalar().Pick(suite.RandomStream())
pubK := suite.Point().Mul(privK, nil)
package main

fmt.Println("PUBLIC_KEY:", pubK)
import (
"fmt"
"go.dedis.ch/kyber/v3/group/edwards25519"
"go.dedis.ch/kyber/v3/util/key"
)

func main() {
pair := key.NewKeyPair(&edwards25519.SuiteEd25519{})

fmt.Println("PUBLIC_KEY:", pubK)
fmt.Println("PRIVATE_KEY:", privK)
}
```

You can also use the `cli` program to generate the keys:

```sh
npm run keygen
```

# Run the program

Once all the previous steps done, the project can be run using `npm start`
Expand Down
12 changes: 12 additions & 0 deletions web/backend/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Backend CLI, currently providing 3 commands for user management:
import { Command } from 'commander';
import { SequelizeAdapter } from 'casbin-sequelize-adapter';
import { newEnforcer } from 'casbin';
import { curve } from '@dedis/kyber';

const program = new Command();

Expand Down Expand Up @@ -65,4 +66,15 @@ program
console.log('Permissions removed successfully!');
});

program
.command('keygen')
.description('Create a new keypair for the .env')
.action(() => {
const ed25519 = curve.newCurve('edwards25519');
const priv = ed25519.scalar().pick();
const pub = ed25519.point().mul(priv);
console.log(`PRIVATE_KEY=${priv}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it normal to simply print them instead of saving them where they are needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here is to create the values that are needed for the .env file, so not to store them anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a line saying "please make sure to store this somewhere" as people might indeed expect the values to also be written to a file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an output, but now it won't be usable in scripts anymore...

console.log(`PUBLIC_KEY=${pub}`);
});

program.parse();