├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── LICENSE.build ├── README.md ├── agent.js ├── app.css ├── app.html ├── app.js ├── bower.json ├── build.sh ├── download-google-smart-card-client-library.py ├── manifest.json ├── pinCache.js ├── pinDialog.css ├── pinDialog.html ├── pinDialog.js ├── smart-ssh_128.png ├── smart-ssh_48.png └── smartCard.js /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | bower_components/ 3 | smart-ssh.zip 4 | google-smart-card-client-library.js 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | smart-ssh uses [bower](https://bower.io/) to manage its dependencies. 5 | 6 | ## Building 7 | Run `build.sh`. This will 8 | 1. install bower dependencies, 9 | 2. download the [Google Smart Card Client library](https://github.com/GoogleChrome/chromeos_smart_card_connector/releases), 10 | 3. copy all resources into the `build` folder, 11 | 4. compress the contents of the `build` folder into a ZIP file. 12 | In order to load the extension into Chrome, activate `Developer mode` on `chrome://extensions` and select the `build` folder after clicking on `Load unpacked extension...`. 13 | 14 | ## Contributing 15 | 1. Fork [this repository](https://github.com/FabianHenneke/smart-ssh). 16 | 2. Create a feature branch with 17 | `git checkout -b my-new-feature` 18 | 3. Commit your changes via 19 | `git commit -am "Add new feature"` 20 | 4. Push the branch with 21 | `git push origin my-new-feature` 22 | 5. Create a pull request. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2017 Fabian Henneke 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /LICENSE.build: -------------------------------------------------------------------------------- 1 | This software underlies the following license: 2 | 3 | The MIT License (MIT) 4 | Copyright (c) 2017 Fabian Henneke 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | 12 | 13 | This software uses ‘Material Icons’ , which underly the following license: 14 | 15 | Copyright (c) 2017 Google 16 | 17 | Apache License 18 | Version 2.0, January 2004 19 | http://www.apache.org/licenses/ 20 | 21 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 22 | 23 | 1. Definitions. 24 | 25 | "License" shall mean the terms and conditions for use, reproduction, 26 | and distribution as defined by Sections 1 through 9 of this document. 27 | 28 | "Licensor" shall mean the copyright owner or entity authorized by 29 | the copyright owner that is granting the License. 30 | 31 | "Legal Entity" shall mean the union of the acting entity and all 32 | other entities that control, are controlled by, or are under common 33 | control with that entity. For the purposes of this definition, 34 | "control" means (i) the power, direct or indirect, to cause the 35 | direction or management of such entity, whether by contract or 36 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 37 | outstanding shares, or (iii) beneficial ownership of such entity. 38 | 39 | "You" (or "Your") shall mean an individual or Legal Entity 40 | exercising permissions granted by this License. 41 | 42 | "Source" form shall mean the preferred form for making modifications, 43 | including but not limited to software source code, documentation 44 | source, and configuration files. 45 | 46 | "Object" form shall mean any form resulting from mechanical 47 | transformation or translation of a Source form, including but 48 | not limited to compiled object code, generated documentation, 49 | and conversions to other media types. 50 | 51 | "Work" shall mean the work of authorship, whether in Source or 52 | Object form, made available under the License, as indicated by a 53 | copyright notice that is included in or attached to the work 54 | (an example is provided in the Appendix below). 55 | 56 | "Derivative Works" shall mean any work, whether in Source or Object 57 | form, that is based on (or derived from) the Work and for which the 58 | editorial revisions, annotations, elaborations, or other modifications 59 | represent, as a whole, an original work of authorship. For the purposes 60 | of this License, Derivative Works shall not include works that remain 61 | separable from, or merely link (or bind by name) to the interfaces of, 62 | the Work and Derivative Works thereof. 63 | 64 | "Contribution" shall mean any work of authorship, including 65 | the original version of the Work and any modifications or additions 66 | to that Work or Derivative Works thereof, that is intentionally 67 | submitted to Licensor for inclusion in the Work by the copyright owner 68 | or by an individual or Legal Entity authorized to submit on behalf of 69 | the copyright owner. For the purposes of this definition, "submitted" 70 | means any form of electronic, verbal, or written communication sent 71 | to the Licensor or its representatives, including but not limited to 72 | communication on electronic mailing lists, source code control systems, 73 | and issue tracking systems that are managed by, or on behalf of, the 74 | Licensor for the purpose of discussing and improving the Work, but 75 | excluding communication that is conspicuously marked or otherwise 76 | designated in writing by the copyright owner as "Not a Contribution." 77 | 78 | "Contributor" shall mean Licensor and any individual or Legal Entity 79 | on behalf of whom a Contribution has been received by Licensor and 80 | subsequently incorporated within the Work. 81 | 82 | 2. Grant of Copyright License. Subject to the terms and conditions of 83 | this License, each Contributor hereby grants to You a perpetual, 84 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 85 | copyright license to reproduce, prepare Derivative Works of, 86 | publicly display, publicly perform, sublicense, and distribute the 87 | Work and such Derivative Works in Source or Object form. 88 | 89 | 3. Grant of Patent License. Subject to the terms and conditions of 90 | this License, each Contributor hereby grants to You a perpetual, 91 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 92 | (except as stated in this section) patent license to make, have made, 93 | use, offer to sell, sell, import, and otherwise transfer the Work, 94 | where such license applies only to those patent claims licensable 95 | by such Contributor that are necessarily infringed by their 96 | Contribution(s) alone or by combination of their Contribution(s) 97 | with the Work to which such Contribution(s) was submitted. If You 98 | institute patent litigation against any entity (including a 99 | cross-claim or counterclaim in a lawsuit) alleging that the Work 100 | or a Contribution incorporated within the Work constitutes direct 101 | or contributory patent infringement, then any patent licenses 102 | granted to You under this License for that Work shall terminate 103 | as of the date such litigation is filed. 104 | 105 | 4. Redistribution. You may reproduce and distribute copies of the 106 | Work or Derivative Works thereof in any medium, with or without 107 | modifications, and in Source or Object form, provided that You 108 | meet the following conditions: 109 | 110 | (a) You must give any other recipients of the Work or 111 | Derivative Works a copy of this License; and 112 | 113 | (b) You must cause any modified files to carry prominent notices 114 | stating that You changed the files; and 115 | 116 | (c) You must retain, in the Source form of any Derivative Works 117 | that You distribute, all copyright, patent, trademark, and 118 | attribution notices from the Source form of the Work, 119 | excluding those notices that do not pertain to any part of 120 | the Derivative Works; and 121 | 122 | (d) If the Work includes a "NOTICE" text file as part of its 123 | distribution, then any Derivative Works that You distribute must 124 | include a readable copy of the attribution notices contained 125 | within such NOTICE file, excluding those notices that do not 126 | pertain to any part of the Derivative Works, in at least one 127 | of the following places: within a NOTICE text file distributed 128 | as part of the Derivative Works; within the Source form or 129 | documentation, if provided along with the Derivative Works; or, 130 | within a display generated by the Derivative Works, if and 131 | wherever such third-party notices normally appear. The contents 132 | of the NOTICE file are for informational purposes only and 133 | do not modify the License. You may add Your own attribution 134 | notices within Derivative Works that You distribute, alongside 135 | or as an addendum to the NOTICE text from the Work, provided 136 | that such additional attribution notices cannot be construed 137 | as modifying the License. 138 | 139 | You may add Your own copyright statement to Your modifications and 140 | may provide additional or different license terms and conditions 141 | for use, reproduction, or distribution of Your modifications, or 142 | for any such Derivative Works as a whole, provided Your use, 143 | reproduction, and distribution of the Work otherwise complies with 144 | the conditions stated in this License. 145 | 146 | 5. Submission of Contributions. Unless You explicitly state otherwise, 147 | any Contribution intentionally submitted for inclusion in the Work 148 | by You to the Licensor shall be under the terms and conditions of 149 | this License, without any additional terms or conditions. 150 | Notwithstanding the above, nothing herein shall supersede or modify 151 | the terms of any separate license agreement you may have executed 152 | with Licensor regarding such Contributions. 153 | 154 | 6. Trademarks. This License does not grant permission to use the trade 155 | names, trademarks, service marks, or product names of the Licensor, 156 | except as required for reasonable and customary use in describing the 157 | origin of the Work and reproducing the content of the NOTICE file. 158 | 159 | 7. Disclaimer of Warranty. Unless required by applicable law or 160 | agreed to in writing, Licensor provides the Work (and each 161 | Contributor provides its Contributions) on an "AS IS" BASIS, 162 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 163 | implied, including, without limitation, any warranties or conditions 164 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 165 | PARTICULAR PURPOSE. You are solely responsible for determining the 166 | appropriateness of using or redistributing the Work and assume any 167 | risks associated with Your exercise of permissions under this License. 168 | 169 | 8. Limitation of Liability. In no event and under no legal theory, 170 | whether in tort (including negligence), contract, or otherwise, 171 | unless required by applicable law (such as deliberate and grossly 172 | negligent acts) or agreed to in writing, shall any Contributor be 173 | liable to You for damages, including any direct, indirect, special, 174 | incidental, or consequential damages of any character arising as a 175 | result of this License or out of the use or inability to use the 176 | Work (including but not limited to damages for loss of goodwill, 177 | work stoppage, computer failure or malfunction, or any and all 178 | other commercial damages or losses), even if such Contributor 179 | has been advised of the possibility of such damages. 180 | 181 | 9. Accepting Warranty or Additional Liability. While redistributing 182 | the Work or Derivative Works thereof, You may choose to offer, 183 | and charge a fee for, acceptance of support, warranty, indemnity, 184 | or other liability obligations and/or rights consistent with this 185 | License. However, in accepting such obligations, You may act only 186 | on Your own behalf and on Your sole responsibility, not on behalf 187 | of any other Contributor, and only if You agree to indemnify, 188 | defend, and hold each Contributor harmless for any liability 189 | incurred by, or claims asserted against, such Contributor by reason 190 | of your accepting any such warranty or additional liability. 191 | 192 | END OF TERMS AND CONDITIONS 193 | 194 | APPENDIX: How to apply the Apache License to your work. 195 | 196 | To apply the Apache License to your work, attach the following 197 | boilerplate notice, with the fields enclosed by brackets "[]" 198 | replaced with your own identifying information. (Don't include 199 | the brackets!) The text should be enclosed in the appropriate 200 | comment syntax for the file format. We also recommend that a 201 | file or class name and description of purpose be included on the 202 | same "printed page" as the copyright notice for easier 203 | identification within third-party archives. 204 | 205 | Copyright [yyyy] [name of copyright owner] 206 | 207 | Licensed under the Apache License, Version 2.0 (the "License"); 208 | you may not use this file except in compliance with the License. 209 | You may obtain a copy of the License at 210 | 211 | http://www.apache.org/licenses/LICENSE-2.0 212 | 213 | Unless required by applicable law or agreed to in writing, software 214 | distributed under the License is distributed on an "AS IS" BASIS, 215 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 216 | See the License for the specific language governing permissions and 217 | limitations under the License. 218 | 219 | 220 | This software uses ‘openpgp.js’ , which underlies the following license: 221 | 222 | GNU LESSER GENERAL PUBLIC LICENSE 223 | Version 3, 29 June 2007 224 | 225 | Copyright (C) 2007 Free Software Foundation, Inc. 226 | Everyone is permitted to copy and distribute verbatim copies 227 | of this license document, but changing it is not allowed. 228 | 229 | 230 | This version of the GNU Lesser General Public License incorporates 231 | the terms and conditions of version 3 of the GNU General Public 232 | License, supplemented by the additional permissions listed below. 233 | 234 | 0. Additional Definitions. 235 | 236 | As used herein, "this License" refers to version 3 of the GNU Lesser 237 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 238 | General Public License. 239 | 240 | "The Library" refers to a covered work governed by this License, 241 | other than an Application or a Combined Work as defined below. 242 | 243 | An "Application" is any work that makes use of an interface provided 244 | by the Library, but which is not otherwise based on the Library. 245 | Defining a subclass of a class defined by the Library is deemed a mode 246 | of using an interface provided by the Library. 247 | 248 | A "Combined Work" is a work produced by combining or linking an 249 | Application with the Library. The particular version of the Library 250 | with which the Combined Work was made is also called the "Linked 251 | Version". 252 | 253 | The "Minimal Corresponding Source" for a Combined Work means the 254 | Corresponding Source for the Combined Work, excluding any source code 255 | for portions of the Combined Work that, considered in isolation, are 256 | based on the Application, and not on the Linked Version. 257 | 258 | The "Corresponding Application Code" for a Combined Work means the 259 | object code and/or source code for the Application, including any data 260 | and utility programs needed for reproducing the Combined Work from the 261 | Application, but excluding the System Libraries of the Combined Work. 262 | 263 | 1. Exception to Section 3 of the GNU GPL. 264 | 265 | You may convey a covered work under sections 3 and 4 of this License 266 | without being bound by section 3 of the GNU GPL. 267 | 268 | 2. Conveying Modified Versions. 269 | 270 | If you modify a copy of the Library, and, in your modifications, a 271 | facility refers to a function or data to be supplied by an Application 272 | that uses the facility (other than as an argument passed when the 273 | facility is invoked), then you may convey a copy of the modified 274 | version: 275 | 276 | a) under this License, provided that you make a good faith effort to 277 | ensure that, in the event an Application does not supply the 278 | function or data, the facility still operates, and performs 279 | whatever part of its purpose remains meaningful, or 280 | 281 | b) under the GNU GPL, with none of the additional permissions of 282 | this License applicable to that copy. 283 | 284 | 3. Object Code Incorporating Material from Library Header Files. 285 | 286 | The object code form of an Application may incorporate material from 287 | a header file that is part of the Library. You may convey such object 288 | code under terms of your choice, provided that, if the incorporated 289 | material is not limited to numerical parameters, data structure 290 | layouts and accessors, or small macros, inline functions and templates 291 | (ten or fewer lines in length), you do both of the following: 292 | 293 | a) Give prominent notice with each copy of the object code that the 294 | Library is used in it and that the Library and its use are 295 | covered by this License. 296 | 297 | b) Accompany the object code with a copy of the GNU GPL and this license 298 | document. 299 | 300 | 4. Combined Works. 301 | 302 | You may convey a Combined Work under terms of your choice that, 303 | taken together, effectively do not restrict modification of the 304 | portions of the Library contained in the Combined Work and reverse 305 | engineering for debugging such modifications, if you also do each of 306 | the following: 307 | 308 | a) Give prominent notice with each copy of the Combined Work that 309 | the Library is used in it and that the Library and its use are 310 | covered by this License. 311 | 312 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 313 | document. 314 | 315 | c) For a Combined Work that displays copyright notices during 316 | execution, include the copyright notice for the Library among 317 | these notices, as well as a reference directing the user to the 318 | copies of the GNU GPL and this license document. 319 | 320 | d) Do one of the following: 321 | 322 | 0) Convey the Minimal Corresponding Source under the terms of this 323 | License, and the Corresponding Application Code in a form 324 | suitable for, and under terms that permit, the user to 325 | recombine or relink the Application with a modified version of 326 | the Linked Version to produce a modified Combined Work, in the 327 | manner specified by section 6 of the GNU GPL for conveying 328 | Corresponding Source. 329 | 330 | 1) Use a suitable shared library mechanism for linking with the 331 | Library. A suitable mechanism is one that (a) uses at run time 332 | a copy of the Library already present on the user's computer 333 | system, and (b) will operate properly with a modified version 334 | of the Library that is interface-compatible with the Linked 335 | Version. 336 | 337 | e) Provide Installation Information, but only if you would otherwise 338 | be required to provide such information under section 6 of the 339 | GNU GPL, and only to the extent that such information is 340 | necessary to install and execute a modified version of the 341 | Combined Work produced by recombining or relinking the 342 | Application with a modified version of the Linked Version. (If 343 | you use option 4d0, the Installation Information must accompany 344 | the Minimal Corresponding Source and Corresponding Application 345 | Code. If you use option 4d1, you must provide the Installation 346 | Information in the manner specified by section 6 of the GNU GPL 347 | for conveying Corresponding Source.) 348 | 349 | 5. Combined Libraries. 350 | 351 | You may place library facilities that are a work based on the 352 | Library side by side in a single library together with other library 353 | facilities that are not Applications and are not covered by this 354 | License, and convey such a combined library under terms of your 355 | choice, if you do both of the following: 356 | 357 | a) Accompany the combined library with a copy of the same work based 358 | on the Library, uncombined with any other library facilities, 359 | conveyed under the terms of this License. 360 | 361 | b) Give prominent notice with the combined library that part of it 362 | is a work based on the Library, and explaining where to find the 363 | accompanying uncombined form of the same work. 364 | 365 | 6. Revised Versions of the GNU Lesser General Public License. 366 | 367 | The Free Software Foundation may publish revised and/or new versions 368 | of the GNU Lesser General Public License from time to time. Such new 369 | versions will be similar in spirit to the present version, but may 370 | differ in detail to address new problems or concerns. 371 | 372 | Each version is given a distinguishing version number. If the 373 | Library as you received it specifies that a certain numbered version 374 | of the GNU Lesser General Public License "or any later version" 375 | applies to it, you have the option of following the terms and 376 | conditions either of that published version or of any later version 377 | published by the Free Software Foundation. If the Library as you 378 | received it does not specify a version number of the GNU Lesser 379 | General Public License, you may choose any version of the GNU Lesser 380 | General Public License ever published by the Free Software Foundation. 381 | 382 | If the Library as you received it specifies that a proxy can decide 383 | whether future versions of the GNU Lesser General Public License shall 384 | apply, that proxy's public statement of acceptance of any version is 385 | permanent authorization for you to choose that version for the 386 | Library. 387 | 388 | GNU GENERAL PUBLIC LICENSE 389 | Version 3, 29 June 2007 390 | 391 | Copyright (C) 2007 Free Software Foundation, Inc. 392 | Everyone is permitted to copy and distribute verbatim copies 393 | of this license document, but changing it is not allowed. 394 | 395 | Preamble 396 | 397 | The GNU General Public License is a free, copyleft license for 398 | software and other kinds of works. 399 | 400 | The licenses for most software and other practical works are designed 401 | to take away your freedom to share and change the works. By contrast, 402 | the GNU General Public License is intended to guarantee your freedom to 403 | share and change all versions of a program--to make sure it remains free 404 | software for all its users. We, the Free Software Foundation, use the 405 | GNU General Public License for most of our software; it applies also to 406 | any other work released this way by its authors. You can apply it to 407 | your programs, too. 408 | 409 | When we speak of free software, we are referring to freedom, not 410 | price. Our General Public Licenses are designed to make sure that you 411 | have the freedom to distribute copies of free software (and charge for 412 | them if you wish), that you receive source code or can get it if you 413 | want it, that you can change the software or use pieces of it in new 414 | free programs, and that you know you can do these things. 415 | 416 | To protect your rights, we need to prevent others from denying you 417 | these rights or asking you to surrender the rights. Therefore, you have 418 | certain responsibilities if you distribute copies of the software, or if 419 | you modify it: responsibilities to respect the freedom of others. 420 | 421 | For example, if you distribute copies of such a program, whether 422 | gratis or for a fee, you must pass on to the recipients the same 423 | freedoms that you received. You must make sure that they, too, receive 424 | or can get the source code. And you must show them these terms so they 425 | know their rights. 426 | 427 | Developers that use the GNU GPL protect your rights with two steps: 428 | (1) assert copyright on the software, and (2) offer you this License 429 | giving you legal permission to copy, distribute and/or modify it. 430 | 431 | For the developers' and authors' protection, the GPL clearly explains 432 | that there is no warranty for this free software. For both users' and 433 | authors' sake, the GPL requires that modified versions be marked as 434 | changed, so that their problems will not be attributed erroneously to 435 | authors of previous versions. 436 | 437 | Some devices are designed to deny users access to install or run 438 | modified versions of the software inside them, although the manufacturer 439 | can do so. This is fundamentally incompatible with the aim of 440 | protecting users' freedom to change the software. The systematic 441 | pattern of such abuse occurs in the area of products for individuals to 442 | use, which is precisely where it is most unacceptable. Therefore, we 443 | have designed this version of the GPL to prohibit the practice for those 444 | products. If such problems arise substantially in other domains, we 445 | stand ready to extend this provision to those domains in future versions 446 | of the GPL, as needed to protect the freedom of users. 447 | 448 | Finally, every program is threatened constantly by software patents. 449 | States should not allow patents to restrict development and use of 450 | software on general-purpose computers, but in those that do, we wish to 451 | avoid the special danger that patents applied to a free program could 452 | make it effectively proprietary. To prevent this, the GPL assures that 453 | patents cannot be used to render the program non-free. 454 | 455 | The precise terms and conditions for copying, distribution and 456 | modification follow. 457 | 458 | TERMS AND CONDITIONS 459 | 460 | 0. Definitions. 461 | 462 | "This License" refers to version 3 of the GNU General Public License. 463 | 464 | "Copyright" also means copyright-like laws that apply to other kinds of 465 | works, such as semiconductor masks. 466 | 467 | "The Program" refers to any copyrightable work licensed under this 468 | License. Each licensee is addressed as "you". "Licensees" and 469 | "recipients" may be individuals or organizations. 470 | 471 | To "modify" a work means to copy from or adapt all or part of the work 472 | in a fashion requiring copyright permission, other than the making of an 473 | exact copy. The resulting work is called a "modified version" of the 474 | earlier work or a work "based on" the earlier work. 475 | 476 | A "covered work" means either the unmodified Program or a work based 477 | on the Program. 478 | 479 | To "propagate" a work means to do anything with it that, without 480 | permission, would make you directly or secondarily liable for 481 | infringement under applicable copyright law, except executing it on a 482 | computer or modifying a private copy. Propagation includes copying, 483 | distribution (with or without modification), making available to the 484 | public, and in some countries other activities as well. 485 | 486 | To "convey" a work means any kind of propagation that enables other 487 | parties to make or receive copies. Mere interaction with a user through 488 | a computer network, with no transfer of a copy, is not conveying. 489 | 490 | An interactive user interface displays "Appropriate Legal Notices" 491 | to the extent that it includes a convenient and prominently visible 492 | feature that (1) displays an appropriate copyright notice, and (2) 493 | tells the user that there is no warranty for the work (except to the 494 | extent that warranties are provided), that licensees may convey the 495 | work under this License, and how to view a copy of this License. If 496 | the interface presents a list of user commands or options, such as a 497 | menu, a prominent item in the list meets this criterion. 498 | 499 | 1. Source Code. 500 | 501 | The "source code" for a work means the preferred form of the work 502 | for making modifications to it. "Object code" means any non-source 503 | form of a work. 504 | 505 | A "Standard Interface" means an interface that either is an official 506 | standard defined by a recognized standards body, or, in the case of 507 | interfaces specified for a particular programming language, one that 508 | is widely used among developers working in that language. 509 | 510 | The "System Libraries" of an executable work include anything, other 511 | than the work as a whole, that (a) is included in the normal form of 512 | packaging a Major Component, but which is not part of that Major 513 | Component, and (b) serves only to enable use of the work with that 514 | Major Component, or to implement a Standard Interface for which an 515 | implementation is available to the public in source code form. A 516 | "Major Component", in this context, means a major essential component 517 | (kernel, window system, and so on) of the specific operating system 518 | (if any) on which the executable work runs, or a compiler used to 519 | produce the work, or an object code interpreter used to run it. 520 | 521 | The "Corresponding Source" for a work in object code form means all 522 | the source code needed to generate, install, and (for an executable 523 | work) run the object code and to modify the work, including scripts to 524 | control those activities. However, it does not include the work's 525 | System Libraries, or general-purpose tools or generally available free 526 | programs which are used unmodified in performing those activities but 527 | which are not part of the work. For example, Corresponding Source 528 | includes interface definition files associated with source files for 529 | the work, and the source code for shared libraries and dynamically 530 | linked subprograms that the work is specifically designed to require, 531 | such as by intimate data communication or control flow between those 532 | subprograms and other parts of the work. 533 | 534 | The Corresponding Source need not include anything that users 535 | can regenerate automatically from other parts of the Corresponding 536 | Source. 537 | 538 | The Corresponding Source for a work in source code form is that 539 | same work. 540 | 541 | 2. Basic Permissions. 542 | 543 | All rights granted under this License are granted for the term of 544 | copyright on the Program, and are irrevocable provided the stated 545 | conditions are met. This License explicitly affirms your unlimited 546 | permission to run the unmodified Program. The output from running a 547 | covered work is covered by this License only if the output, given its 548 | content, constitutes a covered work. This License acknowledges your 549 | rights of fair use or other equivalent, as provided by copyright law. 550 | 551 | You may make, run and propagate covered works that you do not 552 | convey, without conditions so long as your license otherwise remains 553 | in force. You may convey covered works to others for the sole purpose 554 | of having them make modifications exclusively for you, or provide you 555 | with facilities for running those works, provided that you comply with 556 | the terms of this License in conveying all material for which you do 557 | not control copyright. Those thus making or running the covered works 558 | for you must do so exclusively on your behalf, under your direction 559 | and control, on terms that prohibit them from making any copies of 560 | your copyrighted material outside their relationship with you. 561 | 562 | Conveying under any other circumstances is permitted solely under 563 | the conditions stated below. Sublicensing is not allowed; section 10 564 | makes it unnecessary. 565 | 566 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 567 | 568 | No covered work shall be deemed part of an effective technological 569 | measure under any applicable law fulfilling obligations under article 570 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 571 | similar laws prohibiting or restricting circumvention of such 572 | measures. 573 | 574 | When you convey a covered work, you waive any legal power to forbid 575 | circumvention of technological measures to the extent such circumvention 576 | is effected by exercising rights under this License with respect to 577 | the covered work, and you disclaim any intention to limit operation or 578 | modification of the work as a means of enforcing, against the work's 579 | users, your or third parties' legal rights to forbid circumvention of 580 | technological measures. 581 | 582 | 4. Conveying Verbatim Copies. 583 | 584 | You may convey verbatim copies of the Program's source code as you 585 | receive it, in any medium, provided that you conspicuously and 586 | appropriately publish on each copy an appropriate copyright notice; 587 | keep intact all notices stating that this License and any 588 | non-permissive terms added in accord with section 7 apply to the code; 589 | keep intact all notices of the absence of any warranty; and give all 590 | recipients a copy of this License along with the Program. 591 | 592 | You may charge any price or no price for each copy that you convey, 593 | and you may offer support or warranty protection for a fee. 594 | 595 | 5. Conveying Modified Source Versions. 596 | 597 | You may convey a work based on the Program, or the modifications to 598 | produce it from the Program, in the form of source code under the 599 | terms of section 4, provided that you also meet all of these conditions: 600 | 601 | a) The work must carry prominent notices stating that you modified 602 | it, and giving a relevant date. 603 | 604 | b) The work must carry prominent notices stating that it is 605 | released under this License and any conditions added under section 606 | 7. This requirement modifies the requirement in section 4 to 607 | "keep intact all notices". 608 | 609 | c) You must license the entire work, as a whole, under this 610 | License to anyone who comes into possession of a copy. This 611 | License will therefore apply, along with any applicable section 7 612 | additional terms, to the whole of the work, and all its parts, 613 | regardless of how they are packaged. This License gives no 614 | permission to license the work in any other way, but it does not 615 | invalidate such permission if you have separately received it. 616 | 617 | d) If the work has interactive user interfaces, each must display 618 | Appropriate Legal Notices; however, if the Program has interactive 619 | interfaces that do not display Appropriate Legal Notices, your 620 | work need not make them do so. 621 | 622 | A compilation of a covered work with other separate and independent 623 | works, which are not by their nature extensions of the covered work, 624 | and which are not combined with it such as to form a larger program, 625 | in or on a volume of a storage or distribution medium, is called an 626 | "aggregate" if the compilation and its resulting copyright are not 627 | used to limit the access or legal rights of the compilation's users 628 | beyond what the individual works permit. Inclusion of a covered work 629 | in an aggregate does not cause this License to apply to the other 630 | parts of the aggregate. 631 | 632 | 6. Conveying Non-Source Forms. 633 | 634 | You may convey a covered work in object code form under the terms 635 | of sections 4 and 5, provided that you also convey the 636 | machine-readable Corresponding Source under the terms of this License, 637 | in one of these ways: 638 | 639 | a) Convey the object code in, or embodied in, a physical product 640 | (including a physical distribution medium), accompanied by the 641 | Corresponding Source fixed on a durable physical medium 642 | customarily used for software interchange. 643 | 644 | b) Convey the object code in, or embodied in, a physical product 645 | (including a physical distribution medium), accompanied by a 646 | written offer, valid for at least three years and valid for as 647 | long as you offer spare parts or customer support for that product 648 | model, to give anyone who possesses the object code either (1) a 649 | copy of the Corresponding Source for all the software in the 650 | product that is covered by this License, on a durable physical 651 | medium customarily used for software interchange, for a price no 652 | more than your reasonable cost of physically performing this 653 | conveying of source, or (2) access to copy the 654 | Corresponding Source from a network server at no charge. 655 | 656 | c) Convey individual copies of the object code with a copy of the 657 | written offer to provide the Corresponding Source. This 658 | alternative is allowed only occasionally and noncommercially, and 659 | only if you received the object code with such an offer, in accord 660 | with subsection 6b. 661 | 662 | d) Convey the object code by offering access from a designated 663 | place (gratis or for a charge), and offer equivalent access to the 664 | Corresponding Source in the same way through the same place at no 665 | further charge. You need not require recipients to copy the 666 | Corresponding Source along with the object code. If the place to 667 | copy the object code is a network server, the Corresponding Source 668 | may be on a different server (operated by you or a third party) 669 | that supports equivalent copying facilities, provided you maintain 670 | clear directions next to the object code saying where to find the 671 | Corresponding Source. Regardless of what server hosts the 672 | Corresponding Source, you remain obligated to ensure that it is 673 | available for as long as needed to satisfy these requirements. 674 | 675 | e) Convey the object code using peer-to-peer transmission, provided 676 | you inform other peers where the object code and Corresponding 677 | Source of the work are being offered to the general public at no 678 | charge under subsection 6d. 679 | 680 | A separable portion of the object code, whose source code is excluded 681 | from the Corresponding Source as a System Library, need not be 682 | included in conveying the object code work. 683 | 684 | A "User Product" is either (1) a "consumer product", which means any 685 | tangible personal property which is normally used for personal, family, 686 | or household purposes, or (2) anything designed or sold for incorporation 687 | into a dwelling. In determining whether a product is a consumer product, 688 | doubtful cases shall be resolved in favor of coverage. For a particular 689 | product received by a particular user, "normally used" refers to a 690 | typical or common use of that class of product, regardless of the status 691 | of the particular user or of the way in which the particular user 692 | actually uses, or expects or is expected to use, the product. A product 693 | is a consumer product regardless of whether the product has substantial 694 | commercial, industrial or non-consumer uses, unless such uses represent 695 | the only significant mode of use of the product. 696 | 697 | "Installation Information" for a User Product means any methods, 698 | procedures, authorization keys, or other information required to install 699 | and execute modified versions of a covered work in that User Product from 700 | a modified version of its Corresponding Source. The information must 701 | suffice to ensure that the continued functioning of the modified object 702 | code is in no case prevented or interfered with solely because 703 | modification has been made. 704 | 705 | If you convey an object code work under this section in, or with, or 706 | specifically for use in, a User Product, and the conveying occurs as 707 | part of a transaction in which the right of possession and use of the 708 | User Product is transferred to the recipient in perpetuity or for a 709 | fixed term (regardless of how the transaction is characterized), the 710 | Corresponding Source conveyed under this section must be accompanied 711 | by the Installation Information. But this requirement does not apply 712 | if neither you nor any third party retains the ability to install 713 | modified object code on the User Product (for example, the work has 714 | been installed in ROM). 715 | 716 | The requirement to provide Installation Information does not include a 717 | requirement to continue to provide support service, warranty, or updates 718 | for a work that has been modified or installed by the recipient, or for 719 | the User Product in which it has been modified or installed. Access to a 720 | network may be denied when the modification itself materially and 721 | adversely affects the operation of the network or violates the rules and 722 | protocols for communication across the network. 723 | 724 | Corresponding Source conveyed, and Installation Information provided, 725 | in accord with this section must be in a format that is publicly 726 | documented (and with an implementation available to the public in 727 | source code form), and must require no special password or key for 728 | unpacking, reading or copying. 729 | 730 | 7. Additional Terms. 731 | 732 | "Additional permissions" are terms that supplement the terms of this 733 | License by making exceptions from one or more of its conditions. 734 | Additional permissions that are applicable to the entire Program shall 735 | be treated as though they were included in this License, to the extent 736 | that they are valid under applicable law. If additional permissions 737 | apply only to part of the Program, that part may be used separately 738 | under those permissions, but the entire Program remains governed by 739 | this License without regard to the additional permissions. 740 | 741 | When you convey a copy of a covered work, you may at your option 742 | remove any additional permissions from that copy, or from any part of 743 | it. (Additional permissions may be written to require their own 744 | removal in certain cases when you modify the work.) You may place 745 | additional permissions on material, added by you to a covered work, 746 | for which you have or can give appropriate copyright permission. 747 | 748 | Notwithstanding any other provision of this License, for material you 749 | add to a covered work, you may (if authorized by the copyright holders of 750 | that material) supplement the terms of this License with terms: 751 | 752 | a) Disclaiming warranty or limiting liability differently from the 753 | terms of sections 15 and 16 of this License; or 754 | 755 | b) Requiring preservation of specified reasonable legal notices or 756 | author attributions in that material or in the Appropriate Legal 757 | Notices displayed by works containing it; or 758 | 759 | c) Prohibiting misrepresentation of the origin of that material, or 760 | requiring that modified versions of such material be marked in 761 | reasonable ways as different from the original version; or 762 | 763 | d) Limiting the use for publicity purposes of names of licensors or 764 | authors of the material; or 765 | 766 | e) Declining to grant rights under trademark law for use of some 767 | trade names, trademarks, or service marks; or 768 | 769 | f) Requiring indemnification of licensors and authors of that 770 | material by anyone who conveys the material (or modified versions of 771 | it) with contractual assumptions of liability to the recipient, for 772 | any liability that these contractual assumptions directly impose on 773 | those licensors and authors. 774 | 775 | All other non-permissive additional terms are considered "further 776 | restrictions" within the meaning of section 10. If the Program as you 777 | received it, or any part of it, contains a notice stating that it is 778 | governed by this License along with a term that is a further 779 | restriction, you may remove that term. If a license document contains 780 | a further restriction but permits relicensing or conveying under this 781 | License, you may add to a covered work material governed by the terms 782 | of that license document, provided that the further restriction does 783 | not survive such relicensing or conveying. 784 | 785 | If you add terms to a covered work in accord with this section, you 786 | must place, in the relevant source files, a statement of the 787 | additional terms that apply to those files, or a notice indicating 788 | where to find the applicable terms. 789 | 790 | Additional terms, permissive or non-permissive, may be stated in the 791 | form of a separately written license, or stated as exceptions; 792 | the above requirements apply either way. 793 | 794 | 8. Termination. 795 | 796 | You may not propagate or modify a covered work except as expressly 797 | provided under this License. Any attempt otherwise to propagate or 798 | modify it is void, and will automatically terminate your rights under 799 | this License (including any patent licenses granted under the third 800 | paragraph of section 11). 801 | 802 | However, if you cease all violation of this License, then your 803 | license from a particular copyright holder is reinstated (a) 804 | provisionally, unless and until the copyright holder explicitly and 805 | finally terminates your license, and (b) permanently, if the copyright 806 | holder fails to notify you of the violation by some reasonable means 807 | prior to 60 days after the cessation. 808 | 809 | Moreover, your license from a particular copyright holder is 810 | reinstated permanently if the copyright holder notifies you of the 811 | violation by some reasonable means, this is the first time you have 812 | received notice of violation of this License (for any work) from that 813 | copyright holder, and you cure the violation prior to 30 days after 814 | your receipt of the notice. 815 | 816 | Termination of your rights under this section does not terminate the 817 | licenses of parties who have received copies or rights from you under 818 | this License. If your rights have been terminated and not permanently 819 | reinstated, you do not qualify to receive new licenses for the same 820 | material under section 10. 821 | 822 | 9. Acceptance Not Required for Having Copies. 823 | 824 | You are not required to accept this License in order to receive or 825 | run a copy of the Program. Ancillary propagation of a covered work 826 | occurring solely as a consequence of using peer-to-peer transmission 827 | to receive a copy likewise does not require acceptance. However, 828 | nothing other than this License grants you permission to propagate or 829 | modify any covered work. These actions infringe copyright if you do 830 | not accept this License. Therefore, by modifying or propagating a 831 | covered work, you indicate your acceptance of this License to do so. 832 | 833 | 10. Automatic Licensing of Downstream Recipients. 834 | 835 | Each time you convey a covered work, the recipient automatically 836 | receives a license from the original licensors, to run, modify and 837 | propagate that work, subject to this License. You are not responsible 838 | for enforcing compliance by third parties with this License. 839 | 840 | An "entity transaction" is a transaction transferring control of an 841 | organization, or substantially all assets of one, or subdividing an 842 | organization, or merging organizations. If propagation of a covered 843 | work results from an entity transaction, each party to that 844 | transaction who receives a copy of the work also receives whatever 845 | licenses to the work the party's predecessor in interest had or could 846 | give under the previous paragraph, plus a right to possession of the 847 | Corresponding Source of the work from the predecessor in interest, if 848 | the predecessor has it or can get it with reasonable efforts. 849 | 850 | You may not impose any further restrictions on the exercise of the 851 | rights granted or affirmed under this License. For example, you may 852 | not impose a license fee, royalty, or other charge for exercise of 853 | rights granted under this License, and you may not initiate litigation 854 | (including a cross-claim or counterclaim in a lawsuit) alleging that 855 | any patent claim is infringed by making, using, selling, offering for 856 | sale, or importing the Program or any portion of it. 857 | 858 | 11. Patents. 859 | 860 | A "contributor" is a copyright holder who authorizes use under this 861 | License of the Program or a work on which the Program is based. The 862 | work thus licensed is called the contributor's "contributor version". 863 | 864 | A contributor's "essential patent claims" are all patent claims 865 | owned or controlled by the contributor, whether already acquired or 866 | hereafter acquired, that would be infringed by some manner, permitted 867 | by this License, of making, using, or selling its contributor version, 868 | but do not include claims that would be infringed only as a 869 | consequence of further modification of the contributor version. For 870 | purposes of this definition, "control" includes the right to grant 871 | patent sublicenses in a manner consistent with the requirements of 872 | this License. 873 | 874 | Each contributor grants you a non-exclusive, worldwide, royalty-free 875 | patent license under the contributor's essential patent claims, to 876 | make, use, sell, offer for sale, import and otherwise run, modify and 877 | propagate the contents of its contributor version. 878 | 879 | In the following three paragraphs, a "patent license" is any express 880 | agreement or commitment, however denominated, not to enforce a patent 881 | (such as an express permission to practice a patent or covenant not to 882 | sue for patent infringement). To "grant" such a patent license to a 883 | party means to make such an agreement or commitment not to enforce a 884 | patent against the party. 885 | 886 | If you convey a covered work, knowingly relying on a patent license, 887 | and the Corresponding Source of the work is not available for anyone 888 | to copy, free of charge and under the terms of this License, through a 889 | publicly available network server or other readily accessible means, 890 | then you must either (1) cause the Corresponding Source to be so 891 | available, or (2) arrange to deprive yourself of the benefit of the 892 | patent license for this particular work, or (3) arrange, in a manner 893 | consistent with the requirements of this License, to extend the patent 894 | license to downstream recipients. "Knowingly relying" means you have 895 | actual knowledge that, but for the patent license, your conveying the 896 | covered work in a country, or your recipient's use of the covered work 897 | in a country, would infringe one or more identifiable patents in that 898 | country that you have reason to believe are valid. 899 | 900 | If, pursuant to or in connection with a single transaction or 901 | arrangement, you convey, or propagate by procuring conveyance of, a 902 | covered work, and grant a patent license to some of the parties 903 | receiving the covered work authorizing them to use, propagate, modify 904 | or convey a specific copy of the covered work, then the patent license 905 | you grant is automatically extended to all recipients of the covered 906 | work and works based on it. 907 | 908 | A patent license is "discriminatory" if it does not include within 909 | the scope of its coverage, prohibits the exercise of, or is 910 | conditioned on the non-exercise of one or more of the rights that are 911 | specifically granted under this License. You may not convey a covered 912 | work if you are a party to an arrangement with a third party that is 913 | in the business of distributing software, under which you make payment 914 | to the third party based on the extent of your activity of conveying 915 | the work, and under which the third party grants, to any of the 916 | parties who would receive the covered work from you, a discriminatory 917 | patent license (a) in connection with copies of the covered work 918 | conveyed by you (or copies made from those copies), or (b) primarily 919 | for and in connection with specific products or compilations that 920 | contain the covered work, unless you entered into that arrangement, 921 | or that patent license was granted, prior to 28 March 2007. 922 | 923 | Nothing in this License shall be construed as excluding or limiting 924 | any implied license or other defenses to infringement that may 925 | otherwise be available to you under applicable patent law. 926 | 927 | 12. No Surrender of Others' Freedom. 928 | 929 | If conditions are imposed on you (whether by court order, agreement or 930 | otherwise) that contradict the conditions of this License, they do not 931 | excuse you from the conditions of this License. If you cannot convey a 932 | covered work so as to satisfy simultaneously your obligations under this 933 | License and any other pertinent obligations, then as a consequence you may 934 | not convey it at all. For example, if you agree to terms that obligate you 935 | to collect a royalty for further conveying from those to whom you convey 936 | the Program, the only way you could satisfy both those terms and this 937 | License would be to refrain entirely from conveying the Program. 938 | 939 | 13. Use with the GNU Affero General Public License. 940 | 941 | Notwithstanding any other provision of this License, you have 942 | permission to link or combine any covered work with a work licensed 943 | under version 3 of the GNU Affero General Public License into a single 944 | combined work, and to convey the resulting work. The terms of this 945 | License will continue to apply to the part which is the covered work, 946 | but the special requirements of the GNU Affero General Public License, 947 | section 13, concerning interaction through a network will apply to the 948 | combination as such. 949 | 950 | 14. Revised Versions of this License. 951 | 952 | The Free Software Foundation may publish revised and/or new versions of 953 | the GNU General Public License from time to time. Such new versions will 954 | be similar in spirit to the present version, but may differ in detail to 955 | address new problems or concerns. 956 | 957 | Each version is given a distinguishing version number. If the 958 | Program specifies that a certain numbered version of the GNU General 959 | Public License "or any later version" applies to it, you have the 960 | option of following the terms and conditions either of that numbered 961 | version or of any later version published by the Free Software 962 | Foundation. If the Program does not specify a version number of the 963 | GNU General Public License, you may choose any version ever published 964 | by the Free Software Foundation. 965 | 966 | If the Program specifies that a proxy can decide which future 967 | versions of the GNU General Public License can be used, that proxy's 968 | public statement of acceptance of a version permanently authorizes you 969 | to choose that version for the Program. 970 | 971 | Later license versions may give you additional or different 972 | permissions. However, no additional obligations are imposed on any 973 | author or copyright holder as a result of your choosing to follow a 974 | later version. 975 | 976 | 15. Disclaimer of Warranty. 977 | 978 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 979 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 980 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 981 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 982 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 983 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 984 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 985 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 986 | 987 | 16. Limitation of Liability. 988 | 989 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 990 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 991 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 992 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 993 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 994 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 995 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 996 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 997 | SUCH DAMAGES. 998 | 999 | 17. Interpretation of Sections 15 and 16. 1000 | 1001 | If the disclaimer of warranty and limitation of liability provided 1002 | above cannot be given local legal effect according to their terms, 1003 | reviewing courts shall apply local law that most closely approximates 1004 | an absolute waiver of all civil liability in connection with the 1005 | Program, unless a warranty or assumption of liability accompanies a 1006 | copy of the Program in return for a fee. 1007 | 1008 | END OF TERMS AND CONDITIONS 1009 | 1010 | How to Apply These Terms to Your New Programs 1011 | 1012 | If you develop a new program, and you want it to be of the greatest 1013 | possible use to the public, the best way to achieve this is to make it 1014 | free software which everyone can redistribute and change under these terms. 1015 | 1016 | To do so, attach the following notices to the program. It is safest 1017 | to attach them to the start of each source file to most effectively 1018 | state the exclusion of warranty; and each file should have at least 1019 | the "copyright" line and a pointer to where the full notice is found. 1020 | 1021 | 1022 | Copyright (C) 1023 | 1024 | This program is free software: you can redistribute it and/or modify 1025 | it under the terms of the GNU General Public License as published by 1026 | the Free Software Foundation, either version 3 of the License, or 1027 | (at your option) any later version. 1028 | 1029 | This program is distributed in the hope that it will be useful, 1030 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1031 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1032 | GNU General Public License for more details. 1033 | 1034 | You should have received a copy of the GNU General Public License 1035 | along with this program. If not, see . 1036 | 1037 | Also add information on how to contact you by electronic and paper mail. 1038 | 1039 | If the program does terminal interaction, make it output a short 1040 | notice like this when it starts in an interactive mode: 1041 | 1042 | Copyright (C) 1043 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 1044 | This is free software, and you are welcome to redistribute it 1045 | under certain conditions; type `show c' for details. 1046 | 1047 | The hypothetical commands `show w' and `show c' should show the appropriate 1048 | parts of the General Public License. Of course, your program's commands 1049 | might be different; for a GUI interface, you would use an "about box". 1050 | 1051 | You should also get your employer (if you work as a programmer) or school, 1052 | if any, to sign a "copyright disclaimer" for the program, if necessary. 1053 | For more information on this, and how to apply and follow the GNU GPL, see 1054 | . 1055 | 1056 | The GNU General Public License does not permit incorporating your program 1057 | into proprietary programs. If your program is a subroutine library, you 1058 | may consider it more useful to permit linking proprietary applications with 1059 | the library. If this is what you want to do, use the GNU Lesser General 1060 | Public License instead of this License. But first, please read 1061 | . 1062 | 1063 | 1064 | This software uses ‘Google Chrome OS Smart Card Connector API’ , which underlies the following license: 1065 | 1066 | Copyright 2016 Google Inc. All Rights Reserved. 1067 | 1068 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 1069 | You may obtain a copy of the License at 1070 | 1071 | http://www.apache.org/licenses/LICENSE-2.0 1072 | 1073 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1074 | See the License for the specific language governing permissions and limitations under the License. 1075 | 1076 | 1077 | This software uses ‘chrome-promise’ , which underlies the following license: 1078 | 1079 | The MIT License (MIT) 1080 | 1081 | Copyright (c) 2015 Tomás Fox 1082 | 1083 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 1084 | 1085 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 1086 | 1087 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1088 | 1089 | 1090 | 1091 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **DEPRECATED:** Secure Shell - OpenPGP smart card support (smart-ssh) 2 | ========= 3 | 4 | The smart card support offered by `smart-ssh` has been integrated into the [official Secure Shell app](https://chrome.google.com/webstore/detail/secure-shell/pnhechapfaindjhompbnflcldabbghjo) and can be used via the relay option `--ssh-agent=gsc`. More details can be found in the official [setup guide](https://chromium.googlesource.com/apps/libapps/+/master/nassh/doc/hardware-keys.md). 5 | 6 | ## License 7 | [MIT](https://github.com/FabianHenneke/smart-ssh/blob/master/LICENSE) 8 | -------------------------------------------------------------------------------- /agent.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | const util = openpgp.util; 5 | const GSC = GoogleSmartCard; 6 | 7 | const AGENT_MESSAGE_TYPE = 'auth-agent@openssh.com'; 8 | 9 | const SSH_AGENT_FAILURE = 5; 10 | const SSH_AGENT_SUCCESS = 6; 11 | 12 | const SSH2_AGENTC_REQUEST_IDENTITIES = 11; 13 | const SSH2_AGENTC_SIGN_REQUEST = 13; 14 | 15 | const SSH2_AGENT_IDENTITIES_ANSWER = 12; 16 | const SSH2_AGENT_SIGN_RESPONSE = 14; 17 | 18 | /** 19 | * Client title for the connection to the server App. 20 | * 21 | * Currently this is only used for the debug logs produced by the server App. 22 | */ 23 | const CLIENT_TITLE = 'smart-ssh'; 24 | 25 | /** 26 | * Identifier of the server App. 27 | */ 28 | const SERVER_APP_ID = GSC.PcscLiteCommon.Constants.SERVER_OFFICIAL_APP_ID; 29 | 30 | 31 | let identityCache = {}; 32 | 33 | async function fetchIdentities(manager) { 34 | identityCache = {}; 35 | let readers; 36 | try { 37 | readers = await manager.listReaders(); 38 | } catch (error) { 39 | console.log('Failed to list readers.'); 40 | await smartCard.logError(error); 41 | return []; 42 | } 43 | return Promise.all(readers.map(async function(reader) { 44 | const asyncManager = new smartCard.OpenPGPSmartCardManager(); 45 | await asyncManager.establishContext(); 46 | try { 47 | await asyncManager.connect(reader); 48 | } catch (error) { 49 | console.log(`Failed to connect to reader ${reader}, skipping.`); 50 | await smartCard.logError(error); 51 | await asyncManager.releaseContext(); 52 | return []; 53 | } 54 | let readerKeyBlob; 55 | let readerKeyId; 56 | try { 57 | await asyncManager.selectApplet(); 58 | if (await asyncManager.fetchPinVerificationTriesRemaining() === 59 | 0) { 60 | await asyncManager.disconnect(); 61 | return {}; 62 | } 63 | readerKeyBlob = await asyncManager.fetchPublicKeyBlob(); 64 | readerKeyId = await asyncManager.fetchAuthenticationPublicKeyId(); 65 | } catch (error) { 66 | console.log( 67 | `Failed to get public key ID from reader ${reader}, skipping.` 68 | ); 69 | await smartCard.logError(error); 70 | return []; 71 | } finally { 72 | await asyncManager.disconnect(); 73 | await asyncManager.releaseContext(); 74 | } 75 | identityCache[util.bin2str(readerKeyBlob)] = { 76 | reader, 77 | readerKeyId 78 | }; 79 | return [readerKeyBlob]; 80 | })) 81 | .then(identities => [].concat(...identities)); 82 | } 83 | 84 | // TODO: exclude comment? 85 | // SSH agent protocol, Section 2.5.2 86 | async function handleRequestIdentities() { 87 | await smartCard.initializeApiContext(); 88 | const manager = new smartCard.OpenPGPSmartCardManager(); 89 | await manager.establishContext(); 90 | const identities = await fetchIdentities(manager); 91 | await manager.releaseContext(); 92 | const header = util.concatUint8Array([ 93 | new Uint8Array([SSH2_AGENT_IDENTITIES_ANSWER]), 94 | util.writeNumber(identities.length, 4) 95 | ]); 96 | const body = util.concatUint8Array(identities.map(identity => 97 | util.concatUint8Array([ 98 | util.writeNumber(identity.length, 4), 99 | identity, 100 | util.writeNumber(0, 4) 101 | //util.writeNumber(identity.reader.length, 4), 102 | //new Uint8Array(util.str2bin(identity.reader)) 103 | ]) 104 | )); 105 | return Array.from(util.concatUint8Array([header, body])); 106 | } 107 | 108 | async function requestAndVerifyPin(manager, fingerprint) { 109 | let pin = pinCache.getPin(fingerprint, manager.reader); 110 | let cachePin = false; 111 | // TODO: try 112 | let dialogData = { 113 | fingerprint, 114 | reader: manager.readerShort, 115 | triesRemaining: await manager.fetchPinVerificationTriesRemaining(), 116 | } 117 | if (!pin) { 118 | const pinDialogPromise = new Promise(function(resolve) { 119 | dialogData.resolvePromise = (pin, cachePin) => resolve([pin, 120 | cachePin 121 | ]); 122 | }); 123 | chrome.app.window.create('pinDialog.html', { 124 | id: 'pinDialog', 125 | innerBounds: { 126 | minWidth: 230, 127 | maxWidth: 230, 128 | minHeight: 100, 129 | maxHeight: 100 130 | }, 131 | alwaysOnTop: true, 132 | frame: 'none', 133 | resizable: false, 134 | visibleOnAllWorkspaces: true 135 | }, 136 | createdWindow => createdWindow.contentWindow.data = dialogData 137 | ); 138 | // Wait for user to enter PIN 139 | [pin, cachePin] = await pinDialogPromise; 140 | } 141 | const pinBytes = util.str2Uint8Array(util.encode_utf8(pin)); 142 | // Verify PIN for authentication 143 | try { 144 | await manager.transmit(new smartCard.CommandAPDU(0x00, 0x20, 0x00, 0x82, 145 | pinBytes)); 146 | // At this point PIN verification has succeeded 147 | if (cachePin) 148 | pinCache.putPin(fingerprint, manager.reader, pin); 149 | } catch (error) { 150 | if (util.isUint8Array(error) && error.length === 2) { 151 | // Special status bytes 152 | switch (util.readNumber(error)) { 153 | // Invalid PIN, ask again 154 | case 0x6982: 155 | // Delete the (invalid) PIN if cached 156 | // This should only ever happen if the user changes the PIN while it 157 | // is still cached. Requires a very fast user. 158 | if (cachePin) 159 | pinCache.deletePin(fingerprint, manager.reader); 160 | await requestAndVerifyPin(manager); 161 | break; 162 | // Device is blocked (this should not be reached as we check the 163 | // number of remaining tries and block PIN entry in this case) 164 | case 0x6983: 165 | throw Error('Device is blocked.'); 166 | default: 167 | throw error; 168 | } 169 | } else { 170 | // pcsclite error 171 | throw error; 172 | } 173 | } 174 | } 175 | 176 | const HashAlgorithms = { 177 | SHA1: { 178 | algorithmNumber: 2, 179 | inputLength: 35, 180 | signaturePrefix: 'ssh-rsa', 181 | }, 182 | SHA256: { 183 | algorithmNumber: 8, 184 | inputLength: 51, 185 | signaturePrefix: 'rsa-sha2-256', 186 | }, 187 | SHA512: { 188 | algorithmNumber: 10, 189 | inputLength: 83, 190 | signaturePrefix: 'rsa-sha2-512', 191 | }, 192 | }; 193 | 194 | async function authenticateOnSmartCard( 195 | manager, reader, readerKeyId, data, hashAlgo) { 196 | try { 197 | await manager.connect(reader); 198 | } catch (error) { 199 | console.log(`Failed to connect to reader ${reader}.`); 200 | await smartCard.logError(error); 201 | return; 202 | } 203 | let currentReaderKeyId; 204 | try { 205 | currentReaderKeyId = await manager.fetchAuthenticationPublicKeyId(); 206 | } catch (error) { 207 | console.log(`Failed to fetch public key ID from reader ${reader}.`); 208 | await smartCard.logError(error); 209 | await manager.disconnect(); 210 | return; 211 | } 212 | if (!util.equalsUint8Array(readerKeyId, currentReaderKeyId)) { 213 | console.log(`Public key ID changed for ${reader}.`); 214 | await manager.disconnect(); 215 | return; 216 | } 217 | const fingerprint = util.hexidump(readerKeyId.slice(4)).toUpperCase(); 218 | try { 219 | await requestAndVerifyPin(manager, fingerprint); 220 | } catch (error) { 221 | console.log('PIN verification failed.'); 222 | await smartCard.logError(error); 223 | await manager.disconnect(); 224 | return; 225 | } 226 | let modulusLength; 227 | try { 228 | modulusLength = await manager.fetchAuthenticationModulusLengthBytes(); 229 | } catch (error) { 230 | console.log(`Failed to fetch key modulus length from reader ${reader}.`); 231 | await smartCard.logError(error); 232 | await manager.disconnect(); 233 | return; 234 | } 235 | const pkcsEncodedMessage = new Uint8Array( 236 | openpgp.crypto.pkcs1.emsa.encode(hashAlgo.algorithmNumber, 237 | util.bin2str(data), modulusLength) 238 | .toByteArray()); 239 | const authenticationInput = pkcsEncodedMessage.slice(-hashAlgo.inputLength); 240 | let signature; 241 | try { 242 | signature = await manager.transmit(new smartCard.CommandAPDU(0x00, 0x88, 243 | 0x00, 0x00, authenticationInput)); 244 | } catch (error) { 245 | console.log('Internal authenticate failed.'); 246 | await smartCard.logError(error); 247 | await manager.disconnect(); 248 | return; 249 | } 250 | await manager.disconnect(); 251 | return signature; 252 | } 253 | 254 | // SSH agent protocol, Section 2.6.2 255 | async function handleSignRequest(body) { 256 | const keyBlobLength = util.readNumber(body.slice(0, 4)); 257 | const keyBlob = body.slice(4, 4 + keyBlobLength); 258 | const dataLength = util.readNumber(body.slice(4 + keyBlobLength, 4 + 259 | keyBlobLength + 4)); 260 | if (4 + keyBlobLength + 4 + dataLength !== body.length - 4) { 261 | console.log('SSH2_AGENTC_SIGN_REQUEST: Invalid length fields'); 262 | return [SSH_AGENT_FAILURE]; 263 | } 264 | const data = body.slice(4 + keyBlobLength + 4, 4 + keyBlobLength + 4 + 265 | dataLength); 266 | const flags = util.readNumber(body.slice(body.length - 4)); 267 | let hashAlgo; 268 | if (flags === 0) { 269 | hashAlgo = HashAlgorithms.SHA1; 270 | } else if (flags & 0b100) { 271 | hashAlgo = HashAlgorithms.SHA512; 272 | } else if (flags & 0b10) { 273 | hashAlgo = HashAlgorithms.SHA256; 274 | } else { 275 | console.log('SSH2_AGENTC_SIGN_REQUEST: unsupported flags'); 276 | return [SSH_AGENT_FAILURE]; 277 | } 278 | const keyBlobStr = util.bin2str(keyBlob); 279 | if (!(keyBlobStr in identityCache)) { 280 | console.log('SSH2_AGENTC_SIGN_REQUEST: Invalid key blob/requested'); 281 | return [SSH_AGENT_FAILURE]; 282 | } 283 | const { 284 | reader, 285 | readerKeyId 286 | } = identityCache[keyBlobStr]; 287 | await smartCard.initializeApiContext(); 288 | const manager = new smartCard.OpenPGPSmartCardManager(); 289 | await manager.establishContext(); 290 | const signature = await authenticateOnSmartCard(manager, reader, 291 | readerKeyId, data, hashAlgo); 292 | await manager.releaseContext(); 293 | if (!signature) 294 | return [SSH_AGENT_FAILURE]; 295 | const response = util.concatUint8Array([ 296 | new Uint8Array([SSH2_AGENT_SIGN_RESPONSE]), 297 | util.writeNumber(4 + hashAlgo.signaturePrefix.length + 4 + 298 | signature.length, 4), 299 | util.writeNumber(hashAlgo.signaturePrefix.length, 4), 300 | new Uint8Array(util.str2bin(hashAlgo.signaturePrefix)), 301 | util.writeNumber(signature.length, 4), 302 | signature 303 | ]); 304 | return Array.from(response); 305 | } 306 | 307 | async function agent(request, port) { 308 | if (request.type !== AGENT_MESSAGE_TYPE) 309 | return; 310 | 311 | let responseData; 312 | switch (request.data[0]) { 313 | // Ping 314 | case 0: 315 | try { 316 | await smartCard.initializeApiContext(); 317 | responseData = [SSH_AGENT_SUCCESS]; 318 | } catch (error) { 319 | console.log(error); 320 | responseData = [SSH_AGENT_FAILURE]; 321 | } 322 | break; 323 | case SSH2_AGENTC_REQUEST_IDENTITIES: 324 | try { 325 | responseData = await handleRequestIdentities(); 326 | } catch (error) { 327 | console.log(error); 328 | responseData = [SSH_AGENT_FAILURE]; 329 | } 330 | break; 331 | case SSH2_AGENTC_SIGN_REQUEST: 332 | try { 333 | responseData = await handleSignRequest(request.data.slice(1)); 334 | } catch (error) { 335 | console.log(error); 336 | responseData = [SSH_AGENT_FAILURE]; 337 | } 338 | break; 339 | default: 340 | console.log('Unsupported request:', request.data); 341 | responseData = [SSH_AGENT_FAILURE]; 342 | } 343 | port.postMessage({ 344 | type: AGENT_MESSAGE_TYPE, 345 | data: responseData 346 | }); 347 | } 348 | 349 | chrome.runtime.onConnectExternal.addListener(function(port) { 350 | port.onMessage.addListener(agent); 351 | }); 352 | chrome.runtime.onSuspend.addListener(function() { 353 | console.log('agent unloaded'); 354 | }); 355 | chrome.app.runtime.onLaunched.addListener(function() { 356 | chrome.app.window.create('app.html', { 357 | id: 'app', 358 | innerBounds: { 359 | minWidth: 900, 360 | maxWidth: 900, 361 | minHeight: 500 362 | }, 363 | resizable: true, 364 | }); 365 | }); 366 | })(); 367 | -------------------------------------------------------------------------------- /app.css: -------------------------------------------------------------------------------- 1 | html { 2 | overflow-y: scroll; 3 | } 4 | 5 | body { 6 | font-family: sans-serif; 7 | font-size: 16px; 8 | } 9 | 10 | .code { 11 | font-family: monospace; 12 | user-select: text; 13 | } 14 | 15 | .nowrap { 16 | white-space: nowrap; 17 | /* Pass events to the parent */ 18 | pointer-events: none; 19 | } 20 | 21 | li { 22 | padding-top: 5px; 23 | padding-bottom: 5px; 24 | } 25 | 26 | li.step-inapplicable { 27 | text-decoration: line-through; 28 | } 29 | 30 | input { 31 | font-family: monospace; 32 | font-size: 16px; 33 | } 34 | 35 | .relay-options { 36 | width: 60%; 37 | margin-top: 10px; 38 | } 39 | 40 | .identity-table { 41 | table-layout: fixed; 42 | width: 95%; 43 | white-space: nowrap; 44 | border-collapse: collapse; 45 | font-family: monospace; 46 | font-size: 14px; 47 | } 48 | 49 | .identity-table th { 50 | text-align: left; 51 | } 52 | 53 | .identity-table-body tr { 54 | border-top: 1px solid #ccc; 55 | border-bottom: 1px solid #ccc; 56 | } 57 | 58 | .identity-table-body td { 59 | white-space: nowrap; 60 | word-wrap: break-word; 61 | overflow: hidden; 62 | text-overflow: ellipsis; 63 | vertical-align: top; 64 | text-align: center; 65 | padding: 10px 2px 10px 2px; 66 | } 67 | 68 | .col-reader { 69 | width: 27%; 70 | } 71 | 72 | .col-fingerprint { 73 | width: 13%; 74 | } 75 | 76 | .col-ssh-key { 77 | width: 60%; 78 | } 79 | 80 | td.ssh-key { 81 | display: inline-flex; 82 | /* TODO: Make table layout padding-aware */ 83 | width: 98%; 84 | font-size: 0; 85 | text-align: left; 86 | } 87 | 88 | .ssh-key::before { 89 | content: attr(data-head); 90 | text-overflow: ellipsis; 91 | overflow: hidden; 92 | font-size: 14px; 93 | } 94 | 95 | .ssh-key::after { 96 | content: attr(data-tail); 97 | font-size: 14px; 98 | } 99 | 100 | .ssh-key:hover { 101 | display: block; 102 | font-size: inherit; 103 | white-space: normal; 104 | user-select: text; 105 | } 106 | 107 | .ssh-key:hover::before { 108 | display: none; 109 | } 110 | 111 | .ssh-key:hover::after { 112 | display: none; 113 | } 114 | -------------------------------------------------------------------------------- /app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Secure Shell - OpenPGP smart card support 7 | 8 | 9 | 10 | 11 |

How to use SSH private keys stored on a smart card:

12 |
    13 |
  1. 14 | Install (or re-enable) the Smart Card Connector app. 15 |
  2. 16 |
  3. 17 | 18 | Insert a smart card... 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
    ReaderFingerprintSSH public key
    32 |
  4. 33 |
  5. 34 | Add the following to your connection's 'relay options' (not the 'SSH Arguments') in the Secure Shell app:
    35 | 36 |
  6. 37 |
  7. 38 | Connect in Secure Shell and you will be asked for your smart card PIN. Confirm with Enter and optionally choose to cache the PIN until you either lock the device or remove the smart card. 39 |
  8. 40 |
41 |
Tip: The SSH agent will handle connection requests even if this app window is closed. 42 |
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | let manager = null; 5 | 6 | async function getIdentities() { 7 | let readers; 8 | try { 9 | readers = await manager.listReaders(); 10 | } catch (error) { 11 | console.log('Failed to list readers.'); 12 | smartCard.logError(error); 13 | return []; 14 | } 15 | let identities = []; 16 | for (const reader of readers) { 17 | try { 18 | await manager.connect(reader); 19 | } catch (error) { 20 | console.log(`Failed to connect to reader ${reader}, skipping.`); 21 | smartCard.logError(error); 22 | continue; 23 | } 24 | let readerKeyBlob; 25 | let readerKeyId; 26 | try { 27 | await manager.selectApplet(); 28 | readerKeyBlob = await manager.fetchPublicKeyBlobBase64(); 29 | readerKeyId = await manager.fetchAuthenticationPublicKeyIdString(); 30 | } catch (error) { 31 | console.log( 32 | `Failed to get public key ID from reader ${reader}, skipping.`); 33 | smartCard.logError(error); 34 | continue; 35 | } finally { 36 | await manager.disconnect(); 37 | } 38 | identities.push({ 39 | reader, 40 | readerKeyBlob, 41 | readerKeyId 42 | }); 43 | } 44 | return identities; 45 | } 46 | 47 | function showIdentities(identities) { 48 | if (identities.length > 0) { 49 | document.getElementsByClassName('identity-table-body')[0].innerHTML = 50 | ''; 51 | document.getElementsByClassName('add-identity-message')[0].innerHTML = 52 | `Add one of the following SSH public keys to ~/.ssh/authorized_keys on the server:`; 53 | for (const identity of identities) { 54 | const identityRow = document.createElement('tr'); 55 | const readerElement = document.createElement('td'); 56 | readerElement.innerText = identity.reader; 57 | readerElement.title = identity.reader; 58 | const readerKeyIdElement = document.createElement('td'); 59 | readerKeyIdElement.innerText = 60 | `${identity.readerKeyId.substring(0, 4)} ${identity.readerKeyId.substring(4)}`; 61 | const readerKeyBlobElement = document.createElement('td'); 62 | readerKeyBlobElement.className = 'ssh-key'; 63 | readerKeyBlobElement.dataset.head = 'ssh-rsa ' + identity.readerKeyBlob 64 | .substr(0, identity.readerKeyBlob.length - 30); 65 | readerKeyBlobElement.dataset.tail = identity.readerKeyBlob.substr(-30); 66 | readerKeyBlobElement.innerHTML = 67 | `ssh-rsa ${identity.readerKeyBlob}`; 68 | readerKeyBlobElement.onclick = function(e) { 69 | const range = document.createRange(); 70 | range.selectNodeContents(e.target); 71 | window.getSelection().removeAllRanges(); 72 | window.getSelection().addRange(range); 73 | }; 74 | identityRow.appendChild(readerElement); 75 | identityRow.appendChild(readerKeyIdElement); 76 | identityRow.appendChild(readerKeyBlobElement); 77 | document.getElementsByClassName('identity-table-body')[0].appendChild( 78 | identityRow); 79 | } 80 | } else { 81 | document.getElementsByClassName('identity-table-body')[0].innerHTML = 82 | ''; 83 | document.getElementsByClassName('add-identity-message')[0].textContent = 84 | 'Insert a smart card...'; 85 | } 86 | } 87 | 88 | async function onReaderEvent() { 89 | const identities = await getIdentities(); 90 | showIdentities(identities); 91 | manager.callOnReaderEvent(onReaderEvent); 92 | } 93 | 94 | window.onload = async function() { 95 | document.getElementsByClassName('relay-options')[0].value = 96 | `--ssh-agent=${chrome.runtime.id}`; 97 | document.getElementsByClassName('relay-options')[0].onclick = function( 98 | e) { 99 | e.target.select(); 100 | }; 101 | 102 | try { 103 | await smartCard.initializeApiContext(); 104 | manager = new smartCard.OpenPGPSmartCardManager(); 105 | await manager.establishContext(); 106 | } catch (_) { 107 | document.getElementsByClassName('install-connector-step')[0].classList 108 | .remove('step-inapplicable'); 109 | document.querySelectorAll('.install-connector-step ~ li') 110 | .forEach(el => el.classList.add('step-inapplicable')); 111 | return; 112 | } 113 | await onReaderEvent(); 114 | }; 115 | 116 | })(); 117 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smart-ssh", 3 | "homepage": "https://github.com/FabianHenneke/smart-ssh", 4 | "authors": [ 5 | "Fabian Henneke" 6 | ], 7 | "description": "Use OpenPGP smart cards for SSH public key authentication", 8 | "main": "manifest.json", 9 | "keywords": [ 10 | "smart card", 11 | "cros", 12 | "chrome os", 13 | "yubikey", 14 | "nitrokey", 15 | "ssh", 16 | "secure shell", 17 | "ssh agent", 18 | "public key" 19 | ], 20 | "license": "MIT", 21 | "private": true, 22 | "ignore": [ 23 | "**/.*", 24 | "bower_components" 25 | ], 26 | "dependencies": { 27 | "openpgp": "^2.5.0", 28 | "material-design-icons": "^3.0.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | bower install 3 | python download-google-smart-card-client-library.py 4 | 5 | rm -rf build 6 | rm smart-ssh.zip 7 | 8 | mkdir build 9 | declare -a files=("agent.js" 10 | "app.css" 11 | "app.html" 12 | "app.js" 13 | "pinDialog.css" 14 | "pinDialog.html" 15 | "pinDialog.js" 16 | "pinCache.js" 17 | "smartCard.js" 18 | "manifest.json" 19 | "google-smart-card-client-library.js" 20 | "smart-ssh_48.png" 21 | "smart-ssh_128.png" 22 | "bower_components/openpgp/dist/openpgp.min.js" 23 | "bower_components/material-design-icons/action/1x_web/ic_lock_open_black_24dp.png" 24 | "bower_components/material-design-icons/communication/1x_web/ic_vpn_key_black_24dp.png" 25 | "bower_components/material-design-icons/action/1x_web/ic_help_black_24dp.png" 26 | "bower_components/material-design-icons/hardware/1x_web/ic_sim_card_black_24dp.png") 27 | 28 | cp --parents "${files[@]}" build/ 29 | cp LICENSE.build build/LICENSE 30 | 31 | cd build 32 | zip -r ../smart-ssh.zip * 33 | -------------------------------------------------------------------------------- /download-google-smart-card-client-library.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright 2017 Google Inc. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Downloads from GitHub the latest released version of the client library for 17 | communicating to the Google Smart Card Connector app.""" 18 | 19 | import json 20 | import os 21 | import sys 22 | import urllib2 23 | 24 | GITHUB_REPO_OWNER = "GoogleChrome" 25 | GITHUB_REPO = "chromeos_smart_card_connector" 26 | CLIENT_LIBRARY_ASSET_NAME = "google-smart-card-client-library.js" 27 | OUTPUT_FILE_NAME = "google-smart-card-client-library.js" 28 | 29 | GITHUB_LATEST_RELEASE_URL_TEMPLATE = \ 30 | "https://api.github.com/repos/{owner}/{repo}/releases/latest" 31 | 32 | def main(): 33 | sys.stderr.write('Accessing GitHub API...\n') 34 | latest_release_url = GITHUB_LATEST_RELEASE_URL_TEMPLATE.format( 35 | owner=GITHUB_REPO_OWNER, repo=GITHUB_REPO) 36 | latest_release_info = json.load(urllib2.urlopen(latest_release_url)) 37 | 38 | client_library_download_url = None 39 | for asset in latest_release_info.get("assets", []): 40 | if asset["name"] == CLIENT_LIBRARY_ASSET_NAME: 41 | client_library_download_url = asset["browser_download_url"] 42 | if client_library_download_url is None: 43 | raise RuntimeError("Asset with the client library not found in the latest " 44 | "GitHub release") 45 | 46 | sys.stderr.write('Downloading from "{0}"...\n'.format( 47 | client_library_download_url)) 48 | client_library = urllib2.urlopen(client_library_download_url).read() 49 | 50 | if os.path.dirname(__file__): 51 | output_file_path = os.path.join( 52 | os.path.relpath(os.path.dirname(__file__)), OUTPUT_FILE_NAME) 53 | else: 54 | output_file_path = OUTPUT_FILE_NAME 55 | with open(output_file_path, "wt") as f: 56 | f.write(client_library) 57 | 58 | sys.stderr.write( 59 | 'Successfully finished. The library is stored at "{0}".\n'.format( 60 | output_file_path)) 61 | 62 | if __name__ == '__main__': 63 | main() 64 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | "minimum_chrome_version": "55", 4 | 5 | "name": "Secure Shell - OpenPGP smart card support", 6 | "short_name": "smart-ssh", 7 | "description": "Use OpenPGP smart cards for SSH public key authentication", 8 | "version": "0.0.8", 9 | "author": "Fabian Henneke", 10 | "icons": { 11 | "48": "smart-ssh_48.png", 12 | "128": "smart-ssh_128.png" 13 | }, 14 | 15 | "app": { 16 | "background": { 17 | "scripts": [ 18 | "bower_components/openpgp/dist/openpgp.min.js", 19 | "google-smart-card-client-library.js", 20 | "smartCard.js", 21 | "pinCache.js", 22 | "agent.js" 23 | ] 24 | } 25 | }, 26 | 27 | "externally_connectable": { 28 | "ids": [ 29 | "hmgggebkhjjkiimkjlknpdgapncghehh", 30 | "okddffdblfhhnmhodogpojmfkjmhinfp", 31 | "ooiklbnjmhbcgemelgfhaeaocllobloj", 32 | "pnhechapfaindjhompbnflcldabbghjo" 33 | ] 34 | }, 35 | 36 | "permissions": [ 37 | "alwaysOnTopWindows", 38 | "idle", 39 | "notifications" 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /pinCache.js: -------------------------------------------------------------------------------- 1 | const pinCache = (function() { 2 | 'use strict'; 3 | 4 | let pinCache = {}; 5 | 6 | function clearCache() { 7 | pinCache = {}; 8 | } 9 | 10 | function getPinCount() { 11 | let count = 0; 12 | for (const key in pinCache) 13 | count += pinCache[key].length; 14 | return count; 15 | } 16 | 17 | function putPin(key, reader, pin, registerOnDisconnectCallback) { 18 | if (!(key in pinCache)) 19 | pinCache[key] = {}; 20 | pinCache[key][reader] = pin; 21 | window.setTimeout(async function() { 22 | await smartCard.initializeApiContext(); 23 | const manager = new smartCard.OpenPGPSmartCardManager(); 24 | await manager.establishContext(); 25 | await manager.callOnDisconnect(reader, function() { 26 | deletePin(key, reader); 27 | const pinCount = getPinCount(); 28 | let message; 29 | if (pinCount === 1) 30 | message = `1 PIN still cached`; 31 | else if (pinCount > 1) 32 | message = `${pinCount} PINs still cached`; 33 | else 34 | message = `PIN cache has been cleared`; 35 | chrome.notifications.create(null, { 36 | type: 'basic', 37 | iconUrl: 'bower_components/material-design-icons/communication/1x_web/ic_vpn_key_black_24dp.png', 38 | title: 'Card removed', 39 | message 40 | }); 41 | manager.releaseContext(); 42 | }); 43 | }, 1) 44 | } 45 | 46 | function getPin(key, reader) { 47 | if (key in pinCache) 48 | if (reader in pinCache[key]) 49 | return pinCache[key][reader]; 50 | return null; 51 | } 52 | 53 | function deletePin(key, reader) { 54 | if (key in pinCache) { 55 | // Remove reader (or do nothing if not present) 56 | delete pinCache[key][reader]; 57 | // Remove key if it has no other readers assigned 58 | if (Object.keys(pinCache[key]).length === 0) 59 | delete pinCache[key]; 60 | } 61 | } 62 | 63 | chrome.idle.onStateChanged.addListener(function(state) { 64 | if (state === "locked") 65 | clearCache(); 66 | }); 67 | 68 | chrome.runtime.onSuspend.addListener(function() { 69 | console.log('pinCache unloaded'); 70 | }); 71 | 72 | return { 73 | putPin, 74 | getPin, 75 | deletePin 76 | }; 77 | })(); 78 | -------------------------------------------------------------------------------- /pinDialog.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 5px; 3 | margin: 0; 4 | font-family: sans-serif; 5 | min-width: 230px; 6 | background: white; 7 | font-size: 14px; 8 | } 9 | 10 | .pin-entry form { 11 | margin-bottom: 5px; 12 | } 13 | 14 | .pin-entry input[type="password"] { 15 | box-sizing: border-box; 16 | width: 100%; 17 | border: 0; 18 | border-bottom: 1px solid #bbb; 19 | background: url("bower_components/material-design-icons/action/1x_web/ic_lock_open_black_24dp.png") center right 6px / 16px 16px no-repeat; 20 | } 21 | 22 | .pin-entry input[type="password"]:focus { 23 | outline: 0; 24 | } 25 | 26 | .pin-entry input[readOnly] { 27 | background: #bbb; 28 | } 29 | 30 | .pin-entry input[type="checkbox"] { 31 | vertical-align: middle; 32 | } 33 | 34 | .pin-entry label span { 35 | vertical-align: middle; 36 | } 37 | 38 | .pin-entry input[type="submit"] { 39 | display: none; 40 | } 41 | 42 | .info { 43 | display: flex; 44 | justify-content: space-between; 45 | box-sizing: border-box; 46 | width: 95%; 47 | padding: 8px 2px 8px 2px; 48 | } 49 | 50 | .info .fingerprint-info { 51 | background: url("bower_components/material-design-icons/communication/1x_web/ic_vpn_key_black_24dp.png") center left 2px / 16px 16px no-repeat; 52 | padding: 6px 0px 6px 22px; 53 | } 54 | 55 | .info .reader-info { 56 | background: url("bower_components/material-design-icons/hardware/1x_web/ic_sim_card_black_24dp.png") center left 2px / 16px 16px no-repeat; 57 | padding: 6px 0px 6px 22px; 58 | } 59 | 60 | .cache-help { 61 | display: inline-block; 62 | background: url("bower_components/material-design-icons/action/1x_web/ic_help_black_24dp.png") center center / 16px 16px no-repeat; 63 | width: 16px; 64 | height: 16px; 65 | } 66 | -------------------------------------------------------------------------------- /pinDialog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Unlock smart card 7 | 8 | 9 | 10 | 11 |
12 |
13 | 14 | 15 |
16 | 17 | 18 |
19 | 24 |
25 |
26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /pinDialog.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | function init() { 5 | document.getElementsByName('pinBox')[0].placeholder = 6 | `PIN (${data.triesRemaining} tries remaining)`; 7 | document.getElementsByName('pinBox')[0].select(); 8 | 9 | document.getElementsByClassName('fingerprint-info')[0].textContent = 10 | `${data.fingerprint.substring(0, 4)} ${data.fingerprint.substring(4)}`; 11 | document.getElementsByClassName('reader-info')[0].textContent = data.reader; 12 | document.getElementsByName('cachePinCheckbox')[0].onchange = function(e) { 13 | document.getElementsByName('pinBox')[0].select(); 14 | }; 15 | 16 | document.forms[0].onsubmit = function(e) { 17 | e.preventDefault(); 18 | data.resolvePromise(e.target.elements['pinBox'].value, 19 | e.target.elements['cachePinCheckbox'].checked); 20 | window.close(); 21 | }; 22 | } 23 | 24 | window.onload = init; 25 | })(); 26 | -------------------------------------------------------------------------------- /smart-ssh_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fmeum/smart-ssh/0cce9b52fc998864f31e730f0bb47491db4cbb58/smart-ssh_128.png -------------------------------------------------------------------------------- /smart-ssh_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fmeum/smart-ssh/0cce9b52fc998864f31e730f0bb47491db4cbb58/smart-ssh_48.png -------------------------------------------------------------------------------- /smartCard.js: -------------------------------------------------------------------------------- 1 | const smartCard = (function() { 2 | 'use strict'; 3 | 4 | const util = openpgp.util; 5 | 6 | const GSC = GoogleSmartCard; 7 | const Constants = GSC.PcscLiteCommon.Constants; 8 | const API = GSC.PcscLiteClient.API; 9 | 10 | /** 11 | * Client title for the connection to the server App. 12 | * 13 | * Currently this is only used for the debug logs produced by the server App. 14 | */ 15 | const CLIENT_TITLE = 'smart-ssh'; 16 | 17 | /** 18 | * Identifier of the server App. 19 | */ 20 | const SERVER_APP_ID = GSC.PcscLiteCommon.Constants.SERVER_OFFICIAL_APP_ID; 21 | 22 | /** 23 | * Context for using the PC/SC-Lite client API. 24 | * 25 | * This object establishes and manages a connection to the server App. Upon 26 | * successful connection, a GoogleSmartCard.PcscLiteClient.API object is 27 | * returned through the callback, that allows to perform PC/SC-Lite client API 28 | * requests. 29 | * @type {GSC.PcscLiteClient.Context} 30 | */ 31 | let apiContext = null; 32 | let api = null; 33 | 34 | function apiContextDisposedListener() { 35 | console.log('smartCard: API context disposed'); 36 | apiContext = null; 37 | } 38 | 39 | async function initializeApiContext() { 40 | if (!apiContext || !api) { 41 | apiContext = new GSC.PcscLiteClient.Context(CLIENT_TITLE, 42 | SERVER_APP_ID); 43 | // Wait for an API context for at most 0.5 seconds 44 | api = await Promise.race([ 45 | new Promise(function(resolve) { 46 | apiContext.addOnInitializedCallback(resolve); 47 | apiContext.addOnDisposeCallback(apiContextDisposedListener); 48 | apiContext.initialize(); 49 | }), 50 | new Promise(resolve => setTimeout(resolve, 500)) 51 | ]); 52 | } 53 | if (!apiContext || !api) 54 | throw Error( 55 | 'Smart Card Connector extension not installed or disabled.'); 56 | } 57 | 58 | async function logError(error) { 59 | // Numeric error codes signify PC/SC-Lite errors 60 | if (typeof error === 'number') { 61 | console.log('failed: PC/SC-Lite error: ' + error); 62 | try { 63 | const errorText = await api.pcsc_stringify_error(error); 64 | console.log('PC/SC-Lite error text: ' + errorText); 65 | } catch (e) { 66 | console.log(e); 67 | } 68 | } else { 69 | console.log(error); 70 | } 71 | } 72 | 73 | class OpenPGPSmartCardManager { 74 | constructor() { 75 | this.connected = false; 76 | this.context = 0; 77 | this.reader = null; 78 | this.cardHandle = 0; 79 | this.activeProtocol = 0; 80 | this.appletSelected = false; 81 | } 82 | 83 | get readerShort() { 84 | if (this.reader.includes('Yubikey NEO-N')) 85 | return 'Yubikey NEO-N'; 86 | else if (this.reader.includes('Yubikey NEO')) 87 | return 'YubiKey NEO'; 88 | else if (this.reader.includes('Yubikey 4')) 89 | return 'YubiKey 4'; 90 | else 91 | return this.reader; 92 | } 93 | 94 | async establishContext() { 95 | if (!(await this.isValidContext())) { 96 | this.context = await this._execute(api.SCardEstablishContext( 97 | API.SCARD_SCOPE_SYSTEM, null, null)); 98 | } 99 | } 100 | 101 | async isValidContext() { 102 | try { 103 | await this._execute(api.SCardIsValidContext(this.context)); 104 | } catch (_) { 105 | return false; 106 | } 107 | return true; 108 | } 109 | 110 | async listReaders() { 111 | if ((await this.isValidContext()) && !this.connected) { 112 | return this._execute(api.SCardListReaders(this.context, null)); 113 | } 114 | } 115 | 116 | async connect(reader) { 117 | if ((await this.isValidContext()) && !this.connected) { 118 | this.reader = reader; 119 | [this.cardHandle, this.activeProtocol] = await this._execute(api 120 | .SCardConnect(this.context, 121 | this.reader, 122 | API.SCARD_SHARE_EXCLUSIVE, 123 | API.SCARD_PROTOCOL_T1)); 124 | this.connected = true; 125 | } 126 | } 127 | 128 | _execute(sCardPromise) { 129 | return sCardPromise.then(result => new Promise( 130 | function(resolve, reject) { 131 | result.get((...args) => args.length > 1 ? resolve(args) : 132 | resolve( 133 | args[0]), reject); 134 | })); 135 | } 136 | 137 | async _getData(result) { 138 | result[1] = new Uint8Array(result[1]); 139 | let data = result[1].slice(0, -2); 140 | const returnCode = result[1].slice(-2); 141 | if (returnCode[0] === 0x61) { 142 | const dataContinued = await this.transmit(new CommandAPDU(0x00, 143 | 0xC0, 0x00, 0x00)); 144 | data = util.concatUint8Array([data, dataContinued]); 145 | } else if (!(returnCode[0] === 0x90 && returnCode[1] === 0x00)) { 146 | console.log('Operation returned specific status bytes:', 147 | returnCode); 148 | throw returnCode; 149 | } 150 | return data; 151 | } 152 | 153 | async transmit(commandAPDU) { 154 | if (this.connected) { 155 | let data = null; 156 | for (const command of commandAPDU.commands) { 157 | const result = await this._execute(api.SCardTransmit(this.cardHandle, 158 | API.SCARD_PCI_T1, Array.from(command))); 159 | data = await this._getData(result); 160 | } 161 | return data; 162 | } 163 | } 164 | 165 | async selectApplet() { 166 | if (this.connected && !this.appletSelected) { 167 | await this.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x00, new Uint8Array( 168 | [0xD2, 0x76, 0x00, 0x01, 0x24, 0x01]))); 169 | this.appletSelected = true; 170 | } 171 | } 172 | 173 | async disconnect() { 174 | if (this.connected) { 175 | await this._execute(api.SCardDisconnect(this.cardHandle, API.SCARD_LEAVE_CARD)); 176 | this.appletSelected = false; 177 | this.connected = false; 178 | this.reader = null; 179 | this.cardHandle = 0; 180 | this.activeProtocol = 0; 181 | } 182 | } 183 | 184 | async releaseContext() { 185 | if (!(await this.isValidContext())) 186 | return; 187 | if (this.connected) 188 | await this.disconnect(); 189 | await this._execute(api.SCardReleaseContext(this.context)); 190 | this.context = 0; 191 | } 192 | 193 | async callOnDisconnect(readerName, callback) { 194 | if (!await this.isValidContext()) { 195 | callback(); 196 | } else { 197 | // Returns immediately 198 | let readerState = await this._execute(api.SCardGetStatusChange( 199 | this.context, 200 | API.INFINITE, [API.createSCardReaderStateIn( 201 | readerName, API.SCARD_STATE_UNAWARE, 0x1)])); 202 | readerState[0].current_state = readerState[0].event_state; 203 | 204 | while (readerState[0].current_state & API.SCARD_STATE_PRESENT) { 205 | try { 206 | const newState = await this._execute(api.SCardGetStatusChange( 207 | this.context, 208 | API.INFINITE, [API.createSCardReaderStateIn( 209 | readerName, readerState[0].current_state, 0x1)])); 210 | readerState[0].current_state = newState[0].event_state; 211 | } catch (error) { 212 | if (error == API.SCARD_E_CANCELLED) 213 | return; 214 | if (error != API.SCARD_E_TIMEOUT) { 215 | callback(); 216 | throw error; 217 | } 218 | } 219 | } 220 | callback(); 221 | } 222 | } 223 | 224 | async callOnReaderEvent(callback) { 225 | if (!await this.isValidContext()) { 226 | throw Error('smartCard.callOnReaderEvent: Invalid context'); 227 | } else { 228 | await this._execute(api.SCardGetStatusChange( 229 | this.context, 230 | API.INFINITE, [API.createSCardReaderStateIn( 231 | '\\\\?PnP?\\Notification', API.SCARD_STATE_UNAWARE, 0x1 232 | )])); 233 | callback(); 234 | } 235 | } 236 | 237 | async cancelListeners() { 238 | await this._execute(api.SCardCancel(this.context)); 239 | } 240 | 241 | // See RFC 4253, Section 6.6 and RFC 4251, Section 5 242 | async fetchPublicKeyBlob() { 243 | const publicKeyTemplate = DataObject.fromBytes(await this.transmit( 244 | new CommandAPDU(0x00, 0x47, 0x81, 0x00, new Uint8Array([0xA4, 245 | 0x00 246 | ])))); 247 | let modulus = publicKeyTemplate.lookup(0x81); 248 | if (modulus[0] & (1 << 7)) 249 | modulus = util.concatUint8Array([new Uint8Array([0]), modulus]); 250 | const exponent = publicKeyTemplate.lookup(0x82); 251 | return util.concatUint8Array([ 252 | util.writeNumber(7, 4), 253 | new Uint8Array(util.str2bin('ssh-rsa')), 254 | util.writeNumber(exponent.length, 4), 255 | exponent, 256 | util.writeNumber(modulus.length, 4), 257 | modulus 258 | ]); 259 | } 260 | 261 | async fetchPublicKeyBlobBase64() { 262 | return btoa(String.fromCharCode.apply( 263 | null, await this.fetchPublicKeyBlob())); 264 | } 265 | 266 | async fetchAuthenticationPublicKeyId() { 267 | const appRelatedData = DataObject.fromBytes(await this.transmit( 268 | new CommandAPDU(0x00, 0xCA, 0x00, 0x6E))); 269 | return appRelatedData.lookup(0xC5).subarray(52, 60); 270 | } 271 | 272 | async fetchAuthenticationPublicKeyIdString() { 273 | return util.hexidump((await this.fetchAuthenticationPublicKeyId()) 274 | .slice(4)).toUpperCase(); 275 | } 276 | 277 | async fetchAuthenticationModulusLengthBytes() { 278 | const appRelatedData = DataObject.fromBytes(await this.transmit( 279 | new CommandAPDU(0x00, 0xCA, 0x00, 0x6E))); 280 | return util.readNumber(appRelatedData.lookup(0xC3).subarray(1, 3)) / 281 | 8; 282 | } 283 | 284 | async fetchPinVerificationTriesRemaining() { 285 | const appRelatedData = DataObject.fromBytes(await this.transmit( 286 | new CommandAPDU(0x00, 0xCA, 0x00, 0x6E))); 287 | return appRelatedData.lookup(0xC4)[4]; 288 | } 289 | } 290 | 291 | class CommandAPDU { 292 | constructor(cla, ins, p1, p2, data) { 293 | this.commands = []; 294 | 295 | if (!data) { 296 | this.commands.push(new Uint8Array([cla, ins, p1, p2, 0x00])); 297 | return; 298 | } 299 | 300 | let remainingBytes = data.length; 301 | 302 | while (remainingBytes > 0xFF) { 303 | const header = new Uint8Array([cla | 1 << 4, ins, p1, p2, 0xFF]); 304 | const body = data.subarray(data.length - remainingBytes, data.length - 305 | remainingBytes + 0xFF); 306 | const footer = new Uint8Array([0x00]); 307 | this.commands.push(util.concatUint8Array([header, body, footer])); 308 | remainingBytes -= 0xFF; 309 | } 310 | 311 | const header = new Uint8Array([cla, ins, p1, p2, remainingBytes]); 312 | const body = data.subarray(data.length - remainingBytes, data.length); 313 | const footer = new Uint8Array([0x00]); 314 | this.commands.push(util.concatUint8Array([header, body, footer])); 315 | } 316 | } 317 | 318 | const DATA_OBJECT_TAG = { 319 | 0x5E: 'Login data', 320 | 0x5F50: 'URL to public keys', 321 | 322 | 0x65: 'Cardholder Related Data', 323 | 0x5B: 'Name', 324 | 0x5F2D: 'Language preference', 325 | 0x5F35: 'Sex', 326 | 327 | 0x6E: 'Application Related Data', 328 | 0x4F: 'Application Identifier', 329 | 0x5F52: 'Historical bytes', 330 | 0x73: 'Discretionary data objects', 331 | 0xC0: 'Extended capabilities', 332 | 0xC1: 'Algorithm attributes: signature', 333 | 0xC2: 'Algorithm attributes: decryption', 334 | 0xC3: 'Algorithm attributes: authentication', 335 | 0xC4: 'PW Status Bytes', 336 | 0xC5: 'Fingerprints', 337 | 0xC6: 'CA Fingerprints', 338 | 0xCD: 'Generation Timestamps', 339 | 340 | 0x7A: 'Security support template', 341 | 0x93: 'Digital signature counter', 342 | 343 | 0x7F49: 'Public key template', 344 | 0x81: 'Modulus', 345 | 0x82: 'Public exponent' 346 | }; 347 | 348 | const DATA_OBJECT_TAG_CLASS = { 349 | 0: 'universal', 350 | 1: 'application', 351 | 2: 'context-specific', 352 | 3: 'private' 353 | }; 354 | 355 | class DataObject { 356 | 357 | lookup(tag) { 358 | if (this.tag === tag) 359 | if (this.isConstructed) 360 | return this.children; 361 | else 362 | return this.value; 363 | else { 364 | if (this.isConstructed) { 365 | for (let child of this.children) { 366 | let result = child.lookup(tag); 367 | if (result !== null) 368 | return result; 369 | } 370 | } 371 | return null; 372 | } 373 | } 374 | 375 | static fromBytesWithStart(bytes, start) { 376 | let pos = start; 377 | if (pos < bytes.length) { 378 | const dataObject = new DataObject(); 379 | const tagByte = bytes[pos++]; 380 | dataObject.tagClass = tagByte >>> 6; 381 | dataObject.tagClassDescription = DATA_OBJECT_TAG_CLASS[dataObject 382 | .tagClass]; 383 | const isConstructed = !!(tagByte & (1 << 5)); 384 | dataObject.isConstructed = isConstructed; 385 | 386 | let tagNumber = tagByte & 0b00011111; 387 | let numTagNumberBytes = 1; 388 | if (tagNumber === 0b00011111) { 389 | if (!(bytes[pos] & 0b01111111)) 390 | throw Error('First byte of the tag number is 0'); 391 | tagNumber = 0; 392 | do { 393 | tagNumber = (tagNumber << 7) + (bytes[pos] & 0b01111111); 394 | ++numTagNumberBytes; 395 | } while (bytes[pos++] & (1 << 7)); 396 | } 397 | dataObject.tagNumber = tagNumber; 398 | dataObject.tag = util.readNumber(bytes.slice(pos - 399 | numTagNumberBytes, pos)); 400 | dataObject.tagDescription = DATA_OBJECT_TAG[dataObject.tag] || 401 | ``; 402 | 403 | const lengthByte = bytes[pos++]; 404 | let valueLength = 0; 405 | if (lengthByte <= 0x7F) { 406 | valueLength = lengthByte; 407 | } else { 408 | const numLengthBytes = lengthByte & 0b01111111; 409 | for (let i = 0; i < numLengthBytes; ++i) { 410 | valueLength = (valueLength * 0x100) + bytes[pos++]; 411 | } 412 | } 413 | dataObject.valueLength = valueLength; 414 | 415 | const valueStart = pos; 416 | const valueEnd = pos + valueLength; 417 | const value = bytes.slice(valueStart, valueEnd); 418 | 419 | if (isConstructed) { 420 | dataObject.children = []; 421 | while (pos < valueEnd) { 422 | // Skip zero bytes inbetween tags 423 | if (!bytes[pos]) { 424 | ++pos; 425 | continue; 426 | } 427 | let child; 428 | [child, pos] = DataObject.fromBytesWithStart(bytes, pos); 429 | dataObject.children.push(child); 430 | } 431 | } else { 432 | dataObject.value = value; 433 | } 434 | return [dataObject, valueEnd]; 435 | } else { 436 | return [null, start]; 437 | } 438 | } 439 | 440 | static fromBytes(bytes) { 441 | return DataObject.fromBytesWithStart(bytes, 0)[0]; 442 | } 443 | } 444 | 445 | chrome.runtime.onSuspend.addListener(function() { 446 | console.log('smartCard: unloaded'); 447 | console.log(new Error().stack); 448 | }); 449 | 450 | initializeApiContext(); 451 | 452 | return { 453 | OpenPGPSmartCardManager, 454 | CommandAPDU, 455 | DataObject, 456 | initializeApiContext, 457 | logError 458 | } 459 | })(); 460 | --------------------------------------------------------------------------------