Skip to content

Commit 22ad514

Browse files
xor-gatetechknowlogick
authored andcommitted
Fix issue where ecdsa and other key types are not synced from LDAP (#5092) (#5094)
* Fix issue where ecdsa and other key types are not synced from LDAP authentication provider fixes #5092 * integrations/auth_ldap_test.go: Add Hermes Conrad new ecdsa-sha2-nistp256 publickey fingerprint * integrations/auth_ldap_test.go: Use ssh-keygen -lf <filename> -E sha256
1 parent b686bd0 commit 22ad514

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

integrations/auth_ldap_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var gitLDAPUsers = []ldapUser{
4343
SSHKeys: []string{
4444
"SHA256:qLY06smKfHoW/92yXySpnxFR10QFrLdRjf/GNPvwcW8",
4545
"SHA256:QlVTuM5OssDatqidn2ffY+Lc4YA5Fs78U+0KOHI51jQ",
46+
"SHA256:DXdeUKYOJCSSmClZuwrb60hUq7367j4fA+udNC3FdRI",
4647
},
4748
IsAdmin: true,
4849
},

models/user.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/go-xorm/xorm"
3030
"github.com/nfnt/resize"
3131
"golang.org/x/crypto/pbkdf2"
32+
"golang.org/x/crypto/ssh"
3233

3334
"code.gitea.io/git"
3435
api "code.gitea.io/sdk/gitea"
@@ -1454,7 +1455,8 @@ func deleteKeysMarkedForDeletion(keys []string) (bool, error) {
14541455
func addLdapSSHPublicKeys(s *LoginSource, usr *User, SSHPublicKeys []string) bool {
14551456
var sshKeysNeedUpdate bool
14561457
for _, sshKey := range SSHPublicKeys {
1457-
if strings.HasPrefix(strings.ToLower(sshKey), "ssh") {
1458+
_, _, _, _, err := ssh.ParseAuthorizedKey([]byte(sshKey))
1459+
if err == nil {
14581460
sshKeyName := fmt.Sprintf("%s-%s", s.Name, sshKey[0:40])
14591461
if _, err := AddPublicKey(usr.ID, sshKeyName, sshKey, s.ID); err != nil {
14601462
log.Error(4, "addLdapSSHPublicKeys[%s]: Error adding LDAP Public SSH Key for user %s: %v", s.Name, usr.Name, err)

0 commit comments

Comments
 (0)