Skip to content
Snippets Groups Projects
Commit 9e81c8f8 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Add a `getndf` subcommand to client

parent c38a9609
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,43 @@ GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/clien
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o release/client.darwin64 main.go
```
To get an NDF from a network gateway and the permissioning server, use the `getndf` subcommand. The `getndf` subcommand allows command line users to poll the NDF from both a gateway and the permissioning server without any pre-established client connection. It requires an IP address, port, and ssl certificate. You can download an ssl cert with:
```
openssl s_client -showcerts -connect permissioning.prod.cmix.rip:11420 < /dev/null 2>&1 | openssl x509 -outform PEM > certfile.pem
```
Example usage for Gateways:
```
$ go run main.go getndf --gwhost localhost:8440 --cert ~/integration/keys/cmix.rip.crt | jq . | head
{
"Timestamp": "2021-01-29T01:19:49.227246827Z",
"Gateways": [
{
"Id": "BRM+Iotl6ujIGhjRddZMBdauapS7Z6jL0FJGq7IkUdYB",
"Address": ":8440",
"Tls_certificate": "-----BEGIN CERTIFICATE-----\nMIIDbDCCAlSgAwIBAgIJAOUNtZneIYECMA0GCSqGSIb3DQEBBQUAMGgxCzAJBgNV\nBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlDbGFyZW1vbnQx\nGzAZBgNVBAoMElByaXZhdGVncml0eSBDb3JwLjETMBEGA1UEAwwKKi5jbWl4LnJp\ncDAeFw0xOTAzMDUxODM1NDNaFw0yOTAzMDIxODM1NDNaMGgxCzAJBgNVBAYTAlVT\nMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQHDAlDbGFyZW1vbnQxGzAZBgNV\nBAoMElByaXZhdGVncml0eSBDb3JwLjETMBEGA1UEAwwKKi5jbWl4LnJpcDCCASIw\nDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAPP0WyVkfZA/CEd2DgKpcudn0oDh\nDwsjmx8LBDWsUgQzyLrFiVigfUmUefknUH3dTJjmiJtGqLsayCnWdqWLHPJYvFfs\nWYW0IGF93UG/4N5UAWO4okC3CYgKSi4ekpfw2zgZq0gmbzTnXcHF9gfmQ7jJUKSE\ntJPSNzXq+PZeJTC9zJAb4Lj8QzH18rDM8DaL2y1ns0Y2Hu0edBFn/OqavBJKb/uA\nm3AEjqeOhC7EQUjVamWlTBPt40+B/6aFJX5BYm2JFkRsGBIyBVL46MvC02MgzTT9\nbJIJfwqmBaTruwemNgzGu7Jk03hqqS1TUEvSI6/x8bVoba3orcKkf9HsDjECAwEA\nAaMZMBcwFQYDVR0RBA4wDIIKKi5jbWl4LnJpcDANBgkqhkiG9w0BAQUFAAOCAQEA\nneUocN4AbcQAC1+b3To8u5UGdaGxhcGyZBlAoenRVdjXK3lTjsMdMWb4QctgNfIf\nU/zuUn2mxTmF/ekP0gCCgtleZr9+DYKU5hlXk8K10uKxGD6EvoiXZzlfeUuotgp2\nqvI3ysOm/hvCfyEkqhfHtbxjV7j7v7eQFPbvNaXbLa0yr4C4vMK/Z09Ui9JrZ/Z4\ncyIkxfC6/rOqAirSdIp09EGiw7GM8guHyggE4IiZrDslT8V3xIl985cbCxSxeW1R\ntgH4rdEXuVe9+31oJhmXOE9ux2jCop9tEJMgWg7HStrJ5plPbb+HmjoX3nBO04E5\n6m52PyzMNV+2N21IPppKwA==\n-----END CERTIFICATE-----\n"
},
{
"Id": "JCBd9mAQb2BW8hc8H9avy1ubcjUAa7MHrPp0dBU/VqQB",
```
Example usage for the Permissioning server:
```
$ go run main.go getndf --permhost localhost:18000 --cert ~/integration/keys/cmix.rip.crt | jq . | head
{
"Timestamp": "2021-01-29T01:19:49.227246827Z",
"Gateways": [
{
"Id": "BRM+Iotl6ujIGhjRddZMBdauapS7Z6jL0FJGq7IkUdYB",
"Address": ":8440",
"Tls_certificate": "-----BEGIN CERTIFICATE-----\nMIIDbDCCAlSgAwIBAgIJAOUNtZneIYECM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V3xIl985cbCxSxeW1R\ntgH4rdEXuVe9+31oJhmXOE9ux2jCop9tEJMgWg7HStrJ5plPbb+HmjoX3nBO04E5\n6m52PyzMNV+2N21IPppKwA==\n-----END CERTIFICATE-----\n"
},
{
"Id": "JCBd9mAQb2BW8hc8H9avy1ubcjUAa7MHrPp0dBU/VqQB",
```
Basic command line usage, sending unsafe, unencrypted messages to yourself:
```
......
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
// Package cmd initializes the CLI and config parsers as well as the logger.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
// "gitlab.com/elixxir/client/interfaces/contact"
// "gitlab.com/elixxir/client/interfaces/message"
// "gitlab.com/elixxir/client/switchboard"
// "gitlab.com/elixxir/client/ud"
// "gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/comms/client"
"gitlab.com/xx_network/comms/connect"
//"time"
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/utils"
)
const opensslCertDL = ("openssl s_client -showcerts -connect ip:port < " +
"/dev/null 2>&1 | openssl x509 -outform PEM > certfile.pem")
// getNDFCmd user discovery subcommand, allowing user lookup and registration for
// allowing others to search.
// This basically runs a client for these functions with the UD module enabled.
// Normally, clients don't need it so it is not loaded for the rest of the
// commands.
var getNDFCmd = &cobra.Command{
Use: "getndf",
Short: ("Download the network definition file from the network " +
"and print it."),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
gwHost := viper.GetString("gwhost")
permHost := viper.GetString("permhost")
certPath := viper.GetString("cert")
// Load the certificate
var cert []byte
if certPath != "" {
cert, _ = utils.ReadFile(certPath)
}
if len(cert) == 0 {
jww.FATAL.Panicf("Could not load a certificate, "+
"provide a certificate file with --cert.\n\n"+
"You can download a cert using openssl:\n\n%s",
opensslCertDL)
}
params := connect.GetDefaultHostParams()
params.AuthEnabled = false
comms, _ := client.NewClientComms(nil, nil, nil, nil)
// Gateway lookup
if gwHost != "" {
host, _ := connect.NewHost(&id.TempGateway, gwHost,
cert, params)
pollMsg := &pb.GatewayPoll{
Partial: &pb.NDFHash{
Hash: nil,
},
LastUpdate: uint64(0),
ClientID: id.DummyUser.Marshal(),
}
resp, err := comms.SendPoll(host, pollMsg)
if err != nil {
jww.FATAL.Panicf("Unable to poll %s for NDF:"+
" %+v",
gwHost, err)
}
fmt.Printf("%s", resp.PartialNDF.Ndf)
return
}
if permHost != "" {
host, _ := connect.NewHost(&id.Permissioning, permHost,
cert, params)
pollMsg := &pb.NDFHash{
Hash: []byte("DummyUserRequest"),
}
resp, err := comms.RequestNdf(host, pollMsg)
if err != nil {
jww.FATAL.Panicf("Unable to ask %s for NDF:"+
" %+v",
permHost, err)
}
fmt.Printf("%s", resp.Ndf)
return
}
fmt.Println("Enter --gwhost or --permhost and --cert please")
},
}
func init() {
getNDFCmd.Flags().StringP("gwhost", "", "",
"Poll this gateway host:port for the NDF")
viper.BindPFlag("gwhost",
getNDFCmd.Flags().Lookup("gwhost"))
getNDFCmd.Flags().StringP("permhost", "", "",
"Poll this permissioning host:port for the NDF")
viper.BindPFlag("permhost",
getNDFCmd.Flags().Lookup("permhost"))
getNDFCmd.Flags().StringP("cert", "", "",
"Check with the TLS certificate at this path")
viper.BindPFlag("cert",
getNDFCmd.Flags().Lookup("cert"))
rootCmd.AddCommand(getNDFCmd)
}
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2020-12-30 13:10:27.265664 -0600 CST m=+0.032380471
// 2021-01-28 22:23:27.98267073 +0000 UTC m=+0.009712900
package globals
const GITVERSION = `8185927 Merge branch 'XX-2971/contactCompression' into 'release'`
const GITVERSION = `c38a960 Merge branch 'XX-3071/knownRoundsImpliesBug' into 'release'`
const SEMVER = "1.4.0"
const DEPENDENCIES = `module gitlab.com/elixxir/client
......@@ -14,31 +14,30 @@ require (
github.com/golang/protobuf v1.4.3
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/mitchellh/mapstructure v1.4.0 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pkg/errors v0.9.1
github.com/smartystreets/assertions v1.0.1 // indirect
github.com/spf13/afero v1.4.0 // indirect
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20201229200853-c403d72e877c
gitlab.com/elixxir/crypto v0.0.7-0.20201222203132-9b4cc1ae3da6
gitlab.com/elixxir/ekv v0.1.4-0.20201217220111-9c7e8be21577
gitlab.com/elixxir/primitives v0.0.3-0.20201229212305-2ab1e938b1cb
gitlab.com/xx_network/comms v0.0.4-0.20201222193955-56206d700360
gitlab.com/xx_network/crypto v0.0.5-0.20201215233953-36cca1af8b2f
gitlab.com/xx_network/primitives v0.0.4-0.20201229212313-fe33d9809f27
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e // indirect
google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4 // indirect
google.golang.org/grpc v1.33.2 // indirect
gitlab.com/elixxir/comms v0.0.4-0.20210125231706-c782d1f645ea
gitlab.com/elixxir/crypto v0.0.7-0.20210125231257-b52a556be893
gitlab.com/elixxir/ekv v0.1.4
gitlab.com/elixxir/primitives v0.0.3-0.20210126180712-bfbfb725c75a
gitlab.com/xx_network/comms v0.0.4-0.20210121204701-7a1eb0542424
gitlab.com/xx_network/crypto v0.0.5-0.20210121204626-b251b926e4f7
gitlab.com/xx_network/primitives v0.0.4-0.20210121203635-8a771fc14f8a
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20210105210732-16f7687f5001 // indirect
google.golang.org/genproto v0.0.0-20210105202744-fe13368bc0e1 // indirect
google.golang.org/grpc v1.34.0 // indirect
google.golang.org/protobuf v1.25.0
gopkg.in/ini.v1 v1.61.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
)
replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1
......
......@@ -3,7 +3,6 @@ module gitlab.com/elixxir/client
go 1.13
require (
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.4.3
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
......@@ -17,11 +16,9 @@ require (
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.1
github.com/ugorji/go v1.1.4 // indirect
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20210125231706-c782d1f645ea
gitlab.com/elixxir/crypto v0.0.7-0.20210125231257-b52a556be893
gitlab.com/elixxir/comms v0.0.4-0.20210129201143-e9ffafea7e19
gitlab.com/elixxir/crypto v0.0.7-0.20210128232700-0d547d16aff5
gitlab.com/elixxir/ekv v0.1.4
gitlab.com/elixxir/primitives v0.0.3-0.20210126180712-bfbfb725c75a
gitlab.com/xx_network/comms v0.0.4-0.20210121204701-7a1eb0542424
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment