-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
6,387 additions
and
1,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* This file is part of Cockpit. | ||
* | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* Cockpit is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Cockpit is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import cockpit from "cockpit"; | ||
import client from "./client"; | ||
|
||
import { get_existing_passphrase, unlock_with_type } from "./crypto-keyslots.jsx"; // XXX | ||
import { set_crypto_auto_option } from "./utils.js"; | ||
import { dialog_open, PassInput } from "./dialog.jsx"; | ||
|
||
const _ = cockpit.gettext; | ||
|
||
export function unlock(block) { | ||
const crypto = client.blocks_crypto[block.path]; | ||
if (!crypto) | ||
return; | ||
|
||
function unlock_with_passphrase() { | ||
const crypto = client.blocks_crypto[block.path]; | ||
if (!crypto) | ||
return; | ||
|
||
dialog_open({ | ||
Title: _("Unlock"), | ||
Fields: [ | ||
PassInput("passphrase", _("Passphrase"), {}) | ||
], | ||
Action: { | ||
Title: _("Unlock"), | ||
action: function (vals) { | ||
return (crypto.Unlock(vals.passphrase, {}) | ||
.then(() => set_crypto_auto_option(block, true))); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
return get_existing_passphrase(block, true).then(type => { | ||
return (unlock_with_type(client, block, null, type) | ||
.then(() => set_crypto_auto_option(block, true)) | ||
.catch(() => unlock_with_passphrase())); | ||
}); | ||
} | ||
|
||
export function lock(block) { | ||
const crypto = client.blocks_crypto[block.path]; | ||
if (!crypto) | ||
return; | ||
|
||
return crypto.Lock({}).then(() => set_crypto_auto_option(block, false)); | ||
} | ||
|
||
export function std_lock_action(backing_block, content_block) { | ||
if (backing_block == content_block) | ||
return null; | ||
|
||
return { title: _("Lock"), action: () => lock(backing_block) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.