<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>WebCrypto API for Document Signing</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Nick Hofstede</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Nick Van den Bleeken</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Use Case</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Inventive Designers</institution>
          ,
          <addr-line>Sint Bernardsesteenweg 552, 2660 Antwerp, Belgium, https://</addr-line>
        </aff>
      </contrib-group>
      <abstract>
        <p>This paper focuses on digitally signing documents as a speci c use case for making secure hardware available to a web application. We explore the current options available to implementers and the drawbacks associated with each option. Then we look at the emerging Web Cryptography API developed by the W3C and discover missing functionality needed to implement this use case. Finally, we suggest a way to extend the API in order to support digitally signing documents using secure hardware.</p>
      </abstract>
      <kwd-group>
        <kwd>web applications</kwd>
        <kwd>secure hardware</kwd>
        <kwd>Web Cryptography API</kwd>
        <kwd>W3C</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>1.1</p>
    </sec>
    <sec id="sec-2">
      <title>Signing Documents</title>
      <p>
        The European Union recognizes three levels of digital signatures [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]: electronic
signatures like scanned in handwritten signatures or email footers, advanced
electronic signatures which are created using modern cryptography standards
and quali ed signatures which are advanced electronic signatures satisfying
additional requirements. This last level is an advanced electronic signature made
using a key which has a quali ed certi cate associated with it. Quali ed certi
cates can only be issued by certi ed certi cate authorities and are only issued
using the most stringent processes and only to the most secure type of keys. In
return, quali ed signatures must be considered equivalent to handwritten
signatures by a judge whereas other electronic signatures are open to interpretation
based on the actual details. The peace of mind this obligation provides makes
them a requirement often encountered.
      </p>
      <p>The requirement that a key should be kept under the sole control of the owner
for quali ed certi cation is interpreted to mean the key should be embedded in
a hardware device. This to make sure undetected copying is impossible. In order
to create a quali ed signature, a European citizen will therefore always need a
smart card or key dongle. A web application creating digital signatures should
therefore be able to access the secure hardware of the user.
1.2</p>
    </sec>
    <sec id="sec-3">
      <title>Electronic Identity Cards</title>
      <p>The requirement for secure hardware prompted several European countries to
issue electronic identity cards to their citizens. Currently countries like Belgium,
Germany and many others provide electronic identity cards capable of creating
electronic signatures [2{10] and more countries are planning on issuing them.</p>
      <p>These cards, many of them issued mandatory, create a large group of users
with access to secure hardware and a certi cate ready to create legally
binding electronic signatures. Governments have begun using these cards in web
applications for the retrieval of o cial documents like birth certi cates (after
authentication) or submitting online tax forms (requiring a signature). Many
more use cases for government and corporate applications can be thought of,
but in this paper we will be focussing on signing documents.
2</p>
      <sec id="sec-3-1">
        <title>Current Situation</title>
        <p>Using these identity cards in web applications today is possible, but serious
drawbacks exist.
2.1</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Client-side TLS</title>
      <p>The rst applications that popped up were using client-side TLS for
authentication. The user navigates to a website and is asked to authenticate herself. Most
if not all of the identity cards come with middleware that either adds the certi
cate to the operating system's key ring allowing it to be accessed by browsers,
or installs speci c browser plug-ins registering the certi cate for client-side use.</p>
      <p>After the user has authenticated herself, consent with the content to be
submitted to the application (like a tax form for example) is typically given by
pushing a button. Proof of this consent is then carried by the auditing
information logged by the web application. No real electronic signature is created and
consent can only be inferred from the audit logs of the web application.</p>
      <p>Even this simple scheme can lead to problems when one is not careful. In
particular, revocation checks often need to be explicitly enabled at the SSL
termination point as it is typically disabled by default. Additionally, client-side
authentication su ers from a few other problems like not being able to log out of
a session and somewhat bad usability due to it being needed before a connection
to the server is established and a web page providing guidance can be shown.
While this can be worked around using di erent domains, it would be preferable
if the authentication process is initiated by the web page itself to allow for a
richer user experience.</p>
      <p>In any case, no actual quali ed electronic signature is created, only an audit
trail.
2.2</p>
    </sec>
    <sec id="sec-5">
      <title>Java Plugin</title>
      <p>
        If a quali ed electronic signature needs to be created to sign a PDF document,
or to create an archive containing a XAdES signature for example, the browser
needs to access the smart card. This can be done using a custom plug-in, but a
better option is to use a more widely available general purpose plug-in for this
task. Chances are the user already has this plug-in installed which avoids going
through an additional installation procedure. Using javascript and a Java applet,
data can be shipped to and signed by the secure hardware. Typically, one of two
methods is used. Either the applet probes for a library installed as part of the
card's middleware using JNI, or the smart card is accessed directly using APDU
commands available in standard java runtimes starting from version 6 [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ].
      </p>
      <p>The Java plug-in needs to be installed and the applet needs to be granted
additional privileges. This is cumbersome, but until recently it was a reasonable
approach. After a series of vulnerabilities in Java however, browsers either disable
the plug-in, or only allow it to run when it is the latest version and has been
given explicit permission. This degrades the user experience so much that using
an applet is no longer a viable option.
3</p>
      <sec id="sec-5-1">
        <title>Evaluation of the Web Cryptography API</title>
        <p>
          Mainly driven by mobile applications being implemented as web applications,
more and more functionality, including access to hardware like GPS sensors [
          <xref ref-type="bibr" rid="ref12">12</xref>
          ]
and cameras [
          <xref ref-type="bibr" rid="ref13">13</xref>
          ], has been made available through javascript API's. When we
rst heard about a Web Cryptography API [
          <xref ref-type="bibr" rid="ref14">14</xref>
          ] being under development we
looked at it to remove the dependency on a Java applet to access the secure
hardware device and do the signing. With a use case like \The ability to select
credentials and sign statements can be necessary to perform high-value
transactions such as those involved in nance, corporate security, and identity-related
claims about personal data." in the working group's charter [
          <xref ref-type="bibr" rid="ref15">15</xref>
          ] as a goal this
did not seem far-fetched at all.
3.1
        </p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>Design</title>
      <p>In order to keep the scope of the API limited, the Working group has de ned a
very narrow scope for its main document. In order to stay away from concepts
that are not portable between operating systems, cryptographic libraries or user
agent implementations, provisioning operations or the discovery of cryptographic
modules is considered out of scope.</p>
      <p>While this might seem like a severe restriction, by supporting key generation
functions it still allows for many cryptographic use cases. Indeed, as long as the
keys are generated by the api, the provided operations (encrypt, decrypt, sign,
verify, digest, deriveKey, importKey and exportKey) allow for a wide array
of applications like secure messaging, data integrity protection of cached data
and cloud storage.</p>
      <p>On the more practical side of designing the API, the working group follows
JavaScript best practices and tries to make every call that might take some
time, or that might conceivably require user interaction to be asynchronous.
This allows for the program ow of the javascript application to continue while
waiting for the user the grant permissions, enter a pin number or calculations to
be completed.
3.2</p>
    </sec>
    <sec id="sec-7">
      <title>Signing</title>
      <p>The key types and sign operations supported by the API are suited for the use
case we have in mind. The issue has been raised whether \broken" cryptography
algorithms like SHA1 and PKCS#1 v1.15 should be included, but for the sake
of backwards compatibility and integration with server-side software it has been
decided they remain. While we hope the world quickly moves on to the more
modern alternatives which are supported as well, given the number of deployed
smartcards implementing only these older algorithms, excluding them would
seriously limit the applicability of the API today.
3.3</p>
    </sec>
    <sec id="sec-8">
      <title>Key Discovery</title>
      <p>Recognizing that not all use cases work with keys generated by the
application itself, the group started work on key discovery in a separate working draft
[16]. In order to limit the scope and driven by a use case focussing on trusted
platform modules (TPMs) and digital rights management (DRM), the speci
cation currently limits itself to \discovering named, origin-speci c pre-provisioned
cryptographic keys for use with the Web Cryptography API". While this allows
for user agents to make keys stored on secure elements like TPMs available to
web applications originating from a given domain under a known name, none of
those adjectives are a good match for the signing use case.</p>
      <p>While it might be possible to assign names to the keys provided by the secure
hardware, in all naming schemes we could come up with it would be impossible
for the web application to guess what that name might be. Additionally, the keys
contained in the secure hardware wouldn't be origin-speci c either. A user shall
want to use her smart card to authenticate herself to di erent web applications.
Finally, the keys are not pre-provisioned. A way to prompt the user to (re)insert
her smart card or USB dongle would be needed.</p>
      <p>Key discovery as currently conceived by the WebCrypto Key Discovery draft
isn't useful for discovering keys that reside on users' smart cards.
3.4</p>
    </sec>
    <sec id="sec-9">
      <title>Certi cate Based Discovery</title>
      <p>Instead of name-based key discovery we believe attribute-based discovery of keys
based on the key's algorithm or the accompanying certi cate is necessary. By
limiting the keys known to the browser by algorithm, issuing certi cate authority,
intended usage and other relevant properties, a short list could be presented to
the user where she can pick the key needed to complete the action she started.</p>
      <p>While this operation closely resembles selecting the appropriate key to use
when setting up client-side TLS, it should be noted that this operation can be
made asynchronous and can be initiated after a page has been presented to
the user. It is conceivable that the user prompt takes the same form as other
requests for access to speci c resources like your location or camera. The main
di erence might be that this wouldn't have an \Allow" and \Disallow" button,
but a \Select..." one popping up a dialog requiring further interaction.
4</p>
      <sec id="sec-9-1">
        <title>Proposed Extension</title>
        <p>Despite its current shortcomings, we believe the Web Cryptography API forms
a solid basis. We joined the working group to help shape the API and make the
use case outlined in this paper possible. We're currently working on a proposal
that will extend the current API to enable the creation of web applications that
use secure hardware for the creation of digital signatures.
4.1</p>
      </sec>
    </sec>
    <sec id="sec-10">
      <title>Additional API</title>
      <p>We propose a new X509Certificate class, and two new asynchronous methods.
A rst one to search for certi cates and related keys, and a second one to enable
exporting certi cates to a byte array.</p>
      <p>The X509CertificateSelector will take a dictionary containing lters.
Filters include things like issuing certi cate authority, usage ags, key algorithm,
validity dates and others.</p>
      <p>Invoking the X509CertificateSelector will create a subset of all known
certi cates known to the browser and initiate a selection procedure by the user
agent. This procedure can start with a subtle banner to request access like the
location or media capture API's. When clicked, the subset can be presented as
a list to the user. Confronted with the list, the user will pick the certi cate
appropriate for the action she started and grant the web application access to
the associated keys. This grant is origin-speci c. When the keys are used an
additional dialog window prompting for a pin code may be shown.</p>
      <p>By keeping the user in the loop and requiring her to explicitly allow access to
the certi cate and keys stored in the operating system's store, this API can't be
used to ngerprint users or glance information from unrelated certi cates stored
in the store.</p>
      <p>The export functionality is necessary because the certi cate (or certi cates
as you probably need the entire chain) used will likely have to be embedded in
or associated with the digital signature that is being created.
4.2</p>
    </sec>
    <sec id="sec-11">
      <title>Prototype</title>
      <p>We are implementing enough of the WebCrypto API and the proposed extensions
as a browser plug-in to validate this proposal [20]. The code is available under
an Apache license on github [21].</p>
      <p>Note This is an initial proposal and not all issues have been discovered or indeed
resolved. We welcome comments, insights and code contributions you may have
or want to share.
16. World Wide Web Consortium. WebCrypto Key Discovery. W3C Working Draft 08
January 2013. Retrieved from
http://www.w3.org/TR/2013/WD-webcrypto-keydiscovery-20130108/
17. Cryptographic Token Interface Standard. Version 2.30, Editor Simon McMahon
with Robert Gri n of RSA as project coordinator. RSA PSS mechanism parameters.</p>
      <p>Retrieved from http://www.cryptsoft.com/pkcs11doc/v230/
18. Mac Developer Library. kSecInputIsDigest constant de nition. Retrieved from
https://developer.apple.com/library/mac/search/?q=kSecInputIsDigest
19. Windows Dev Center. CryptSignHash function documentation. Retrieved from
http://msdn.microsoft.com/en-us/library/windows/desktop/aa380280
20. Inventive Designers API proposal, version 79f54d9 Retrieved from
https://github.com/InventiveDesigners/webcrypto-key-certi
cate-discoveryjs/wiki/API
21. GitHub, Inc. Inventive Designers' webcrypto-key-certi cate-discovery-js repository.</p>
      <p>Retrieved from https://github.com/InventiveDesigners/webcrypto-key-certi
catediscovery-js</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>European</given-names>
            <surname>Parliament</surname>
          </string-name>
          and Council.
          <source>Directive</source>
          <year>1999</year>
          /93/EC on a
          <article-title>Community framework for electronic signatures. 13 December 1999</article-title>
          . Retrieved from http://eurlex.europa.eu/LexUriServ/LexUriServ.do?uri=CELEX:31999L0093:EN:NOT
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Austria</surname>
          </string-name>
          .
          <article-title>The Austrian electronic ID Card \Burgerkarte"</article-title>
          .
          <source>Retrieved</source>
          from http://www.buergerkarte.at/
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Belgium</surname>
          </string-name>
          .
          <article-title>The Belgian electronic ID Card</article-title>
          . Retrieved from http://eid.belgium.be/
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Estonia</surname>
          </string-name>
          .
          <article-title>The Estonian eID Card, \EstEID"</article-title>
          . Retrieved from http://www.id.ee/
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Finland</surname>
          </string-name>
          . The Finnish eID Card, \'FINEID'. Retrieved from http://www. neid. /
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Germany</surname>
          </string-name>
          .
          <article-title>The German electronic ID Card, \Personalausweis"</article-title>
          . Retrieved from http://www.personalausweisportal.de/
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Italy</surname>
          </string-name>
          .
          <article-title>Carta di Identit Elettronica (C.I.E), the Italian electronic ID Card</article-title>
          . Retrieved from http://www.halnet.it/cie/
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Portugal</surname>
          </string-name>
          .
          <article-title>The Portuguese electronic ID Card, \Carto de Cidado"</article-title>
          . Retrieved from http://www.cartaodecidadao.pt/
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Spain</surname>
          </string-name>
          .
          <source>The Spanish eID Card</source>
          . Retrieved from http://www.dnielectronico.es/
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Sweden</surname>
          </string-name>
          .
          <article-title>Fakta om nationellt id-kort (Facts about the national ID card)</article-title>
          . Retrieved from http://www.polisen.se/inter/nodeid=33378&amp;pageversion=1.jsp
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Oracle</surname>
          </string-name>
          .
          <article-title>Java Smart Card I/O API</article-title>
          .
          <article-title>Javadoc, package speci cation</article-title>
          . Retrieved from http://docs.oracle.com/javase/6/docs/jre/api/security/smartcardio/spec/
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Geolocation</surname>
            <given-names>API</given-names>
          </string-name>
          <article-title>Speci cation W3C Proposed Recommendation 10 May 2012 Retrieved from</article-title>
          http://www.w3.org/TR/geolocation-API/
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <given-names>HTML</given-names>
            <surname>Media Capture W3C Last Call</surname>
          </string-name>
          Working Draft 26 March 2013 Retrieved from http://dev.w3.org/2009/dap/camera/
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14. World Wide Web Consortium.
          <source>Web Cryptography API. W3C Working Draft 8 January</source>
          <year>2013</year>
          . Retrieved from http://www.w3.org/TR/2013/WD-WebCryptoAPI20130108/
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15. World Wide Web Consortium. Web Cryptography Working Group Charter.
          <article-title>3 April 2013</article-title>
          . Retrieved from http://www.w3.org/
          <year>2011</year>
          /11/webcryptography-charter.html
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>