This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proxy SSH traffic through krkeyfilter
send host authentication replies to krd include corresponding host authentication in signature request to enclave
- Loading branch information
Showing
7 changed files
with
271 additions
and
20 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,7 @@ | ||
package kr | ||
|
||
type HostAuth struct { | ||
HostKey []byte `json:"host_key"` | ||
Signature []byte `json:"signature"` | ||
HostNames []string `json:"host_names"` | ||
} |
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,57 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
func parseSessionFromSignaturePayload(data []byte) (session []byte, err error) { | ||
// from https://github.com/golang/crypto/blob/master/ssh/common.go#L243-L264 | ||
signedDataFormat := struct { | ||
Session []byte | ||
Type byte | ||
User string | ||
Service string | ||
Method string | ||
Sign bool | ||
Algo []byte | ||
PubKey []byte | ||
}{} | ||
err = ssh.Unmarshal(data, &signedDataFormat) | ||
if err != nil { | ||
return | ||
} | ||
log.Notice(fmt.Sprintf("%+v", signedDataFormat)) | ||
session = signedDataFormat.Session | ||
return | ||
} | ||
|
||
func hostForPublicKey(pk ssh.PublicKey) (hosts []string, err error) { | ||
marshaledPk := pk.Marshal() | ||
knownHostsBytes, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".ssh", "known_hosts")) | ||
if err != nil { | ||
return | ||
} | ||
var rest []byte | ||
rest = knownHostsBytes | ||
for { | ||
_, hosts, hostPubkey, _, knownHostsBytes, err := ssh.ParseKnownHosts(rest) | ||
if hostPubkey != nil && bytes.Equal(hostPubkey.Marshal(), marshaledPk) { | ||
return hosts, nil | ||
} | ||
rest = knownHostsBytes | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
continue | ||
} | ||
} | ||
return | ||
} |
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
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
Oops, something went wrong.