diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 4 | ||||
-rw-r--r-- | models/issue.go | 6 | ||||
-rw-r--r-- | models/ssh_key.go | 47 |
3 files changed, 17 insertions, 40 deletions
diff --git a/models/action.go b/models/action.go index 4e5f461a..33d5246e 100644 --- a/models/action.go +++ b/models/action.go @@ -123,6 +123,10 @@ func (a *Action) ShortRepoName() string { } func (a *Action) GetRepoPath() string { + return path.Join(a.RepoUserName, a.RepoName) +} + +func (a *Action) ShortRepoPath() string { return path.Join(a.ShortRepoUserName(), a.ShortRepoName()) } diff --git a/models/issue.go b/models/issue.go index 22ea7251..6188da5c 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1595,13 +1595,13 @@ func createComment(e *xorm.Session, u *User, repo *Repository, issue *Issue, com // Notify watchers. act := &Action{ ActUserID: u.Id, - ActUserName: u.LowerName, + ActUserName: u.Name, ActEmail: u.Email, OpType: COMMENT_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]), RepoID: repo.ID, - RepoUserName: repo.Owner.LowerName, - RepoName: repo.LowerName, + RepoUserName: repo.Owner.Name, + RepoName: repo.Name, IsPrivate: repo.IsPrivate, } if err = notifyWatchers(e, act); err != nil { diff --git a/models/ssh_key.go b/models/ssh_key.go index f0db4de4..a7b1680f 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -21,6 +21,7 @@ import ( "github.com/Unknwon/com" "github.com/go-xorm/xorm" + "golang.org/x/crypto/ssh" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" @@ -164,48 +165,20 @@ func CheckPublicKeyString(content string) (_ string, err error) { return "", errors.New("only a single line with a single key please") } - // write the key to a file⦠- tmpFile, err := ioutil.TempFile(os.TempDir(), "keytest") - if err != nil { - return "", err + fields := strings.Fields(content) + if len(fields) < 2 { + return "", errors.New("too less fields") } - tmpPath := tmpFile.Name() - defer os.Remove(tmpPath) - tmpFile.WriteString(content) - tmpFile.Close() - // Check if ssh-keygen recognizes its contents. - stdout, stderr, err := process.Exec("CheckPublicKeyString", "ssh-keygen", "-lf", tmpPath) + key, err := base64.StdEncoding.DecodeString(fields[1]) if err != nil { - return "", errors.New("ssh-keygen -lf: " + stderr) - } else if len(stdout) < 2 { - return "", errors.New("ssh-keygen returned not enough output to evaluate the key: " + stdout) + return "", fmt.Errorf("StdEncoding.DecodeString: %v", err) } - - // The ssh-keygen in Windows does not print key type, so no need go further. - if setting.IsWindows { - return content, nil - } - - sshKeygenOutput := strings.Split(stdout, " ") - if len(sshKeygenOutput) < 4 { - return content, ErrKeyUnableVerify{stdout} - } - - // Check if key type and key size match. - if !setting.Service.DisableMinimumKeySizeCheck { - keySize := com.StrTo(sshKeygenOutput[0]).MustInt() - if keySize == 0 { - return "", errors.New("cannot get key size of the given key") - } - - keyType := strings.Trim(sshKeygenOutput[len(sshKeygenOutput)-1], " ()\n") - if minimumKeySize := setting.Service.MinimumKeySizes[keyType]; minimumKeySize == 0 { - return "", fmt.Errorf("unrecognized public key type: %s", keyType) - } else if keySize < minimumKeySize { - return "", fmt.Errorf("the minimum accepted size of a public key %s is %d", keyType, minimumKeySize) - } + pkey, err := ssh.ParsePublicKey([]byte(key)) + if err != nil { + return "", fmt.Errorf("ParsePublicKey: %v", err) } + log.Trace("Key type: %s", pkey.Type()) return content, nil } |