]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
part of request #3163623: add support to login via ssl client certificate. web interf...
authorChristian Weiske <cweiske@cweiske.de>
Wed, 4 May 2011 15:08:25 +0000 (17:08 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 4 May 2011 15:08:25 +0000 (17:08 +0200)
data/schema/6.sql
data/tables.sql
data/templates/toolbar.inc.php
src/SemanticScuttle/Service/User.php

index 4ae7cb917ce8d6320d3803d0d56b3a78f2ee965a..bc85ffdd28afbdec70c2fecfa2d6b1c55f4b42e6 100644 (file)
@@ -2,3 +2,13 @@ CREATE TABLE `sc_version` (
   `schema_version` int(11) NOT NULL
 ) DEFAULT CHARSET=utf8;
 INSERT INTO `sc_version` (`schema_version`) VALUES ('6');
+
+CREATE TABLE `sc_users_sslclientcerts` (
+  `id` INT NOT NULL AUTO_INCREMENT ,
+  `uId` INT NOT NULL ,
+  `sslSerial` VARCHAR( 32 ) NOT NULL ,
+  `sslName` VARCHAR( 64 ) NOT NULL ,
+  `sslEmail` VARCHAR( 64 ) NOT NULL ,
+  PRIMARY KEY ( `id` ) ,
+  UNIQUE (`id`)
+) CHARACTER SET utf8 COLLATE utf8_general_ci;
index 7a9c5bdf9d04caecc0e38b9639b5c318ba00c6df..af0c81be77bc442faca7c402e45159a2c30a27af 100644 (file)
@@ -77,6 +77,16 @@ CREATE TABLE `sc_users` (
 
 -- --------------------------------------------------------
 
+CREATE TABLE `sc_users_sslclientcerts` (
+  `id` INT NOT NULL AUTO_INCREMENT ,
+  `uId` INT NOT NULL ,
+  `sslSerial` VARCHAR( 32 ) NOT NULL ,
+  `sslName` VARCHAR( 64 ) NOT NULL ,
+  `sslEmail` VARCHAR( 64 ) NOT NULL ,
+  PRIMARY KEY ( `id` ) ,
+  UNIQUE (`id`)
+) CHARACTER SET utf8 COLLATE utf8_general_ci;
+
 -- 
 -- Table structure for table `sc_watched`
 -- 
index 0d9bf49dde61301e292da348bd01de86260a8adf..fb6638dda0e068d4f7d55383d19fba0a4d01faa6 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-if ($userservice->isLoggedOn()) {
+if ($userservice->isLoggedOn() && is_object($currentUser)) {
     $cUserId = $userservice->getCurrentUserId();
     $cUsername = $currentUser->getUsername();
 ?>
index 9ef8430b8b47e3bb3c8e9e8184ac69932cf93d46..0071f9b34db2f44306f419ede93b5df81338be63 100644 (file)
@@ -390,6 +390,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
                 $this->db->sql_freeresult($dbresult);
                 return (int)$_SESSION[$this->getSessionKey()];
             }
+        } else if (isset($_SERVER['SSL_CLIENT_M_SERIAL'])
+            && isset($_SERVER['SSL_CLIENT_V_END'])
+        ) {
+            $id = $this->getUserIdFromSslClientCert();
+            if ($id !== false) {
+                $this->setCurrentUserId($id);
+                return (int)$_SESSION[$this->getSessionKey()];
+            }
         }
         return false;
     }
@@ -420,6 +428,48 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
 
 
 
+    /**
+     * Tries to detect the user ID from the SSL client certificate passed
+     * to the web server.
+     *
+     * @return mixed Integer user ID if the certificate is valid and
+     *               assigned to a user, boolean false otherwise
+     */
+    protected function getUserIdFromSslClientCert()
+    {
+        if (!isset($_SERVER['SSL_CLIENT_M_SERIAL'])
+            || !isset($_SERVER['SSL_CLIENT_V_END'])
+        ) {
+            return false;
+        }
+        //TODO: verify this var is always there
+        if ($_SERVER['SSL_CLIENT_V_REMAIN'] <= 0) {
+            return false;
+        }
+
+        $serial = $_SERVER['SSL_CLIENT_M_SERIAL'];
+        $query = 'SELECT uId'
+            . ' FROM ' . $this->getTableName() . '_sslclientcerts'
+            . ' WHERE sslSerial = \'' . $this->db->sql_escape($serial) . '\'';
+        if (!($dbresult = $this->db->sql_query($query))) {
+            message_die(
+                GENERAL_ERROR, 'Could not load user for client certificate',
+                '', __LINE__, __FILE__, $query, $this->db
+            );
+            return false;
+        }
+
+        $row = $this->db->sql_fetchrow($dbresult);
+        $this->db->sql_freeresult($dbresult);
+
+        if (!$row) {
+            return false;
+        }
+        return (int)$row['uId'];
+    }
+
+
+
     /**
      * Try to authenticate and login a user with
      * username and password.