Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go testclient #93

Closed
wants to merge 46 commits into from
Closed

go testclient #93

wants to merge 46 commits into from

Conversation

liamsi
Copy link
Member

@liamsi liamsi commented Sep 24, 2016

Minimalistic test-client. Part of #90.

  • currently registration & lookup is implemented

Differences to a real client implementation:

  • client doesn't use (twitter-)bot for registration (see discussion: Client cli #90 (comment))
  • thus, registration only works from the same machine as the server is running on
  • client does not store and verify the hash chain
  • client uses testutils package (which doesn't verify server's tls-cert. chain, for instance)

I would prefer to have the current code reviewed and create separate (smaller) issues/PRs for the above bullet-points.

TODOs:

@liamsi liamsi force-pushed the client_go branch 3 times, most recently from 6e9a1fb to 026d786 Compare September 25, 2016 17:20
@liamsi liamsi changed the title [WIP] Client go Client go Sep 25, 2016
@liamsi
Copy link
Member Author

liamsi commented Sep 25, 2016

@c633 @masomel @arlolra Whoever has time: I think this is ready for a first review.

Start the server and play around with:

cd $GOPATH/src/github.com/coniks-sys/coniks-go/client/testclient/
go build 
./testclient register -n alice -k totally-fake-key -s /tmp/coniks.sock # adjust the socket according to your server config
./testclient lookup -n alice
./testclient lookup -n aaalice
# wait for epoch to finish and again try
./testclient lookup -n alice

@liamsi liamsi changed the title Client go go testclient Sep 25, 2016
@@ -107,7 +107,7 @@ func (server *ConiksServer) makeHandler(acceptableTypes map[int]bool) func(msg [
response, e := server.dir.HandleOps(req)
switch req.Type {
case KeyLookupType, KeyLookupInEpochType, MonitoringType:
server.RLock()
server.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

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

Could you rebase this pull on top of master branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

fmt.Println("Error while retrieving repsonse: " + err.Error())
os.Exit(-1)
}
response, errCode := client.UnmarshalResponse(p.KeyLookupType,
Copy link
Member

Choose a reason for hiding this comment

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

For L36 - L80, I think we will eventually have client.Verify(operationType, response) function that wraps all these verifications. This function would also need to handle this TODO (https://github.com/coniks-sys/coniks-go/blob/master/client/cgo/verification.go#L40-L45), much like what you did below. What do you think?

The same for registration code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense! Do you think this should be done in this PR, too? (or in a separate one)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe in a separate one. I can handle this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe in a separate one. I can handle this.

I could also take care of this (if you haven't started yet)

Copy link
Member

@vqhuy vqhuy Oct 11, 2016

Choose a reason for hiding this comment

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

Thanks! I'm working on this in #74. How do you feel about https://github.com/coniks-sys/coniks-go/blob/f0e42ca6d6ce4b0ade502a769f4b8727d8c295d8/client/client.go?

I think we should have a Client struct in protocol package and make msg.Verify()'s arguments as its fields. (I'm working on this)

c := res.Verify(name, []byte(res.AP.Leaf.Value), 0, nil,
conf.SigningPubKey)
// verify auth. path:
if c != p.Passed || res.AP == nil ||
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I guess this makes sense. Especially if we want a clear API someone can use as a reference to implement his own client.

Copy link
Member

Choose a reason for hiding this comment

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

If we do so, should we also need to verify the hash chain as well?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can store the latest STR to client/config.toml (with an explanation that that field is being used for testing only, the developers should actually store the latest STR in some persistent storages) and whenever the test client runs, it reads the latest STR from this config file. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we do so, should we also need to verify the hash chain as well?

I think, yes we should.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can store the latest STR to client/config.toml

Yeah, maybe for testing purposes that's a good idea!

@masomel
Copy link
Member

masomel commented Sep 26, 2016

@liamsi I'm trying to run the test client with the following command:

testclient register -config /disk/local/melara/coniks-testclient/config.toml -n alice -k totally-fake-key -s /tmp/coniks.sock

and get the following error: Failed to load config: open onfig: no such file or directory. The -config flag doesn't seem to be working (looks like it's interpreting -config as -c onfig). Is this expected?

@liamsi
Copy link
Member Author

liamsi commented Sep 26, 2016

@masomel It seems like you have to call it with --config instead of -config if you choose the long flag name. I didn't know that either (I'm using the cobra framework for the first time, too). If you run it with the -h flag it shows -c, --config string Config file ....


The client looks for a file called 'config.toml' in its current working directory.
If you prefer the config-file to be named or stored somewhere different you can
specify where to look for the config with the -config flag. For example:
Copy link
Member

Choose a reason for hiding this comment

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

-config should be --config or -c

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, fixed in: a1f8c6f

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a mkConfig is fair enough? (see my comment #93 (comment)).

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not fully understand your comment. I guess, you mean create a mkConfigjust for the client (makes sense); but how does that relate to storing the STR in the config, too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you proposing that for boostraping the chain we should write the initial STR into the config file? If yes, mkConfig is called before the server is started and hence before the first STR is created.

Copy link
Member

Choose a reason for hiding this comment

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

I just want to have a generated template file for the test client.

Are you proposing that for boostraping the chain we should write the initial STR into the config file?

It's a good idea. But do we run the test client on the same machine as the key server?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just want to have a generated template file for the test client.

OK, makes sense.

It's a good idea. But do we run the test client on the same machine as the key server?

Currently, the testclient only works if ran on the same machine as the key-server: #90 (comment)
Eventually, this will change.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, great!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done (mkConfig) as discussed in 2638588

Copy link
Member

Choose a reason for hiding this comment

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

Great!

For more information consult: https://godoc.org/github.com/coniks-sys/coniks-go/bots

Example call:
coniksclient register -name Alice@twitter -key fake_test_key`,
Copy link
Member

Choose a reason for hiding this comment

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

s/-name/--name and s/-key/--key

Copy link
Member Author

Choose a reason for hiding this comment

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

I should have sticked with the short version of flags in the usage string (which I tried myself) ;-) Thanks for testing it! Fixed in bd8d071

@masomel masomel added this to the 0.1.0 milestone Sep 29, 2016
fmt.Println("Succesfully registered name: " + name)
// TODO Where should the client save seen STRs and the TB?
// (or should it wait till the next epoch to see if the
// TB was actually inserted?)
Copy link
Member

Choose a reason for hiding this comment

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

There maybe have more than one TB since the client could also receive the TB of her contacts, and we definitely have to check if the TB as been included as promised. Given that we will have a ConiksClient to store verified STRs and TBs (see 266d8cd#diff-75d470fe65b4ef49cd55654004d3edeaR29), I'm thinking that should we store both STRs and TBs in this struct?

Copy link
Member Author

Choose a reason for hiding this comment

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

There maybe have more than one TB since the client could also receive the TB of her contacts, and we definitely have to check if the TB as been included as promised.

The client struct looks definitely like a good idea and I agree this would be the good place to store STRs and TBs (at least in memory). The current ConiksClient also only stores one TB, or not?

Copy link
Member

Choose a reason for hiding this comment

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

It should store an array of TB. Wait me a sec.

}
req, err := createLookupRequest(name)
if err != nil {
fmt.Println("Couldn'r create request!")
Copy link
Member

Choose a reason for hiding this comment

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

Nit-picking: s/Couldn'r/Couldn't

"github.com/spf13/cobra"
)

// TODO figure out if this needs to be a separate command or we can simply re-use
Copy link
Member

Choose a reason for hiding this comment

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

Or we can temporarily remove this command?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed ...

Use: "register",
Short: "Register a name-to-key binding.",
Long: `Register a new name-to-key binding on the CONIKS-server.
Note that, for the registration to work, the test-client needs to be running on the same machine as the key-server.
Copy link
Member

Choose a reason for hiding this comment

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

Since #130 has landed, could we remove this note?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also removed

@liamsi liamsi force-pushed the client_go branch 3 times, most recently from 7abbabc to ea9a12d Compare November 24, 2016 17:51
var res []byte
if conf.RegAddress == "" {
// fallback to conf.Address if empty
conf.RegAddress = conf.Address
Copy link
Member

Choose a reason for hiding this comment

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

Can we define a regAddress := conf.RegAddress above and then set that here?

}

func createRegistrationMsg(name, key string) ([]byte, error) {
return json.Marshal(&p.Request{
Copy link
Member

Choose a reason for hiding this comment

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

This probably belongs in encoding.go

// TODO: Save the cc to verify the TB and for later
// usage (TOFU checks)
case p.ReqNameExisted:
// Key-change isn't currently supported; see:
Copy link
Member

Choose a reason for hiding this comment

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

We won't be here for a key change because we won't get a .CheckPassed

Copy link
Member

Choose a reason for hiding this comment

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

Probably we should finish #133 first.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, can we remove this comment in favour of a pointer to that then?

case p.ReqSuccess:
key, err := response.GetKey()
if err != nil {
fmt.Println("Cannot the key from the response, error: " + err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

Cannot get the key

@arlolra
Copy link
Member

arlolra commented Nov 27, 2016

I think this looks good. You should squash and merge it ;)

@liamsi
Copy link
Member Author

liamsi commented Nov 27, 2016

I think this looks good. You should squash and merge it ;)

I've followed the latest changes and I agree (I might be biased, though ;-). Thanks again for taking care and finishing/cleaning up this PR @c633 @arlolra!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants