-
Couldn't load subscription status.
- Fork 716
Compatibility with Ubuntu 18.04 LTS (bionic) as a host OS #331
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| package sshutil | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "errors" | ||
| "fmt" | ||
| "io/fs" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
| "sync" | ||
|
|
||
| "github.com/coreos/go-semver/semver" | ||
| "github.com/lima-vm/lima/pkg/lockutil" | ||
| "github.com/lima-vm/lima/pkg/osutil" | ||
| "github.com/lima-vm/lima/pkg/store/dirnames" | ||
|
|
@@ -102,6 +106,15 @@ func DefaultPubKeys(loadDotSSH bool) ([]PubKey, error) { | |
| return res, nil | ||
| } | ||
|
|
||
| var sshInfo struct { | ||
| sync.Once | ||
| // aesAccelerated is set to true when AES acceleration is available. | ||
| // Available on almost all modern Intel/AMD processors. | ||
| aesAccelerated bool | ||
| // openSSHVersion is set to the version of OpenSSH, or semver.New("0.0.0") if the version cannot be determined. | ||
| openSSHVersion semver.Version | ||
| } | ||
|
|
||
| func CommonArgs(useDotSSH bool) ([]string, error) { | ||
| configDir, err := dirnames.LimaConfigDir() | ||
| if err != nil { | ||
|
|
@@ -159,16 +172,24 @@ func CommonArgs(useDotSSH bool) ([]string, error) { | |
| "-F", "/dev/null", | ||
| ) | ||
|
|
||
| // By default, `ssh` choose [email protected], even when AES accelerator is available. | ||
| // (OpenSSH_8.1p1, macOS 11.6, MacBookPro 2020, Core i7-1068NG7) | ||
| // | ||
| // We prioritize AES algorithms when AES accelerator is available. | ||
| if aesAccelerated { | ||
| logrus.Debugf("AES accelerator seems available, prioritizing [email protected] and [email protected]") | ||
| args = append(args, "-o", "Ciphers=^[email protected],[email protected]") | ||
| } else { | ||
| logrus.Debugf("AES accelerator does not seem available, prioritizing [email protected]") | ||
| args = append(args, "-o", "Ciphers=^[email protected]") | ||
| sshInfo.Do(func() { | ||
| sshInfo.aesAccelerated = detectAESAcceleration() | ||
| sshInfo.openSSHVersion = detectOpenSSHVersion() | ||
| }) | ||
|
|
||
| // Only OpenSSH version 8.0 and later support adding ciphers to the front of the default set | ||
| if !sshInfo.openSSHVersion.LessThan(*semver.New("8.0.0")) { | ||
| // By default, `ssh` choose [email protected], even when AES accelerator is available. | ||
| // (OpenSSH_8.1p1, macOS 11.6, MacBookPro 2020, Core i7-1068NG7) | ||
| // | ||
| // We prioritize AES algorithms when AES accelerator is available. | ||
| if sshInfo.aesAccelerated { | ||
| logrus.Debugf("AES accelerator seems available, prioritizing [email protected] and [email protected]") | ||
| args = append(args, "-o", "Ciphers=^[email protected],[email protected]") | ||
| } else { | ||
| logrus.Debugf("AES accelerator does not seem available, prioritizing [email protected]") | ||
| args = append(args, "-o", "Ciphers=^[email protected]") | ||
| } | ||
| } | ||
| return args, nil | ||
| } | ||
|
|
@@ -195,7 +216,25 @@ func SSHArgs(instDir string, useDotSSH bool) ([]string, error) { | |
| return args, nil | ||
| } | ||
|
|
||
| // aesAccelerated is set to true when AES acceleration is available. | ||
| // | ||
| // Available on almost all modern Intel/AMD processors. | ||
| var aesAccelerated = detectAESAcceleration() | ||
| func detectOpenSSHVersion() semver.Version { | ||
| var ( | ||
| v semver.Version | ||
| stderr bytes.Buffer | ||
| ) | ||
| cmd := exec.Command("ssh", "-V") | ||
| cmd.Stderr = &stderr | ||
| if err := cmd.Run(); err != nil { | ||
| logrus.Warnf("failed to run %v: stderr=%q", cmd.Args, stderr.String()) | ||
| } else { | ||
| regex := regexp.MustCompile(`^OpenSSH_(\d+\.\d+)(?:p(\d+))?\b`) | ||
| matches := regex.FindSubmatch(stderr.Bytes()) | ||
| if len(matches) == 3 { | ||
| if len(matches[2]) == 0 { | ||
| matches[2] = []byte("0") | ||
| } | ||
| v = *semver.New(fmt.Sprintf("%s.%s", matches[1], matches[2])) | ||
| } | ||
| } | ||
| logrus.Debugf("OpenSSH version %s detected", v) | ||
| return v | ||
| } | ||
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.
Can we have unit tests?
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.
Just for the regexp? Then yes, we can move it to a separate function that can be tested without calling
ssh -V.