MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / sshSaveEmptyPassphrase

Method sshSaveEmptyPassphrase

cli/pkg/common/sshremote.go:657–717  ·  view source on GitHub ↗

ExecSSHSetPasswordPolicy func GetBasicPassword(host string, token string, ownerGuid string) (password string, err error) { password = "" var ws []WorkspacePolicy ws, err = GetWSPolicies("3", host, token, ownerGuid) if len(ws) > 0 { detail := Detail{} if ws[len(ws)-1].Detail != "" { err =

()

Source from the content-addressed store, hash-verified

655
656// 保存一个空密码,保证后续的git clone不需要输入私钥的密码
657func (instance *SSHRemote) sshSaveEmptyPassphrase() {
658 // 如果本身就是空密码,就不需要执行了
659 output, _ := instance.ExeSSHCommand("ssh-keygen -f ~/.ssh/id_rsa -p")
660 if !strings.Contains(output, "Enter old passphrase") {
661 return
662 }
663
664 session, err := instance.Connection.NewSession()
665 CheckError(err)
666 defer session.Close()
667
668 modes := ssh.TerminalModes{
669 ssh.ECHO: 0, // disable echoing
670 ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
671 ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
672 }
673
674 err = session.RequestPty("xterm", 80, 40, modes)
675 CheckError(err)
676
677 stdoutB := new(bytes.Buffer)
678 session.Stdout = stdoutB
679 in, _ := session.StdinPipe()
680
681 go func(in io.Writer, output *bytes.Buffer) {
682
683 var t int = 0
684
685 for {
686 str := string(output.Bytes()[t:])
687 if str == "" {
688 continue
689 }
690
691 t = output.Len()
692
693 if strings.Contains(str, "Enter old passphrase") {
694 SmartIDELog.Console(i18n.GetInstance().Common.Info_please_enter_password)
695
696 password, err := gopass.GetPasswdMasked()
697 CheckError(err)
698
699 _, err = in.Write([]byte(string(password) + "\n"))
700 CheckError(err)
701 } else if strings.Contains(str, "Enter new passphrase (empty for no passphrase)") {
702 _, err = in.Write([]byte("\n"))
703 CheckError(err)
704 } else if strings.Contains(str, "Enter same passphrase again") {
705 _, err = in.Write([]byte("\n"))
706 CheckError(err)
707 SmartIDELog.Info(i18nInstance.Common.Info_ssh_rsa_cancel_pwd_successed)
708 break
709 } else {
710 SmartIDELog.Debug(str)
711 }
712 }
713 }(in, stdoutB)
714

Callers 1

ExecSSHkeyPolicyMethod · 0.95

Calls 7

ExeSSHCommandMethod · 0.95
CheckErrorFunction · 0.85
ConsoleMethod · 0.80
WriteMethod · 0.80
InfoMethod · 0.80
DebugMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected