Skip to content

Commit

Permalink
forbidden public key which is contained in authorized_keys file
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Dec 15, 2014
1 parent 22b5d31 commit 4442a7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Gitprep/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ sub update_authorized_keys_file {
}

# Parse file
my $result = $self->_parse_authorized_keys_file($authorized_keys_file);
my $result = $self->parse_authorized_keys_file($authorized_keys_file);
my $before_part = $result->{before_part};
my $gitprep_part = $result->{gitprep_part};
my $after_part = $result->{after_part};
Expand Down Expand Up @@ -524,7 +524,7 @@ sub update_authorized_keys_file {
}
}

sub _parse_authorized_keys_file {
sub parse_authorized_keys_file {
my ($self, $file) = @_;

my $start_symbol = "# gitprep start";
Expand Down
25 changes: 24 additions & 1 deletion templates/user-settings/ssh.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
],
key => [
['not_blank' => 'key is empty'],
# Check if key format is valid
sub {
my ($original_key, $args, $vc) = @_;

Expand All @@ -49,7 +50,29 @@
return {result => 0, message => 'Key already exists'};
}
else {
return {result => 1, output => $key}
my $key_is_contained;
my $authorized_keys_file = app->manager->authorized_keys_file;
if (defined $authorized_keys_file) {
my $result
= app->manager->parse_authorized_keys_file($authorized_keys_file);

my $before_part = $result->{before_part};
my $after_part = $result->{after_part};
my $other_part = "$before_part\n$after_part";
if ($other_part =~ /\s\Q$original_key_edit\E(\s|$)/) {
$key_is_contained = 1;
}
}

if ($key_is_contained) {
return {
result => 0,
message => "authorized_keys file already contain this key"
};
}
else {
return {result => 1, output => $key}
}
}
}
else {
Expand Down

0 comments on commit 4442a7d

Please sign in to comment.