Skip to content

Commit

Permalink
formatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo committed Jun 22, 2020
2 parents c2846bd + 5288b9d commit 355295c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
tests/dhsm-signer/dtc/config/
tests/dhsm-signer/dtcnode/config/
tests/pkcs11-test/config
dtc-config.yaml
dtcnode-config.yaml
/dtc-config.yaml
/dtcnode-config.yaml
30 changes: 15 additions & 15 deletions cmd/rsa.go → cmd/create.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
package cmd

import (
"github.com/niclabs/dtcconfig/rsa"
"github.com/niclabs/dtcconfig/config"
"github.com/spf13/cobra"
)

var serverConfig rsa.ClientConfigParams
var serverConfig config.ClientConfigParams

func init() {
rsaCmd.Flags().StringVarP(
createCmd.Flags().StringVarP(
&serverConfig.Host,
"host",
"H",
"",
"IP or domain name that the nodes will see from the client")
rsaCmd.Flags().StringSliceVarP(
createCmd.Flags().StringSliceVarP(
&serverConfig.Nodes,
"nodes",
"n",
[]string{},
"comma separated list of nodes in ip:port format")
rsaCmd.Flags().StringVarP(
createCmd.Flags().StringVarP(
&serverConfig.ConfigPath,
"config",
"c",
"./dtc-config.yaml",
"path where to output the local config file")
rsaCmd.Flags().StringVarP(
createCmd.Flags().StringVarP(
&serverConfig.NodesConfigPath,
"nodes-config",
"k",
"./nodes",
"path to a folder where to output the nodes config files")
rsaCmd.Flags().StringVarP(
createCmd.Flags().StringVarP(
&serverConfig.LogPath,
"log",
"l",
"/tmp/dtc.log",
"path to a file where to output the services logs")
rsaCmd.Flags().StringVarP(
createCmd.Flags().StringVarP(
&serverConfig.DBPath,
"db",
"d",
"./db.sqlite3",
"path to a file where to put Sqlite3 database")
rsaCmd.Flags().IntVarP(
createCmd.Flags().IntVarP(
&serverConfig.Threshold,
"threshold",
"t",
0,
"Minimum number of nodes required to sign")
_ = rsaCmd.MarkFlagRequired("host")
_ = rsaCmd.MarkFlagRequired("nodes")
_ = rsaCmd.MarkFlagRequired("threshold")
_ = createCmd.MarkFlagRequired("host")
_ = createCmd.MarkFlagRequired("nodes")
_ = createCmd.MarkFlagRequired("threshold")
}

var rsaCmd = &cobra.Command{
Use: "rsa",
Short: "Generates a configuration file for tcrsa nodes and server",
var createCmd = &cobra.Command{
Use: "create",
Short: "Generates a configuration file for dtc nodes and server",
RunE: func(cmd *cobra.Command, args []string) error {
return serverConfig.GenerateConfig()
},
Expand Down
1 change: 1 addition & 0 deletions cmd/gencurve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/pebbe/zmq4"
"github.com/spf13/cobra"
)
Expand Down
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package cmd

import (
"github.com/spf13/cobra"
"log"
"os"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(rsaCmd)
rootCmd.AddCommand(createCmd)
rootCmd.AddCommand(genCurveCmd)
Log = log.New(os.Stderr, "", 0)
}

// Log is used by all the subcommands
var Log *log.Logger

var rootCmd = &cobra.Command{
Expand All @@ -22,6 +24,7 @@ var rootCmd = &cobra.Command{
For more information, visit "https://github.com/niclabs/dtcconfig".`,
}

// Execute executes the program
func Execute() {
if err := rootCmd.Execute(); err != nil {
Log.Printf("Error: %s", err)
Expand Down
26 changes: 15 additions & 11 deletions rsa/config.go → config/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package rsa
package config

import (
"fmt"
"net/url"
"os"
"path"
"strconv"
"strings"

dtc "github.com/niclabs/dtc/v3/config"
node "github.com/niclabs/dtcnode/v3/config"
Expand Down Expand Up @@ -34,7 +34,7 @@ type ClientConfig struct {
ZMQ dtc.ZMQConfig
}

// GenerateConfig creates all the configuration related to RSA DTC implementation
// GenerateConfig creates all the configuration related to DTC implementation
func (conf *ClientConfigParams) GenerateConfig() error {
if conf.Threshold > len(conf.Nodes) {
return fmt.Errorf("threshold must be less or equal than nodes number")
Expand Down Expand Up @@ -69,8 +69,8 @@ func (conf *ClientConfigParams) GenerateConfig() error {
},
Criptoki: dtc.CriptokiConfig{
ManufacturerID: "NICLabs",
Model: "dHSM RSA",
Description: "Distributed HSM using RSA signatures",
Model: "dHSM",
Description: "Distributed HSM",
SerialNumber: "1",
MinPinLength: 3,
MaxPinLength: 10,
Expand Down Expand Up @@ -162,15 +162,19 @@ func (conf *ClientConfigParams) CreateNodes(clientPubKey string) ([]*dtc.NodeCon

// GetHostAndPort splits a host and port string. Returns an error if something goes wrong.
func GetHostAndPort(ipPort string) (ip string, port uint16, err error) {
nodeArr := strings.Split(ipPort, ":")
if len(nodeArr) != 2 {
err = fmt.Errorf("node ip and port format invalid. It should be ip:port\n")
hostURL, err := url.Parse("zmq://" + ipPort)
if err != nil {
return
}
ip = hostURL.Hostname()
portStr := hostURL.Port()
if len(portStr) == 0 {
err = fmt.Errorf("port not defined", err)
return
}
ip = nodeArr[0]
portInt, err := strconv.Atoi(nodeArr[1])
portInt, err := strconv.Atoi(portStr)
if err != nil {
err = fmt.Errorf("could not convert port to int: %s\n", err)
err = fmt.Errorf("could not convert port to integer: %s", err)
return
}
port = uint16(portInt)
Expand Down
10 changes: 3 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ For more information, check the [DTC project wiki](https://github.com/niclabs/dt

## The command

Currently it supports the creation of the following configurations:

* RSA

# Quick Use Mode

* Install the same requisites from [DTC](https://github.com/niclabs/dtc) README.
Expand All @@ -23,16 +19,16 @@ Currently it supports the creation of the following configurations:

# How to use

## RSA mode
## Create Configuration mode

`./dtcconfig rsa`
`./dtcconfig create`

The command has the following parameters:

```
-c, --config string path where to output the local config file (default "/etc/dtc/dtc-config.yaml")
-d, --db string path to a file where to put Sqlite3 database (default "/etc/dtc/db.sqlite3")
-h, --help help for rsa
-h, --help help for command
-H, --host string (Required) IP or domain name that the nodes will see from the client
-l, --log string path to a file where to output the services logs (default "/var/log/dtc.log")
-n, --nodes strings (Required) comma separated list of nodes in ip:port format
Expand Down

0 comments on commit 355295c

Please sign in to comment.