2018-02-12 15:32:00 +00:00
|
|
|
--
|
|
|
|
-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
|
2018-02-19 18:11:35 +00:00
|
|
|
-- Copyright (C) 2018 Kyle Evans <kevans@FreeBSD.org>
|
2018-02-12 15:32:00 +00:00
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- Redistribution and use in source and binary forms, with or without
|
|
|
|
-- modification, are permitted provided that the following conditions
|
|
|
|
-- are met:
|
|
|
|
-- 1. Redistributions of source code must retain the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer.
|
|
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer in the
|
|
|
|
-- documentation and/or other materials provided with the distribution.
|
|
|
|
--
|
|
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
-- SUCH DAMAGE.
|
|
|
|
--
|
|
|
|
-- $FreeBSD$
|
|
|
|
--
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local core = require("core")
|
|
|
|
local screen = require("screen")
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local password = {}
|
2018-02-19 17:54:22 +00:00
|
|
|
|
2018-02-20 14:45:58 +00:00
|
|
|
-- Module exports
|
2018-02-12 15:32:00 +00:00
|
|
|
function password.read()
|
2018-02-21 01:10:03 +00:00
|
|
|
local str = ""
|
|
|
|
local n = 0
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 20:17:08 +00:00
|
|
|
while true do
|
2018-02-21 01:10:03 +00:00
|
|
|
ch = io.getchar()
|
2018-02-21 01:35:19 +00:00
|
|
|
if ch == core.KEY_ENTER then
|
2018-02-21 01:10:03 +00:00
|
|
|
break
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-17 05:26:28 +00:00
|
|
|
-- XXX TODO: Evaluate if we really want this or not, as a
|
|
|
|
-- security consideration of sorts
|
2018-02-21 01:35:19 +00:00
|
|
|
if ch == core.KEY_BACKSPACE or ch == core.KEY_DELETE then
|
|
|
|
if n > 0 then
|
2018-02-21 01:10:03 +00:00
|
|
|
n = n - 1
|
|
|
|
-- loader.printc("\008 \008")
|
|
|
|
str = str:sub(1, n)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
else
|
2018-02-21 01:10:03 +00:00
|
|
|
-- loader.printc("*")
|
|
|
|
str = str .. string.char(ch)
|
|
|
|
n = n + 1
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-21 20:17:08 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
return str
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function password.check()
|
2018-02-21 01:10:03 +00:00
|
|
|
screen.clear()
|
|
|
|
screen.defcursor()
|
2018-02-17 05:26:28 +00:00
|
|
|
-- pwd is optionally supplied if we want to check it
|
|
|
|
local function do_prompt(prompt, pwd)
|
2018-02-21 01:35:19 +00:00
|
|
|
while true do
|
2018-02-21 01:10:03 +00:00
|
|
|
loader.printc(prompt)
|
|
|
|
local read_pwd = password.read()
|
2018-02-21 01:35:19 +00:00
|
|
|
if pwd == nil or pwd == read_pwd then
|
2018-02-17 05:52:25 +00:00
|
|
|
-- Throw an extra newline after password prompt
|
2018-02-21 01:10:03 +00:00
|
|
|
print("")
|
|
|
|
return read_pwd
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
print("\n\nloader: incorrect password!\n")
|
|
|
|
loader.delay(3*1000*1000)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-17 05:26:28 +00:00
|
|
|
end
|
|
|
|
local function compare(prompt, pwd)
|
2018-02-21 01:35:19 +00:00
|
|
|
if pwd == nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
return
|
2018-02-17 05:26:28 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
do_prompt(prompt, pwd)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local boot_pwd = loader.getenv("bootlock_password")
|
|
|
|
compare("Boot password: ", boot_pwd)
|
2018-02-12 15:32:00 +00:00
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local geli_prompt = loader.getenv("geom_eli_passphrase_prompt")
|
2018-02-21 01:35:19 +00:00
|
|
|
if geli_prompt ~= nil and geli_prompt:lower() == "yes" then
|
2018-02-21 01:10:03 +00:00
|
|
|
local passphrase = do_prompt("GELI Passphrase: ")
|
|
|
|
loader.setenv("kern.geom.eli.passphrase", passphrase)
|
2018-02-17 05:26:28 +00:00
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
local pwd = loader.getenv("password")
|
2018-02-21 01:35:19 +00:00
|
|
|
if pwd ~= nil then
|
2018-02-21 01:10:03 +00:00
|
|
|
core.autoboot()
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
2018-02-21 01:10:03 +00:00
|
|
|
compare("Password: ", pwd)
|
2018-02-12 15:32:00 +00:00
|
|
|
end
|
|
|
|
|
2018-02-21 01:10:03 +00:00
|
|
|
return password
|