Indefero

Indefero Commit Details


Date:2010-02-27 10:42:09 (14 years 9 months ago)
Author:Loic d'Anterroches
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:d3b76975cdc852f5c1d674b95d034f32a29d5f11
Parents: 64fb5b3bf0b56f0ba23ecda28c84434dee2e3be9
Message:Added the option to have a strong check of the ssh key with ssh-keygen.

Changes:

File differences

src/IDF/Form/Admin/UserCreate.php
164164
165165
166166
167
168
169
170
171
172
173
174
175
167
176168
177169
178170
function clean_ssh_key()
{
$key = trim($this->cleaned_data['ssh_key']);
if (strlen($key) == 0) {
return '';
}
$key = str_replace(array("\n", "\r"), '', $key);
if (!preg_match('#^ssh\-[a-z]{3}\s(\S+)\s\S+$#', $key, $matches)) {
throw new Pluf_Form_Invalid(__('The format of the key is not valid. It must start with ssh-dss or ssh-rsa, a long string on a single line and at the end a comment.'));
}
return $key;
return IDF_Form_UserAccount::checkSshKey($this->cleaned_data['ssh_key']);
}
function clean_last_name()
src/IDF/Form/UserAccount.php
189189
190190
191191
192
192
193
194
195
196
197
198
199
200
201
202
193203
194
204
195205
196206
197207
......
199209
200210
201211
212
213
214
215
216
217
218
219
220
221
222
202223
203224
204225
226
227
228
229
230
231
205232
206233
207234
return $this->user;
}
function clean_ssh_key()
/**
* Check an ssh key.
*
* It will throw a Pluf_Form_Invalid exception if it cannot
* validate the key.
*
* @param $key string The key
* @param $user int The user id of the user of the key (0)
* @return string The clean key
*/
public static function checkSshKey($key, $user=0)
{
$key = trim($this->cleaned_data['ssh_key']);
$key = trim($key);
if (strlen($key) == 0) {
return '';
}
if (!preg_match('#^ssh\-[a-z]{3}\s(\S+)\s\S+$#', $key, $matches)) {
throw new Pluf_Form_Invalid(__('The format of the key is not valid. It must start with ssh-dss or ssh-rsa, a long string on a single line and at the end a comment.'));
}
if (Pluf::f('idf_strong_key_check', false)) {
$tmpfile = Pluf::f('tmp_folder', '/tmp').$user.'-key';
file_put_contents($tmpfile, $key, LOCK_EX);
$cmd = Pluf::f('idf_exec_cmd_prefix', '').
'ssh-keygen -l -f '.escapeshellarg($tmpfile);
exec($cmd, $out, $return);
unlink($tmpfile);
if ($return != 0) {
throw new Pluf_Form_Invalid(__('Please check the key as it does not appears to be a valid key.'));
}
}
return $key;
}
function clean_ssh_key()
{
return self::checkSshKey($this->cleaned_data['ssh_key'],
$this->user->id);
}
function clean_last_name()
{
$last_name = trim($this->cleaned_data['last_name']);

Archive Download the corresponding diff file

Page rendered in 0.08352s using 13 queries.