Skip to content

Commit

Permalink
feat(cli): copy signature when using secure live updates (#5896)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpoole authored Sep 7, 2022
1 parent 9658fe1 commit 0f17177
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export interface LiveUpdateConfig {
channel: string;
autoUpdateMethod: AutoUpdateMethod;
maxVersions?: number;
key?: string;
}

export type AutoUpdateMethod = 'none' | 'background';
Expand All @@ -548,4 +549,11 @@ export interface PluginsConfig {
shell: Portal;
apps: Portal[];
};

/**
* Capacitor Live Updates plugin configuration
*
* @since 4.2.0
*/
LiveUpdates?: LiveUpdateConfig;
}
45 changes: 45 additions & 0 deletions cli/src/tasks/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ export async function copy(
usesCapacitorPortals = true;
}

let usesLiveUpdates = false;
if (
allPlugins.filter(plugin => plugin.id === '@capacitor/live-updates')
.length > 0
) {
usesLiveUpdates = true;
}

if (platformName === config.ios.name) {
if (usesCapacitorPortals) {
await copyFederatedWebDirs(config, await config.ios.webDirAbs);
Expand All @@ -92,6 +100,9 @@ export async function copy(
config.app.webDirAbs,
);
}
if (usesLiveUpdates) {
await copySecureLiveUpdatesKey(config, config.ios.nativeTargetDirAbs);
}
await copyCapacitorConfig(config, config.ios.nativeTargetDirAbs);
const cordovaPlugins = await getCordovaPlugins(config, platformName);
await handleCordovaPluginsJS(cordovaPlugins, config, platformName);
Expand All @@ -105,6 +116,9 @@ export async function copy(
config.app.webDirAbs,
);
}
if (usesLiveUpdates) {
await copySecureLiveUpdatesKey(config, config.android.assetsDirAbs);
}
await copyCapacitorConfig(config, config.android.assetsDirAbs);
const cordovaPlugins = await getCordovaPlugins(config, platformName);
await handleCordovaPluginsJS(cordovaPlugins, config, platformName);
Expand Down Expand Up @@ -207,3 +221,34 @@ function isPortal(config: any): config is Portal {
(config as Portal).name !== undefined
);
}

async function copySecureLiveUpdatesKey(config: Config, nativeAbsDir: string) {
if (!config.app.extConfig?.plugins?.LiveUpdates?.key) {
return;
}

const secureLiveUpdatesKeyFile = config.app.extConfig.plugins.LiveUpdates.key;
const keyAbsFromPath = join(config.app.rootDir, secureLiveUpdatesKeyFile);
const keyAbsToPath = join(nativeAbsDir, basename(keyAbsFromPath));
const keyRelToDir = relative(config.app.rootDir, nativeAbsDir);

if (!(await pathExists(keyAbsFromPath))) {
logger.warn(
`Cannot copy Secure Live Updates signature file from ${c.strong(
keyAbsFromPath,
)} to ${keyRelToDir}\n` +
`Signature file does not exist at specified key path.`,
);

return;
}

await runTask(
`Copying Secure Live Updates key from ${c.strong(
secureLiveUpdatesKeyFile,
)} to ${keyRelToDir}`,
async () => {
return fsCopy(keyAbsFromPath, keyAbsToPath);
},
);
}

0 comments on commit 0f17177

Please sign in to comment.