Slide 1

Slide 1 text

#webbundle_study #webbundle_study 2019/12/12 Jxck

Slide 2

Slide 2 text

WebPackaging Spec ● SXG (was Signing) ● WebBundles (was Bundling) ● Loading 2

Slide 3

Slide 3 text

draft-yasskin-wpack-bundled-exchanges-02 3

Slide 4

Slide 4 text

Web Bundles Spec 4 ● Yes: How parser work ● No: How encoder produce bundle

Slide 5

Slide 5 text

5 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] All you need is CBOR encoder/decoder

Slide 6

Slide 6 text

6 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [* any ], length: bytes .size 8 ] magic number via emoji in UTF8 webbundle file start with cbor array header(length 6) + magic so first 10 byte is below [0x86, 0x48, 0xF0, 0x9F, 0x8C, 0x90, 0xF0, 0x9F, 0x93, 0xA6] (if array length changes with adding more element to cbor array in the future. first 10 byte will change, before you reach to version number.)

Slide 7

Slide 7 text

7 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [* any ], length: bytes .size 8 ] cbor version "1" is in this spec, chrome uses "b1" for beta.

Slide 8

Slide 8 text

8 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [* any ], length: bytes .size 8 ] URL for this content. if parse errors, this will use as fallback url.

Slide 9

Slide 9 text

9 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [* any ], length: bytes .size 8 ] index for section, enables direct access to section. ["index", 100, // 0- 99 "responses", 200, // 100-199 "manifest", 300, // 200-299 "signatures", 400, // 300-399 "critical", 500] // 400-499

Slide 10

Slide 10 text

10 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] Index Section index for response section. URL => [variation, offset, length] { "http://example.com/index.html": [["ja"], 1, 100], // for Accept-Encoding: ja "http://example.com/index.html": [["en"], 101, 100], // for Accept-Encoding: en "http://example.com/style.css": [[ ], 201, 100], "http://example.com/script.js": [[ ], 301, 100], "http://example.com/favicon.ico": [[ ], 401, 100], } variation: based on Content-Language, Content-Encoding(?),

Slide 11

Slide 11 text

11 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] Responses Section [ [ HTTP Header (Cbor Map) HTTP Body (Cbor Byte string) ], [ HTTP Header (Cbor Map) HTTP Body (Cbor Byte string) ] ... ]

Slide 12

Slide 12 text

12 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] Manifest Section manifest = manifest-url

Slide 13

Slide 13 text

13 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] Signature Section signatures = [ authorities: [*authority], vouched-subsets: [*{ authority: index-in-authorities, sig: bstr, signed: bstr ; Expected to hold a signed-subset item. }], ] // Reject all signatures by an RSA public key.

Slide 14

Slide 14 text

14 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] Critical Section > The "critical" section lists sections of the bundle that the client needs to understand in order to load the bundle correctly ???

Slide 15

Slide 15 text

15 Top Level Structure ; CBOR Array webbundle = [ magic: h'', ; UTF-8 version: bytes .size 4, primary-url: whatwg-url, section-lengths:bytes.cbor [*(section-name:tstr,length:uint)], sections: [*(index|manifest|signatures|critical|responses)], length: bytes .size 8 ] Length length of webbundle in self extracting executables (like ASAR in Electron), pointer in tail works fine. because of concatnating $ cat runtime webpackage > extracting_bin $ cat extracting_bin other_webpackage https://github.com/WICG/webpackage/issues/20

Slide 16

Slide 16 text

overview ● format via cbor ● has index for direct access ● can contain ○ index ○ response ○ signature ○ manifest (url) ○ etc 16

Slide 17

Slide 17 text

Serve Webbundle ● Via HTTP ○ Content-Type: application/webbundle ○ X-Content-Type-Options: nosniff ● Vai other ○ USB ○ AirDrop ○ WebShare ○ etc 17

Slide 18

Slide 18 text

how it works 18

Slide 19

Slide 19 text

19 Q: 1 Magic String & File detection webbundle = [ magic version // 1 primary-url section-lengths sections length ] head = read_first_10_byte(path) if (head == [86 48 F0 9F 8C 90 F0 9F 93 A6]) { // this is web bundle switch (parse_cbor(path)['version']) { // version switch } } else { // this is not web bundle }

Slide 20

Slide 20 text

20 Q: 1 Magic String & File detection webbundle = [ magic version // 2 primary-url section-lengths sections extension // new length ] head = read_first_10_byte(path) if (head == [86 48 F0 9F 8C 90 F0 9F 93 A6]) { // this is web bundle switch (parse_cbor(path)['version']) { // version switch } } else if (head == [87 48 F0 9F 8C 90 F0 9F 93 A6] // this is also new web bundle switch (parse_cbor(path)['version']) { // version switch } } else { // this is not web bundle }

Slide 21

Slide 21 text

21 Q: 1 Magic String & File detection // current webbundle = [ magic version primary-url section-lengths sections length ] // seems better ? webbundle = [ magic body = [ version primary-url section-lengths sections ] length ] // first 10 byte always starts in any version // “83 48 F0 9F 8C 90 F0 9F 93 A6” https://github.com/WICG/webpackage/issues/528

Slide 22

Slide 22 text

22 Q: 2 Length at end // current webbundle = [ magic version primary-url section-lengths sections length ] move length at last really works? https://github.com/WICG/webpackage/issues/20#issuecomment-564370002

Slide 23

Slide 23 text

23 Related ● Web Bundles ○ https://wicg.github.io/webpackage/draft-yasskin-wpack-bundled-exchan ges.html

Slide 24

Slide 24 text

Jack