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

prevent running key exchange if hello-only flag set #228

Merged
merged 3 commits into from
Nov 2, 2019

Conversation

thegwan
Copy link
Collaborator

@thegwan thegwan commented Oct 21, 2019

Fixed hello-only bug to prevent key exchange sequence from entering at all if the hello-only flag is set

@thegwan
Copy link
Collaborator Author

thegwan commented Oct 21, 2019

It looks like the continuous integration test is failing on cannot find package "github.com/cespare/xxhash/v2", but I don't think I'm using this?

@dadrian
Copy link
Member

dadrian commented Oct 22, 2019

@thegwan if you cherry-pick 8e713fa onto this PR, it should fix CI

t.sentInitPacket = nil
t.cond.Broadcast()
t.writtenSinceKex = 0
t.mu.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

The code looks correct, but my only concern is the duplication of the cleanup to unblock writers, and the mutex lock taken before a conditional and then unlocked in the if/else branches of the conditional.

Could the same thing be accomplished by inverting the HelloOnly check, like so:

	t.mu.Lock()

	firstKex := t.sessionID == nil
	if !t.config.HelloOnly {
		err = t.enterKeyExchangeLocked(p)
		if err != nil {
			// drop connection
			t.conn.Close()
			t.writeError = err
		}

		if debugHandshake {
			log.Printf("%s exited key exchange (first %v), err %v", t.id(), firstKex, err)
		}
	}
	// Unblock writers.
	t.sentInitMsg = nil
	t.sentInitPacket = nil
	t.cond.Broadcast()
	t.writtenSinceKex = 0
	t.mu.Unlock()

	if err != nil {
		return nil, err
	}

This does create an unnecessary err check at the end iif HelloOnly is true, but reduces code duplication and keeps the mutex lock/unlock balanced outside conditionals.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sounds good, making the change

@thegwan thegwan merged commit dd47852 into zmap:master Nov 2, 2019
@thegwan thegwan deleted the helloonly-fix branch November 2, 2019 18:51
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.

3 participants