summaryrefslogtreecommitdiffstats
path: root/tests/lib/security
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-08-27 00:49:53 +0200
committerLukas Reschke <lukas@owncloud.com>2014-08-27 00:49:53 +0200
commit3329e0f2b22207a24ddb4953bbf11964b23682d9 (patch)
tree54bfeb8fa17492d29633928c62c259312d0af5e4 /tests/lib/security
parentd26a9c3c5819be48b76586c2fa60da9a7a9829dd (diff)
downloadnextcloud-server-3329e0f2b22207a24ddb4953bbf11964b23682d9.tar.gz
nextcloud-server-3329e0f2b22207a24ddb4953bbf11964b23682d9.zip
Use DI
Diffstat (limited to 'tests/lib/security')
-rw-r--r--tests/lib/security/crypto.php12
1 files changed, 6 insertions, 6 deletions
diff --git a/tests/lib/security/crypto.php b/tests/lib/security/crypto.php
index e07a60267e8..6211e3e8227 100644
--- a/tests/lib/security/crypto.php
+++ b/tests/lib/security/crypto.php
@@ -12,7 +12,7 @@ class CryptoTest extends \PHPUnit_Framework_TestCase {
function testDefaultEncrypt() {
$stringToEncrypt = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.';
- $crypto = new Crypto();
+ $crypto = new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
$ciphertext = $crypto->encrypt($stringToEncrypt);
$this->assertEquals($stringToEncrypt, $crypto->decrypt($ciphertext));
@@ -27,17 +27,17 @@ class CryptoTest extends \PHPUnit_Framework_TestCase {
*/
function testWrongPassword() {
$stringToEncrypt = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.';
- $encryptCrypto = new Crypto();
+ $encryptCrypto = new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
$ciphertext = $encryptCrypto->encrypt($stringToEncrypt);
- $decryptCrypto = new Crypto();
+ $decryptCrypto = new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
$this->assertFalse($decryptCrypto->decrypt($ciphertext, 'A wrong password!'));
}
function testLaterDecryption() {
$stringToEncrypt = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.';
$encryptedString = '560f5436ba864b9f12f7f7ca6d41c327554a6f2c0a160a03316b202af07c65163274993f3a46e7547c07ba89304f00594a2f3bd99f83859097c58049c39d0d4ade10e0de914ff0604961e7c849d0271ed6c0b23f984ba16e7d033e3305fb0910e7b6a2a65c988d17dbee71d8f953684d|d2kdFUspVjC0Y0sr|1a5feacf87eaa6869a6abdfba9a296e7bbad45b6ad89f7dce67cdc98e2da5dc4379cc672cc655e52bbf19599bf59482fbea13a73937697fa656bf10f3fc4f1aa';
- $crypto = new Crypto();
+ $crypto = new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
$this->assertEquals($stringToEncrypt, $crypto->decrypt($encryptedString, 'ThisIsAVeryS3cur3P4ssw0rd'));
}
@@ -47,7 +47,7 @@ class CryptoTest extends \PHPUnit_Framework_TestCase {
*/
function testWrongIV() {
$encryptedString = '560f5436ba864b9f12f7f7ca6d41c327554a6f2c0a160a03316b202af07c65163274993f3a46e7547c07ba89304f00594a2f3bd99f83859097c58049c39d0d4ade10e0de914ff0604961e7c849d0271ed6c0b23f984ba16e7d033e3305fb0910e7b6a2a65c988d17dbee71d8f953684d|d2kdFUspVjC0o0sr|1a5feacf87eaa6869a6abdfba9a296e7bbad45b6ad89f7dce67cdc98e2da5dc4379cc672cc655e52bbf19599bf59482fbea13a73937697fa656bf10f3fc4f1aa';
- $crypto = new Crypto();
+ $crypto = new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
$crypto->decrypt($encryptedString, 'ThisIsAVeryS3cur3P4ssw0rd');
}
@@ -57,7 +57,7 @@ class CryptoTest extends \PHPUnit_Framework_TestCase {
*/
function testWrongParameters() {
$encryptedString = '1|2';
- $crypto = new Crypto();
+ $crypto = new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
$crypto->decrypt($encryptedString, 'ThisIsAVeryS3cur3P4ssw0rd');
}
}
88 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?php
/**
 * ownCloud
 *
 * @author Frank Karlitschek
 * @author Jakob Sack
 * @copyright 2010 Frank Karlitschek karlitschek@kde.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * This class provides an easy way for apps to store config values in the
 * database.
 */

class OC_OCSClient{

	/**
	 * @brief Get the url of the OCS AppStore server. 
	 * @returns string of the AppStore server
	 *
	 * This function returns the url of the OCS AppStore server. It´s possible to set it in the config file or it will fallback to the default
	 */
	private static function getAppStoreURL(){
		$configurl=OC_Config::getValue('appstoreurl', '');
		if($configurl<>'') {
			$url=$configurl;
		}else{
			$url='http://api.apps.owncloud.com/v1';
		}
		return($url);
	}

        /**
         * @brief Get the url of the OCS KB server. 
         * @returns string of the KB server
         * This function returns the url of the OCS knowledge base server. It´s possible to set it in the config file or it will fallback to the default
         */
        private static function getKBURL(){
                $configurl=OC_Config::getValue('knowledgebaseurl', '');
                if($configurl<>'') {
                        $url=$configurl;
                }else{
                        $url='http://api.apps.owncloud.com/v1';
                }
                return($url);
        }


	/**
	 * @brief Get all the categories from the OCS server
	 * @returns array with category ids
	 *
	 * This function returns a list of all the application categories on the OCS server
	 */
	public static function getCategories(){
		$url=OC_OCSClient::getAppStoreURL().'/content/categories';
	
		$xml=@file_get_contents($url);
		if($xml==FALSE){
			return NULL;
		}
		$data=simplexml_load_string($xml);
	
		$tmp=$data->data;
		$cats=array();

		foreach($tmp->category as $key=>$value) {

			$id= (int) $value->id;
			$name= (string) $value->name;
			$cats[$id]=$name;

		}

		return $cats;
	}

	/**
	 * @brief Get all the applications from the OCS server
	 * @returns array with application data
	 *
	 * This function returns a list of all the applications on the OCS server
	 */
	public static function getApplications($categories){
		if(OC_Config::getValue('appstoreenabled', true)==false){
			return(array());
		}

		if(is_array($categories)) {
			$categoriesstring=implode('x',$categories);
		}else{
			$categoriesstring=$categories;
		}
		$url=OC_OCSClient::getAppStoreURL().'/content/data?categories='.urlencode($categoriesstring).'&sortmode=new&page=0&pagesize=10';
		$apps=array();
		$xml=@file_get_contents($url);
		if($xml==FALSE){
			return NULL;
		}
		$data=simplexml_load_string($xml);

		$tmp=$data->data->content;
		for($i = 0; $i < count($tmp); $i++) {
			$app=array();
			$app['id']=(string)$tmp[$i]->id;
			$app['name']=(string)$tmp[$i]->name;
			$app['type']=(string)$tmp[$i]->typeid;
			$app['typename']=(string)$tmp[$i]->typename;
			$app['personid']=(string)$tmp[$i]->personid;
			$app['license']=(string)$tmp[$i]->license;
			$app['detailpage']=(string)$tmp[$i]->detailpage;
			$app['preview']=(string)$tmp[$i]->smallpreviewpic1;
			$app['changed']=strtotime($tmp[$i]->changed);
			$app['description']=(string)$tmp[$i]->description;
	
			$apps[]=$app;
		} 
		return $apps;
	}


	/**
	 * @brief Get an the applications from the OCS server
	 * @returns array with application data
	 *
	 * This function returns an  applications from the OCS server
	 */
	public static function getApplication($id){
		$url=OC_OCSClient::getAppStoreURL().'/content/data/'.urlencode($id);

		$xml=@file_get_contents($url);
		if($xml==FALSE){
			OC_Log::write('core','Unable to parse OCS content',OC_Log::FATAL);
			return NULL;
		}
		$data=simplexml_load_string($xml);

		$tmp=$data->data->content;
		$app=array();
		$app['id']=$tmp->id;
		$app['name']=$tmp->name;
		$app['type']=$tmp->typeid;
		$app['typename']=$tmp->typename;
		$app['personid']=$tmp->personid;
		$app['detailpage']=$tmp->detailpage;
		$app['preview1']=$tmp->smallpreviewpic1;
		$app['preview2']=$tmp->smallpreviewpic2;
		$app['preview3']=$tmp->smallpreviewpic3;
		$app['changed']=strtotime($tmp->changed);
		$app['description']=$tmp->description;
		$app['detailpage']=$tmp->detailpage;

		return $app;
	}

        /**
         * @brief Get the download url for an application from the OCS server
         * @returns array with application data
         *
         * This function returns an download url for an applications from the OCS server
         */
        public static function getApplicationDownload($id,$item){
                $url=OC_OCSClient::getAppStoreURL().'/content/download/'.urlencode($id).'/'.urlencode($item);

                $xml=@file_get_contents($url);
                if($xml==FALSE){
                        OC_Log::write('core','Unable to parse OCS content',OC_Log::FATAL);
                        return NULL;
                }
                $data=simplexml_load_string($xml);

                $tmp=$data->data->content;
                $app=array();
                if(isset($tmp->downloadlink)) { 
	 		$app['downloadlink']=$tmp->downloadlink;
		}else{
	 		$app['downloadlink']='';
		}
                return $app;
        }


	/**
	 * @brief Get all the knowledgebase entries from the OCS server
	 * @returns array with q and a data
	 *
	 * This function returns a list of all the knowledgebase entries from the OCS server
	 */
	public static function getKnownledgebaseEntries($page,$pagesize,$search=''){	
		if(OC_Config::getValue('knowledgebaseenabled', true)==false){
			$kbe=array();
			$kbe['totalitems']=0;
			return $kbe;
		}

		$p= (int) $page;
		$s= (int) $pagesize;
		if($search<>'') $searchcmd='&search='.urlencode($search); else $searchcmd='';
		$url=OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='.$p.'&pagesize='.$s.$searchcmd;

		$kbe=array();
		$xml=@file_get_contents($url);
		if($xml==FALSE){
			OC_Log::write('core','Unable to parse knowledgebase content',OC_Log::FATAL);
			return NULL;
		}
		$data=simplexml_load_string($xml);

		$tmp=$data->data->content;
		for($i = 0; $i < count($tmp); $i++) {
			$kb=array();
			$kb['id']=$tmp[$i]->id;
			$kb['name']=$tmp[$i]->name;
			$kb['description']=$tmp[$i]->description;
			$kb['answer']=$tmp[$i]->answer;
			$kb['preview1']=$tmp[$i]->smallpreviewpic1;
			$kb['detailpage']=$tmp[$i]->detailpage;
			$kbe[]=$kb;
		}
		$total=$data->meta->totalitems;
		$kbe['totalitems']=$total;
                return $kbe;
	}



}