2 -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
3 -- All rights reserved.
5 -- Redistribution and use in source and binary forms, with or without
6 -- modification, are permitted provided that the following conditions
8 -- 1. Redistributions of source code must retain the above copyright
9 -- notice, this list of conditions and the following disclaimer.
10 -- 2. Redistributions in binary form must reproduce the above copyright
11 -- notice, this list of conditions and the following disclaimer in the
12 -- documentation and/or other materials provided with the distribution.
14 -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 local core = require("core");
32 local screen = require("screen");
34 function password.read()
40 if (ch == core.KEY_ENTER) then
43 -- XXX TODO: Evaluate if we really want this or not, as a
44 -- security consideration of sorts
45 if (ch == core.KEY_BACKSPACE) or (ch == core.KEY_DELETE) then
48 -- loader.printc("\008 \008");
52 -- loader.printc("*");
53 str = str .. string.char(ch);
60 function password.check()
62 -- pwd is optionally supplied if we want to check it
63 local function do_prompt(prompt, pwd)
65 loader.printc(prompt);
66 local read_pwd = password.read();
67 if (not pwd) or (pwd == read_pwd) then
68 -- Throw an extra newline after password prompt
72 print("\n\nloader: incorrect password!\n");
73 loader.delay(3*1000*1000);
76 local function compare(prompt, pwd)
80 do_prompt(prompt, pwd);
83 local boot_pwd = loader.getenv("bootlock_password");
84 compare("Boot password: ", boot_pwd);
86 local geli_prompt = loader.getenv("geom_eli_passphrase_prompt");
87 if (geli_prompt ~= nil) and (geli_prompt:lower() == "yes") then
88 local passphrase = do_prompt("GELI Passphrase: ");
89 loader.setenv("kern.geom.eli.passphrase", passphrase);
92 local pwd = loader.getenv("password");
96 compare("Password: ", pwd);