0

By developing a Cinnamon Desklet I need to save access to an API that contains a password.
Storing it as "entry" type in settins-schema.json seems to be not so secure.

Does anyone have any common practice/example (eg: via gnome-keyring) how you can store info securely in desklets standard config? Or does anyone know a Desklet that can be taken as an example?

2 Answers2

0

The best way to store passwords securely in a Desklet is to use the gnome-keyring. This will allow you to store the password in a secure location that is only accessible by the Desklet.

Mohamed Elgazar
  • 778
  • 4
  • 9
  • Thanks. I was thinking on the same. After some hours I managed to do it - despite the documentations available :) Sharing in the next post. – Janos Toberling Oct 16 '22 at 13:58
0

So for those who are trying to save password in Cinnamon Desklet/Applet/Extension to gnome-keyring:

In your (desklet|applet|etc..).js:

...
// Some imports you will need:
const Secret = imports.gi.Secret;
const Clutter = imports.gi.Clutter;
const ModalDialog = imports.ui.modalDialog;

...
class YouClass{
   constructor(){
     ...
          this.STORE_SCHEMA = new Secret.Schema("org.myOwn.Schema",Secret.SchemaFlags.NONE,{});
     ...
   }

    on_password_stored(source, result) {
        Secret.password_store_finish(result);
    }

    onPasswordSave() {

            let dialog = new PasswordDialog (
                _("'%s' settings..\nPlease enter password:").format(this._(this._meta.name)),
                (password) => {
                    Secret.password_store(this.STORE_SCHEMA, {}, Secret.COLLECTION_DEFAULT,
                      "MyFancyPassword", password, null, this.on_password_stored);
                }
            );
            dialog.open();

    }

    needMyPasswordFunction() {
        let password = Secret.password_lookup_sync(this.STORE_SCHEMA, {}, null );


    }


}

// --- Define PasswordDialog
class PasswordDialog extends ModalDialog.ModalDialog {

    constructor(label, callback){
        super();

        this.contentLayout.add(new St.Label({ text: label }));
        this.callback = callback;
        this.entry = new St.Entry({ style: 'background: green; color:yellow;' });
        this.entry.clutter_text.set_password_char('\u25cf');
        this.contentLayout.add(this.entry);
        this.setInitialKeyFocus( this.entry.clutter_text );

        this.setButtons([
          {
              label: "Save", 
              action: ()  => {
                  const pwd = this.entry.get_text();
                  this.callback( pwd );
                  this.destroy();
              }, 
              key: Clutter.KEY_Return, 
              focused: false
          },
          {
              label: "Cancel", 
              action: ()  => {
                  this.destroy();
              },  
              key: null, 
              focused: false
          }
        ]);

    }
}



And if you want to link with a config button put this also to settings-schema.json:

    "savepassword": {
        "type": "button",
        "description": "Enter and save password ...",
        "callback": "onPasswordSave"
    }