Skip to content

Commit c7f74d5

Browse files
committed
ready for prod
1 parent b2c6eb4 commit c7f74d5

1 file changed

Lines changed: 16 additions & 76 deletions

File tree

apps/pwabuilder/src/script/components/windows-form.ts

Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ const ajv = new Ajv2020({ allErrors: true });
2222
addFormats(ajv);
2323
let actionsSchemaValidation: any = null;
2424

25-
const encryptedSchema = {
26-
"encrypted": "s+En3NVL4S07lD0o0yGjnXxE0ogmOZjDrcY/1OwNI/HnhP/0MuvU128qfTGqJ5a+pa/y6HRU05Ze4A94oyTT+Y94kDgyc3cZhJJlnoobkk5L/KqordTIkOJzd+Kk3Ne6uIFfpdolBebyAsAUG4k8HfFxrSmXZolOpgNkFtIFO9NmrIothQ8c6AmclrmwoLEO7/WhIfNz",
27-
"iv": "FTS/P9blv27EMwzl",
28-
"salt": "/az9m+mDok+U453B/9KRkA==",
29-
"tag": "oarRvJIvZaz3rWA/StuzQQ=="
30-
};
31-
3225
@customElement('windows-form')
3326

3427
export class WindowsForm extends AppPackageFormBase {
@@ -43,7 +36,6 @@ export class WindowsForm extends AppPackageFormBase {
4336
@state() userBackgroundColor: string = "";
4437
@state() showUploadActionsFile: boolean = false;
4538
@state() actionsFileError: string | null = null;
46-
@state() schemaUrl: string | null = null
4739

4840
static get styles() {
4941
return [
@@ -308,7 +300,21 @@ export class WindowsForm extends AppPackageFormBase {
308300
if (!checked) {
309301
delete this.packageOptions.webActionManifestFile;
310302
actionsSchemaValidation = null;
311-
this.schemaUrl = null;
303+
} else {
304+
try {
305+
const SCHEMA_ID = "https://aka.ms/appactions.schema.json";
306+
const SCHEMA_URL = "https://raw.githubusercontent.com/microsoft/App-Actions-On-Windows-Samples/refs/heads/main/schema/ActionsSchema.json?token=GHSAT0AAAAAADD4LIMQ7SLS7TZ25YF3NMVO2BF7BSA";
307+
if (!ajv.getSchema(SCHEMA_ID)) {
308+
const response = await fetch(SCHEMA_URL);
309+
const actionsSchema = await response.json();
310+
ajv.addSchema(actionsSchema, SCHEMA_ID);
311+
}
312+
313+
actionsSchemaValidation = ajv.getSchema(SCHEMA_ID);
314+
this.actionsFileError = null;
315+
} catch (err) {
316+
this.actionsFileError = "Schema setup failed.";
317+
}
312318
}
313319
}
314320

@@ -322,71 +328,6 @@ export class WindowsForm extends AppPackageFormBase {
322328
return bytes.buffer;
323329
}
324330

325-
326-
async decryptURLWithPassword(e: Event): Promise<void> {
327-
const input = e.target as HTMLInputElement;
328-
const password: string = input.value.trim();
329-
330-
const { encrypted, iv, salt, tag } = encryptedSchema;
331-
332-
try {
333-
const ivBuf = this.base64ToArrayBuffer(iv);
334-
const saltBuf = this.base64ToArrayBuffer(salt);
335-
const tagBuf = this.base64ToArrayBuffer(tag);
336-
const encryptedBuf = this.base64ToArrayBuffer(encrypted);
337-
338-
const keyMaterial = await crypto.subtle.importKey(
339-
"raw",
340-
new TextEncoder().encode(password),
341-
{ name: "PBKDF2" },
342-
false,
343-
["deriveKey"]
344-
);
345-
346-
const key = await crypto.subtle.deriveKey(
347-
{
348-
name: "PBKDF2",
349-
salt: saltBuf,
350-
iterations: 100000,
351-
hash: "SHA-256"
352-
},
353-
keyMaterial,
354-
{ name: "AES-GCM", length: 256 },
355-
false,
356-
["decrypt"]
357-
);
358-
359-
const combined = new Uint8Array(encryptedBuf.byteLength + tagBuf.byteLength);
360-
combined.set(new Uint8Array(encryptedBuf), 0);
361-
combined.set(new Uint8Array(tagBuf), encryptedBuf.byteLength);
362-
363-
const decrypted = await crypto.subtle.decrypt(
364-
{
365-
name: "AES-GCM",
366-
iv: ivBuf,
367-
tagLength: 128,
368-
},
369-
key,
370-
combined
371-
);
372-
373-
this.schemaUrl = new TextDecoder().decode(decrypted);
374-
375-
const SCHEMA_ID = "https://aka.ms/appactions.schema.json";
376-
if (!ajv.getSchema(SCHEMA_ID)) {
377-
const response = await fetch(this.schemaUrl);
378-
const actionsSchema = await response.json();
379-
ajv.addSchema(actionsSchema, SCHEMA_ID);
380-
}
381-
382-
actionsSchemaValidation = ajv.getSchema(SCHEMA_ID);
383-
this.actionsFileError = null;
384-
} catch (err) {
385-
console.error("Failed to decrypt schema URL or compile schema:", err);
386-
this.actionsFileError = "Invalid decryption key or schema setup failed.";
387-
}
388-
}
389-
390331
async actionsFileChanged(e: Event) {
391332
if (!e) return;
392333

@@ -800,8 +741,7 @@ export class WindowsForm extends AppPackageFormBase {
800741
</div>
801742
${this.showUploadActionsFile ?
802743
html`
803-
<input type="text" name="decryption" label="password-input" placeholder="enter decryption key to access" @change=${(e: Event) => this.decryptURLWithPassword(e)} />
804-
<input id="actions-file-picker" ?disabled=${!this.schemaUrl} class=${classMap({ 'actions-error': this.actionsFileError !== null })} type="file" label="actions-manifest-input" accept=".json" @change=${(e: Event) => this.actionsFileChanged(e)}/>
744+
<input id="actions-file-picker" class=${classMap({ 'actions-error': this.actionsFileError !== null })} type="file" label="actions-manifest-input" accept=".json" @change=${(e: Event) => this.actionsFileChanged(e)}/>
805745
${this.actionsFileError ? html`<div class="actions-error-message">${this.actionsFileError}</div>` : ''}
806746
` :
807747
null

0 commit comments

Comments
 (0)