[LockManager] Use proper hmac function for LSLockManager.
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 23 Nov 2012 03:35:15 +0000 (19:35 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 23 Nov 2012 03:35:15 +0000 (19:35 -0800)
Change-Id: If4a3d25a61bcc7cf26beb32abf3d4cc655ca4c55

includes/filebackend/lockmanager/LSLockManager.php
maintenance/locking/LockServerDaemon.php

index 8942818..3de6183 100644 (file)
@@ -169,7 +169,7 @@ class LSLockManager extends QuorumLockManager {
                $authKey = $this->lockServers[$lockSrv]['authKey'];
                // Build of the command as a flat string...
                $values = implode( '|', $values );
-               $key = sha1( $this->session . $action . $type . $values . $authKey );
+               $key = hash_hmac( 'sha1', "{$this->session}\n{$action}\n{$type}\n{$values}", $authKey );
                // Send out the command...
                if ( fwrite( $conn, "{$this->session}:$key:$action:$type:$values\n" ) === false ) {
                        return false;
index c591665..4358989 100644 (file)
@@ -242,7 +242,9 @@ class LockServerDaemon {
                $m = explode( ':', $data ); // <session, key, command, type, values>
                if ( count( $m ) == 5 ) {
                        list( $session, $key, $command, $type, $values ) = $m;
-                       if ( sha1( $session . $command . $type . $values . $this->authKey ) !== $key ) {
+                       $goodKey = hash_hmac( 'sha1',
+                               "{$session}\n{$command}\n{$type}\n{$values}", $this->authKey );
+                       if ( $goodKey !== $key ) {
                                return 'BAD_KEY';
                        } elseif ( strlen( $session ) !== 32 ) {
                                return 'BAD_SESSION';