/**
  * Removes a personal root certificate from the users' trust store
  *
  * @NoAdminRequired
  * @NoSubadminRequired
  * @param string $certificateIdentifier
  * @return DataResponse
  */
 public function removePersonalRootCertificate($certificateIdentifier)
 {
     if ($this->isCertificateImportAllowed() === false) {
         return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN);
     }
     $this->certificateManager->removeCertificate($certificateIdentifier);
     return new DataResponse();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     if (!file_exists($path)) {
         $output->writeln('<error>certificate not found</error>');
         return;
     }
     $certData = file_get_contents($path);
     $name = basename($path);
     $this->certificateManager->addCertificate($certData, $name);
 }
Example #3
0
 /**
  * Sets the default options to the client
  */
 private function setDefaultOptions()
 {
     // Either use user bundle or the system bundle if nothing is specified
     if ($this->certificateManager->listCertificates() !== []) {
         $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath());
     } else {
         $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null));
     }
     $this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
     if ($this->getProxyUri() !== '') {
         $this->client->setDefaultOption('proxy', $this->getProxyUri());
     }
 }
Example #4
0
 /**
  * Sets the default options to the client
  */
 private function setDefaultOptions()
 {
     // Either use default bundle or the user bundle if nothing is specified
     if ($this->certificateManager->listCertificates() !== []) {
         $dataDir = $this->config->getSystemValue('datadirectory');
         $this->client->setDefaultOption('verify', $dataDir . '/' . $this->certificateManager->getCertificateBundle());
     } else {
         $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/config/ca-bundle.crt');
     }
     $this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
     if ($this->getProxyUri() !== '') {
         $this->client->setDefaultOption('proxy', $this->getProxyUri());
     }
 }
Example #5
0
 public function getShareInfo()
 {
     $remote = $this->getRemote();
     $token = $this->getToken();
     $password = $this->getPassword();
     $url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('password' => $password)));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     $path = $this->certificateManager->getCertificateBundle();
     if (is_readable($path)) {
         curl_setopt($ch, CURLOPT_CAINFO, $path);
     }
     $result = curl_exec($ch);
     $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $errorMessage = curl_error($ch);
     curl_close($ch);
     if (!empty($errorMessage)) {
         throw new \Exception($errorMessage);
     }
     switch ($status) {
         case 401:
         case 403:
             throw new ForbiddenException();
         case 404:
             throw new NotFoundException();
         case 500:
             throw new \Exception();
     }
     return json_decode($result, true);
 }
	public function testRemoveCertificate() {
		$this->certificateManager
			->expects($this->once())
			->method('removeCertificate')
			->with('CertificateToRemove');

		$this->assertEquals(new DataResponse(), $this->certificateController->removePersonalRootCertificate('CertificateToRemove'));
	}
Example #7
0
 /**
  * Sets the default options to the client
  */
 private function setDefaultOptions()
 {
     // Either use user bundle or the system bundle if nothing is specified
     if ($this->certificateManager->listCertificates() !== []) {
         $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath());
     } else {
         // If the instance is not yet setup we need to use the static path as
         // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate
         // a view
         if ($this->config->getSystemValue('installed', false)) {
             $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null));
         } else {
             $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
         }
     }
     $this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
     if ($this->getProxyUri() !== '') {
         $this->client->setDefaultOption('proxy', $this->getProxyUri());
     }
 }
Example #8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $outputType = $input->getOption('output');
     if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
         $certificates = array_map(function (ICertificate $certificate) {
             return ['name' => $certificate->getName(), 'common_name' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), 'expire' => $certificate->getExpireDate()->format(\DateTime::ATOM), 'issuer' => $certificate->getIssuerName(), 'issuer_organization' => $certificate->getIssuerOrganization(), 'issue_date' => $certificate->getIssueDate()->format(\DateTime::ATOM)];
         }, $this->certificateManager->listCertificates());
         if ($outputType === self::OUTPUT_FORMAT_JSON) {
             $output->writeln(json_encode(array_values($certificates)));
         } else {
             $output->writeln(json_encode(array_values($certificates), JSON_PRETTY_PRINT));
         }
     } else {
         $table = new Table($output);
         $table->setHeaders(['File Name', 'Common Name', 'Organization', 'Valid Until', 'Issued By']);
         $rows = array_map(function (ICertificate $certificate) {
             return [$certificate->getName(), $certificate->getCommonName(), $certificate->getOrganization(), $this->l->l('date', $certificate->getExpireDate()), $certificate->getIssuerName()];
         }, $this->certificateManager->listCertificates());
         $table->setRows($rows);
         $table->render();
     }
 }
Example #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $this->certificateManager->removeCertificate($name);
 }
	/**
	 * Removes a personal root certificate from the users' trust store
	 *
	 * @NoAdminRequired
	 * @NoSubadminRequired
	 * @param string $certificateIdentifier
	 * @return DataResponse
	 */
	public function removePersonalRootCertificate($certificateIdentifier) {
		$this->certificateManager->removeCertificate($certificateIdentifier);
		return new DataResponse();
	}