]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
prepare user interface to register and delete client certificates on the profile...
authorChristian Weiske <cweiske@cweiske.de>
Tue, 10 May 2011 13:23:58 +0000 (15:23 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 10 May 2011 13:23:58 +0000 (15:23 +0200)
data/templates/editprofile-sslclientcerts.tpl.php
src/SemanticScuttle/Model/User/SslClientCert.php
src/SemanticScuttle/Service/User/SslClientCert.php
www/profile.php

index e6fc5c32f87e2c03a09df2aafc69c563162a9e8e..c43def456d27d08534fb8705ee70a050eefc159f 100644 (file)
@@ -3,6 +3,7 @@
 <table>
  <thead>
   <tr>
+   <th>Options</th>
    <th><?php echo T_('Serial'); ?></th>
    <th><?php echo T_('Name'); ?></th>
    <th><?php echo T_('Email'); ?></th>
@@ -11,7 +12,8 @@
  </thead>
  <tbody>
  <?php foreach($sslClientCerts as $cert) { ?>
-   <tr <?php if ($cert->isCurrent()) { echo 'class="ssl-current"'; } ?>>
+  <tr <?php if ($cert->isCurrent()) { echo 'class="ssl-current"'; } ?>>
+   <td><a href="#FIXME">delete</a></td>
    <td><?php echo htmlspecialchars($cert->sslSerial); ?></td>
    <td><?php echo htmlspecialchars($cert->sslName); ?></td>
    <td><?php echo htmlspecialchars($cert->sslEmail); ?></td>
 <?php } else { ?>
  <p><?php echo T_('No certificates registered'); ?></p>
 <?php } ?>
+
+<?php if ($currentCert) { ?>
+ <?php if ($currentCert->isRegistered($sslClientCerts)) { ?>
+  <p><?php echo T_('Your current certificate is already registered with your account.'); ?></p>
+ <?php } else { ?>
+  <p>
+   <a href="#FIXME">
+    <?php echo T_('Register current certificate to automatically login.'); ?>
+   </a>
+  </p>
+ <?php } ?>
+<?php } else { ?>
+ <p><?php echo T_('Your browser does not provide a certificate.'); ?></p>
+<?php } ?>
index ab7b288f287bf63b1f8a2bc5c831d1b0d64cfb83..383b601aa8f727d52ba0811c8352c8a5b1a59967 100644 (file)
@@ -29,9 +29,11 @@ class SemanticScuttle_Model_User_SslClientCert
     public $sslName;
     public $sslEmail;
 
+
+
     /**
      * Creates and returns a new object and fills it with
-     * tha passed values from the database.
+     * the passed values from the database.
      *
      * @param array $arCertRow Database row array
      *
@@ -50,6 +52,29 @@ class SemanticScuttle_Model_User_SslClientCert
 
 
 
+    /**
+     * Loads the user's/browser's client certificate information into
+     * an object and returns it.
+     * Expects that all information is available.
+     * Better check with
+     * SemanticScuttle_Service_User_SslClientCert::hasValidCert() before.
+     *
+     * @return SemanticScuttle_Model_User_SslClientCert
+     *
+     * @see SemanticScuttle_Service_User_SslClientCert::hasValidCert()
+     */
+    public static function fromCurrentCert()
+    {
+        $cert = new self();
+        $cert->sslSerial         = $_SERVER['SSL_CLIENT_M_SERIAL'];
+        $cert->sslClientIssuerDn = $_SERVER['SSL_CLIENT_I_DN'];
+        $cert->sslName           = $_SERVER['SSL_CLIENT_S_DN_CN'];
+        $cert->sslEmail          = $_SERVER['SSL_CLIENT_S_DN_Email'];
+        return $cert;
+    }
+
+
+
     /**
      * Tells you if this certificate is the one the user is currently browsing
      * with.
@@ -68,5 +93,56 @@ class SemanticScuttle_Model_User_SslClientCert
             && $this->sslClientIssuerDn == $_SERVER['SSL_CLIENT_I_DN'];
     }
 
+
+
+    /**
+     * Checks if this certificate is registered (exists) in the certificate
+     * array
+     *
+     * @param array $arCertificates Array of certificate objects
+     *
+     * @return boolean True or false
+     */
+    public function isRegistered($arCertificates)
+    {
+        foreach ($arCertificates as $cert) {
+            if ($cert->equals($this)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+
+    /**
+     * Deletes this certificate from database
+     *
+     * @return boolean True if all went well, false if not
+     */
+    public function delete()
+    {
+        $ok = SemanticScuttle_Service_Factory::get('User_SslClientCert')
+            ->delete($this);
+        if ($ok) {
+            $this->id = null;
+        }
+        return $ok;
+    }
+
+
+
+    /**
+     * Compares this certificate with the given one.
+     *
+     * @param SemanticScuttle_Service_Factory $cert Another user certificate
+     *
+     * @return boolean True if both match.
+     */
+    public function equals(SemanticScuttle_Model_User_SslClientCert $cert)
+    {
+        return $this->sslSerial == $cert->sslSerial
+            && $this->sslClientIssuerDn == $cert->sslClientIssuerDn;
+    }
 }
 ?>
\ No newline at end of file
index 3c69788cf3ffe658bbd0b1aa1089e748d0a7d101..b6545dfad298983e06edb92929855264c518a2bd 100644 (file)
@@ -208,5 +208,43 @@ class SemanticScuttle_Service_User_SslClientCert extends SemanticScuttle_DbServi
         $this->db->sql_freeresult($dbresult);
         return $certs;
     }
+
+
+
+    /**
+     * Deletes a SSL client certificate.
+     * No security checks are made here.
+     *
+     * @param mixed $cert Certificate object or certificate database id.
+     *                    Objects are of type
+     *                    SemanticScuttle_Model_User_SslClientCert
+     *
+     * @return boolean True if all went well, false if it could not be deleted
+     */
+    public function delete($cert)
+    {
+        if ($cert instanceof SemanticScuttle_Model_User_SslClientCert) {
+            $id = (int)$cert->id;
+        } else {
+            $id = (int)$cert;
+        }
+
+        if ($id === 0) {
+            return false;
+        }
+
+        $query = 'DELETE FROM ' . $this->getTableName()
+            .' WHERE uId = ' . $id;
+
+        if (!($dbresult = $this->db->sql_query($query))) {
+            message_die(
+                GENERAL_ERROR, 'Could not delete user certificate',
+                '', __LINE__, __FILE__, $query, $this->db
+            );
+            return false;
+        }
+
+        return true;
+    }
 }
 ?>
\ No newline at end of file
index 446c089d53a1bce6dcdd28696d97357cb05e3a5a..5ffc959f131447e39845b77bb37005d5183d84c1 100644 (file)
@@ -119,11 +119,16 @@ if (!$userservice->isLoggedOn() || $currentUser->getId() != $userid) {
        $_SESSION['token_stamp'] = time();
 
        $templatename = 'editprofile.tpl.php';
-       $tplVars['formaction']  = createURL('profile', $user);
-       $tplVars['token'] = $_SESSION['token'];
-       $tplVars['sslClientCerts'] = SemanticScuttle_Service_Factory::get(
-               'User_SslClientCert'
-       )->getUserCerts($currentUser->getId());
+
+       $tplVars['formaction'] = createURL('profile', $user);
+       $tplVars['token']      = $_SESSION['token'];
+
+    $scert = SemanticScuttle_Service_Factory::get('User_SslClientCert');
+       $tplVars['sslClientCerts'] = $scert->getUserCerts($currentUser->getId());
+       $tplVars['currentCert']    = null;
+    if ($scert->hasValidCert()) {
+        $tplVars['currentCert'] = SemanticScuttle_Model_User_SslClientCert::fromCurrentCert();
+    }
 }
 
 $tplVars['objectUser'] = $userinfo;