* @param AppFetcher $appFetcher
* @param IClientService $clientService
* @param ITempManager $tempManager
- * @param ILogger $logger
*
- * @return bool Whether the installation was successful or not
- * @throws \Exception
+ * @throws \Exception If the installation was not successful
*/
public function downloadApp($appId,
AppFetcher $appFetcher,
IClientService $clientService,
- ITempManager $tempManager,
- ILogger $logger) {
+ ITempManager $tempManager) {
$appId = strtolower($appId);
$apps = $appFetcher->get();
$x509->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
$x509->loadX509($app['certificate']);
if($x509->validateSignature() !== true) {
- $logger->error(
+ throw new \Exception(
sprintf(
'App with id %s has a certificate not issued by a trusted Code Signing Authority',
$appId
'app' => 'core',
]
);
- return false;
}
// Verify if the certificate is issued for the requested app id
$certInfo = openssl_x509_parse($app['certificate']);
if(!isset($certInfo['subject']['CN'])) {
- $logger->error(
+ throw new \Exception(
sprintf(
'App with id %s has a cert with no CN',
$appId
'app' => 'core',
]
);
- return false;
}
if($certInfo['subject']['CN'] !== $appId) {
- $logger->error(
+ throw new \Exception(
sprintf(
'App with id %s has a cert issued to %s',
$appId,
'app' => 'core',
]
);
- return false;
}
// Download the release
$tempFile = $tempManager->getTemporaryFile('.tar.gz');
$client = $clientService->newClient();
- // FIXME: Proper way to determine what the latest release is
$client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
// Check if the signature actually matches the downloaded content
$xml = simplexml_load_file($extractDir . '/' . $appId . '/appinfo/info.xml');
libxml_disable_entity_loader($loadEntities);
if((string)$xml->id !== $appId) {
- $logger->error(
+ throw new \Exception(
sprintf(
'App for id %s has a wrong app ID in info.xml: %s',
$appId,
'app' => 'core',
]
);
- return false;
}
// Move to app folder
}
OC_Helper::copyr($extractDir, $baseDir);
OC_Helper::rmdirr($extractDir);
- return true;
} else {
- $logger->error(
+ throw new \Exception(
sprintf(
'Could not extract app with ID %s to %s',
$appId,
'app' => 'core',
]
);
- return false;
}
} else {
// Signature does not match
- $logger->error(
+ throw new \Exception(
sprintf(
'App with id %s has invalid signature',
$appId
}
}
}
-
- return false;
}
/**
$isDownloaded = $installer->isDownloaded($appId);
if(!$isDownloaded) {
- $state = $installer->downloadApp(
+ $installer->downloadApp(
$appId,
new \OC\App\AppStore\Fetcher\AppFetcher(
\OC::$server->getAppDataDir('appstore'),
$config
),
\OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->getLogger()
+ \OC::$server->getTempManager()
);
-
- if($state !== true) {
- throw new \Exception(
- sprintf(
- 'Could not download app with id: %s',
- $appId
- )
- );
- }
}
if (!Installer::isInstalled($appId)) {