├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── decorators │ ├── index.ts │ ├── method.ts │ ├── property.ts │ └── signal.ts ├── index.ts ├── interfaces │ ├── collection.ts │ ├── dbus-interface.ts │ ├── index.ts │ └── service.ts └── models │ ├── access.ts │ ├── dbus-argument.ts │ ├── dbus-signature.ts │ ├── dbus-type.ts │ ├── index.ts │ ├── object-path.ts │ ├── secret.ts │ └── secrets-map.ts ├── tsconfig.json └── types └── dbus.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node,linux,macos,windows,visualstudiocode 3 | # Edit at https://www.gitignore.io/?templates=node,linux,macos,windows,visualstudiocode 4 | 5 | ### Linux ### 6 | *~ 7 | 8 | # temporary files which can be created if a process still has a handle open of a deleted file 9 | .fuse_hidden* 10 | 11 | # KDE directory preferences 12 | .directory 13 | 14 | # Linux trash folder which might appear on any partition or disk 15 | .Trash-* 16 | 17 | # .nfs files are created when an open file is removed but is still being accessed 18 | .nfs* 19 | 20 | ### macOS ### 21 | # General 22 | .DS_Store 23 | .AppleDouble 24 | .LSOverride 25 | 26 | # Icon must end with two \r 27 | Icon 28 | 29 | # Thumbnails 30 | ._* 31 | 32 | # Files that might appear in the root of a volume 33 | .DocumentRevisions-V100 34 | .fseventsd 35 | .Spotlight-V100 36 | .TemporaryItems 37 | .Trashes 38 | .VolumeIcon.icns 39 | .com.apple.timemachine.donotpresent 40 | 41 | # Directories potentially created on remote AFP share 42 | .AppleDB 43 | .AppleDesktop 44 | Network Trash Folder 45 | Temporary Items 46 | .apdisk 47 | 48 | ### Node ### 49 | # Logs 50 | logs 51 | *.log 52 | npm-debug.log* 53 | yarn-debug.log* 54 | yarn-error.log* 55 | 56 | # Runtime data 57 | pids 58 | *.pid 59 | *.seed 60 | *.pid.lock 61 | 62 | # Directory for instrumented libs generated by jscoverage/JSCover 63 | lib-cov 64 | 65 | # Coverage directory used by tools like istanbul 66 | coverage 67 | 68 | # nyc test coverage 69 | .nyc_output 70 | 71 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 72 | .grunt 73 | 74 | # Bower dependency directory (https://bower.io/) 75 | bower_components 76 | 77 | # node-waf configuration 78 | .lock-wscript 79 | 80 | # Compiled binary addons (https://nodejs.org/api/addons.html) 81 | build/Release 82 | 83 | # Dependency directories 84 | node_modules/ 85 | jspm_packages/ 86 | 87 | # TypeScript v1 declaration files 88 | typings/ 89 | 90 | # Optional npm cache directory 91 | .npm 92 | 93 | # Optional eslint cache 94 | .eslintcache 95 | 96 | # Optional REPL history 97 | .node_repl_history 98 | 99 | # Output of 'npm pack' 100 | *.tgz 101 | 102 | # Yarn Integrity file 103 | .yarn-integrity 104 | 105 | # dotenv environment variables file 106 | .env 107 | .env.test 108 | 109 | # parcel-bundler cache (https://parceljs.org/) 110 | .cache 111 | 112 | # next.js build output 113 | .next 114 | 115 | # nuxt.js build output 116 | .nuxt 117 | 118 | # vuepress build output 119 | .vuepress/dist 120 | 121 | # Serverless directories 122 | .serverless/ 123 | 124 | # FuseBox cache 125 | .fusebox/ 126 | 127 | # DynamoDB Local files 128 | .dynamodb/ 129 | 130 | ### VisualStudioCode ### 131 | .vscode/* 132 | !.vscode/settings.json 133 | !.vscode/tasks.json 134 | !.vscode/launch.json 135 | !.vscode/extensions.json 136 | 137 | ### VisualStudioCode Patch ### 138 | # Ignore all local history of files 139 | .history 140 | 141 | ### Windows ### 142 | # Windows thumbnail cache files 143 | Thumbs.db 144 | ehthumbs.db 145 | ehthumbs_vista.db 146 | 147 | # Dump file 148 | *.stackdump 149 | 150 | # Folder config file 151 | [Dd]esktop.ini 152 | 153 | # Recycle Bin used on file shares 154 | $RECYCLE.BIN/ 155 | 156 | # Windows Installer files 157 | *.cab 158 | *.msi 159 | *.msix 160 | *.msm 161 | *.msp 162 | 163 | # Windows shortcuts 164 | *.lnk 165 | 166 | # End of https://www.gitignore.io/api/node,linux,macos,windows,visualstudiocode 167 | 168 | *.js 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Andreas Backx 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BitWarden Libsecret 2 | 3 | This is a proof of concept that shows how I would implement [libsecret's DBUS API](https://specifications.freedesktop.org/secret-service/index.html) into BitWarden. This would allow you to use BitWarden as the sole password manager on your Linux computer. It would remove the need for GNOME keyring and KDE Wallet. At the same time it would allow for native autocompletion in Google Chrome and Firefox without the use of an extension. 4 | 5 | This proof of concept does not work. The current issues/questions that I am facing: 6 | 7 | - [ ] Find/create a proper Javascript/TypeScript DBUS API. 8 | 9 | Neither [dbus-native](https://github.com/sidorares/dbus-native) nor [node-dbus](https://github.com/Shouqun/node-dbus) seem to be actively maintained and they both are not stable enough it seems to be used in production software. 10 | 11 | For how far that I tested I could not get dbus-native to even run because it was saying that [`data` was undefined](https://github.com/sidorares/dbus-native/blob/master/lib/marshall.js#L60). It could just be that I was making a mistake. It is however a very old library and contains no documentation whatsoever. 12 | 13 | Node-dbus does seem to be the weaker one from the two as it lacks some obvious features and is the least actively maintained. It however is currently used as it is the only one that doesn't crash when I tried to add the `Service.OpenSession` method. It however has an [open issue](https://github.com/Shouqun/node-dbus/issues/132) where it does not support returning multiple values from a method. There are also a lot more old issues. 14 | 15 | It is imo the best idea to create our own DBus library. 16 | 17 | Still not all of the libsecret DBus interfaces are implemented. Though the purpose of this poc was to inspect how to implement the DBus communication. Adding the actual functionality, should "simply" be plugging it into the BitWarden's desktop project. 18 | 19 | The current implementation abstracts the interaction of the DBus using decorators. It should make it easy to make changes without knowing how DBus works exactly. 20 | 21 | _Note: I am no frontend developer. I simply made this proof of concept because I would really like to see the password manager incorporated more into the Linux system and applications. BitWarden's desktop application is written in TypeScript so it was obvious to use TypeScript for this proof of concept._ 22 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "libsecrets-poc", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "dbus": { 8 | "version": "1.0.3", 9 | "resolved": "https://registry.npmjs.org/dbus/-/dbus-1.0.3.tgz", 10 | "integrity": "sha1-vO2hSGc7wvzKIEK6BqlZZXYmibw=", 11 | "requires": { 12 | "nan": "^2.1.0" 13 | } 14 | }, 15 | "nan": { 16 | "version": "2.12.1", 17 | "resolved": "https://registry.npmjs.org/nan/-/nan-2.12.1.tgz", 18 | "integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==" 19 | }, 20 | "typescript": { 21 | "version": "3.2.4", 22 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.4.tgz", 23 | "integrity": "sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg==" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "libsecret-poc", 3 | "version": "1.0.0", 4 | "description": "Libsecret proof of concept for BitWarden.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Andreas Backx", 10 | "license": "MIT", 11 | "dependencies": { 12 | "dbus": "^1.0.3", 13 | "typescript": "^3.2.4" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export * from './method'; 2 | export * from './property'; 3 | export * from './signal'; 4 | 5 | -------------------------------------------------------------------------------- /src/decorators/method.ts: -------------------------------------------------------------------------------- 1 | import { DBusArgument } from '../models'; 2 | 3 | export function Method(input: DBusArgument[], output: DBusArgument[] = []) { 4 | console.log('input:', input); 5 | 6 | input.forEach((value: DBusArgument) => { 7 | console.log(value); 8 | }) 9 | 10 | console.log('output:', output); 11 | return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 12 | // console.log('target:', target); 13 | // console.log('target.constructor.name:', target.constructor.name); 14 | // console.log('propertyKey:', propertyKey); 15 | // console.log('descriptor:', descriptor); 16 | // console.log('target.methods:', target.methods); 17 | 18 | if (!target.methods) { 19 | target.methods = []; 20 | } 21 | 22 | target.methods.push( 23 | { 24 | name: propertyKey, 25 | opts: { 26 | in: input, 27 | out: output, 28 | }, 29 | handler: descriptor.value, 30 | } 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/decorators/property.ts: -------------------------------------------------------------------------------- 1 | import { Access, DBusType } from '../models'; 2 | 3 | // TODO 4 | export function Property(type: DBusType | string, access: Access = Access.READ) { 5 | return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/decorators/signal.ts: -------------------------------------------------------------------------------- 1 | import { DBusArgument } from '../models'; 2 | 3 | // TODO 4 | export function Signal(input: DBusArgument[] = []) { 5 | return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import DBus from 'dbus'; 2 | import { Service } from './interfaces'; 3 | 4 | const serviceName = 'org.freedesktop.secrets'; 5 | var service = DBus.registerService('session', serviceName); 6 | 7 | console.log(DBus.Define(String, 'test')); 8 | 9 | // TODO Add the serviceInterface to some state. 10 | var serviceInterface = new Service(); 11 | serviceInterface.attachService(service); 12 | 13 | /* TODO 14 | Convert all of the folders from BitWarden to Collection objects: 15 | 16 | let folders = getAllFoldersOrSomething() 17 | folders.forEach((folder: Folder) => { 18 | let collection = new Collection(folder); 19 | collection.attachService(service); 20 | 21 | Add the collection to some state here as well to keep track of it. 22 | }) 23 | */ 24 | -------------------------------------------------------------------------------- /src/interfaces/collection.ts: -------------------------------------------------------------------------------- 1 | import { Method, Property, Signal } from "../decorators"; 2 | import { Access, DBusType, ObjectPath, Secret } from "../models"; 3 | import { DBusInterface } from "./dbus-interface"; 4 | 5 | interface ItemAttributes { 6 | [key: string]: string; 7 | } 8 | 9 | interface ItemProperties { 10 | [key: string]: any; 11 | } 12 | 13 | export class Collection extends DBusInterface { 14 | public path: string 15 | public name: string 16 | 17 | /** 18 | * TODO Decide how to create collection objects. 19 | * Because they should be a wrapper around BitWarden's folders. 20 | */ 21 | public constructor(path: string, name: string) { 22 | super() 23 | 24 | this.path = path; 25 | this.name = name; 26 | } 27 | 28 | /** 29 | * TypeScript doesn't support different constructors with totally different arguments. 30 | * But there needs to be a way to create collections from the folders in BitWarden. 31 | * @param folder Folder class that is used in BitWarden. 32 | */ 33 | public static fromFolder(folder: any): Collection { 34 | return new Collection(folder.path, folder.name); 35 | } 36 | 37 | @Method([]) 38 | public Delete( 39 | callback: (prompt: ObjectPath) => any 40 | ) { 41 | // TODO Delete the entire collection. 42 | this.detachService(); 43 | } 44 | 45 | @Method([]) 46 | public SearchItems( 47 | attributes: ItemAttributes, 48 | callback: (results: ObjectPath[]) => any 49 | ) { } 50 | 51 | @Method([]) 52 | public CreateItem( 53 | properties: ItemProperties, 54 | secret: Secret, 55 | replace: boolean, 56 | callback: (item: ObjectPath, prompt: ObjectPath) => any 57 | ) { } 58 | 59 | @Signal() 60 | public ItemCreated() { } 61 | 62 | @Signal() 63 | public ItemDeleted() { } 64 | 65 | @Signal() 66 | public ItemChanged() { } 67 | 68 | @Property(`${DBusType.ARRAY}${DBusType.OBJECT_PATH}`) 69 | get Items(): ObjectPath[] { 70 | return [] 71 | } 72 | 73 | @Property(DBusType.STRING, Access.READWRITE) 74 | get Label(): string { 75 | return "" 76 | } 77 | 78 | @Property(DBusType.BOOLEAN) 79 | get Locked(): boolean { 80 | return true 81 | } 82 | 83 | @Property(DBusType.UINT64) 84 | get Created(): number { 85 | return 0 86 | } 87 | 88 | @Property(DBusType.UINT64) 89 | get Modified(): number { 90 | return 0 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/interfaces/dbus-interface.ts: -------------------------------------------------------------------------------- 1 | 2 | export abstract class DBusInterface { 3 | 4 | public abstract path: string 5 | public abstract name: string 6 | 7 | private object: any 8 | private service: any 9 | 10 | /** 11 | * Has to be nullable because otherwise it will overwrite the value written by the decorator. 12 | */ 13 | public methods?: any[] 14 | 15 | public attachService(service: any) { 16 | this.service = service 17 | 18 | console.log('updateService') 19 | 20 | this.object = service.createObject(this.path) 21 | var objectInterface = this.object.createInterface(this.name) 22 | 23 | 24 | if (this.methods) { 25 | this.methods.forEach((method: any) => { 26 | // console.log('method.name:', method.name) 27 | // console.log('method.opts.in:', method.opts.in) 28 | // console.log('method.opts.out:', method.opts.out) 29 | // console.log('method.handler:', method.handler) 30 | 31 | objectInterface.addMethod(method.name, method.opts, method.handler) 32 | }) 33 | } 34 | 35 | console.log('objectInterface methods') 36 | console.log(objectInterface.methods) 37 | 38 | 39 | objectInterface.update() 40 | 41 | 42 | console.log('objectInterface introspection') 43 | console.log(objectInterface.introspection) 44 | } 45 | 46 | public detachService() { 47 | this.service.removeObject(this.object); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './dbus-interface'; 2 | export * from './service'; 3 | -------------------------------------------------------------------------------- /src/interfaces/service.ts: -------------------------------------------------------------------------------- 1 | import { Method, Property, Signal } from '../decorators'; 2 | import { DBusType, ObjectPath, SecretsMap } from '../models'; 3 | import { DBusInterface as DBUSInterface } from './dbus-interface'; 4 | 5 | /** 6 | * org.freedesktop.Secret.Service 7 | * 8 | * This should perhaps be converted to a singleton as there is only one service. 9 | */ 10 | export class Service extends DBUSInterface { 11 | 12 | public path: string = '/org/freedesktop/secrets' 13 | public name: string = 'org.freedesktop.Secret.Service' 14 | 15 | /** 16 | * OpenSession creates a session with the given algorithm and input for that algorithm. 17 | * 18 | * There is a plain algorithm that doesn't provide encryption, 19 | * which needs to be supported. 20 | * https://specifications.freedesktop.org/secret-service/ch07s02.html 21 | * 22 | * Then there is a Diffie-Helman algorithm: 23 | * https://specifications.freedesktop.org/secret-service/ch07s03.html 24 | * 25 | * I suggest we only implement the plain algorithm in the beginning and then 26 | * in the end we implement the other algorithm as only the plain one is strongly 27 | * recommended to be supported. 28 | */ 29 | @Method( 30 | [ 31 | { 32 | name: 'algorithm', 33 | type: DBusType.STRING, 34 | }, { 35 | name: 'input', 36 | type: DBusType.VARIANT, 37 | } 38 | ], [ 39 | { 40 | name: 'output', 41 | type: DBusType.STRING, 42 | }, { 43 | name: 'result', 44 | type: DBusType.VARIANT, 45 | } 46 | ], 47 | ) 48 | public OpenSession( 49 | algorithm: string, input: any, 50 | callback: (output: string, result: ObjectPath) => any 51 | ) { 52 | /* TODO 53 | let session = new Session(algorithm, input) 54 | const output = session.output <-- this is a getter 55 | session.attachService(this.service) 56 | callback(session.output, session.path) 57 | */ 58 | } 59 | 60 | @Method( 61 | [ 62 | { 63 | name: 'properties', 64 | type: `{${DBusType.STRING}${DBusType.VARIANT}}`, 65 | }, 66 | { 67 | name: 'alias', 68 | type: DBusType.STRING, 69 | }, 70 | ], [ 71 | { 72 | name: 'collection', 73 | type: DBusType.OBJECT_PATH, 74 | }, 75 | { 76 | name: 'prompt', 77 | type: DBusType.OBJECT_PATH, 78 | }, 79 | ], 80 | ) 81 | public CreateCollection( 82 | properties: object, alias: string, 83 | callback: (collection: ObjectPath, prompt: ObjectPath) => any) { 84 | /* TODO 85 | let collection = new Collection(properties, alias) 86 | collection.attachService(this.service) 87 | callback(collection.path, collection.prompt.path) 88 | */ 89 | } 90 | 91 | 92 | @Method( 93 | [ 94 | { 95 | name: 'attributes', 96 | type: `{${DBusType.STRING}${DBusType.STRING}}`, 97 | }, 98 | ], [ 99 | { 100 | name: 'unlocked', 101 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 102 | }, 103 | { 104 | name: 'locked', 105 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 106 | }, 107 | ], 108 | ) 109 | public SearchItems( 110 | attributes: object, 111 | callback: (unlocked: ObjectPath[], locked: ObjectPath[]) => any) { 112 | /* 113 | let 114 | */ 115 | } 116 | 117 | 118 | @Method( 119 | [ 120 | { 121 | name: 'objects', 122 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 123 | }, 124 | ], [ 125 | { 126 | name: 'unlocked', 127 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 128 | }, 129 | { 130 | name: 'prompt', 131 | type: DBusType.OBJECT_PATH, 132 | }, 133 | ], 134 | ) 135 | public Unlock( 136 | objects: ObjectPath[], 137 | callback: (unlocked: ObjectPath[], prompt: ObjectPath) => any) { 138 | } 139 | 140 | 141 | @Method( 142 | [ 143 | { 144 | name: 'objects', 145 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 146 | }, 147 | ], [ 148 | { 149 | name: 'locked', 150 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 151 | }, 152 | { 153 | name: 'prompt', 154 | type: DBusType.OBJECT_PATH, 155 | }, 156 | ], 157 | ) 158 | public Lock( 159 | objects: ObjectPath[], 160 | callback: (locked: ObjectPath[], prompt: ObjectPath) => any) { 161 | 162 | } 163 | 164 | 165 | @Method( 166 | [ 167 | { 168 | name: 'items', 169 | type: `${DBusType.ARRAY}${DBusType.OBJECT_PATH}`, 170 | }, 171 | ], [ 172 | { 173 | name: 'session', 174 | type: DBusType.OBJECT_PATH, 175 | }, 176 | ], 177 | ) 178 | public GetSecrets( 179 | items: ObjectPath[], session: ObjectPath, 180 | callback: (secrets: SecretsMap) => any) { 181 | 182 | } 183 | 184 | @Method( 185 | [ 186 | { 187 | name: 'name', 188 | type: DBusType.STRING, 189 | }, 190 | ], [ 191 | { 192 | name: 'collection', 193 | type: DBusType.OBJECT_PATH, 194 | }, 195 | ], 196 | ) 197 | public ReadAlias( 198 | name: string, 199 | callback: (collection: ObjectPath) => any) { 200 | 201 | } 202 | 203 | @Method( 204 | [ 205 | { 206 | name: 'name', 207 | type: DBusType.STRING, 208 | }, 209 | { 210 | name: 'collection', 211 | type: DBusType.OBJECT_PATH, 212 | }, 213 | ], 214 | ) 215 | public SetAlias( 216 | name: string, collection: string, 217 | callback: () => any) { 218 | 219 | } 220 | 221 | @Signal() 222 | public CollectionCreated(collection: ObjectPath) { } 223 | 224 | @Signal() 225 | public CollectionDeleted(collection: ObjectPath) { } 226 | 227 | @Signal() 228 | public CollectionChanged(collection: ObjectPath) { } 229 | 230 | @Property(`${DBusType.ARRAY}${DBusType.OBJECT_PATH}`) 231 | get Collections(): ObjectPath[] { 232 | return [] 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /src/models/access.ts: -------------------------------------------------------------------------------- 1 | 2 | export enum Access { 3 | READWRITE, 4 | READ, 5 | WRITE 6 | } 7 | -------------------------------------------------------------------------------- /src/models/dbus-argument.ts: -------------------------------------------------------------------------------- 1 | import { DBusSignature } from '.'; 2 | 3 | export interface DBusArgument { 4 | name: string, 5 | type: DBusSignature, 6 | } 7 | -------------------------------------------------------------------------------- /src/models/dbus-signature.ts: -------------------------------------------------------------------------------- 1 | import { DBusType } from "./dbus-type"; 2 | 3 | export type DBusSignature = string | DBusType; 4 | -------------------------------------------------------------------------------- /src/models/dbus-type.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * I want to change this to a class where you can use the Builder pattern or something 4 | * so you can create array, struct, and dict types. 5 | */ 6 | export enum DBusType { 7 | BOOLEAN = 'b', 8 | BYTE = 'y', 9 | // Integers 10 | INT16 = 'n', 11 | UINT16 = 'q', 12 | INT32 = 'i', 13 | UINT32 = 'u', 14 | INT64 = 'x', 15 | UINT64 = 't', 16 | DOUBLE = 'd', 17 | 18 | STRING = 's', 19 | 20 | SIGNATURE = 'g', 21 | OBJECT_PATH = 'o', 22 | 23 | // Array usage: 24 | // ab: array of booleans 25 | // a(bs): array of a struct with a boolean and a string 26 | ARRAY = 'a', 27 | // Struct usage: () 28 | STRUCT = 'r', 29 | // Dictionary usage: {} 30 | DICT = 'e', 31 | VARIANT = 'v', 32 | } 33 | -------------------------------------------------------------------------------- /src/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './access'; 2 | export * from './dbus-argument'; 3 | export * from './dbus-signature'; 4 | export * from './dbus-type'; 5 | export * from './object-path'; 6 | export * from './secret'; 7 | export * from './secrets-map'; 8 | 9 | -------------------------------------------------------------------------------- /src/models/object-path.ts: -------------------------------------------------------------------------------- 1 | 2 | export type ObjectPath = string; 3 | -------------------------------------------------------------------------------- /src/models/secret.ts: -------------------------------------------------------------------------------- 1 | import { ObjectPath } from "."; 2 | 3 | export type Byte = number; 4 | 5 | export interface Secret { 6 | session: ObjectPath, 7 | parameters: Byte[], 8 | value: Byte[], 9 | contentType: string 10 | } 11 | -------------------------------------------------------------------------------- /src/models/secrets-map.ts: -------------------------------------------------------------------------------- 1 | import { Secret } from "."; 2 | 3 | export interface SecretsMap { 4 | // [key: ObjectPath], but this is not supported. 5 | // https://github.com/Microsoft/TypeScript/issues/1778 6 | [key: string]: Secret; 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "*": [ 6 | "types/*" 7 | ] 8 | }, 9 | /* Basic Options */ 10 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 11 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 12 | // "lib": [], /* Specify library files to be included in the compilation. */ 13 | // "allowJs": true, /* Allow javascript files to be compiled. */ 14 | // "checkJs": true, /* Report errors in .js files. */ 15 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 16 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 17 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 18 | // "outFile": "./", /* Concatenate and emit output to single file. */ 19 | // "outDir": "./", /* Redirect output structure to the directory. */ 20 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 21 | // "removeComments": true, /* Do not emit comments to output. */ 22 | // "noEmit": true, /* Do not emit outputs. */ 23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 26 | /* Strict Type-Checking Options */ 27 | "strict": true, /* Enable all strict type-checking options. */ 28 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 29 | // "strictNullChecks": true, /* Enable strict null checks. */ 30 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 31 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 32 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 33 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 34 | /* Additional Checks */ 35 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 36 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 37 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 38 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 39 | /* Module Resolution Options */ 40 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 41 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 42 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 43 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 44 | // "typeRoots": [], /* List of folders to include type definitions from. */ 45 | // "types": [], /* Type declaration files to be included in compilation. */ 46 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 47 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 48 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 49 | /* Source Map Options */ 50 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 51 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 52 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 53 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 54 | /* Experimental Options */ 55 | "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */ 56 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /types/dbus.d.ts: -------------------------------------------------------------------------------- 1 | export = dbus; 2 | declare const dbus: any; 3 | --------------------------------------------------------------------------------