Skip to content

Commit 44cec8e

Browse files
committed
Relax public key validation for old (possibly non-conforming) keys.
1 parent 7f766a2 commit 44cec8e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: app/controllers/gitolite_public_keys_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ def find_gitolite_public_key
127127

128128
def destroy_key
129129
@gitolite_public_key[:active] = 0
130-
@gitolite_public_key.save
130+
131+
# Since we are ultimately destroying this key, just force save (since old keys may fail new validations)
132+
@gitolite_public_key.save((Rails::VERSION::STRING.split('.')[0].to_i > 2) ? { :validate => false } : false)
133+
131134
flash[:notice] = l(:notice_public_key_deleted, :title=>keylabel(@gitolite_public_key))
132135
end
133136
end

Diff for: app/models/gitolite_public_key.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,18 @@ def self.user_to_user_token(user)
9898

9999
# Strip leading and trailing whitespace
100100
def strip_whitespace
101+
# Don't mess with existing keys (since cannot change key text anyway)
102+
return if !new_record?
103+
101104
self.title = title.strip
102105
self.key = key.strip
103106
end
104107

105108
# Remove control characters from key
106109
def remove_control_characters
110+
# Don't mess with existing keys (since cannot change key text anyway)
111+
return if !new_record?
112+
107113
# First -- let the first control char or space stand (to divide key type from key)
108114
# Really, this is catching a special case in which there is a \n between type and key.
109115
# Most common case turns first space back into space....
@@ -126,7 +132,7 @@ def has_not_been_changed
126132
end
127133

128134
def key_format_and_uniqueness
129-
return if key.blank? || !new_record?
135+
return if key.blank?
130136

131137
# First, check that key crypto type is present and of correct form. Also, decode base64 and see if key
132138
# crypto type matches. Note that we ignore presence of comment!
@@ -185,6 +191,7 @@ def key_format_and_uniqueness
185191
allkeys += (GitolitePublicKey.active.all)
186192

187193
allkeys.each do |existingkey|
194+
next if existingkey.id == id
188195
existingpieces = existingkey.key.match(/^(\S+)\s+(\S+)/)
189196
if existingpieces && (existingpieces[2] == keypieces[2])
190197
# Hm.... have a duplicate key!

0 commit comments

Comments
 (0)