summaryrefslogtreecommitdiffstats
path: root/settings/ajax/addRootCertificate.php
blob: 9be8fd0025b7611207c34e63b886eeef2cb88da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

OCP\JSON::checkAppEnabled('files_external');
OCP\JSON::callCheck();

$l = new OC_L10N('core');

if (!($filename = $_FILES['rootcert_import']['name'])) {
	header('Location:' . OCP\Util::linkToRoute("settings_personal"));
	exit;
}

$fh = fopen($_FILES['rootcert_import']['tmp_name'], 'r');
$data = fread($fh, filesize($_FILES['rootcert_import']['tmp_name']));
fclose($fh);
$filename = $_FILES['rootcert_import']['name'];

$certificateManager = \OC::$server->getCertificateManager();

if ($cert = $certificateManager->addCertificate($data, $filename)) {
	OCP\JSON::success(array(
		'name' => $cert->getName(),
		'commonName' => $cert->getCommonName(),
		'organization' => $cert->getOrganization(),
		'validFrom' => $cert->getIssueDate()->getTimestamp(),
		'validTill' => $cert->getExpireDate()->getTimestamp(),
		'validFromString' => $l->l('date', $cert->getIssueDate()),
		'validTillString' => $l->l('date', $cert->getExpireDate()),
		'issuer' => $cert->getIssuerName(),
		'issuerOrganization' => $cert->getIssuerOrganization()
	));
} else {
	OCP\JSON::error(array('error' => 'Couldn\'t import SSL root certificate, allowed formats: PEM and DER'));
}