https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113409

Revision: 113409
Author:   platonides
Date:     2012-03-08 21:48:52 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
Follow-up r113405. Add support for changing ssh key formats 
using ssh-keygen, too.
Fixes bug 33324: Automatically convert uploaded keys from 
RFC 4251 to openssh format.

Modified Paths:
--------------
    trunk/extensions/OpenStackManager/OpenStackManager.php
    trunk/extensions/OpenStackManager/special/SpecialNovaKey.php

Modified: trunk/extensions/OpenStackManager/OpenStackManager.php
===================================================================
--- trunk/extensions/OpenStackManager/OpenStackManager.php      2012-03-08 
21:44:03 UTC (rev 113408)
+++ trunk/extensions/OpenStackManager/OpenStackManager.php      2012-03-08 
21:48:52 UTC (rev 113409)
@@ -83,6 +83,11 @@
 $wgOpenStackManagerNovaDefaultProject = "";
 
 /**
+ * Path to the ssh-keygen utility. Used for converting ssh key formats. False 
to disable its use.
+ */
+$wgSshKeygen = 'ssh-keygen';
+
+/**
  * Path to the puttygen utility. Used for converting ssh key formats. False to 
disable its use.
  */
 $wgPuttygen = 'puttygen';

Modified: trunk/extensions/OpenStackManager/special/SpecialNovaKey.php
===================================================================
--- trunk/extensions/OpenStackManager/special/SpecialNovaKey.php        
2012-03-08 21:44:03 UTC (rev 113408)
+++ trunk/extensions/OpenStackManager/special/SpecialNovaKey.php        
2012-03-08 21:48:52 UTC (rev 113409)
@@ -182,11 +182,27 @@
        }
        
        /**
+        * Converts a public ssh key to openssh format.
+        * @param $keydata SSH public/private key in some format
+        * @return mixed Public key in openssh format or false
+        */
+       static function opensshFormatKey($keydata) {
+               global $wgSshKeygen, $wgPuttygen;
+               
+               $public = self::opensshFormatKeySshKeygen( $keydata );
+               
+               if ( !$public )
+                       $public = self::opensshFormatKeyPuttygen( $keydata );
+
+               return $public;
+       }
+       
+       /**
         * Converts a public ssh key to openssh format, using puttygen.
         * @param $keydata SSH public/private key in some format
         * @return mixed Public key in openssh format or false
         */
-       static function opensshFormatKey($keydata) {
+       static function opensshFormatKeyPuttygen($keydata) {
                global $wgPuttygen;
                if ( wfIsWindows() || !$wgPuttygen )
                        return false;
@@ -233,11 +249,14 @@
                return $data;
        }
 
-       /*
-       // This alternative function uses only pipes, but doesn't work due to 
puttygen opening the input file several times.
-       static function opensshFormatKey($keydata) {
-               global $wgPuttygen;
-               if ( wfIsWindows() || !$wgPuttygen )
+       /**
+        * Converts a public ssh key to openssh format, using ssh-keygen.
+        * @param $keydata SSH public/private key in some format
+        * @return mixed Public key in openssh format or false
+        */
+       static function opensshFormatKeySshKeygen($keydata) {
+               global $wgSshKeygen;
+               if ( wfIsWindows() || !$wgSshKeygen )
                        return false;
                
                $descriptorspec = array(
@@ -246,14 +265,14 @@
                   2 => array("file", wfGetNull(), "a")
                );
                
-               $process = proc_open( escapeshellcmd( $wgPuttygen ) . ' -O 
public-openssh -o /dev/stdout /dev/stdin', $descriptorspec, $pipes );
+               $process = proc_open( escapeshellcmd( $wgSshKeygen ) . ' -i -f 
/dev/stdin', $descriptorspec, $pipes );
                if ( $process === false )
                        return false;
                
                fwrite( $pipes[0], $keydata );
                fclose( $pipes[0] );
                $data = stream_get_contents( $pipes[1] );
-               var_dump($data);
+               
                fclose( $pipes[1] );
                proc_close( $process );
                
@@ -262,8 +281,8 @@
                
                return $data;
        }
-       */
        
+       
        /**
         * @param  $formData
         * @param string $entryPoint


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to