Add LSformRule :: ssh_pub_key

This commit is contained in:
Benjamin Renard 2017-12-22 17:13:48 +01:00
parent 11abb3e1f8
commit 049efb1eef
4 changed files with 60 additions and 0 deletions

View file

@ -64,6 +64,7 @@ règles.</para>
&conf-LSattribute-check-data-rangelength; &conf-LSattribute-check-data-rangelength;
&conf-LSattribute-check-data-regex; &conf-LSattribute-check-data-regex;
&conf-LSattribute-check-data-required; &conf-LSattribute-check-data-required;
&conf-LSattribute-check-data-ssh_pub_key;
&conf-LSattribute-check-data-telephonenumber; &conf-LSattribute-check-data-telephonenumber;
</sect3> </sect3>

View file

@ -19,4 +19,5 @@
<!ENTITY conf-LSattribute-check-data-rangelength SYSTEM "rangelength.docbook"> <!ENTITY conf-LSattribute-check-data-rangelength SYSTEM "rangelength.docbook">
<!ENTITY conf-LSattribute-check-data-regex SYSTEM "regex.docbook"> <!ENTITY conf-LSattribute-check-data-regex SYSTEM "regex.docbook">
<!ENTITY conf-LSattribute-check-data-required SYSTEM "required.docbook"> <!ENTITY conf-LSattribute-check-data-required SYSTEM "required.docbook">
<!ENTITY conf-LSattribute-check-data-ssh_pub_key SYSTEM "ssh_pub_key.docbook">
<!ENTITY conf-LSattribute-check-data-telephonenumber SYSTEM "telephonenumber.docbook"> <!ENTITY conf-LSattribute-check-data-telephonenumber SYSTEM "telephonenumber.docbook">

View file

@ -0,0 +1,10 @@
<sect4 id="config-LSattribute-check-data-ssh_pub_key">
<title>ssh_pub_key</title>
<para>Cette règle vérifie que la valeur est une clé publique SSH.</para>
<para>Cette vérification utilise tout d'abord une expression régulière
pour valider la forme syntaxique de la clé publique
(<literal>ssh-[type] [clé au format base64] [commentaire]</literal>) puis
tente de décoder la partie en base64 de la clé pour vérifier qu'il s'agit
bien d'une chaine de caractères dans laquelle on retrouve bien le type de
la clé (<literal>ssh-[type]</literal>).</para>
</sect4>

View file

@ -0,0 +1,48 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* http://ldapsaisie.labs.libre-entreprise.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* LSformRule to check SSH public key
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformRule_ssh_pub_key extends LSformRule {
/**
* Validate SSH public key value
*
* @param string $values The value to validate
* @param array $options Validation options
* @param object $formElement The related formElement object
*
* @return boolean true if the value is valide, false if not
*/
function validate($value,$options,$formElement) {
if (preg_match('/^(ssh-[a-z0-9]+) +([^ ]+) +(.*)$/', $value, $m)) {
$data=@base64_decode($m[2]);
if (is_string($data) && strpos($data, $m[1]))
return true;
}
return false;
}
}