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

Client library for verifications #39

Merged
merged 9 commits into from
Aug 2, 2016
Merged

Client library for verifications #39

merged 9 commits into from
Aug 2, 2016

Conversation

vqhuy
Copy link
Member

@vqhuy vqhuy commented Jul 28, 2016

I merged branch no-getset since we can take the advantages of struct fields (e.g., https://github.com/coniks-sys/coniks-go/blob/9c253690f74c41d9763111bd660cbb8108236b86/client/cgo/coniks.go#L105-L107).
I will fixed other getters when the #36 is clarified.

@arlolra
Copy link
Member

arlolra commented Jul 28, 2016

This is probably just a personal preference thing, but merging in branches complicates rebasing.

Next time you want to depend on another branch, I'd suggest you rebase your change on top of that branch. If that branch is already pushed, you can even create a pull request against that branch so that only the above changes are shown in the PR here.

@vqhuy
Copy link
Member Author

vqhuy commented Jul 28, 2016

Next time you want to depend on another branch, I'd suggest you rebase your change on top of that branch. If that branch is already pushed, you can even create a pull request against that branch so that only the above changes are shown in the PR here.

Yeah, thanks for your advices!

Btw, I also rebased this branch on top of master branch.

unsigned char pk[] = {28,149,90,106,83,99,227,227,211,89,29,250,220,141,17,203,254,130,127,134,175,133,156,164,83,58,139,228,79,64,252,75};
unsigned char m[] = {97,108,105,99,101};
unsigned char index[] = {96,43,9,174,212,169,113,184,98,128,48,210,186,218,171,145,115,82,29,23,177,126,63,169,232,125,248,165,91,134,76,32};
unsigned char proof[] = {213,244,36,141,83,73,206,202,94,3,40,174,237,156,101,140,222,18,24,211,136,24,74,63,246,211,142,186,255,123,73,12,33,252,200,161,18,208,124,150,91,42,229,156,96,225,154,226,206,143,161,1,141,188,34,7,124,45,222,189,89,116,36,3,233,126,71,41,140,29,36,34,138,167,217,239,16,210,51,125,28,127,7,34,89,219,181,82,86,154,10,155,159,144,158,179};
Copy link
Member

Choose a reason for hiding this comment

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

It would be clearer (and easier to maintain) if you moved generating and serializing this data into the go testVRFVerify and passed it as arguments to C.testVRFVerify.

int testVRFVerify(unsigned char *pk, ...) {

At present, it's hard to tell what it is and why it's correct.

Same for all the tests below.

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. Will do it.

Copy link
Member Author

@vqhuy vqhuy Jul 30, 2016

Choose a reason for hiding this comment

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

I fixed it in 763c2649aba5826e3320c48b4eff3a78cfb688a9. I also made some changes on AuthenticationPath struct: converting PrunedTree from slice of slices to slice of arrays; and adding method to get latest STR from PAD (ec3675936cd8e32df44c0f9b494c60aa2df82c23)

@masomel masomel force-pushed the master branch 3 times, most recently from 25a6925 to 2f704cf Compare July 29, 2016 20:03
@vqhuy vqhuy force-pushed the client-cgo branch 3 times, most recently from 6c7ae21 to b246175 Compare July 30, 2016 02:32
@vqhuy
Copy link
Member Author

vqhuy commented Jul 30, 2016

I think this ready for another review @arlolra @liamsi @masomel

@liamsi
Copy link
Member

liamsi commented Jul 30, 2016

Looks good to me!

unsigned char *m, int mSize,
unsigned char *index, int indexSize,
unsigned char *proof, int proofSize) {
if (cgoVrfVerify(pk, pkSize, m, mSize,
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you just return cgoVrfVerify(..)? Why are these if blocks here?

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 make sure the flow: converting from golang types to C types and then from C types to golang types works as expected.

Copy link
Member

Choose a reason for hiding this comment

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

You don't trust the golang developers? :)

Copy link
Member Author

@vqhuy vqhuy Jul 30, 2016

Choose a reason for hiding this comment

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

No, it's not what I mean, haha. I mean my use of something like unsafe.Pointer and others ...
Ok, I agree that they could be simplified as you said.

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 re-read my code and realized that I missed something. What I mean when using these C functions as bridges is that I want to make the same scenario as when the lib being used in the add-on with js-ctypes. That is the input should be type unsigned char* and passed to go functions that take arguments type unsafe.Pointer. Hopefully it makes sense to you.

Copy link
Member

@arlolra arlolra Jul 31, 2016

Choose a reason for hiding this comment

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

Sorry, I probably wasn't being clear. I was asking for this,

int testVRFVerify(unsigned char *pk, int pkSize,
    unsigned char *m, int mSize,
    unsigned char *index, int indexSize,
    unsigned char *proof, int proofSize) {
  return cgoVrfVerify(pk, pkSize, m, mSize,
    index, indexSize, proof, proofSize);
}

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, my bad :(. Thanks!

func main() {}

//export cgoEd25519SignatureVerify
func cgoEd25519SignatureVerify(pk unsafe.Pointer, pkSize C.int,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just call this cgoSignatureVerify to not expose the scheme?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree.

@vqhuy
Copy link
Member Author

vqhuy commented Aug 2, 2016

I wasn't finished reviewing before we went down that rabbit hole last night.

Aw, sorry :(

Would it be possible to rename cgo/coniks.go to something like cgo/verification.go?

Yup, makes sense.

}
}

func testVerifyProofOfAbsenceSamePrefix(t *testing.T) {
Copy link
Member

@masomel masomel Aug 2, 2016

Choose a reason for hiding this comment

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

Just to make sure I've understood this test correctly. The difference between this proof of absence test and the one in VerifyAuthPath is that the string "a" in this test definitely shares the same prefix as "key1", which will give you a user leaf node in the proof? While "123" in the previous test does not share the same prefix as "key1", "key2" or "key3", which will give you an empty node? I'm wondering if we should also be explicitly checking the leaf type in these tests. Though I know this is checked implicitly when the auth path is hashed, so maybe that's enough?

Copy link
Member Author

@vqhuy vqhuy Aug 2, 2016

Choose a reason for hiding this comment

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

Did you mean we need to assert the string "a" shares the same prefix as "key1"?

I copied this test from proof_test.go, and it already has type assertion there. Hopefully it makes it clearer.

Copy link
Member

Choose a reason for hiding this comment

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

No, since this is done in merkletree.VerifyAuthPath(), right? I mean, should we assert that proof.Leaf.IsEmpty() is false for "a" and true for "123" in testVerifyAuthPath() above.

Copy link
Member Author

@vqhuy vqhuy Aug 2, 2016

Choose a reason for hiding this comment

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

No, since this is done in merkletree.VerifyAuthPath(), right?

Yes, it is. So if there is anything go wrong, the hash verification would return false. So I think we don't need to explicitly assert it in these tests.

Copy link
Member

Choose a reason for hiding this comment

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

So if there is anything go wrong, the hash verification would return false.

True. I guess, I thought this was an additional way to test that the hash verification is working. But using the hash verification is probably enough for this assertion.

- added benchmarks for creating large directory and doing lookups from large directory
- TB test
- MakeRand and Digest test
- s/createLargePadForBenchmark/createPad <- could be useful for other tests, too
- added tests for some edge cases
- removed obsolete check `uint64 < 0` which can't happen and error
- benchmark pad.Update(nil) in tree with 10^5 users (takes on average 0.23 s and consumes 72 MB)
- more stress tests/benchmarks for PAD Update and LookUp (used for pprof)
- test coverage in utils package
@@ -19,6 +19,7 @@ hijacking secure communications without getting caught.
## Golang Library
The packages in this library implement the various components of the CONIKS system and may be imported individually.

- ``client``: Client-side protocol implementation
Copy link
Member

@masomel masomel Aug 2, 2016

Choose a reason for hiding this comment

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

Should this explanation say something more like "Client-side protocol cgo (or C?) hooks"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@masomel
Copy link
Member

masomel commented Aug 2, 2016

LGTM.

func cgoVerifySignature(pk unsafe.Pointer, pkSize C.int,
message unsafe.Pointer, size C.int,
sig unsafe.Pointer, sigSize C.int) C.int {
if int(pkSize) < sign.PublicKeySize {
Copy link
Member

Choose a reason for hiding this comment

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

Should we define SignatureSize = 64 in crypto/sign.go?

What's the intention of these quick check anyways? Who are they benefiting? We know the expected lengths of these buffers, except for message. Passing in all these length is kind of verbose, but I guess you're trying to be safe and avoid the chance for an out-of-bounds read.

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 guess you're trying to be safe and avoid the chance for an out-of-bounds read.

Yes, since we are dealing with unsafe.Pointer. Should I remove these checks?

Copy link
Member

Choose a reason for hiding this comment

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

Should I remove these checks?

Nah. But add one for the SignatureSize as well.

@vqhuy vqhuy force-pushed the client-cgo branch 2 times, most recently from 38bbad4 to 03cf223 Compare August 2, 2016 20:44
}
}

func testVerifyHashChain(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice work!

@arlolra
Copy link
Member

arlolra commented Aug 2, 2016

LGTM

Squashed commits:
[03cf223] Fix fatal bug in hash chain verification function
[328b245] Compile client crypto library with cgo
@vqhuy vqhuy merged commit ddf4ab8 into master Aug 2, 2016
@arlolra arlolra deleted the client-cgo branch August 2, 2016 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants