]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow user to upload his own root certificate for secure webdav mount
authorBjoern Schiessle <schiessle@owncloud.com>
Fri, 6 Jul 2012 13:58:38 +0000 (15:58 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Fri, 6 Jul 2012 13:58:38 +0000 (15:58 +0200)
apps/files_external/ajax/addRootCertificate.php
apps/files_external/ajax/removeRootCertificate.php
apps/files_external/lib/config.php
apps/files_external/lib/webdav.php
apps/files_external/templates/settings.php
lib/connector/sabre/client.php

index 33cd64d2c7a6e261d39876b9a8d41b5407b1fe98..c192855629209e5b45491ca9f5339f30a5f43fe2 100644 (file)
@@ -4,9 +4,23 @@ OCP\JSON::checkAppEnabled('files_external');
 
 $view = \OCP\Files::getStorage("files_external");
 $from = $_FILES['rootcert_import']['tmp_name'];
-$to = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").$_FILES['rootcert_import']['name'];
+$path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
+$to = $path.$_FILES['rootcert_import']['name'];
 move_uploaded_file($from, $to);
 
+//check if it is a PEM certificate, otherwise convert it if possible
+$fh = fopen($to, 'r');
+$data = fread($fh, filesize($to));
+fclose($fh);
+if (!strpos($data, 'BEGIN CERTIFICATE')) {
+       $pem = chunk_split(base64_encode($data), 64, "\n");\r
+       $pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n";
+       $fh = fopen($to, 'w');
+       fwrite($fh, $pem);
+}
+
+OC_Mount_Config::createCertificateBundle();
+
 header("Location: settings/personal.php");
 exit;
 ?>
\ No newline at end of file
index 05f2fdef2d16445f62bead338df92acf585cb737..a00922f4210023298491d7f8d0f9662a6711c605 100644 (file)
@@ -4,6 +4,7 @@ OCP\JSON::checkAppEnabled('files_external');
 
 $view = \OCP\Files::getStorage("files_external");
 $cert = $_POST['cert'];
-$file = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").$cert;
+$file = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/'.$cert;
 unlink($file);
+OC_Mount_Config::createCertificateBundle();
 ?>
\ No newline at end of file
index 4e82e6b254859fd92911e25266e4e971055a6e09..5630df77a91a5936c0962b8bfdca3076d43a3d21 100755 (executable)
@@ -244,7 +244,8 @@ class OC_Mount_Config {
         */\r
        public static function getCertificates() {
                $view = \OCP\Files::getStorage('files_external');
-               $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");
+               $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
+               if (!is_dir($path)) mkdir($path);
                $result = array();
                $handle = opendir($path);
                while (false !== ($file = readdir($handle))) {
@@ -252,6 +253,30 @@ class OC_Mount_Config {
                }
                return $result;
        }
+       
+       /**
+        * creates certificate bundle
+        */
+       public static function createCertificateBundle() {
+               $view = \OCP\Files::getStorage("files_external");\r
+               $path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");\r
+               \r
+               $certs = OC_Mount_Config::getCertificates();\r
+               $fh_certs = fopen($path."/rootcerts.crt", 'w');\r
+               foreach ($certs as $cert) {\r
+                       $file=$path.'/uploads/'.$cert;\r
+                       $fh = fopen($file, "r");\r
+                       $data = fread($fh, filesize($file));\r
+                       fclose($fh);
+                       if (strpos($data, 'BEGIN CERTIFICATE')) {\r
+                               fwrite($fh_certs, $data);
+                       }\r
+               }\r
+               \r
+               fclose($fh_certs);
+               
+               return true;
+       } 
 
 }
 
index 9b874e62e33495cf0d1e1a44ee94da3c95893443..ea6ca65b976206109c26b581e1887f843cb37fc4 100644 (file)
@@ -45,7 +45,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
                $this->client = new OC_Connector_Sabre_Client($settings);
                
                if($caview = \OCP\Files::getStorage('files_external')) {
-                       $this->client->setCurlSettings(array(CURLOPT_CAPATH => \OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("")));
+                       $this->client->setCurlSettings(array(CURLOPT_CAINFO => \OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt'));
                }
                //create the root folder if necesary
                $this->mkdir('');
index 8f8fe8d527f3218db6462396cfae4b7f76755818..3d65e9b74733519824f5b815f6971ac90d8c647d 100644 (file)
@@ -81,7 +81,7 @@
                </table>
                <br />
                
-               <?php if (!$_['isAdminPage'] && false):  // disabled until sabredav can handle uploaded ca certs   ?>
+               <?php if (!$_['isAdminPage']):  ?>
                <table id="sslCertificate" data-admin='<?php echo json_encode($_['isAdminPage']); ?>'>
                        <thead>
                                <tr>
index bcf564c06d15dcedac118f66acf9ab41331ba5ae..b799b541a055b5dd5af23f95bb8e7131ed29b6dd 100644 (file)
@@ -68,7 +68,7 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client {
         * @return array\r
         */\r
        public function request($method, $url = '', $body = null, $headers = array()) {\r
-                \r
+\r
                $this->curlSettings[CURLOPT_POSTFIELDS] = $body;         \r
                $url = $this->getAbsoluteUrl($url);\r
        \r