Skip to content

Commit

Permalink
Merge pull request #3168 from LibreSign/fix/download-binaries
Browse files Browse the repository at this point in the history
Fix/download binaries
  • Loading branch information
vitormattos authored Jun 18, 2024
2 parents d03c27d + 190ff2d commit 152f564
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ appstore: clean
cp tests/fixtures/small_valid.pdf $(appstore_sign_dir)/$(app_name)/tests/fixtures

$(occ) config:app:set libresign certificate_engine --value cfssl
$(occ) libresign:install --all
$(occ) libresign:install --all --architecture aarch64
$(occ) libresign:install --all --architecture x86_64
$(occ) libresign:developer:sign-setup --privateKey=$(cert_dir)/$(app_name).key \
--certificate=$(cert_dir)/$(app_name).crt

Expand Down
3 changes: 3 additions & 0 deletions lib/Command/Developer/SignSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
$output->writeln('Successfully signed');
unlink(__DIR__ . '/../../../build/tools/certificates/local/root.crt');
unlink(__DIR__ . '/../../../build/tools/certificates/local/libresign.crt');
unlink(__DIR__ . '/../../../build/tools/certificates/local/libresign.key');
} catch (\Exception $e) {
$output->writeln('Error: ' . $e->getMessage());
return 1;
Expand Down
7 changes: 6 additions & 1 deletion lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IEventSource;
use OCP\IEventSourceFactory;
use OCP\IL10N;
Expand All @@ -34,6 +35,7 @@ class AdminController extends AEnvironmentAwareController {
private IEventSource $eventSource;
public function __construct(
IRequest $request,
private IAppConfig $appConfig,
private ConfigureCheckService $configureCheckService,
private InstallService $installService,
private CertificateEngineHandler $certificateEngineHandler,
Expand Down Expand Up @@ -191,8 +193,11 @@ public function installAndValidate(): void {
$this->installService->installJava($async);
$this->installService->installJSignPdf($async);
$this->installService->installPdftk($async);
$this->installService->installCfssl($async);
if ($this->appConfig->getAppValue('certificate_engine') === 'cfssl') {
$this->installService->installCfssl($async);
}

$this->configureCheckService->disableCache();
$this->eventSource->send('configure_check', $this->configureCheckService->checkAll());
$seconds = 0;
while ($this->installService->isDownloadWip()) {
Expand Down
10 changes: 10 additions & 0 deletions lib/Service/Install/ConfigureCheckService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\Libresign\Service\Install;

use OC\AppConfig;
use OC\SystemConfig;
use OCA\Libresign\Handler\CertificateEngine\Handler as CertificateEngine;
use OCA\Libresign\Handler\JSignPdfHandler;
Expand All @@ -16,22 +17,31 @@

class ConfigureCheckService {
private string $architecture;
private bool $isCacheDisabled = false;
public function __construct(
private IAppConfig $appConfig,
private SystemConfig $systemConfig,
private AppConfig $ocAppConfig,
private JSignPdfHandler $jSignPdfHandler,
private CertificateEngine $certificateEngine,
private SignSetupService $signSetupService,
) {
$this->architecture = php_uname('m');
}

public function disableCache(): void {
$this->isCacheDisabled = true;
}

/**
* Get result of all checks
*
* @return ConfigureCheckHelper[]
*/
public function checkAll(): array {
if ($this->isCacheDisabled) {
$this->ocAppConfig->clearCache();
}
$result = [];
$result = array_merge($result, $this->checkSign());
$result = array_merge($result, $this->checkCertificate());
Expand Down
25 changes: 23 additions & 2 deletions src/store/configureCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const useConfigureCheckStore = function(...args) {
const store = defineStore('configureCheck', {
state: () => ({
items: [],
state: 'in progress',
downloadInProgress: false,
}),

actions: {
Expand All @@ -26,11 +28,30 @@ export const useConfigureCheckStore = function(...args) {
&& this.items.filter((o) => o.resource === 'cfssl').length > 0
&& this.items.filter((o) => o.resource === 'cfssl' && o.status === 'error').length === 0
},
updateItems(items) {
set(this, 'items', items)
const java = this.items.filter((o) => o.resource === 'java' && o.status === 'error').length === 0
const jsignpdf = this.items.filter((o) => o.resource === 'jsignpdf' && o.status === 'error').length === 0
const cfssl = this.items.filter((o) => o.resource === 'cfssl' && o.status === 'error').length === 0
if (!java
|| !jsignpdf
|| !cfssl
) {
set(this, 'state', 'need download')
} else {
set(this, 'state', 'done')
}
set(this, 'downloadInProgress', false)
},
async checkSetup() {
const response = await axios.get(
set(this, 'state', 'in progress')
set(this, 'downloadInProgress', true)
await axios.get(
generateOcsUrl('/apps/libresign/api/v1/admin/configure-check'),
)
set(this, 'items', response.data.ocs.data)
.then(({ data }) => {
this.updateItems(data.ocs.data)
})
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion src/views/Settings/ConfigureCheck.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- eslint-disable vue/no-v-html -->

<template>
<NcSettingsSection :name="name" :description="description">
<NcSettingsSection v-if="configureCheckStore.items.length > 0" :name="name" :description="description">
<table class="grid">
<tbody>
<tr class="group-header">
Expand Down
81 changes: 29 additions & 52 deletions src/views/Settings/DownloadBinaries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<NcButton class="primary"
type="primary"
native-type="submit"
:disabled="downloadInProgress"
:disabled="configureCheckStore.downloadInProgress"
@click="installAndValidate">
<template #icon>
<NcLoadingIcon v-if="downloadInProgress" :size="20" />
<NcLoadingIcon v-if="configureCheckStore.downloadInProgress" :size="20" />
</template>
{{ labelDownloadAllBinaries }}
</NcButton>
Expand All @@ -33,8 +33,6 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcProgressBar from '@nextcloud/vue/dist/Components/NcProgressBar.js'
import { generateOcsUrl } from '@nextcloud/router'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
import { set } from 'vue'
import { useConfigureCheckStore } from '../../store/configureCheck.js'
Expand All @@ -54,9 +52,6 @@ export default {
data() {
return {
name: t('libresign', 'Dependencies'),
description: t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.'),
labelDownloadAllBinaries: t('libresign', 'Download binaries'),
downloadInProgress: false,
errors: [],
downloadStatus: {
java: 0,
Expand All @@ -65,56 +60,37 @@ export default {
},
}
},
mounted() {
subscribe('libresign:config-check', this.configureCheck)
},
beforeUnmount() {
unsubscribe('libresign:config-check')
},
methods: {
async configureCheck() {
this.changeState('in progress')
axios.get(generateOcsUrl('/apps/libresign/api/v1/admin/configure-check'))
.then(({ data }) => {
this.configureCheckStore.items = data.ocs.data
const java = data.ocs.data.filter((o) => o.resource === 'java' && o.status === 'error').length === 0
const jsignpdf = data.ocs.data.filter((o) => o.resource === 'jsignpdf' && o.status === 'error').length === 0
const cfssl = data.ocs.data.filter((o) => o.resource === 'cfssl' && o.status === 'error').length === 0
if (!java
|| !jsignpdf
|| !cfssl
) {
this.changeState('need download')
} else {
this.changeState('done')
}
})
computed: {
labelDownloadAllBinaries() {
if (this.configureCheckStore.state === 'in progress') {
return t('libresign', 'Loading …')
} else if (this.configureCheckStore.state === 'downloading binaries') {
return t('libresign', 'Downloading binaries')
} else if (this.configureCheckStore.state === 'need download') {
return t('libresign', 'Download binaries')
} else if (this.configureCheckStore.state === 'done') {
return t('libresign', 'Validate setup')
}
return t('libresign', 'Download binaries')
},
changeState(state) {
if (state === 'in progress') {
this.errors = []
this.downloadInProgress = true
this.labelDownloadAllBinaries = t('libresign', 'Downloading binaries')
this.description = t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.')
} else if (state === 'waiting check') {
this.downloadInProgress = false
this.labelDownloadAllBinaries = t('libresign', 'Binaries downloaded')
this.description = t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.')
} else if (state === 'need download') {
this.downloadInProgress = false
this.labelDownloadAllBinaries = t('libresign', 'Download binaries')
this.description = t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.')
} else if (state === 'done') {
this.downloadInProgress = false
this.labelDownloadAllBinaries = t('libresign', 'Validate setup')
this.description = t('libresign', 'Binaries downloaded')
description() {
if (this.configureCheckStore.state === 'in progress') {
return t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.')
} else if (this.configureCheckStore.state === 'need download') {
return t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.')
}
return t('libresign', 'Binaries required to work. Download size could be nearly 340MB, please wait a moment.')
},
},
methods: {
installAndValidate() {
const self = this
const updateEventSource = new OC.EventSource(generateOcsUrl('/apps/libresign/api/v1/admin/install-and-validate'))
this.changeState('in progress')
set(this.configureCheckStore, 'state', 'in progress')
set(this.configureCheckStore, 'downloadInProgress', true)
this.errors = []
updateEventSource.listen('total_size', function(message) {
set(self.configureCheckStore, 'state', 'downloading binaries')
const downloadStatus = JSON.parse(message)
Object.keys(downloadStatus).forEach(service => {
set(self.downloadStatus, service, downloadStatus[service])
Expand All @@ -125,11 +101,12 @@ export default {
})
updateEventSource.listen('errors', function(message) {
self.errors = JSON.parse(message)
self.changeState('need download')
set(self.configureCheckStore, 'state', 'need download')
})
updateEventSource.listen('done', function() {
self.downloadStatus = {}
self.changeState('waiting check')
set(self.configureCheckStore, 'state', 'done')
set(self.configureCheckStore, 'downloadInProgress', false)
})
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/views/Settings/RootCertificateCfssl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import { generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import CertificateCustonOptions from './CertificateCustonOptions.vue'
import { selectCustonOption } from '../../helpers/certification.js'
Expand Down Expand Up @@ -224,7 +224,7 @@ export default {
}
this.certificate = response.data.ocs.data.data
this.afterCertificateGenerated()
emit('libresign:config-check')
this.configureCheckStore.checkSetup()
return
} catch (e) {
console.error(e)
Expand Down
4 changes: 2 additions & 2 deletions src/views/Settings/RootCertificateOpenSsl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import { generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import CertificateCustonOptions from './CertificateCustonOptions.vue'
import { selectCustonOption } from '../../helpers/certification.js'
Expand Down Expand Up @@ -210,7 +210,7 @@ export default {
}
this.certificate = response.data.ocs.data.data
this.afterCertificateGenerated()
emit('libresign:config-check')
this.configureCheckStore.checkSetup()
return
} catch (e) {
console.error(e)
Expand Down

0 comments on commit 152f564

Please sign in to comment.