-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add OSSH #1098
Draft
hwh33
wants to merge
9
commits into
main
Choose a base branch
from
harry/ossh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+465
−46
Draft
Add OSSH #1098
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
48039f3
Add OSSH
hwh33 67a9f3f
Merge remote-tracking branch 'origin/devel' into harry/ossh
hwh33 551b78c
Upgrade getlantern/http-proxy-lantern
hwh33 fcf5cef
Merge remote-tracking branch 'origin/devel' into harry/ossh
hwh33 db2509b
Update http-proxy-lantern
hwh33 dab3e95
Merge remote-tracking branch 'origin/devel' into harry/ossh
hwh33 0030ea8
Upgrade getlantern/ossh
hwh33 2c1a644
Upgrade getlantern/http-proxy-lantern
hwh33 f90c34e
Fix build error
hwh33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,61 @@ | ||
package chained | ||
|
||
import ( | ||
"context" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"net" | ||
|
||
"golang.org/x/crypto/ssh" | ||
|
||
"github.com/getlantern/errors" | ||
"github.com/getlantern/flashlight/ops" | ||
"github.com/getlantern/netx" | ||
"github.com/getlantern/ossh" | ||
) | ||
|
||
type osshImpl struct { | ||
nopCloser | ||
reportDialCore reportDialCoreFn | ||
addr string | ||
cfg ossh.DialerConfig | ||
} | ||
|
||
func newOSSHImpl(addr string, s *ChainedServerInfo, reportDialCore reportDialCoreFn) (proxyImpl, error) { | ||
keyword := s.ptSetting("ossh_obfuscation_keyword") | ||
if keyword == "" { | ||
return nil, errors.New("obfuscation keyword must be configured") | ||
} | ||
keyPEM := s.ptSetting("ossh_server_public_key") | ||
if keyPEM == "" { | ||
return nil, errors.New("server public key must be configured") | ||
} | ||
keyBlock, rest := pem.Decode([]byte(keyPEM)) | ||
if len(rest) > 0 { | ||
return nil, errors.New("failed to decode server public key as PEM block") | ||
} | ||
if keyBlock.Type != "RSA PUBLIC KEY" { | ||
return nil, errors.New("expected key block of type 'RSA PUBLIC KEY', got %v", keyBlock.Type) | ||
} | ||
rsaKey, err := x509.ParsePKCS1PublicKey(keyBlock.Bytes) | ||
if err != nil { | ||
return nil, errors.New("failed to parse server public key as PKCS1: %v", err) | ||
} | ||
sshKey, err := ssh.NewPublicKey(rsaKey) | ||
if err != nil { | ||
return nil, errors.New("failed to convert RSA key to SSH key: %v", err) | ||
} | ||
cfg := ossh.DialerConfig{ObfuscationKeyword: keyword, ServerPublicKey: sshKey} | ||
|
||
return &osshImpl{reportDialCore: reportDialCore, addr: addr, cfg: cfg}, nil | ||
} | ||
|
||
func (impl *osshImpl) dialServer(op *ops.Op, ctx context.Context) (net.Conn, error) { | ||
tcpConn, err := impl.reportDialCore(op, func() (net.Conn, error) { | ||
return netx.DialContext(ctx, "tcp", impl.addr) | ||
}) | ||
if err != nil { | ||
return nil, errors.New("failed to dial TCP: %v", err) | ||
} | ||
return ossh.Client(tcpConn, impl.cfg) | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean that OSSH is always multiplexed. Would we ever not want to multiplex?