@@ -1588,9 +1588,23 @@ func deleteKeysMarkedForDeletion(keys []string) (bool, error) {
1588
1588
func addLdapSSHPublicKeys (usr * User , s * LoginSource , sshPublicKeys []string ) bool {
1589
1589
var sshKeysNeedUpdate bool
1590
1590
for _ , sshKey := range sshPublicKeys {
1591
- _ , _ , _ , _ , err := ssh .ParseAuthorizedKey ([]byte (sshKey ))
1592
- if err == nil {
1593
- sshKeyName := fmt .Sprintf ("%s-%s" , s .Name , sshKey [0 :40 ])
1591
+ var err error
1592
+ found := false
1593
+ keys := []byte (sshKey )
1594
+ loop:
1595
+ for len (sshKey ) > 0 && err == nil {
1596
+ var out ssh.PublicKey
1597
+ var comment string
1598
+ // We ignore options as they are not relevant to Gitea
1599
+ out , comment , _ , keys , err = ssh .ParseAuthorizedKey (keys )
1600
+ if err != nil {
1601
+ break loop
1602
+ }
1603
+ found = true
1604
+ marshalled := out .Marshal ()
1605
+ sshKeyName := fmt .Sprintf ("%s-%s" , s .Name , marshalled [0 :40 ])
1606
+
1607
+ marshalled = append (marshalled , []byte (" " + comment )... )
1594
1608
if _ , err := AddPublicKey (usr .ID , sshKeyName , sshKey , s .ID ); err != nil {
1595
1609
if IsErrKeyAlreadyExist (err ) {
1596
1610
log .Trace ("addLdapSSHPublicKeys[%s]: LDAP Public SSH Key %s already exists for user" , s .Name , usr .Name )
@@ -1601,7 +1615,8 @@ func addLdapSSHPublicKeys(usr *User, s *LoginSource, sshPublicKeys []string) boo
1601
1615
log .Trace ("addLdapSSHPublicKeys[%s]: Added LDAP Public SSH Key for user %s" , s .Name , usr .Name )
1602
1616
sshKeysNeedUpdate = true
1603
1617
}
1604
- } else {
1618
+ }
1619
+ if ! found && err != nil {
1605
1620
log .Warn ("addLdapSSHPublicKeys[%s]: Skipping invalid LDAP Public SSH Key for user %s: %v" , s .Name , usr .Name , sshKey )
1606
1621
}
1607
1622
}
0 commit comments