password.lua (b57465454b35f6e24a6df02a93a27d0136c016d9) | password.lua (aedd6be5c7c3096828fafa6c1528f3966b9e3aa5) |
---|---|
1-- 2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org> 4-- All rights reserved. 5-- 6-- Redistribution and use in source and binary forms, with or without 7-- modification, are permitted provided that the following conditions 8-- are met: --- 13 unchanged lines hidden (view full) --- 22-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25-- SUCH DAMAGE. 26-- 27-- $FreeBSD$ 28-- 29 | 1-- 2-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org> 4-- All rights reserved. 5-- 6-- Redistribution and use in source and binary forms, with or without 7-- modification, are permitted provided that the following conditions 8-- are met: --- 13 unchanged lines hidden (view full) --- 22-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25-- SUCH DAMAGE. 26-- 27-- $FreeBSD$ 28-- 29 |
30local core = require("core"); 31local screen = require("screen"); | 30local core = require("core") 31local screen = require("screen") |
32 | 32 |
33local password = {}; | 33local password = {} |
34 35-- Module exports 36function password.read() | 34 35-- Module exports 36function password.read() |
37 local str = ""; 38 local n = 0; | 37 local str = "" 38 local n = 0 |
39 40 repeat | 39 40 repeat |
41 ch = io.getchar(); | 41 ch = io.getchar() |
42 if (ch == core.KEY_ENTER) then | 42 if (ch == core.KEY_ENTER) then |
43 break; | 43 break |
44 end 45 -- XXX TODO: Evaluate if we really want this or not, as a 46 -- security consideration of sorts 47 if (ch == core.KEY_BACKSPACE) or (ch == core.KEY_DELETE) then 48 if (n > 0) then | 44 end 45 -- XXX TODO: Evaluate if we really want this or not, as a 46 -- security consideration of sorts 47 if (ch == core.KEY_BACKSPACE) or (ch == core.KEY_DELETE) then 48 if (n > 0) then |
49 n = n - 1; 50 -- loader.printc("\008 \008"); 51 str = str:sub(1, n); | 49 n = n - 1 50 -- loader.printc("\008 \008") 51 str = str:sub(1, n) |
52 end 53 else | 52 end 53 else |
54 -- loader.printc("*"); 55 str = str .. string.char(ch); 56 n = n + 1; | 54 -- loader.printc("*") 55 str = str .. string.char(ch) 56 n = n + 1 |
57 end | 57 end |
58 until (n == 16); 59 return str; | 58 until (n == 16) 59 return str |
60end 61 62function password.check() | 60end 61 62function password.check() |
63 screen.clear(); 64 screen.defcursor(); | 63 screen.clear() 64 screen.defcursor() |
65 -- pwd is optionally supplied if we want to check it 66 local function do_prompt(prompt, pwd) 67 while (true) do | 65 -- pwd is optionally supplied if we want to check it 66 local function do_prompt(prompt, pwd) 67 while (true) do |
68 loader.printc(prompt); 69 local read_pwd = password.read(); | 68 loader.printc(prompt) 69 local read_pwd = password.read() |
70 if (not pwd) or (pwd == read_pwd) then 71 -- Throw an extra newline after password prompt | 70 if (not pwd) or (pwd == read_pwd) then 71 -- Throw an extra newline after password prompt |
72 print(""); 73 return read_pwd; | 72 print("") 73 return read_pwd |
74 end | 74 end |
75 print("\n\nloader: incorrect password!\n"); 76 loader.delay(3*1000*1000); | 75 print("\n\nloader: incorrect password!\n") 76 loader.delay(3*1000*1000) |
77 end 78 end 79 local function compare(prompt, pwd) 80 if (pwd == nil) then | 77 end 78 end 79 local function compare(prompt, pwd) 80 if (pwd == nil) then |
81 return; | 81 return |
82 end | 82 end |
83 do_prompt(prompt, pwd); | 83 do_prompt(prompt, pwd) |
84 end 85 | 84 end 85 |
86 local boot_pwd = loader.getenv("bootlock_password"); 87 compare("Boot password: ", boot_pwd); | 86 local boot_pwd = loader.getenv("bootlock_password") 87 compare("Boot password: ", boot_pwd) |
88 | 88 |
89 local geli_prompt = loader.getenv("geom_eli_passphrase_prompt"); | 89 local geli_prompt = loader.getenv("geom_eli_passphrase_prompt") |
90 if (geli_prompt ~= nil) and (geli_prompt:lower() == "yes") then | 90 if (geli_prompt ~= nil) and (geli_prompt:lower() == "yes") then |
91 local passphrase = do_prompt("GELI Passphrase: "); 92 loader.setenv("kern.geom.eli.passphrase", passphrase); | 91 local passphrase = do_prompt("GELI Passphrase: ") 92 loader.setenv("kern.geom.eli.passphrase", passphrase) |
93 end 94 | 93 end 94 |
95 local pwd = loader.getenv("password"); | 95 local pwd = loader.getenv("password") |
96 if (pwd ~= nil) then | 96 if (pwd ~= nil) then |
97 core.autoboot(); | 97 core.autoboot() |
98 end | 98 end |
99 compare("Password: ", pwd); | 99 compare("Password: ", pwd) |
100end 101 | 100end 101 |
102return password; | 102return password |