Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Comments

Add gobindClient package and a gobind friendly interface to core/client/kt/verify.go#736

Merged
gdbelvin merged 13 commits intogoogle:masterfrom
AMarcedone:gobind_getEntry
Aug 23, 2017
Merged

Add gobindClient package and a gobind friendly interface to core/client/kt/verify.go#736
gdbelvin merged 13 commits intogoogle:masterfrom
AMarcedone:gobind_getEntry

Conversation

@AMarcedone
Copy link
Contributor

This PR is the first step in modifying the go code to make it gobind friendly.

It allows an android app to make a GetEntry request (which implicitly verifies the response) or to verify a wire encoded proto GetEntryResponse obtained separately.

The code is not ready to merge (you can see lots of TODOs), but early feedback is appreciated.
Will update with a reference to the corresponding PR in keytransparency-java to give you an idea of how the code is used.

@AMarcedone
Copy link
Contributor Author

This depends on google/trillian#734 being merged first. In particular, I am using this trillian: https://github.com/AMarcedone/trillian/tree/signerfactory_replace

@gdbelvin
Copy link
Contributor

gdbelvin commented Aug 9, 2017

Would you mind rebasing this on #716 ?
That should provide a slightly easier interface to work with and avoids creating too many wrapper functions.

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/oauth"
"github.com/google/trillian/crypto/keys/pem"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this file needs a gofmt to keep the imports alphabetized
I've just configured gometalinter for this project. You might enjoy linking it up to your IDE.

package gobindClient

import (
"context"
Copy link
Contributor

@gdbelvin gdbelvin Aug 9, 2017

Choose a reason for hiding this comment

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

It's our convention to organize the imports as follows:

import(
    "golang imports"

    "keytransparency and trillian"

    "third party imports"

    "underscore and renamed imports" 
)

LogPEM []byte
}

// TODO(amarcedone) consider persisting the client or at least the trusted smr, to gain efficiency and stronger consistency guarantees.
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, the design is for the client to persist the trusted SMR itself.
Please create a place for it. Later on we can store and retrieve it from storage etc.


// TODO(amarcedone) consider persisting the client or at least the trusted smr, to gain efficiency and stronger consistency guarantees.

func NewBClientParams(KtURL string, MapID int64, KtTLSCertPEM, VrfPubPEM, KtSigPubKey, LogPEM []byte) *BClientParams {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be easier to pass the PEMs as strings?

return &BClientParams{KtURL, MapID, cKtTLSCertPEM, cVrfPubPEM, cKtSigPubKey, cLogPEM}
}

func BGetEntry(timeoutInMilliseconds int, clientParams *BClientParams, userID, appID string) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

BClientParams is interesting. It looks like it's functioning as a class object?

  • Could we make it a proper class object?
  • If not, it should at least be the first parameter in all function calls.

Copy link
Contributor Author

@AMarcedone AMarcedone Aug 9, 2017

Choose a reason for hiding this comment

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

It can be a proper class (i.e. one can use the syntax BClientParams.MyMethod(myparam) ), but to be directly visible from the Java code it has to only contain members which are gobind friendly.

Another option to increase performance would be to create a client and save it as a global variable of this package, and have GetEntry just use this global client to make requests.
On the java side, we can ensure that there is only one copy of the client available (so only one set of client parameters such as kt address/verification keys can be used at the same time).
Even more, we could use a global variable to store a map of clients (essentially getting around the gobind limitation of not being able to pass around references to arbitrary objects by creating our own reference mechanism), but not sure if that is worth it. Probably one variable as reference would be good for now.

Any thoughts?

}
log := client.NewLogVerifier(hasher, logPubKey)

verifier, err := keymaster.NewVerifierFromPEM(clientParams.KtSigPubKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using the trillian/crypto/keys package for this

// Local copy of io.Writer interface used to redirect logs.
type BWriter interface {
Write(p []byte) (n int, err error)
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

add newline?

return err
}

// TODO(amarcedone) Is context.Background() appropriate here?
Copy link
Contributor

Choose a reason for hiding this comment

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

Context should be created from whatever the equivalent of main is, and passed in as the first argument.

@AMarcedone
Copy link
Contributor Author

Regarding the rebase, this PR does not expose a commitment interface directly to gobind so I do not think it would make any difference.

…ated through gobind. Add support for fetching entries from go directly (i.e. client.GetEntry) and to verify a proto GetEntryResponse obtained separately.
return nil
}

func BInit(timeoutInMs int32) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not use B as a function prefix


func BAddKtServer(ktURL string, insecureTLS bool, ktTLSCertPEM []byte, domainInfoHash []byte) error {
if _, exists := clients[ktURL]; exists == true {
fmt.Errorf("The KtServer connection for %v already exists", ktURL)
Copy link
Contributor

Choose a reason for hiding this comment

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

return error?

fmt.Errorf("The KtServer connection for %v already exists", ktURL)
}

// TODO Add URL validation here.
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO(username):

return []byte{}, err
}

client, exists := clients[ktURL]
Copy link
Contributor

Choose a reason for hiding this comment

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

go style calls exists ok

)

var (
initialized bool
Copy link
Contributor

Choose a reason for hiding this comment

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

remove initalized

Vlog = log.New(ioutil.Discard, "", 0)
)

func checkInitialized() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove


func BGetEntry(ktURL, userID, appID string) ([]byte, error) {

if err := checkInitialized(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

timeout = time.Duration(ms) * time.Millisecond
}

func AddKtServer(ktURL string, insecureTLS bool, ktTLSCertPEM []byte, domainInfoHash []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

AddKTServer

Copy link
Contributor

@gdbelvin gdbelvin left a comment

Choose a reason for hiding this comment

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

This is looking good. Just make Travis happy.

…gcat, as well as standard log. Optionally, vlog can be redirected to a custom java writer
var (
clients map[string]*grpcc.Client = make(map[string]*grpcc.Client)

timeout time.Duration = time.Duration(500) * time.Millisecond
Copy link
Contributor

Choose a reason for hiding this comment

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

just remove the extra cast

if m.writers == nil {
m.writers = []io.Writer{}
}
log.Printf("Added writer: %v", w)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove extra logging statements


type MultiIoWriter struct {
writers []io.Writer
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This belongs in it's own package. client/mutlilogger
Then you can do multilogger.New

@gdbelvin gdbelvin removed the WIP label Aug 23, 2017
@gdbelvin gdbelvin merged commit df5f639 into google:master Aug 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants