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); }
/** * Add a new personal root certificate to the users' trust store * * @NoAdminRequired * @NoSubadminRequired * @return array */ public function addPersonalRootCertificate() { if ($this->isCertificateImportAllowed() === false) { return new DataResponse('Individual certificate management disabled', Http::STATUS_FORBIDDEN); } $file = $this->request->getUploadedFile('rootcert_import'); if (empty($file)) { return new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY); } try { $certificate = $this->certificateManager->addCertificate(file_get_contents($file['tmp_name']), $file['name']); return new DataResponse(['name' => $certificate->getName(), 'commonName' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), 'validFrom' => $certificate->getIssueDate()->getTimestamp(), 'validTill' => $certificate->getExpireDate()->getTimestamp(), 'validFromString' => $this->l10n->l('date', $certificate->getIssueDate()), 'validTillString' => $this->l10n->l('date', $certificate->getExpireDate()), 'issuer' => $certificate->getIssuerName(), 'issuerOrganization' => $certificate->getIssuerOrganization()]); } catch (\Exception $e) { return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY); } }
/** * Add a new personal root certificate to the users' trust store * * @NoAdminRequired * @NoSubadminRequired * @return array */ public function addPersonalRootCertificate() { $headers = []; if ($this->request->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE_8])) { // due to upload iframe workaround, need to set content-type to text/plain $headers['Content-Type'] = 'text/plain'; } if ($this->isCertificateImportAllowed() === false) { return new DataResponse(['message' => 'Individual certificate management disabled'], Http::STATUS_FORBIDDEN, $headers); } $file = $this->request->getUploadedFile('rootcert_import'); if (empty($file)) { return new DataResponse(['message' => 'No file uploaded'], Http::STATUS_UNPROCESSABLE_ENTITY, $headers); } try { $certificate = $this->certificateManager->addCertificate(file_get_contents($file['tmp_name']), $file['name']); return new DataResponse(['name' => $certificate->getName(), 'commonName' => $certificate->getCommonName(), 'organization' => $certificate->getOrganization(), 'validFrom' => $certificate->getIssueDate()->getTimestamp(), 'validTill' => $certificate->getExpireDate()->getTimestamp(), 'validFromString' => $this->l10n->l('date', $certificate->getIssueDate()), 'validTillString' => $this->l10n->l('date', $certificate->getExpireDate()), 'issuer' => $certificate->getIssuerName(), 'issuerOrganization' => $certificate->getIssuerOrganization()], Http::STATUS_OK, $headers); } catch (\Exception $e) { return new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY, $headers); } }