Skip to content

Commit 9fb303f

Browse files
committed
switch to [email protected] key names
this allows to exploit a feature of gitolite, in which gitolite will construct the username of the gitolite user only of the part leading up to the @. this makes the gitolite usernames much easier to predict. also removes the "redmine_" prefix. this change might with existing databases, as the format of the gitolite_public_key identifier changes. I had to remove all keys from the database and re-add them once until gitolite worked again correctly.
1 parent 1b8ccdb commit 9fb303f

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

Diff for: app/models/gitolite_public_key.rb

+21-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ def set_identifier
5454
time_tag = "#{my_time.to_i.to_s}_#{my_time.usec.to_s}"
5555
case key_type
5656
when KEY_TYPE_USER
57-
# add "redmine_" as a prefix to the username, and then the current date
58-
# this helps ensure uniqueness of each key identifier
57+
# add current date to the username, this helps ensure uniqueness of each
58+
# key identifier
5959
#
60-
# also, it ensures that it is very, very unlikely to conflict with any
61-
# existing key name if gitolite config is also being edited manually
62-
"redmine_#{self.user.login.underscore}_#{time_tag}".gsub(/[^0-9a-zA-Z\-]/,'_')
60+
# seperate username and date with an @ character. this will cause gitolite
61+
# to ignore everything after the @ when determining the username.
62+
"#{self.user.login.underscore}".gsub(/[^0-9a-zA-Z\-]/,'_') << "@" << "#{time_tag}".gsub(/[^0-9a-zA-Z\-]/,'_')
6363
when KEY_TYPE_DEPLOY
6464
# add "redmine_deploy_key_" as a prefix, and then the current date
6565
# to help ensure uniqueness of each key identifier
@@ -70,6 +70,21 @@ def set_identifier
7070
end
7171
end
7272

73+
def get_gitusername
74+
begin
75+
case key_type
76+
when KEY_TYPE_USER
77+
# This is equivalent to the username of the redmine user
78+
"#{self.user.login.underscore}".gsub(/[^0-9a-zA-Z\-]/,'_')
79+
when KEY_TYPE_DEPLOY
80+
# git usernames for deploy keys are equivalent to their identifierts
81+
self.identifier
82+
else
83+
nil
84+
end
85+
end
86+
end
87+
7388
# Key type checking functions
7489
def user_key?
7590
key_type == KEY_TYPE_USER
@@ -95,7 +110,7 @@ def reset_identifier
95110

96111
def to_s ; title ; end
97112

98-
@@myregular = /^redmine_(.*)_\d*_\d*(.pub)?$/
113+
@@myregular = /^(.*)@\d*_\d*(.pub)?$/
99114
def self.ident_to_user_token(identifier)
100115
result = @@myregular.match(identifier)
101116
(result != nil) ? result[1] : nil

Diff for: lib/libs/git_hosting.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,9 @@ def self.update_repositories(*args)
10281028

10291029
proj.member_principals.map(&:user).compact.uniq.each do |user|
10301030
if user.allowed_to?(:commit_access, proj)
1031-
proj_write_user_keys += user.gitolite_public_keys.active.user_key.map(&:identifier)
1031+
proj_write_user_keys += user.gitolite_public_keys.active.user_key.map(&:get_gitusername)
10321032
elsif user.allowed_to?(:view_changesets, proj)
1033-
proj_read_user_keys += user.gitolite_public_keys.active.user_key.map(&:identifier)
1033+
proj_read_user_keys += user.gitolite_public_keys.active.user_key.map(&:get_gitusername)
10341034
end
10351035
end
10361036

@@ -1125,9 +1125,9 @@ def self.update_repositories(*args)
11251125

11261126
repo.deployment_credentials.active.select(&:honored?).each do |cred|
11271127
if cred.allowed_to?(:commit_access)
1128-
write_user_keys << cred.gitolite_public_key.identifier
1128+
write_user_keys << cred.gitolite_public_key.get_gitusername
11291129
elsif cred.allowed_to?(:view_changesets)
1130-
read_user_keys << cred.gitolite_public_key.identifier
1130+
read_user_keys << cred.gitolite_public_key.get_gitusername
11311131
end
11321132
end
11331133

0 commit comments

Comments
 (0)