Replace with exception instead of boolean return value
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
parent
01c566883e
commit
0e2aee2be6
|
@ -241,16 +241,13 @@ class Installer {
|
||||||
* @param AppFetcher $appFetcher
|
* @param AppFetcher $appFetcher
|
||||||
* @param IClientService $clientService
|
* @param IClientService $clientService
|
||||||
* @param ITempManager $tempManager
|
* @param ITempManager $tempManager
|
||||||
* @param ILogger $logger
|
|
||||||
*
|
*
|
||||||
* @return bool Whether the installation was successful or not
|
* @throws \Exception If the installation was not successful
|
||||||
* @throws \Exception
|
|
||||||
*/
|
*/
|
||||||
public function downloadApp($appId,
|
public function downloadApp($appId,
|
||||||
AppFetcher $appFetcher,
|
AppFetcher $appFetcher,
|
||||||
IClientService $clientService,
|
IClientService $clientService,
|
||||||
ITempManager $tempManager,
|
ITempManager $tempManager) {
|
||||||
ILogger $logger) {
|
|
||||||
$appId = strtolower($appId);
|
$appId = strtolower($appId);
|
||||||
|
|
||||||
$apps = $appFetcher->get();
|
$apps = $appFetcher->get();
|
||||||
|
@ -261,7 +258,7 @@ class Installer {
|
||||||
$x509->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
|
$x509->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
|
||||||
$x509->loadX509($app['certificate']);
|
$x509->loadX509($app['certificate']);
|
||||||
if($x509->validateSignature() !== true) {
|
if($x509->validateSignature() !== true) {
|
||||||
$logger->error(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'App with id %s has a certificate not issued by a trusted Code Signing Authority',
|
'App with id %s has a certificate not issued by a trusted Code Signing Authority',
|
||||||
$appId
|
$appId
|
||||||
|
@ -270,13 +267,12 @@ class Installer {
|
||||||
'app' => 'core',
|
'app' => 'core',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify if the certificate is issued for the requested app id
|
// Verify if the certificate is issued for the requested app id
|
||||||
$certInfo = openssl_x509_parse($app['certificate']);
|
$certInfo = openssl_x509_parse($app['certificate']);
|
||||||
if(!isset($certInfo['subject']['CN'])) {
|
if(!isset($certInfo['subject']['CN'])) {
|
||||||
$logger->error(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'App with id %s has a cert with no CN',
|
'App with id %s has a cert with no CN',
|
||||||
$appId
|
$appId
|
||||||
|
@ -285,10 +281,9 @@ class Installer {
|
||||||
'app' => 'core',
|
'app' => 'core',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if($certInfo['subject']['CN'] !== $appId) {
|
if($certInfo['subject']['CN'] !== $appId) {
|
||||||
$logger->error(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'App with id %s has a cert issued to %s',
|
'App with id %s has a cert issued to %s',
|
||||||
$appId,
|
$appId,
|
||||||
|
@ -298,13 +293,11 @@ class Installer {
|
||||||
'app' => 'core',
|
'app' => 'core',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the release
|
// Download the release
|
||||||
$tempFile = $tempManager->getTemporaryFile('.tar.gz');
|
$tempFile = $tempManager->getTemporaryFile('.tar.gz');
|
||||||
$client = $clientService->newClient();
|
$client = $clientService->newClient();
|
||||||
// FIXME: Proper way to determine what the latest release is
|
|
||||||
$client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
|
$client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
|
||||||
|
|
||||||
// Check if the signature actually matches the downloaded content
|
// Check if the signature actually matches the downloaded content
|
||||||
|
@ -325,7 +318,7 @@ class Installer {
|
||||||
$xml = simplexml_load_file($extractDir . '/' . $appId . '/appinfo/info.xml');
|
$xml = simplexml_load_file($extractDir . '/' . $appId . '/appinfo/info.xml');
|
||||||
libxml_disable_entity_loader($loadEntities);
|
libxml_disable_entity_loader($loadEntities);
|
||||||
if((string)$xml->id !== $appId) {
|
if((string)$xml->id !== $appId) {
|
||||||
$logger->error(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'App for id %s has a wrong app ID in info.xml: %s',
|
'App for id %s has a wrong app ID in info.xml: %s',
|
||||||
$appId,
|
$appId,
|
||||||
|
@ -335,7 +328,6 @@ class Installer {
|
||||||
'app' => 'core',
|
'app' => 'core',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move to app folder
|
// Move to app folder
|
||||||
|
@ -347,9 +339,8 @@ class Installer {
|
||||||
}
|
}
|
||||||
OC_Helper::copyr($extractDir, $baseDir);
|
OC_Helper::copyr($extractDir, $baseDir);
|
||||||
OC_Helper::rmdirr($extractDir);
|
OC_Helper::rmdirr($extractDir);
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
$logger->error(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Could not extract app with ID %s to %s',
|
'Could not extract app with ID %s to %s',
|
||||||
$appId,
|
$appId,
|
||||||
|
@ -359,11 +350,10 @@ class Installer {
|
||||||
'app' => 'core',
|
'app' => 'core',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Signature does not match
|
// Signature does not match
|
||||||
$logger->error(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'App with id %s has invalid signature',
|
'App with id %s has invalid signature',
|
||||||
$appId
|
$appId
|
||||||
|
@ -375,8 +365,6 @@ class Installer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -345,7 +345,7 @@ class OC_App {
|
||||||
$isDownloaded = $installer->isDownloaded($appId);
|
$isDownloaded = $installer->isDownloaded($appId);
|
||||||
|
|
||||||
if(!$isDownloaded) {
|
if(!$isDownloaded) {
|
||||||
$state = $installer->downloadApp(
|
$installer->downloadApp(
|
||||||
$appId,
|
$appId,
|
||||||
new \OC\App\AppStore\Fetcher\AppFetcher(
|
new \OC\App\AppStore\Fetcher\AppFetcher(
|
||||||
\OC::$server->getAppDataDir('appstore'),
|
\OC::$server->getAppDataDir('appstore'),
|
||||||
|
@ -354,18 +354,8 @@ class OC_App {
|
||||||
$config
|
$config
|
||||||
),
|
),
|
||||||
\OC::$server->getHTTPClientService(),
|
\OC::$server->getHTTPClientService(),
|
||||||
\OC::$server->getTempManager(),
|
\OC::$server->getTempManager()
|
||||||
\OC::$server->getLogger()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if($state !== true) {
|
|
||||||
throw new \Exception(
|
|
||||||
sprintf(
|
|
||||||
'Could not download app with id: %s',
|
|
||||||
$appId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Installer::isInstalled($appId)) {
|
if (!Installer::isInstalled($appId)) {
|
||||||
|
|
Loading…
Reference in New Issue