-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d291f1
commit 08eabe3
Showing
2 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package tunnel | ||
|
||
import ( | ||
"bytes" | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"net" | ||
"strings" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
var errNoHostKeyFound = fmt.Errorf("sshfp: no host key found") | ||
|
||
func dnsHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error { | ||
txtrecords, err := net.LookupTXT("api.holepunch.io") | ||
if err != nil { | ||
return err | ||
} | ||
// SHA256 checksum of key | ||
// TODO should also support other algos | ||
keyFpSHA256 := sha256.Sum256(key.Marshal()) | ||
// TODO very naive way to validate, we should match on key type and algo | ||
// and don't brute force check | ||
for _, entry := range txtrecords { | ||
sshfp := strings.Split(entry, " ") | ||
if len(sshfp) != 3 { | ||
continue | ||
} | ||
fingerPrint := sshfp[2] | ||
fp, err := hex.DecodeString(fingerPrint) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if bytes.Equal(fp, keyFpSHA256[:]) { | ||
return nil | ||
} | ||
} | ||
|
||
return errNoHostKeyFound | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters