c23faa86b5390b2dba57b336492e617f8fb75a69
[src/app-framework-main.git] / docs / widgets.md
1 The widgets
2 ===========
3
4 The widgets are described by the technical recommendations
5 [widgets] and [widgets-digsig].
6
7 In summary, **widgets are ZIP files that can be signed and
8 whose content is described by the file <config.xml>**.
9
10 The configuration file config.xml
11 ---------------------------------
12
13 The file **config.xml** describes important data of the application
14 to the framework:
15
16 - the unique identifier of the application
17 - the name of the application
18 - the type of the application
19 - the icon of the application
20 - the permissions linked to the application
21 - the services and dependancies of the application
22
23 The file MUST be at the root of the widget and MUST be case sensitively name
24 ***config.xml***.
25
26 The file **config.xml** is a XML file described by the document
27 [widgets].
28
29 Here is the example of the config file for the QML application SmartHome.
30
31 ```xml
32 <?xml version="1.0" encoding="UTF-8"?>
33 <widget xmlns="http://www.w3.org/ns/widgets" id="smarthome" version="0.1">
34   <name>SmartHome</name>
35   <icon src="smarthome.png"/>
36   <content src="qml/smarthome/smarthome.qml" type="text/vnd.qt.qml"/>
37   <description>This is the Smarthome QML demo application. It shows some user interfaces for controlling an 
38 automated house. The user interface is completely done with QML.</description>
39   <author>Qt team</author>
40   <license>GPL</license>
41 </widget>
42 ```
43
44 The most important items are:
45
46 - **\<widget id="......"\>**: gives the id of the widget. It must be unique.
47
48 - **\<widget version="......"\>**: gives the version of the widget
49
50 - **\<icon src="..."\>**: gives a path to the icon of the application
51   (can be repeated with different sizes)
52
53 - **\<content src="..." type="..."\>**: this indicates the entry point and its type.
54   The types handled are set through the file /etc/afm/afm-launch.conf
55
56 Further development will add handling of <feature> for requiring and providing
57 permissions and services.
58
59 ---
60
61 ### Standard elements of "config.xml"
62
63 #### The element widget
64
65 ##### the attribute id of widget
66
67 The attribute *id* is mandatory (for version 2.x, blowfish) and must be unique.
68
69 Values for *id* are any non empty string containing only latin letters,
70 arabic digits, and the three characters '.' (dot), '-' (dash) and
71 '_' (underscore).
72
73 Authors can use a mnemonic id or can pick a unique id using
74 command **uuid** or **uuidgen**.
75
76 #### the attribute version of widget
77
78 The attribute *version* is mandatory (for version 2.x, blowfish).
79
80 Values for *id* are any non empty string containing only latin letters,
81 arabic digits, and the three characters '.' (dot), '-' (dash) and
82 '_' (underscore).
83
84 Version values are dot separated fields MAJOR.MINOR.REVISION.
85
86 #### The element content
87
88 The element *content* is mandatory (for version 2.x, blowfish) and must designate a file
89 (subject to localisation) with its attribute *src*.
90
91 The content designed depends on its type. See below for the known types.
92
93 #### The element icon
94
95 The element *icon* is mandatory (for version 2.x, blowfish) and must
96 be unique. It must designate an image file with its attribute *src*.
97
98 ### Known widget types and content
99
100 The configuration file ***/etc/afm/afm-launch.conf*** defines the types
101 of widget known and how to launch it.
102
103 Known types for the type of content are (for version 2.x, blowfish):
104
105 - ***text/html***: 
106    HTML application,
107    content.src designates the home page of the application
108
109 - ***application/x-executable***:
110    Native application,
111    content.src designates the relative path of the binary
112
113 - ***application/vnd.agl.url***:
114    Internet url,
115    content.src designates the url to be used
116
117 - ***application/vnd.agl.service***:
118    AGL service defined as a binder,
119    content.src designates the directory of provided binders,
120    http content, if any, must be put in the subdirectory ***htdocs*** of the widget
121
122 - ***application/vnd.agl.native***:
123    Native application with AGL service defined as a binder,
124    content.src designates the relative path of the binary,
125    bindings, if any must be put in the subdirectory ***lib*** of the widget,
126    http content, if any, must be put in the subdirectory ***htdocs*** of the widget
127
128 - ***text/vnd.qt.qml***, ***application/vnd.agl.qml***:
129    QML application,
130    content.src designate the relative path of the QML root,
131    imports must be put in the subdirectory ***imports*** of the widget
132
133 - ***application/vnd.agl.qml.hybrid***:
134    QML application with bindings,
135    content.src designate the relative path of the QML root,
136    bindings, if any must be put in the subdirectory ***lib*** of the widget,
137    imports must be put in the subdirectory ***imports*** of the widget
138
139 - ***application/vnd.agl.html.hybrid***:
140    HTML application,
141    content.src designates the home page of the application,
142    bindings, if any must be put in the subdirectory ***lib*** of the widget,
143    http content must be put in the subdirectory ***htdocs*** of the widget
144
145 ---
146
147 ### AGL features
148
149 The AGL framework uses the feature tag for specifying security and binding
150 requirement of the widget.
151
152 The current version of AGL (up to 2.0.1, blowfish) has no fully implemented
153 features.
154
155 The features planned to be implemented are described below.
156
157 #### feature name="urn:AGL:required-binding"
158
159 List of the bindings required by the widget.
160
161 Each required binding must be explicited using a <param> entry.
162
163 ##### param name=[required binding name]
164
165 The value is either:
166
167 - required: the binding is mandatorily needed except if the feature
168 isn't required (required="false") and in that case it is optional.
169 - optional: the binding is optional
170
171 #### feature name="urn:AGL:required-permission"
172
173 List of the permissions required by the widget.
174
175 Each required permission must be explicited using a <param> entry.
176
177 ##### param name=[required permission name]
178
179 The value is either:
180
181 - required: the permission is mandatorily needed except if the feature
182 isn't required (required="false") and in that case it is optional.
183 - optional: the permission is optional
184
185 #### feature name="urn:AGL:provided-binding"
186
187 Use this feature for each provided binding of the widget.
188 The parameters are:
189
190 ##### param name="name"
191
192 REQUIRED
193
194 The value is the string that must match the binding prefix.
195 It must be unique.
196
197 ##### param name="src"
198
199 REQUIRED
200
201 The value is the path of the shared library for the binding.
202
203 ##### param name="type"
204
205 REQUIRED
206
207 Currently it must be ***application/vnd.agl.binding.v1***.
208
209
210 ##### param name="scope"
211
212 REQUIRED
213
214 The value indicate the availability of the binidng:
215
216 - private: used only by the widget
217 - public: available to allowed clients as a remote service (requires permission+)
218 - inline: available to allowed clients inside their binding (unsafe, requires permission+++)
219
220 ##### param name="needed-binding"
221
222 OPTIONAL
223
224 The value is a space separated list of binding's names that the binding needs.
225
226 #### feature name="urn:AGL:defined-permission"
227
228 Each required permission must be explicited using a <param> entry.
229
230 ##### param name=[defined permission name]
231
232 The value is the level of the defined permission.
233 Standard levels are: 
234
235 - system
236 - platform
237 - partner
238 - public
239
240 This level defines the level of accreditation required to get the given
241 permission. The accreditions are given by signatures of widgets.
242
243
244 Tools for managing widgets
245 --------------------------
246
247 This project includes tools for managing widgets.
248 These tools are:
249
250 - ***wgtpkg-info***: command line tool to display
251   informations about a widget file.
252
253 - ***wgtpkg-installer***: command line tool to
254   install a widget file.
255
256 - ***wgtpkg-pack***: command line tool to create
257   a widget file from a widget directory.
258
259 - ***wgtpkg-sign***: command line tool to add a signature
260   to a widget directory.
261
262 For all these commands, a tiny help is available with
263 options **-h** or **--help**.
264
265 There is no tool for unpacking a widget. For doing such operation,
266 you can use the command **unzip**.
267
268 To list the files of a widget:
269
270 ```bash
271 $ unzip -l WIDGET
272 ```
273
274 To extract a widget in some directory:
275
276 ```bash
277 $ unzip WIDGET -d DIRECTORY
278 ```
279
280 *Note that DIRECTORY will be created if needed*.
281
282 Getting data about a widget file
283 ---------------------------------
284
285 The command **wgtpkg-info** opens a widget file, reads its **config.xml**
286 file and displays its content in a human readable way.
287
288 Signing and packing widget
289 --------------------------
290
291 ### Signing
292
293 To sign a widget, you need a private key and its certificate.
294
295 The tool **wgtpkg-sign** creates or replace a signature file in
296 the directory of the widget BEFORE its packaging.
297
298 There are two types of signature files: author and distributor.
299
300 Example 1: add an author signature
301
302 ```bash
303 $ wgtpkg-sign -a -k me.key.pem -c me.cert.pem DIRECTORY
304 ```
305
306 Example 2: add a distributor signature
307
308 ```bash
309 $ wgtpkg-sign -k authority.key.pem -c authority.cert.pem DIRECTORY
310 ```
311
312 ### Packing
313
314 This operation can be done using the command **zip** but
315 we provide the tool **wgtpkg-pack** that may add checking.
316
317 Example:
318 ```bash
319 $ wgtpkg-pack DIRECTORY -o file.wgt
320 ```
321 Writing a widget
322 ----------------
323
324 ### What kind of application?
325
326 The file **/etc/afm/afm-launch.conf** explain how to launch applications.
327 (It is the current state that use afm-user-daemon. In a future, it may be
328 replace by systemd features.)
329
330 Currently the applications that can be run are:
331
332 - binary applications: their type is ***application/x-executable***
333
334 - HTML5 applications: their type is ***text/html***
335
336 - QML applications: their type is ***text/vnd.qt.qml***
337
338 ### The steps for writing a widget
339
340 1. make your application
341
342 2. create its configuration file **config.xml**
343
344 3. sign it
345
346 4. pack it
347
348 Fairly easy, no?
349
350 Organization of directory of applications
351 -----------------------------------------
352
353 ### directory where are stored applications
354
355 Applications can be installed in different places: the system itself, extension device.
356 On a phone application are typically installed on the sd card.
357
358 This translates to:
359
360  - /usr/applications: system wide applications
361  - /opt/applications: removable applications
362
363 From here those paths are referenced as: "APPDIR".
364
365 The main path for applications is: APPDIR/PKGID/VER.
366
367 Where:
368
369  - APPDIR is as defined above
370  - PKGID is a directory whose name is the package identifier
371  - VER is the version of the package MAJOR.MINOR
372
373 This organization has the advantage to allow several versions to leave together.
374 This is needed for some good reasons (rolling back) and also for less good reasons (user habits).
375
376 ### Identity of installed files
377
378 All files are installed as user "afm" and group "afm".
379 All files have rw(x) for user and r-(x) for group and others.
380
381 This allows every user to read every file.
382
383 ### labeling the directories of applications
384
385 The data of a user are in its directory and are labelled by the security-manager
386 using the labels of the application.
387
388 [widgets]:          http://www.w3.org/TR/widgets                                    "Packaged Web Apps"
389 [widgets-digsig]:   http://www.w3.org/TR/widgets-digsig                             "XML Digital Signatures for Widgets"
390 [libxml2]:          http://xmlsoft.org/html/index.html                              "libxml2"
391 [app-manifest]:     http://www.w3.org/TR/appmanifest                                "Web App Manifest"
392
393
394 [meta-intel]:       https://github.com/01org/meta-intel-iot-security                "A collection of layers providing security technologies"
395 [widgets]:          http://www.w3.org/TR/widgets                                    "Packaged Web Apps"
396 [widgets-digsig]:   http://www.w3.org/TR/widgets-digsig                             "XML Digital Signatures for Widgets"
397 [libxml2]:          http://xmlsoft.org/html/index.html                              "libxml2"
398 [openssl]:          https://www.openssl.org                                         "OpenSSL"
399 [xmlsec]:           https://www.aleksey.com/xmlsec                                  "XMLSec"
400 [json-c]:           https://github.com/json-c/json-c                                "JSON-c"
401 [d-bus]:            http://www.freedesktop.org/wiki/Software/dbus                   "D-Bus"
402 [libzip]:           http://www.nih.at/libzip                                        "libzip"
403 [cmake]:            https://cmake.org                                               "CMake"
404 [security-manager]: https://wiki.tizen.org/wiki/Security/Tizen_3.X_Security_Manager "Security-Manager"
405 [app-manifest]:     http://www.w3.org/TR/appmanifest                                "Web App Manifest"
406 [tizen-security]:   https://wiki.tizen.org/wiki/Security                            "Tizen security home page"
407 [tizen-secu-3]:     https://wiki.tizen.org/wiki/Security/Tizen_3.X_Overview         "Tizen 3 security overview"
408
409
410
411