[crypto] #29286: proposal for interface which exposes either callback or db.

9 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Dec 15, 2018, 5:23:45 PM12/15/18
to Filippo Valsorda, Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

#29286: proposal for interface which exposes either callback or db.

https://github.com/golang/go/issues/29286

Change-Id: I36458d88170147d2394832b6a9daa95b324015ec
GitHub-Last-Rev: 19b2e7ecb2c88ce500efd673f2c313c957740144
GitHub-Pull-Request: golang/crypto#68
---
M ssh/knownhosts/knownhosts.go
1 file changed, 58 insertions(+), 0 deletions(-)

diff --git a/ssh/knownhosts/knownhosts.go b/ssh/knownhosts/knownhosts.go
index bc3db73..c4851b5 100644
--- a/ssh/knownhosts/knownhosts.go
+++ b/ssh/knownhosts/knownhosts.go
@@ -124,6 +124,13 @@
return l.matcher.match(a)
}

+type KnownHostDB interface {
+ // HostKeyCallback is knownhosts.New without the DB initialization.
+ HostKeyCallback() ssh.HostKeyCallback
+ // HostKeyAlgorithms takes an address and returns a list of matching key types.
+ HostKeyAlgorithms(address string) ([]string, error)
+}
+
type hostKeyDB struct {
// Serialized version of revoked keys
revoked map[string]*KnownKey
@@ -350,6 +357,30 @@
return db.checkAddr(hostToCheck, remoteKey)
}

+// HostKeyAlgorithms returns a list of host key algorithms associated
+// with the given address to ensure we try to match keys we have
+func (db *hostKeyDB) HostKeyAlgorithms(address string) ([]string, error) {
+ // This can be refactored but illustrating that the code is
+ // from check().
+ // Give preference to the hostname if available.
+ knownTypes := []string{}
+
+ host, port, err := net.SplitHostPort(address)
+ if err != nil {
+ return knownTypes, fmt.Errorf("knownhosts: SplitHostPort(%s): %v", address, err)
+ }
+
+ a := addr{host, port}
+
+ // a used here to illustrate similarity to checkAddr
+ for _, l := range db.lines {
+ if l.match(a) {
+ knownTypes = append(knownTypes, l.knownKey.Key.Type())
+ }
+ }
+ return knownTypes, nil
+}
+
// checkAddrs checks if we can find the given public key for any of
// the given addresses. If we only find an entry for the IP address,
// or only the hostname, then this still succeeds.
@@ -408,6 +439,23 @@
return scanner.Err()
}

+// NewDB creates a new Host Key database from the files given and returns it.
+// New could be composed from this and db.HostKeyCallback()
+func NewDB(files ...string) (KnownHostDB, error) {
+ db := newHostKeyDB()
+ for _, fn := range files {
+ f, err := os.Open(fn)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ if err := db.Read(f, fn); err != nil {
+ return nil, err
+ }
+ }
+ return db, nil
+}
+
// New creates a host key callback from the given OpenSSH host key
// files. The returned callback is for use in
// ssh.ClientConfig.HostKeyCallback. By preference, the key check
@@ -435,6 +483,16 @@
return certChecker.CheckHostKey, nil
}

+// HostKeyCallback is the way to get the ssh.HostKeyCallback if you have used NewDB
+func (db *hostKeyDB) HostKeyCallback() ssh.HostKeyCallback {
+ var certChecker ssh.CertChecker
+ certChecker.IsHostAuthority = db.IsHostAuthority
+ certChecker.IsRevoked = db.IsRevoked
+ certChecker.HostKeyFallback = db.check
+
+ return certChecker.CheckHostKey
+}
+
// Normalize normalizes an address into the form used in known_hosts
func Normalize(address string) string {
host, port, err := net.SplitHostPort(address)

To view, visit change 154458. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: crypto
Gerrit-Branch: master
Gerrit-Change-Id: I36458d88170147d2394832b6a9daa95b324015ec
Gerrit-Change-Number: 154458
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gobot Gobot (Gerrit)

unread,
Dec 15, 2018, 5:23:48 PM12/15/18
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.

View Change

    To view, visit change 154458. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: crypto
    Gerrit-Branch: master
    Gerrit-Change-Id: I36458d88170147d2394832b6a9daa95b324015ec
    Gerrit-Change-Number: 154458
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gobot Gobot <go...@golang.org>
    Gerrit-Comment-Date: Sat, 15 Dec 2018 22:23:46 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Bryan C. Mills (Gerrit)

    unread,
    Dec 20, 2018, 4:07:33 PM12/20/18
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Bryan C. Mills, Han-Wen Nienhuys, Filippo Valsorda, Gobot Gobot, golang-co...@googlegroups.com

    View Change

    2 comments:

      • Please format the commit message according to https://github.com/golang/go/wiki/CommitMessage.

        The first line should start with the name of the primary package being changed. The issue reference should be:
        Fixes golang/go#29286
        or
        Updates golang/go#29286

    To view, visit change 154458. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: crypto
    Gerrit-Branch: master
    Gerrit-Change-Id: I36458d88170147d2394832b6a9daa95b324015ec
    Gerrit-Change-Number: 154458
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Han-Wen Nienhuys <han...@google.com>
    Gerrit-CC: Bryan C. Mills <bcm...@google.com>
    Gerrit-CC: Filippo Valsorda <fil...@golang.org>
    Gerrit-CC: Gobot Gobot <go...@golang.org>
    Gerrit-Comment-Date: Thu, 20 Dec 2018 21:07:31 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    M Shulhan (Gerrit)

    unread,
    12:34 AM (1 hour ago) 12:34 AM
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Bryan Mills, Filippo Valsorda, Gopher Robot, golang-co...@googlegroups.com

    M Shulhan voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: crypto
    Gerrit-Branch: master
    Gerrit-Change-Id: I36458d88170147d2394832b6a9daa95b324015ec
    Gerrit-Change-Number: 154458
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: M Shulhan <m.sh...@gmail.com>
    Gerrit-CC: Bryan Mills <bcm...@google.com>
    Gerrit-CC: Filippo Valsorda <fil...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Sun, 07 Jun 2026 04:34:48 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages