xref: /aosp_15_r20/external/pigweed/pw_software_update/design.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_software_update-design:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker--------------------------
4*61c4878aSAndroid Build Coastguard Workerpw_software_update: Design
5*61c4878aSAndroid Build Coastguard Worker--------------------------
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module-subpage::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_software_update
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard WorkerThis page explains the security framing, bundle format and update workflows of
10*61c4878aSAndroid Build Coastguard Worker``pw_software_update``.
11*61c4878aSAndroid Build Coastguard Worker
12*61c4878aSAndroid Build Coastguard WorkerEmbedded TUF
13*61c4878aSAndroid Build Coastguard Worker------------
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard WorkerAt the heart, the ``pw_software_update`` module leverages
16*61c4878aSAndroid Build Coastguard Worker`The Update Framework <https://theupdateframework.io/>`_ (TUF),
17*61c4878aSAndroid Build Coastguard Workeran industry-leading software update security framework that is open, flexible,
18*61c4878aSAndroid Build Coastguard Workerand offers a balanced security and privacy treatment.
19*61c4878aSAndroid Build Coastguard Worker
20*61c4878aSAndroid Build Coastguard WorkerThe ``pw_software_update`` module implements the following building blocks
21*61c4878aSAndroid Build Coastguard Workeraround TUF.
22*61c4878aSAndroid Build Coastguard Worker
23*61c4878aSAndroid Build Coastguard Worker.. mermaid::
24*61c4878aSAndroid Build Coastguard Worker
25*61c4878aSAndroid Build Coastguard Worker   flowchart LR
26*61c4878aSAndroid Build Coastguard Worker          A[/Source/] --> |Build| B[/Target files/]
27*61c4878aSAndroid Build Coastguard Worker          B --> |Assemble & Sign| C[(Update bundle)]
28*61c4878aSAndroid Build Coastguard Worker          C --> |Publish| D[(Available updates)]
29*61c4878aSAndroid Build Coastguard Worker          D --> |OTA| E[Device]
30*61c4878aSAndroid Build Coastguard Worker
31*61c4878aSAndroid Build Coastguard WorkerUpdate bundles
32*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^
33*61c4878aSAndroid Build Coastguard Worker
34*61c4878aSAndroid Build Coastguard WorkerUpdate bundles represent software releases packaged ready for delivery. A bundle
35*61c4878aSAndroid Build Coastguard Workeris essentially an archived folder matching the following structure:
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
38*61c4878aSAndroid Build Coastguard Worker
39*61c4878aSAndroid Build Coastguard Worker   /
40*61c4878aSAndroid Build Coastguard Worker   ├── root_metadata
41*61c4878aSAndroid Build Coastguard Worker   ├── targets_metadata
42*61c4878aSAndroid Build Coastguard Worker   └── targets
43*61c4878aSAndroid Build Coastguard Worker       ├── release_notes.txt
44*61c4878aSAndroid Build Coastguard Worker       ├── manifest.txt
45*61c4878aSAndroid Build Coastguard Worker       ├── rtos.bin
46*61c4878aSAndroid Build Coastguard Worker       └── app.bin
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard WorkerBundles are encoded as serialized "protocol buffers".
49*61c4878aSAndroid Build Coastguard Worker
50*61c4878aSAndroid Build Coastguard WorkerKey structure
51*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard WorkerAs an optimization and trade-off for embedded projects, ``pw_software_update``
54*61c4878aSAndroid Build Coastguard Workeronly supports the "root" and "targets" roles, as represented by
55*61c4878aSAndroid Build Coastguard Worker``root_metadata`` and ``targets_metadata``.
56*61c4878aSAndroid Build Coastguard Worker
57*61c4878aSAndroid Build Coastguard Worker.. mermaid::
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard Worker   flowchart LR
60*61c4878aSAndroid Build Coastguard Worker          A[Verified boot] --> |Embed & Verify| B[/Root key/]
61*61c4878aSAndroid Build Coastguard Worker          B --> |Delegate & Rotate| C[/Targets key/]
62*61c4878aSAndroid Build Coastguard Worker          C --> |Sign| D[/Target files/]
63*61c4878aSAndroid Build Coastguard Worker
64*61c4878aSAndroid Build Coastguard Worker
65*61c4878aSAndroid Build Coastguard WorkerThe "root" role delegates the "targets" role to directly authorize each release.
66*61c4878aSAndroid Build Coastguard Worker
67*61c4878aSAndroid Build Coastguard WorkerThe "root" role can regularly rotate the "targets" role, in effect revoking
68*61c4878aSAndroid Build Coastguard Workerolder versions once a new release is available.
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard WorkerThe "root" role is the "root of trust" for software update and tied into
71*61c4878aSAndroid Build Coastguard Workerverified boot. Due to security risks, ``pw_software_update`` does not use
72*61c4878aSAndroid Build Coastguard Workerpersistent metadata caches that are not covered by verified boot.
73*61c4878aSAndroid Build Coastguard Worker
74*61c4878aSAndroid Build Coastguard WorkerSigning service
75*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^
76*61c4878aSAndroid Build Coastguard WorkerProduction signing keys MUST be kept secure and clean. That means we must
77*61c4878aSAndroid Build Coastguard Workercarefully control access, log usage details, and revoke the key if it was
78*61c4878aSAndroid Build Coastguard Worker(accidentally) used to sign a "questionable" build.
79*61c4878aSAndroid Build Coastguard Worker
80*61c4878aSAndroid Build Coastguard WorkerThis is easier with a signing server built around a key management service.
81*61c4878aSAndroid Build Coastguard Worker
82*61c4878aSAndroid Build Coastguard Worker.. mermaid::
83*61c4878aSAndroid Build Coastguard Worker
84*61c4878aSAndroid Build Coastguard Worker   sequenceDiagram
85*61c4878aSAndroid Build Coastguard Worker     actor Releaser
86*61c4878aSAndroid Build Coastguard Worker
87*61c4878aSAndroid Build Coastguard Worker     Releaser->>Signer: Sign my bundle with my key, please.
88*61c4878aSAndroid Build Coastguard Worker
89*61c4878aSAndroid Build Coastguard Worker     activate Signer
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Worker     Signer->>Signer: Check permission.
92*61c4878aSAndroid Build Coastguard Worker     Signer->>Signer: Validate & sign bundle.
93*61c4878aSAndroid Build Coastguard Worker     Signer->>Signer: Log action. Email alerts.
94*61c4878aSAndroid Build Coastguard Worker     Signer-->>Releaser: Done!
95*61c4878aSAndroid Build Coastguard Worker     deactivate Signer
96*61c4878aSAndroid Build Coastguard Worker
97*61c4878aSAndroid Build Coastguard WorkerWe don't yet have a public-facing service. External users should source their
98*61c4878aSAndroid Build Coastguard Workerown solution.
99*61c4878aSAndroid Build Coastguard Worker
100*61c4878aSAndroid Build Coastguard WorkerBundle verification
101*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^
102*61c4878aSAndroid Build Coastguard Worker
103*61c4878aSAndroid Build Coastguard Worker.. mermaid::
104*61c4878aSAndroid Build Coastguard Worker
105*61c4878aSAndroid Build Coastguard Worker   flowchart LR
106*61c4878aSAndroid Build Coastguard Worker     A[(Incoming bundle)] --> |UpdateBundleAccessor| B[/Verified target files/]
107*61c4878aSAndroid Build Coastguard Worker
108*61c4878aSAndroid Build Coastguard WorkerThe :cpp:type:`UpdateBundleAccessor` decodes, verifies, and exposes the target
109*61c4878aSAndroid Build Coastguard Workerfiles from an incoming bundle. This class hides the details of the bundle
110*61c4878aSAndroid Build Coastguard Workerformat and verification flow from callers.
111*61c4878aSAndroid Build Coastguard Worker
112*61c4878aSAndroid Build Coastguard WorkerUpdate workflow
113*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^
114*61c4878aSAndroid Build Coastguard Worker
115*61c4878aSAndroid Build Coastguard WorkerOn the device side, :cpp:type:`BundledUpdateService` orchestrates an update
116*61c4878aSAndroid Build Coastguard Workersession end-to-end. It drives the backend via a :cpp:type:`BundledUpdateBackend`
117*61c4878aSAndroid Build Coastguard Workerinterface.
118*61c4878aSAndroid Build Coastguard Worker
119*61c4878aSAndroid Build Coastguard Worker:cpp:type:`BundledUpdateService` is invoked via :ref:`module-pw_rpc` after an
120*61c4878aSAndroid Build Coastguard Workerincoming bundle is staged via :ref:`module-pw_transfer`.
121*61c4878aSAndroid Build Coastguard Worker
122*61c4878aSAndroid Build Coastguard Worker.. mermaid::
123*61c4878aSAndroid Build Coastguard Worker
124*61c4878aSAndroid Build Coastguard Worker   stateDiagram-v2
125*61c4878aSAndroid Build Coastguard Worker   direction LR
126*61c4878aSAndroid Build Coastguard Worker
127*61c4878aSAndroid Build Coastguard Worker   [*] --> Inactive
128*61c4878aSAndroid Build Coastguard Worker
129*61c4878aSAndroid Build Coastguard Worker   Inactive --> Transferring: Start()
130*61c4878aSAndroid Build Coastguard Worker   Inactive --> Finished: Start() error
131*61c4878aSAndroid Build Coastguard Worker
132*61c4878aSAndroid Build Coastguard Worker   Transferring --> Transferring: GetStatus()
133*61c4878aSAndroid Build Coastguard Worker   Transferring --> Transferred
134*61c4878aSAndroid Build Coastguard Worker   Transferring --> Aborting: Abort()
135*61c4878aSAndroid Build Coastguard Worker   Transferring --> Finished: Transfer error
136*61c4878aSAndroid Build Coastguard Worker
137*61c4878aSAndroid Build Coastguard Worker   Transferred --> Transferred: GetStatus()
138*61c4878aSAndroid Build Coastguard Worker   Transferred --> Verifying: Verify()
139*61c4878aSAndroid Build Coastguard Worker   Transferred --> Verifying: Apply()
140*61c4878aSAndroid Build Coastguard Worker   Transferred --> Aborting: Abort()
141*61c4878aSAndroid Build Coastguard Worker
142*61c4878aSAndroid Build Coastguard Worker   Verifying --> Verifying: GetStatus()
143*61c4878aSAndroid Build Coastguard Worker   Verifying --> Verified
144*61c4878aSAndroid Build Coastguard Worker   Verifying --> Aborting: Abort()
145*61c4878aSAndroid Build Coastguard Worker
146*61c4878aSAndroid Build Coastguard Worker   Verified --> Verified: GetStatus()
147*61c4878aSAndroid Build Coastguard Worker   Verified --> Applying: Apply()
148*61c4878aSAndroid Build Coastguard Worker   Verified --> Aborting: Abort()
149*61c4878aSAndroid Build Coastguard Worker
150*61c4878aSAndroid Build Coastguard Worker   Applying --> Applying: GetStatus()
151*61c4878aSAndroid Build Coastguard Worker   Applying --> Finished: Apply() OK
152*61c4878aSAndroid Build Coastguard Worker   Applying --> Finished: Apply() error
153*61c4878aSAndroid Build Coastguard Worker
154*61c4878aSAndroid Build Coastguard Worker   Aborting --> Aborting: GetStatus()
155*61c4878aSAndroid Build Coastguard Worker   Aborting --> Finished: Abort() OK
156*61c4878aSAndroid Build Coastguard Worker   Aborting --> Finished: Abort() error
157*61c4878aSAndroid Build Coastguard Worker
158*61c4878aSAndroid Build Coastguard Worker   Finished --> Finished: GetStatus()
159*61c4878aSAndroid Build Coastguard Worker   Finished --> Inactive: Reset()
160*61c4878aSAndroid Build Coastguard Worker   Finished --> Finished: Reset() error
161*61c4878aSAndroid Build Coastguard Worker
162*61c4878aSAndroid Build Coastguard Worker
163*61c4878aSAndroid Build Coastguard WorkerTooling
164*61c4878aSAndroid Build Coastguard Worker^^^^^^^
165*61c4878aSAndroid Build Coastguard Worker
166*61c4878aSAndroid Build Coastguard Worker``pw_software_update`` provides the following tooling support for development
167*61c4878aSAndroid Build Coastguard Workerand integration.
168*61c4878aSAndroid Build Coastguard Worker
169*61c4878aSAndroid Build Coastguard WorkerThe python package
170*61c4878aSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~
171*61c4878aSAndroid Build Coastguard Worker``pw_software_update`` comes with a python package of the same name, providing
172*61c4878aSAndroid Build Coastguard Workerthe following functionalities.
173*61c4878aSAndroid Build Coastguard Worker
174*61c4878aSAndroid Build Coastguard Worker- Local signing key generation for development.
175*61c4878aSAndroid Build Coastguard Worker- TUF root metadata generation and signing.
176*61c4878aSAndroid Build Coastguard Worker- Bundle generation, signing, and verification.
177*61c4878aSAndroid Build Coastguard Worker- Signing server integration.
178*61c4878aSAndroid Build Coastguard Worker
179*61c4878aSAndroid Build Coastguard WorkerA typical use of the package is for build system integration.
180*61c4878aSAndroid Build Coastguard Worker
181*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
182*61c4878aSAndroid Build Coastguard Worker
183*61c4878aSAndroid Build Coastguard Worker   Help on package pw_software_update:
184*61c4878aSAndroid Build Coastguard Worker
185*61c4878aSAndroid Build Coastguard Worker   NAME
186*61c4878aSAndroid Build Coastguard Worker          pw_software_update - pw_software_update
187*61c4878aSAndroid Build Coastguard Worker
188*61c4878aSAndroid Build Coastguard Worker   PACKAGE CONTENTS
189*61c4878aSAndroid Build Coastguard Worker          bundled_update_pb2
190*61c4878aSAndroid Build Coastguard Worker          cli
191*61c4878aSAndroid Build Coastguard Worker          dev_sign
192*61c4878aSAndroid Build Coastguard Worker          generate_test_bundle
193*61c4878aSAndroid Build Coastguard Worker          keys
194*61c4878aSAndroid Build Coastguard Worker          metadata
195*61c4878aSAndroid Build Coastguard Worker          remote_sign
196*61c4878aSAndroid Build Coastguard Worker          root_metadata
197*61c4878aSAndroid Build Coastguard Worker          tuf_pb2
198*61c4878aSAndroid Build Coastguard Worker          update_bundle
199*61c4878aSAndroid Build Coastguard Worker          update_bundle_pb2
200*61c4878aSAndroid Build Coastguard Worker          verify
201*61c4878aSAndroid Build Coastguard Worker
202*61c4878aSAndroid Build Coastguard Worker
203*61c4878aSAndroid Build Coastguard WorkerThe command line utility
204*61c4878aSAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~
205*61c4878aSAndroid Build Coastguard Worker
206*61c4878aSAndroid Build Coastguard WorkerThe ``pw update ...`` CLI (Command Line Interface) is a user-friendly interface
207*61c4878aSAndroid Build Coastguard Workerto the ``pw_software_update`` python package.
208*61c4878aSAndroid Build Coastguard Worker
209*61c4878aSAndroid Build Coastguard WorkerYou can use the CLI to quickly learn and prototype a software update system
210*61c4878aSAndroid Build Coastguard Workerbased on ``pw_software_update`` on your development PC before productionizing
211*61c4878aSAndroid Build Coastguard Workerone. In the future you will be able to use the CLI to update a reference
212*61c4878aSAndroid Build Coastguard Workertarget.
213*61c4878aSAndroid Build Coastguard Worker
214*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
215*61c4878aSAndroid Build Coastguard Worker
216*61c4878aSAndroid Build Coastguard Worker   usage: pw update [sub-commands]
217*61c4878aSAndroid Build Coastguard Worker
218*61c4878aSAndroid Build Coastguard Worker   sub-commands:
219*61c4878aSAndroid Build Coastguard Worker
220*61c4878aSAndroid Build Coastguard Worker          generate-key
221*61c4878aSAndroid Build Coastguard Worker          create-root-metadata
222*61c4878aSAndroid Build Coastguard Worker          sign-root-metadata
223*61c4878aSAndroid Build Coastguard Worker          inspect-root-metadata
224*61c4878aSAndroid Build Coastguard Worker          create-empty-bundle
225*61c4878aSAndroid Build Coastguard Worker          add-root-metadata-to-bundle
226*61c4878aSAndroid Build Coastguard Worker          add-file-to-bundle
227*61c4878aSAndroid Build Coastguard Worker          sign-bundle
228*61c4878aSAndroid Build Coastguard Worker          inspect-bundle
229*61c4878aSAndroid Build Coastguard Worker
230*61c4878aSAndroid Build Coastguard Worker   options:
231*61c4878aSAndroid Build Coastguard Worker          -h, --help            show this help message and exit
232*61c4878aSAndroid Build Coastguard Worker
233*61c4878aSAndroid Build Coastguard Worker
234*61c4878aSAndroid Build Coastguard WorkerTo learn more, see :ref:`module-pw_software_update-cli`.
235