WebUSB: Difference between revisions
m de-duplicate refs |
Citation bot (talk | contribs) Added bibcode. Removed URL that duplicated identifier. Removed access-date with no URL. | Use this bot. Report bugs. | Suggested by Abductive | Category:USB | #UCB_Category 92/96 |
||
(27 intermediate revisions by 17 users not shown) | |||
Line 1: | Line 1: | ||
'''WebUSB''' is a [[JavaScript]] [[application programming interface]] (API) specification<ref name="github-webusb">{{cite web |url=https://wicg.github.io/webusb/|last=Grant |first=R |date=2021-10-06|website= WICG|access-date=2022-01-07|title=WebUSB API}}</ref> for securely providing access to [[USB]] devices from [[web |
{{Short description|JavaScript application programming interface specification}} |
||
'''WebUSB''' is a [[JavaScript]] [[application programming interface]] (API) specification<ref name="github-webusb">{{cite web |url=https://wicg.github.io/webusb/|last=Grant |first=R |date=2021-10-06|website= WICG|access-date=2022-01-07|title=WebUSB API}}</ref> for securely providing access to [[USB]] devices from [[Web application|web applications]].<ref name="Google-webusb2016">{{cite web|url=https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web|title=Access USB Devices on the Web|website=[[Google Developers]]|date=30 March 2016 }}</ref> |
|||
It was published by the Web Platform Incubator Community Group. As of July 2021, it is in Draft Community status, and is supported<ref>{{Cite web|title=WebUSB {{!}} Can I use... Support tables for HTML5, CSS3, etc|url=https://caniuse.com/webusb|access-date=2021-07-02|website=caniuse.com}}</ref> by [[Google Chrome]], [[Microsoft Edge]], [[QQ browser|QQ]], [[Opera (web browser)|Opera]], and [[Samsung Internet]]. |
It was published by the Web Platform Incubator Community Group. As of July 2021, it is in Draft Community status, and is supported<ref>{{Cite web|title=WebUSB {{!}} Can I use... Support tables for HTML5, CSS3, etc|url=https://caniuse.com/webusb|access-date=2021-07-02|website=caniuse.com}}</ref> by [[Google Chrome]], [[Microsoft Edge]], [[QQ browser|QQ]], [[Opera (web browser)|Opera]], and [[Samsung Internet]]. |
||
⚫ | |||
⚫ | A Universal Serial Bus, or a [[USB]] is an industry standard communication protocol used to communicate data across connectors, and cables from computers to peripheral devices and/or other computers.<ref name="Anderson-Universal">{{cite book |last= Anderson|first= Don|date= 2001|title=Universal Serial Bus System Architecture |publisher= Addison-Wesley|edition=2nd |isbn=978-0-201-30975-1}}</ref> WebUSB is a set of API calls that enable access to these hardware devices from web pages. WebUSB is developed by the World Wide Web Consortium (W3C).<ref name="github-webusb"/> The WebUSB API provides a safe, and developer familiar means of communication to edge devices from web pages. The WebUSB API integrates into existing USB libraries and shortens the development cycle for integrating new devices into the web environment by not needing to wait for browser support for these devices. |
||
⚫ | |||
⚫ | Early versions of WebUSB came out around as an alternative to [[Adobe Flash|Flash]], Chrome Serial, and other custom approaches to connecting browsers to hardware. WebUSB aims to solve the four goals of any interface being; fast to make, cross platform, look good, accessibility.<ref name="CSSSConf-Aus">{{cite conference |url=https://www.youtube.com/watch?v=ov2R3vEn14k |title= Suz Hinton - I'm afraid your browser has been talking to the robots again a gentle intro to WebUSB|last1= Hinton|first1= Suz |date= 2018-06-18 |conference= CSSSConf Australia}}</ref> |
||
⚫ | A Universal Serial Bus, or a [[USB]] is an industry standard communication protocol used to communicate data across connectors, and cables from computers to peripheral devices and/or other computers<ref name="Anderson-Universal">{{cite book |last= Anderson|first= Don|date= 2001|title=Universal Serial Bus System Architecture |edition=2nd |isbn=978-0-201-30975-1}}</ref> |
||
⚫ | |||
⚫ | Early versions of |
||
⚫ | WebUSB API's are able to bridge hardware protocols to internet protocols, enabling the creating of uniform gateways linking edge devices to a centralised networks.<ref name="King-Saud-IoT">{{cite journal |last1= Beniwal|first1= Gunjan|last2= Singhrova|first2= Anita|date= 2022|title= A systematic literature review on IoT gateways|journal=Journal of King Saud University - Computer and Information Sciences|volume= 34|issue= 10|pages= 9541–9563|doi= 10.1016/j.jksuci.2021.11.007|s2cid= 244758915|doi-access= free}}</ref> |
||
⚫ | |||
⚫ | The explosion in computing ability over the last few decades has led to an increase in edge devices. Devices such as lights, [[thermometers]], [[HVAC]], motors are increasingly integrated into centralised internet control servers.<ref name="Rondon-Babun">{{cite journal |last1= Rondon|first1= L|last2= Babun|first2= L|last3=Aris|first3=A|last4=Akkaya|first4=A|last5=Uluagac|first5=A| date= 2021|title= Survey on Enterprise Internet-of-Things systems (E-IoT): A security perspective|url=https://www.iso.org/standard/31432.html|journal= ISO|arxiv= 2102.10695|access-date=2021-12-19}}</ref> These devices have evolved from isolated and previously non-integrated development environments. Consequently, they lack the uniform and consistent communication protocol necessary to develop an immediate connectivity to a web service. The WebUSB's API framework standardises disparate protocols and is able to expose non-standard Universal Serial Bus (USB) compatible devices to the web.<ref name="Moz-Web-API">{{cite web |url= https://developer.mozilla.org/en-US/docs/Web/API/WebUSB_API|author=<!--Not stated--> |date=2021 |website= Mozilla Developer Blogs|publisher= Mozilla|access-date=2021-12-19|title=WebUSB API |
||
⚫ | WebUSB API's are able to bridge hardware protocols to internet protocols, enabling the creating of uniform gateways linking edge devices to a centralised networks.<ref name="King-Saud-IoT">{{cite journal |last1= Beniwal|first1= Gunjan|last2= Singhrova|first2= Anita|date= |
||
⚫ | |||
⚫ | The WebUSB looks to sit between the perception layer and the network layer.<ref name="King-Saud-IoT"/> The main goals of software in this gateway are; Scalability, Cost and reliability. The cloud-based deployment of WebUSB libraries enables it to cover scalability, its low overhead deployment significantly lowers cost, and its continual in use development over its lifetime has enabled the framework to attain a high degree of reliability.<ref>{{cite book |last1= Talukder|first1= A.K |title= Big Data Analytics |chapter= The Next Generation Web: Technologies and Services |series= Lecture Notes in Computer Science | date= 2020|chapter-url= https://doi.org/10.1007/978-3-030-66665-1_14|volume= 12581 |pages= 209–229 |doi= 10.1007/978-3-030-66665-1_14 |isbn= 978-3-030-66664-4 |s2cid= 230795240 |access-date=2021-12-19}}</ref> |
||
⚫ | The explosion in computing ability over the last few decades has led to an increase in edge devices. Devices such as |
||
⚫ | |||
⚫ | WebUSB has formed a cornerstone of the BIPES (Block based Integrated Platform for Embedded Systems) architecture framework. This systems architecture model aims to reduce complexity of IoT systems development by aggregating relevant software into 'Blocks' that are complete units of code and can be deployed to an edge device from a centralised cloud infrastructure.<ref name="BIPES-IEEE">{{cite journal |last1= Junior|first1= A. G. D. S.|last2= Gonçalves|first2= L. M. G.|last3=De Paula Caurin|first3= G. A.|last4= Tamanaka|first4=G.T.B | last5= Hernandes|first5=A.C|last6=Aroca|first6=R.V| date= 2020|title= BIPES: Block Based Integrated Platform for Embedded Systems|journal= [[IEEE Access]]|volume=8|pages= 197955–197968|doi= 10.1109/ACCESS.2020.3035083|s2cid= 226854474|doi-access= free|bibcode= 2020IEEEA...8s7955J}}</ref> As already mentioned the role of WebUSB is critically tied to its ability to communicate to embedded software through the USB communication protocol. Once the information is inside WebUSB's JavaScript environment it can be transposed and communicated through a variety of software protocols.<ref name="github-webusb"/> In this particular architecture model WebUSB bridges the gap between [[embedded software]], and the [[web browser]]. The web browser then communicates to the cloud environment using uniform WebUSB constructed data.<ref name="BIPES-IEEE"/> |
||
⚫ | The WebUSB looks to sit between the perception layer and the network layer<ref name="King-Saud-IoT"/> |
||
⚫ | |||
⚫ | WebUSB has formed a cornerstone of the BIPES (Block based Integrated Platform for Embedded Systems) architecture framework. This systems architecture model aims to reduce complexity of IoT systems development by aggregating relevant software into 'Blocks' that are complete units of code and can be deployed to an edge device from a centralised cloud infrastructure.<ref name="BIPES-IEEE">{{cite journal |last1= Junior|first1= A. G. D. S.|last2= Gonçalves|first2= L. M. G.|last3=De Paula Caurin|first3= G. A.|last4= Tamanaka|first4=G.T.B | last5= Hernandes|first5=A.C|last6=Aroca|first6=R.V| date= 2020|title= BIPES: Block Based Integrated Platform for Embedded Systems|journal= [[IEEE Access]]|volume=8| |
||
⚫ | WebUSB provides a web page access to a connector to an edge device. The exposure of any device to the internet carries inherent risks and security concerns.<ref name="Rondon-Babun"/> By product of design USB ports are designed to trust the device they are connected to. Connecting such a port to an internet facing application introduced a new set of security risks and massively expanding the attack surface for would be malicious actors.<ref name="Moz-Web-API"/><ref name="github-webusb"/> |
||
⚫ | For instance a malicious host web page could request data from a peripheral device, which the device would happily fulfil thinking it was communicating through a standard USB connector. To mitigate this type of attack WebUSB developed a <code>requestDevice()</code> function call. This would notify the user that the site was requesting access to the edge device. This is similar to the access requests browser control for when a web page would like to access the inbuilt camera or microphone. Depending on the wariness of the user this protocol can be enough to prevent certain attacks. A second protocol that was developed is the specification of a request originating from a secure context.<ref name="Enabling Smart">{{cite web |last1= Lindström|first1= R|date= 2021|title= Enabling Smartphones to act as IoT Edge Devices via the Browser-based 'WebUSB API' : The future of the browser and the smartphone in home electronics IoT systems.|url= http://urn.kb.se/resolve}}</ref><ref name="github-webusb"/> This ensures that both the code to be executed and the data returned is not intercepted or modified in transit. This security is implemented through the claimInterface() function. This is an OS supported function, and ensures that only a single execution instance can have user space or kernel space driver access to the device, preventing malicious code on a web page from opening a second channel of communication to the device.<ref name="github-webusb"/> Other security considerations included created a public registry of approved connections, but this idea was ultimately scrapped as it required vendors to develop devices with WebUSB in mind.<ref name="github-webusb"/> |
||
⚫ | |||
⚫ | WebUSB provides a web page access to a connector to an edge device. The exposure of any device to the internet carries inherent risks and security concerns<ref name="Rondon-Babun"/> |
||
⚫ | For instance a malicious host web page could request data from a peripheral device, which the device would happily fulfil thinking it was communicating through a standard USB connector. To mitigate this type of attack |
||
The threat surface of a USB however is bi-directional and a malicious peripheral device could attack the host. An infected edge device cannot easily be mitigated by |
The threat surface of a USB however is bi-directional and a malicious peripheral device could attack the host. An infected edge device cannot easily be mitigated by WebUSB API's. In many device configurations trusted USB ports are used to deliver firmware upgrades and a malicious edge device could grant attackers persistence in a system.<ref name="Enabling Smart"/><ref name="Anderson-Universal"/> |
||
In light of the security concerns posed by |
In light of the security concerns posed by WebUSB, it is only supported by an estimated 76% of browsers. Also notably is that support for WebUSB at a browser level has been volatile over time, with stretches of time where certain browsers turned off access after the discovery of particular security threats.<ref>{{cite web|url=https://www.xda-developers.com/google-disables-chrome-webusb/|title=Google disables WebUSB in Chrome amidst phishing concerns|date=7 March 2018|publisher=[[XDA Developers]]}}</ref> It is these security concerns that have plagued alternatives to WebUSB. Particularly Flash and Google Serial failed to take off because they were unable to be used with adequate answers to these fundamental security risks.<ref name="CSSSConf-Aus"/> |
||
== Use in |
== Use in multi-factor authentication == |
||
The ability to own and verify a digital identity on the internet is critical to interaction with internet facing infrastructure. WebUSB in combination with special purpose devices and public identification registries can be used as key piece in an infrastructure scale solution to digital identity on the internet<ref name="Fujita-Inomata">{{cite journal |last1= Fujita|first1= Y|last2= Inomata|first2= A|last3= Kashiwazaki|first3 = H| date= 2019|title= Implementation and Evaluation of a Multi-Factor Web Authentication System with Individual Number Card and WebUSB|url= |journal= Asia-Pacific Network Operations and Management Symposium}}</ref> |
The ability to own and verify a digital identity on the internet is critical to interaction with internet facing infrastructure. WebUSB in combination with special purpose devices and public identification registries can be used as key piece in an infrastructure scale solution to digital identity on the internet.<ref name="Fujita-Inomata">{{cite journal |last1= Fujita|first1= Y|last2= Inomata|first2= A|last3= Kashiwazaki|first3 = H| date= 2019|title= Implementation and Evaluation of a Multi-Factor Web Authentication System with Individual Number Card and WebUSB|url= |journal= Asia-Pacific Network Operations and Management Symposium}}</ref> WebUSB API library is able to standardise the connection of peripheral devices to web pages. The security investment in WebUSB makes it a suitable software component in connecting identifiable devices to the internet.<ref name="github-webusb"/> Recent research has shown the fallibility of SMS based authentication highlighting how key pieces of the infrastructure can be subverted.<ref>{{cite web |url= https://krebsonsecurity.com/2018/08/reddit-breach-highlights-limits-of-sms-based-authentication/|title= Reddit Breach Highlights Limits of SMS-Based Authentication|author=Brian Krebs |date= 2018-06-01|website=krebs on Security |access-date= 2021-12-19}}</ref> Alternative proposals for securing a digital identity involve the use of biometric sensors and/or personal identifiers. However, while these are good at identifying an individual, it is only through WebUSB that they can adequately be integrated into the existing internet tech stack.<ref name="Fujita-Inomata"/> Cryptographically secure solutions for personal identification exist with support from government and specialised hardware. However, these solutions lack generalised specification for web based infrastructure and are generally hard to support. Gateway support for such a communication protocol can be supported by software middlemen, such as WebUSB.<ref name="BIPES-IEEE"/><ref name="Fujita-Inomata"/> |
||
A model system for |
A model system for multi-factor authentication uses WebUSB in tandem with an identifying hardware such as an ID card built to ISO/IEC 7810:2003 ID-1<ref>{{cite web |url= https://www.iso.org/standard/31432.html|title= ISO/IEC 7810:2003 - Identification cards – Physical characteristics | access-date= 2022-01-07|quote=}}</ref> standards. This card would constitute a physical representation of an individual's identity. WebUSB would then act as a middle man in facilitating the transfer of data stored on the hardware to a given web server. The number card would be digitally signed by an authorised party and would digitally connect to a server. This connection would require a device capable of reading ISO/IEC 14443 type B connections.<ref>{{cite web |url= https://www.iso.org/standard/73596.html|title= ISO/IEC 14443-1:2018 - Cards and security devices for personal identification – Contactless proximity objects | access-date= 2022-01-07|quote=}}</ref> In order to make this digital connection valid, WebUSB would serve as software connector.<ref name="Fujita-Inomata"/> |
||
== |
== Usage == |
||
WebUSB will only work on supported browsers, for example [[Google Chrome|Chrome]]. Due to privacy and security concerns it will also only work in a secure context |
WebUSB will only work on supported browsers, for example [[Google Chrome|Chrome]]. Due to privacy and security concerns it will also only work in a secure context i.e.; over [[HTTPS]], and can only be called through a user actions. |
||
For instance in order to instantiate a connection <code>navigator.usb.requestDevice()</code> can only be called through user gesture, such as touch or mouse click. |
For instance in order to instantiate a connection <code>navigator.usb.requestDevice()</code> can only be called through user gesture, such as touch or mouse click. |
||
Similarly protection from |
Similarly protection from WebUSB can be provided using a feature policy. For instance {{code|2=text| |
||
Feature-Policy: fullscreen "*"; usb "none"; payment "self" https://payment.example.com |
Feature-Policy: fullscreen "*"; usb "none"; payment "self" https://payment.example.com}} would prevent WebUSB from running.<ref name="Beaufort">{{cite web |url= https://web.dev/usb/|title= Access WebUSB|last= Beaufort|first= Francis|date= 2021-02-23|website= web.dev|access-date= 2022-01-06}}</ref> |
||
To get access to devices visible to the browser two options are available. <code>navigator.usb.requestDevice()</code> will prompt the user to select which USB access is to be given, or <code>navigator.usb.getDevices()</code> will return a list of USB |
To get access to devices visible to the browser two options are available. <code>navigator.usb.requestDevice()</code> will prompt the user to select which USB access is to be given, or <code>navigator.usb.getDevices()</code> will return a list of USB devices that the origin has access to. |
||
To better search for devices, |
To better search for devices, WebUSB has a number of filtering options. These filters are passed into <code>navigator.usb.requestDevice()</code> as a JavaScript filtering object. These filters are; <code>vendorId</code>,<code>productId</code>,<code>classCode</code>, <code>protocolCode</code>, <code>serialNumber</code>, and <code>subclassCode</code>. |
||
For example, imagine connecting to |
For example, imagine connecting to an [[Arduino]] device, this could be done in the following way. Where {{mono|0x2341}} is Arduino in the list of USB ID's<ref>{{cite web |url= http://www.linux-usb.org/usb.ids|title= Access WebUSB|website= web.dev|access-date= 2022-01-06}}</ref> |
||
<syntaxhighlight lang="javascript"> |
|||
navigator.usb.requestDevice({ filters: [{ vendorId: 0x2341 }] }) |
|||
.then(device => { |
|||
.then(device => { |
|||
console.log(device.productName); |
|||
console.log(device.manufacturerName); |
|||
}) |
}) |
||
.catch(error => { console.error(error); }); |
|||
</syntaxhighlight> |
|||
});</code> |
|||
The USB <code>device</code> descriptor returned from the above snippet will contain all important information about the device such as; version, packet size, configuration options etc. |
The USB <code>device</code> descriptor returned from the above snippet will contain all important information about the device such as; version, packet size, configuration options etc. |
||
The alternative call to <code>navigator.usb.getDevices()</code> will instead look like this; |
The alternative call to <code>navigator.usb.getDevices()</code> will instead look like this; |
||
<syntaxhighlight lang="javascript"> |
|||
navigator.usb.getDevices().then(devices => { |
|||
devices.forEach(device => { |
|||
console.log(device.productName); |
console.log(device.productName); |
||
console.log(device.manufacturerName); |
console.log(device.manufacturerName); |
||
}); |
}); |
||
}) |
}) |
||
</syntaxhighlight> |
|||
In order to talk to the device there are a few important function calls to run through. <code>device.open()</code> will run through all the required steps of setting up the device, <code>device.selectConfiguration()</code> sets up the configuration, importantly how it is powered, and the number of interfaces. It is then important to claim the interface. This can be done through the <code>device.claimInterface</code> function call. This will simulate a real wired connection and ensure that this web page is the only one able to read and write to the device until the connection is released. Finally the call <code>device.controlTransferOut()</code> will set up the device to communicate through the WebUSB Serial API. Once the set up is all done, data can be transferred to the device using <code>device.transferIn()</code> to transfer bulk data to the device, similarly its sister function <code>device.transferOut()</code> to read data from the device<ref name="Beaufort"/><ref name="github-webusb"/> |
In order to talk to the device there are a few important function calls to run through. <code>device.open()</code> will run through all the required steps of setting up the device, <code>device.selectConfiguration()</code> sets up the configuration, importantly how it is powered, and the number of interfaces. It is then important to claim the interface. This can be done through the <code>device.claimInterface</code> function call. This will simulate a real wired connection and ensure that this web page is the only one able to read and write to the device until the connection is released. Finally the call <code>device.controlTransferOut()</code> will set up the device to communicate through the WebUSB Serial API. Once the set up is all done, data can be transferred to the device using <code>device.transferIn()</code> to transfer bulk data to the device, similarly its sister function <code>device.transferOut()</code> to read data from the device.<ref name="Beaufort"/><ref name="github-webusb"/> |
||
=== Interfaces === |
=== Interfaces === |
||
In order to generalise interaction with hardware devices |
In order to generalise interaction with hardware devices WebUSB supports a number of interfaces than abstract away the specific hardware functionality.<ref name="Moz-Web-API"/> |
||
{| class="wikitable" |
{| class="wikitable" |
||
|+ Interfaces |
|+ Interfaces |
||
Line 77: | Line 79: | ||
! Interface Name !! Description |
! Interface Name !! Description |
||
|- |
|- |
||
| USB || Provides attributes and methods for finding and connecting USB devices from a web page. This interface |
| {{mono|USB}} || Provides attributes and methods for finding and connecting USB devices from a web page. This interface inherits from <code>EventTarget</code>. |
||
|- |
|- |
||
| USBConnectionEvent ||This connection event is passed to <code>USB.onconnect</code> or <USB.ondisconnect> when the agent detects a change in the connection status. |
| {{mono|USBConnectionEvent}} || This connection event is passed to <code>USB.onconnect</code> or <code>USB.ondisconnect</code> when the agent detects a change in the connection status. |
||
|- |
|- |
||
| USBDevice ||Interface that provides metadata about the connected device and methods for controlling it. Importantly this is the main interface the developer will use for interacting with the device. |
| {{mono|USBDevice}} || Interface that provides metadata about the connected device and methods for controlling it. Importantly this is the main interface the developer will use for interacting with the device. |
||
|- |
|- |
||
| USBInTransferResult || A representation of the results from a data transfer event from the device to the host. |
| {{mono|USBInTransferResult}} || A representation of the results from a data transfer event from the device to the host. Including field for the data and the status of the transfer. There are three options for status fields; 'ok' meaning the transfer was a success, 'stall' indicating an error producing a stall on the endpoint, or 'babble' which indicates more than expected data was transferred. |
||
|- |
|- |
||
| USBIsochronousInTransferResult||Similar to USBInTransferResult this is a representation of a data transfer from the device to the host when done across an isochronous endpoint. Has no status field, only the packets. |
| {{mono|USBIsochronousInTransferResult}} || Similar to <code>USBInTransferResult</code> this is a representation of a data transfer from the device to the host when done across an isochronous endpoint. Has no status field, only the packets. |
||
|- |
|- |
||
| USBIsochronousInTransferPacket ||Represents the status of an individual packet from a request to transfer data from the device to the host over an isochronous endpoint. Can return the status of either 'ok' or 'stall'. |
| {{mono|USBIsochronousInTransferPacket}} || Represents the status of an individual packet from a request to transfer data from the device to the host over an isochronous endpoint. Can return the status of either 'ok' or 'stall'. |
||
|- |
|- |
||
| USBIsochronousOutTransferResult ||Similar to USBInTransferResult this is a representation of a data transfer from the host to the device when done across an isochronous endpoint. |
| {{mono|USBIsochronousOutTransferResult}} || Similar to <code>USBInTransferResult</code> this is a representation of a data transfer from the host to the device when done across an isochronous endpoint. |
||
|- |
|- |
||
| USBIsochronousOutTransferPacket|| |
| {{mono|USBIsochronousOutTransferPacket}} || Represents the status of an individual packet from a request to transfer data from the host to the device over an isochronous endpoint. Same status fields as <code>USBIsochronousInTransferPacket</code>. |
||
|- |
|- |
||
| USBConfiguration ||Provides information about a particular configuration of a USB device . This includes information about device version, maximum packet size and supported interfaces. |
| {{mono|USBConfiguration}} || Provides information about a particular configuration of a USB device . This includes information about device version, maximum packet size and supported interfaces. |
||
|- |
|- |
||
| USBInterface ||Provides information about an interface provided by the USB device. This includes information on whether it is claimed, as well as its communication protocol. |
| {{mono|USBInterface}} || Provides information about an interface provided by the USB device. This includes information on whether it is claimed, as well as its communication protocol. |
||
|- |
|- |
||
| USBAlternateInterface ||Provides information about a particular configuration of an interface and the particular modes the device can operate in. |
| {{mono|USBAlternateInterface}} || Provides information about a particular configuration of an interface and the particular modes the device can operate in. |
||
|- |
|- |
||
|USBEndPoint ||The USBEndPoint is a unidirectional data stream either into or out of the device. |
| {{mono|USBEndPoint}} || The <code>USBEndPoint</code> is a unidirectional data stream either into or out of the device. |
||
|} |
|} |
||
Line 116: | Line 118: | ||
[[Category:Web development]] |
[[Category:Web development]] |
||
[[Category:Web standards]] |
[[Category:Web standards]] |
||
{{soft-stub}} |
|||
{{web-stub}} |
Latest revision as of 05:14, 15 August 2024
WebUSB is a JavaScript application programming interface (API) specification[1] for securely providing access to USB devices from web applications.[2]
It was published by the Web Platform Incubator Community Group. As of July 2021, it is in Draft Community status, and is supported[3] by Google Chrome, Microsoft Edge, QQ, Opera, and Samsung Internet.
Introduction
[edit]A Universal Serial Bus, or a USB is an industry standard communication protocol used to communicate data across connectors, and cables from computers to peripheral devices and/or other computers.[4] WebUSB is a set of API calls that enable access to these hardware devices from web pages. WebUSB is developed by the World Wide Web Consortium (W3C).[1] The WebUSB API provides a safe, and developer familiar means of communication to edge devices from web pages. The WebUSB API integrates into existing USB libraries and shortens the development cycle for integrating new devices into the web environment by not needing to wait for browser support for these devices.
Early versions of WebUSB came out around as an alternative to Flash, Chrome Serial, and other custom approaches to connecting browsers to hardware. WebUSB aims to solve the four goals of any interface being; fast to make, cross platform, look good, accessibility.[5]
Application to Internet of Things (IoT) architecture
[edit]WebUSB API's are able to bridge hardware protocols to internet protocols, enabling the creating of uniform gateways linking edge devices to a centralised networks.[6]
The explosion in computing ability over the last few decades has led to an increase in edge devices. Devices such as lights, thermometers, HVAC, motors are increasingly integrated into centralised internet control servers.[7] These devices have evolved from isolated and previously non-integrated development environments. Consequently, they lack the uniform and consistent communication protocol necessary to develop an immediate connectivity to a web service. The WebUSB's API framework standardises disparate protocols and is able to expose non-standard Universal Serial Bus (USB) compatible devices to the web.[8]
The WebUSB looks to sit between the perception layer and the network layer.[6] The main goals of software in this gateway are; Scalability, Cost and reliability. The cloud-based deployment of WebUSB libraries enables it to cover scalability, its low overhead deployment significantly lowers cost, and its continual in use development over its lifetime has enabled the framework to attain a high degree of reliability.[9]
WebUSB has formed a cornerstone of the BIPES (Block based Integrated Platform for Embedded Systems) architecture framework. This systems architecture model aims to reduce complexity of IoT systems development by aggregating relevant software into 'Blocks' that are complete units of code and can be deployed to an edge device from a centralised cloud infrastructure.[10] As already mentioned the role of WebUSB is critically tied to its ability to communicate to embedded software through the USB communication protocol. Once the information is inside WebUSB's JavaScript environment it can be transposed and communicated through a variety of software protocols.[1] In this particular architecture model WebUSB bridges the gap between embedded software, and the web browser. The web browser then communicates to the cloud environment using uniform WebUSB constructed data.[10]
Security considerations
[edit]WebUSB provides a web page access to a connector to an edge device. The exposure of any device to the internet carries inherent risks and security concerns.[7] By product of design USB ports are designed to trust the device they are connected to. Connecting such a port to an internet facing application introduced a new set of security risks and massively expanding the attack surface for would be malicious actors.[8][1]
For instance a malicious host web page could request data from a peripheral device, which the device would happily fulfil thinking it was communicating through a standard USB connector. To mitigate this type of attack WebUSB developed a requestDevice()
function call. This would notify the user that the site was requesting access to the edge device. This is similar to the access requests browser control for when a web page would like to access the inbuilt camera or microphone. Depending on the wariness of the user this protocol can be enough to prevent certain attacks. A second protocol that was developed is the specification of a request originating from a secure context.[11][1] This ensures that both the code to be executed and the data returned is not intercepted or modified in transit. This security is implemented through the claimInterface() function. This is an OS supported function, and ensures that only a single execution instance can have user space or kernel space driver access to the device, preventing malicious code on a web page from opening a second channel of communication to the device.[1] Other security considerations included created a public registry of approved connections, but this idea was ultimately scrapped as it required vendors to develop devices with WebUSB in mind.[1]
The threat surface of a USB however is bi-directional and a malicious peripheral device could attack the host. An infected edge device cannot easily be mitigated by WebUSB API's. In many device configurations trusted USB ports are used to deliver firmware upgrades and a malicious edge device could grant attackers persistence in a system.[11][4]
In light of the security concerns posed by WebUSB, it is only supported by an estimated 76% of browsers. Also notably is that support for WebUSB at a browser level has been volatile over time, with stretches of time where certain browsers turned off access after the discovery of particular security threats.[12] It is these security concerns that have plagued alternatives to WebUSB. Particularly Flash and Google Serial failed to take off because they were unable to be used with adequate answers to these fundamental security risks.[5]
Use in multi-factor authentication
[edit]The ability to own and verify a digital identity on the internet is critical to interaction with internet facing infrastructure. WebUSB in combination with special purpose devices and public identification registries can be used as key piece in an infrastructure scale solution to digital identity on the internet.[13] WebUSB API library is able to standardise the connection of peripheral devices to web pages. The security investment in WebUSB makes it a suitable software component in connecting identifiable devices to the internet.[1] Recent research has shown the fallibility of SMS based authentication highlighting how key pieces of the infrastructure can be subverted.[14] Alternative proposals for securing a digital identity involve the use of biometric sensors and/or personal identifiers. However, while these are good at identifying an individual, it is only through WebUSB that they can adequately be integrated into the existing internet tech stack.[13] Cryptographically secure solutions for personal identification exist with support from government and specialised hardware. However, these solutions lack generalised specification for web based infrastructure and are generally hard to support. Gateway support for such a communication protocol can be supported by software middlemen, such as WebUSB.[10][13]
A model system for multi-factor authentication uses WebUSB in tandem with an identifying hardware such as an ID card built to ISO/IEC 7810:2003 ID-1[15] standards. This card would constitute a physical representation of an individual's identity. WebUSB would then act as a middle man in facilitating the transfer of data stored on the hardware to a given web server. The number card would be digitally signed by an authorised party and would digitally connect to a server. This connection would require a device capable of reading ISO/IEC 14443 type B connections.[16] In order to make this digital connection valid, WebUSB would serve as software connector.[13]
Usage
[edit]WebUSB will only work on supported browsers, for example Chrome. Due to privacy and security concerns it will also only work in a secure context i.e.; over HTTPS, and can only be called through a user actions.
For instance in order to instantiate a connection navigator.usb.requestDevice()
can only be called through user gesture, such as touch or mouse click.
Similarly protection from WebUSB can be provided using a feature policy. For instance Feature-Policy: fullscreen "*"; usb "none"; payment "self" https://payment.example.com
would prevent WebUSB from running.[17]
To get access to devices visible to the browser two options are available. navigator.usb.requestDevice()
will prompt the user to select which USB access is to be given, or navigator.usb.getDevices()
will return a list of USB devices that the origin has access to.
To better search for devices, WebUSB has a number of filtering options. These filters are passed into navigator.usb.requestDevice()
as a JavaScript filtering object. These filters are; vendorId
,productId
,classCode
, protocolCode
, serialNumber
, and subclassCode
.
For example, imagine connecting to an Arduino device, this could be done in the following way. Where 0x2341 is Arduino in the list of USB ID's[18]
navigator.usb.requestDevice({ filters: [{ vendorId: 0x2341 }] })
.then(device => {
console.log(device.productName);
console.log(device.manufacturerName);
})
.catch(error => { console.error(error); });
The USB device
descriptor returned from the above snippet will contain all important information about the device such as; version, packet size, configuration options etc.
The alternative call to navigator.usb.getDevices()
will instead look like this;
navigator.usb.getDevices().then(devices => {
devices.forEach(device => {
console.log(device.productName);
console.log(device.manufacturerName);
});
})
In order to talk to the device there are a few important function calls to run through. device.open()
will run through all the required steps of setting up the device, device.selectConfiguration()
sets up the configuration, importantly how it is powered, and the number of interfaces. It is then important to claim the interface. This can be done through the device.claimInterface
function call. This will simulate a real wired connection and ensure that this web page is the only one able to read and write to the device until the connection is released. Finally the call device.controlTransferOut()
will set up the device to communicate through the WebUSB Serial API. Once the set up is all done, data can be transferred to the device using device.transferIn()
to transfer bulk data to the device, similarly its sister function device.transferOut()
to read data from the device.[17][1]
Interfaces
[edit]In order to generalise interaction with hardware devices WebUSB supports a number of interfaces than abstract away the specific hardware functionality.[8]
Interface Name | Description |
---|---|
USB | Provides attributes and methods for finding and connecting USB devices from a web page. This interface inherits from EventTarget .
|
USBConnectionEvent | This connection event is passed to USB.onconnect or USB.ondisconnect when the agent detects a change in the connection status.
|
USBDevice | Interface that provides metadata about the connected device and methods for controlling it. Importantly this is the main interface the developer will use for interacting with the device. |
USBInTransferResult | A representation of the results from a data transfer event from the device to the host. Including field for the data and the status of the transfer. There are three options for status fields; 'ok' meaning the transfer was a success, 'stall' indicating an error producing a stall on the endpoint, or 'babble' which indicates more than expected data was transferred. |
USBIsochronousInTransferResult | Similar to USBInTransferResult this is a representation of a data transfer from the device to the host when done across an isochronous endpoint. Has no status field, only the packets.
|
USBIsochronousInTransferPacket | Represents the status of an individual packet from a request to transfer data from the device to the host over an isochronous endpoint. Can return the status of either 'ok' or 'stall'. |
USBIsochronousOutTransferResult | Similar to USBInTransferResult this is a representation of a data transfer from the host to the device when done across an isochronous endpoint.
|
USBIsochronousOutTransferPacket | Represents the status of an individual packet from a request to transfer data from the host to the device over an isochronous endpoint. Same status fields as USBIsochronousInTransferPacket .
|
USBConfiguration | Provides information about a particular configuration of a USB device . This includes information about device version, maximum packet size and supported interfaces. |
USBInterface | Provides information about an interface provided by the USB device. This includes information on whether it is claimed, as well as its communication protocol. |
USBAlternateInterface | Provides information about a particular configuration of an interface and the particular modes the device can operate in. |
USBEndPoint | The USBEndPoint is a unidirectional data stream either into or out of the device.
|
References
[edit]- ^ a b c d e f g h i Grant, R (2021-10-06). "WebUSB API". WICG. Retrieved 2022-01-07.
- ^ "Access USB Devices on the Web". Google Developers. 30 March 2016.
- ^ "WebUSB | Can I use... Support tables for HTML5, CSS3, etc". caniuse.com. Retrieved 2021-07-02.
- ^ a b Anderson, Don (2001). Universal Serial Bus System Architecture (2nd ed.). Addison-Wesley. ISBN 978-0-201-30975-1.
- ^ a b Hinton, Suz (2018-06-18). Suz Hinton - I'm afraid your browser has been talking to the robots again a gentle intro to WebUSB. CSSSConf Australia.
- ^ a b Beniwal, Gunjan; Singhrova, Anita (2022). "A systematic literature review on IoT gateways". Journal of King Saud University - Computer and Information Sciences. 34 (10): 9541–9563. doi:10.1016/j.jksuci.2021.11.007. S2CID 244758915.
- ^ a b Rondon, L; Babun, L; Aris, A; Akkaya, A; Uluagac, A (2021). "Survey on Enterprise Internet-of-Things systems (E-IoT): A security perspective". ISO. arXiv:2102.10695. Retrieved 2021-12-19.
- ^ a b c "WebUSB API". Mozilla Developer Blogs. Mozilla. 2021. Retrieved 2021-12-19.
- ^ Talukder, A.K (2020). "The Next Generation Web: Technologies and Services". Big Data Analytics. Lecture Notes in Computer Science. Vol. 12581. pp. 209–229. doi:10.1007/978-3-030-66665-1_14. ISBN 978-3-030-66664-4. S2CID 230795240. Retrieved 2021-12-19.
- ^ a b c Junior, A. G. D. S.; Gonçalves, L. M. G.; De Paula Caurin, G. A.; Tamanaka, G.T.B; Hernandes, A.C; Aroca, R.V (2020). "BIPES: Block Based Integrated Platform for Embedded Systems". IEEE Access. 8: 197955–197968. Bibcode:2020IEEEA...8s7955J. doi:10.1109/ACCESS.2020.3035083. S2CID 226854474.
- ^ a b Lindström, R (2021). "Enabling Smartphones to act as IoT Edge Devices via the Browser-based 'WebUSB API' : The future of the browser and the smartphone in home electronics IoT systems".
- ^ "Google disables WebUSB in Chrome amidst phishing concerns". XDA Developers. 7 March 2018.
- ^ a b c d Fujita, Y; Inomata, A; Kashiwazaki, H (2019). "Implementation and Evaluation of a Multi-Factor Web Authentication System with Individual Number Card and WebUSB". Asia-Pacific Network Operations and Management Symposium.
- ^ Brian Krebs (2018-06-01). "Reddit Breach Highlights Limits of SMS-Based Authentication". krebs on Security. Retrieved 2021-12-19.
- ^ "ISO/IEC 7810:2003 - Identification cards – Physical characteristics". Retrieved 2022-01-07.
- ^ "ISO/IEC 14443-1:2018 - Cards and security devices for personal identification – Contactless proximity objects". Retrieved 2022-01-07.
- ^ a b Beaufort, Francis (2021-02-23). "Access WebUSB". web.dev. Retrieved 2022-01-06.
- ^ "Access WebUSB". web.dev. Retrieved 2022-01-06.