2014-04-29 12:26:51 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the TREZOR project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2015-03-02 20:33:06 +00:00
|
|
|
#include <ctype.h>
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
#include "layout2.h"
|
|
|
|
#include "storage.h"
|
|
|
|
#include "oled.h"
|
|
|
|
#include "bitmaps.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "util.h"
|
2014-08-08 17:09:54 +00:00
|
|
|
#include "qr_encode.h"
|
2016-11-17 19:10:57 +00:00
|
|
|
#include "timer.h"
|
2017-05-18 14:19:10 +00:00
|
|
|
#include "bignum.h"
|
2017-06-18 20:22:33 +00:00
|
|
|
#include "gettext.h"
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-07-26 15:51:54 +00:00
|
|
|
#define BITCOIN_DIVISIBILITY (8)
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
void *layoutLast = layoutHome;
|
|
|
|
|
2016-06-08 15:55:25 +00:00
|
|
|
void layoutDialogSwipe(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
|
|
|
layoutLast = layoutDialogSwipe;
|
|
|
|
oledSwipeLeft();
|
|
|
|
layoutDialog(icon, btnNo, btnYes, desc, line1, line2, line3, line4, line5, line6);
|
|
|
|
}
|
|
|
|
|
2014-12-21 17:58:56 +00:00
|
|
|
void layoutProgressSwipe(const char *desc, int permil)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
|
|
|
if (layoutLast == layoutProgressSwipe) {
|
|
|
|
oledClear();
|
|
|
|
} else {
|
|
|
|
layoutLast = layoutProgressSwipe;
|
|
|
|
oledSwipeLeft();
|
|
|
|
}
|
2014-12-21 17:58:56 +00:00
|
|
|
layoutProgress(desc, permil);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 17:52:38 +00:00
|
|
|
void layoutScreensaver(void)
|
|
|
|
{
|
|
|
|
layoutLast = layoutScreensaver;
|
|
|
|
oledClear();
|
|
|
|
oledRefresh();
|
|
|
|
}
|
|
|
|
|
2014-04-29 12:26:51 +00:00
|
|
|
void layoutHome(void)
|
|
|
|
{
|
2015-04-13 17:52:38 +00:00
|
|
|
if (layoutLast == layoutHome || layoutLast == layoutScreensaver) {
|
2014-04-29 12:26:51 +00:00
|
|
|
oledClear();
|
|
|
|
} else {
|
|
|
|
oledSwipeLeft();
|
|
|
|
}
|
2015-04-13 17:52:38 +00:00
|
|
|
layoutLast = layoutHome;
|
2017-06-18 20:22:33 +00:00
|
|
|
const char *label = storage_isInitialized() ? storage_getLabel() : _("Go to trezor.io/start");
|
2015-02-04 20:27:07 +00:00
|
|
|
const uint8_t *homescreen = storage_getHomescreen();
|
|
|
|
if (homescreen) {
|
|
|
|
BITMAP b;
|
|
|
|
b.width = 128;
|
|
|
|
b.height = 64;
|
|
|
|
b.data = homescreen;
|
|
|
|
oledDrawBitmap(0, 0, &b);
|
2014-04-29 12:26:51 +00:00
|
|
|
} else {
|
2015-02-04 20:27:07 +00:00
|
|
|
if (label && strlen(label) > 0) {
|
|
|
|
oledDrawBitmap(44, 4, &bmp_logo48);
|
|
|
|
oledDrawStringCenter(OLED_HEIGHT - 8, label);
|
|
|
|
} else {
|
|
|
|
oledDrawBitmap(40, 0, &bmp_logo64);
|
|
|
|
}
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2017-06-26 17:45:12 +00:00
|
|
|
if (storage_needsBackup()) {
|
|
|
|
oledBox(0, 0, 127, 8, false);
|
|
|
|
oledDrawStringCenter(0, "NEEDS BACKUP!");
|
|
|
|
}
|
2014-04-29 12:26:51 +00:00
|
|
|
oledRefresh();
|
2016-11-17 19:10:57 +00:00
|
|
|
|
|
|
|
// Reset lock screen timeout
|
2016-11-23 19:22:28 +00:00
|
|
|
system_millis_lock_start = system_millis;
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void layoutConfirmOutput(const CoinType *coin, const TxOutputType *out)
|
|
|
|
{
|
2017-05-18 14:19:10 +00:00
|
|
|
char str_out[32];
|
2017-07-26 15:54:04 +00:00
|
|
|
bn_format_uint64(out->amount, NULL, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out));
|
2014-04-29 12:26:51 +00:00
|
|
|
static char first_half[17 + 1];
|
|
|
|
strlcpy(first_half, out->address, sizeof(first_half));
|
2016-06-08 15:55:25 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Cancel"),
|
|
|
|
_("Confirm"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Confirm sending"),
|
2014-04-29 12:26:51 +00:00
|
|
|
str_out,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("to"),
|
2014-04-29 12:26:51 +00:00
|
|
|
first_half,
|
|
|
|
out->address + 17,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layoutConfirmTx(const CoinType *coin, uint64_t amount_out, uint64_t amount_fee)
|
|
|
|
{
|
2017-05-18 14:19:10 +00:00
|
|
|
char str_out[32], str_fee[32];
|
2017-07-26 15:54:04 +00:00
|
|
|
bn_format_uint64(amount_out, NULL, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out));
|
|
|
|
bn_format_uint64(amount_fee, NULL, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, BITCOIN_DIVISIBILITY, 0, false, str_fee, sizeof(str_fee));
|
2016-06-08 15:55:25 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Cancel"),
|
|
|
|
_("Confirm"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Really send"),
|
2014-04-29 12:26:51 +00:00
|
|
|
str_out,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("from your wallet?"),
|
|
|
|
_("Fee included:"),
|
2014-04-29 12:26:51 +00:00
|
|
|
str_fee,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-15 10:08:54 +00:00
|
|
|
void layoutFeeOverThreshold(const CoinType *coin, uint64_t fee)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
2017-05-18 14:19:10 +00:00
|
|
|
char str_fee[32];
|
2017-07-26 15:54:04 +00:00
|
|
|
bn_format_uint64(fee, NULL, coin->has_coin_shortcut ? coin->coin_shortcut : NULL, BITCOIN_DIVISIBILITY, 0, false, str_fee, sizeof(str_fee));
|
2016-06-08 15:55:25 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Cancel"),
|
|
|
|
_("Confirm"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Fee"),
|
2017-05-18 14:19:10 +00:00
|
|
|
str_fee,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("is unexpectedly high."),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL,
|
2017-06-18 20:22:33 +00:00
|
|
|
_("Send anyway?"),
|
2014-04-29 12:26:51 +00:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-27 16:23:04 +00:00
|
|
|
// split longer string into 4 rows, rowlen chars each
|
|
|
|
const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen)
|
2014-04-29 12:26:51 +00:00
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
static char str[4][32 + 1];
|
|
|
|
if (rowlen > 32) {
|
|
|
|
rowlen = 32;
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
|
|
|
memset(str, 0, sizeof(str));
|
2014-11-27 16:23:04 +00:00
|
|
|
strlcpy(str[0], (char *)msg, rowlen + 1);
|
|
|
|
if (len > rowlen) {
|
|
|
|
strlcpy(str[1], (char *)msg + rowlen, rowlen + 1);
|
|
|
|
}
|
|
|
|
if (len > rowlen * 2) {
|
|
|
|
strlcpy(str[2], (char *)msg + rowlen * 2, rowlen + 1);
|
|
|
|
}
|
|
|
|
if (len > rowlen * 3) {
|
|
|
|
strlcpy(str[3], (char *)msg + rowlen * 3, rowlen + 1);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2014-11-26 17:52:30 +00:00
|
|
|
static const char *ret[4] = { str[0], str[1], str[2], str[3] };
|
|
|
|
return ret;
|
|
|
|
}
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2014-11-26 17:52:30 +00:00
|
|
|
void layoutSignMessage(const uint8_t *msg, uint32_t len)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
_("Sign message?"),
|
2014-06-20 22:31:44 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
2014-04-29 12:26:51 +00:00
|
|
|
}
|
2014-06-02 18:40:20 +00:00
|
|
|
|
2016-04-25 21:03:57 +00:00
|
|
|
void layoutVerifyAddress(const char *address)
|
|
|
|
{
|
|
|
|
const char **str = split_message((const uint8_t *)address, strlen(address), 17);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_info, _("Cancel"), _("Confirm"),
|
|
|
|
_("Confirm address?"),
|
|
|
|
_("Message signed by:"),
|
2017-07-12 16:44:56 +00:00
|
|
|
str[0], str[1], str[2], NULL, NULL);
|
2016-04-25 21:03:57 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 18:40:20 +00:00
|
|
|
void layoutVerifyMessage(const uint8_t *msg, uint32_t len)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_info, _("Cancel"), _("Confirm"),
|
|
|
|
_("Verified message"),
|
2014-06-20 22:31:44 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
2014-06-02 18:40:20 +00:00
|
|
|
}
|
2014-06-07 12:21:59 +00:00
|
|
|
|
|
|
|
void layoutCipherKeyValue(bool encrypt, const char *key)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message((const uint8_t *)key, strlen(key), 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
encrypt ? _("Encode value of this key?") : _("Decode value of this key?"),
|
2014-06-20 22:31:44 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
2014-06-07 12:21:59 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2014-11-26 17:52:30 +00:00
|
|
|
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
signing ? _("Encrypt+Sign message?") : _("Encrypt message?"),
|
2014-11-26 17:52:30 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address)
|
|
|
|
{
|
2014-11-27 16:23:04 +00:00
|
|
|
const char **str = split_message(msg, len, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_info, NULL, _("OK"),
|
|
|
|
address ? _("Decrypted signed message") : _("Decrypted message"),
|
2014-11-26 17:52:30 +00:00
|
|
|
str[0], str[1], str[2], str[3], NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2017-09-04 06:12:33 +00:00
|
|
|
void layoutResetWord(const char *word, int pass, int word_pos, bool last)
|
|
|
|
{
|
|
|
|
layoutLast = layoutResetWord;
|
|
|
|
oledSwipeLeft();
|
|
|
|
|
|
|
|
const char *btnYes;
|
|
|
|
if (last) {
|
|
|
|
if (pass == 1) {
|
|
|
|
btnYes = _("Finish");
|
|
|
|
} else {
|
|
|
|
btnYes = _("Again");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
btnYes = _("Next");
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *action;
|
|
|
|
if (pass == 1) {
|
|
|
|
action = _("Please check the seed");
|
|
|
|
} else {
|
|
|
|
action = _("Write down the seed");
|
|
|
|
}
|
|
|
|
|
|
|
|
char index_str[] = "##th word is:";
|
|
|
|
if (word_pos < 10) {
|
|
|
|
index_str[0] = ' ';
|
|
|
|
} else {
|
|
|
|
index_str[0] = '0' + word_pos / 10;
|
|
|
|
}
|
|
|
|
index_str[1] = '0' + word_pos % 10;
|
|
|
|
if (word_pos == 1 || word_pos == 21) {
|
|
|
|
index_str[2] = 's'; index_str[3] = 't';
|
|
|
|
} else
|
|
|
|
if (word_pos == 2 || word_pos == 22) {
|
|
|
|
index_str[2] = 'n'; index_str[3] = 'd';
|
|
|
|
} else
|
|
|
|
if (word_pos == 3 || word_pos == 23) {
|
|
|
|
index_str[2] = 'r'; index_str[3] = 'd';
|
|
|
|
}
|
|
|
|
|
|
|
|
int left = 0;
|
|
|
|
oledClear();
|
|
|
|
oledDrawBitmap(0, 0, &bmp_icon_info);
|
|
|
|
left = bmp_icon_info.width + 4;
|
|
|
|
|
|
|
|
oledDrawString(left, 0 * 9, action);
|
|
|
|
oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str);
|
|
|
|
oledDrawStringDouble(left, 3 * 9, word);
|
|
|
|
oledHLine(OLED_HEIGHT - 13);
|
|
|
|
oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
|
|
|
|
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
|
|
|
|
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
|
|
|
oledRefresh();
|
|
|
|
}
|
|
|
|
|
2017-07-11 19:30:01 +00:00
|
|
|
void layoutAddress(const char *address, const char *desc, bool qrcode)
|
2014-08-08 17:09:54 +00:00
|
|
|
{
|
2017-07-11 19:30:01 +00:00
|
|
|
if (layoutLast != layoutAddress) {
|
|
|
|
oledSwipeLeft();
|
|
|
|
} else {
|
|
|
|
oledClear();
|
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
layoutLast = layoutAddress;
|
|
|
|
|
2017-07-11 19:30:01 +00:00
|
|
|
if (qrcode) {
|
|
|
|
static unsigned char bitdata[QR_MAX_BITDATA];
|
|
|
|
int side = qr_encode(QR_LEVEL_M, 0, address, 0, bitdata);
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2017-07-11 19:30:01 +00:00
|
|
|
if (side > 0 && side <= 29) {
|
|
|
|
oledInvert(0, 0, (side + 2) * 2, (side + 2) * 2);
|
|
|
|
for (int i = 0; i < side; i++) {
|
|
|
|
for (int j = 0; j< side; j++) {
|
|
|
|
int a = j * side + i;
|
|
|
|
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
|
|
|
|
oledClearPixel(2 + i * 2, 2 + j * 2);
|
|
|
|
oledClearPixel(3 + i * 2, 2 + j * 2);
|
|
|
|
oledClearPixel(2 + i * 2, 3 + j * 2);
|
|
|
|
oledClearPixel(3 + i * 2, 3 + j * 2);
|
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-11 19:30:01 +00:00
|
|
|
} else if (side > 0 && side <= 60) {
|
|
|
|
oledInvert(0, 0, (side + 3), (side + 3));
|
|
|
|
for (int i = 0; i < side; i++) {
|
|
|
|
for (int j = 0; j< side; j++) {
|
|
|
|
int a = j * side + i;
|
|
|
|
if (bitdata[a / 8] & (1 << (7 - a % 8))) {
|
|
|
|
oledClearPixel(2 + i, 2 + j);
|
|
|
|
}
|
2017-01-06 15:18:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-11 19:30:01 +00:00
|
|
|
uint32_t addrlen = strlen(address);
|
|
|
|
uint32_t rowlen = addrlen / 2;
|
|
|
|
if (addrlen % 2) {
|
|
|
|
rowlen++;
|
|
|
|
}
|
|
|
|
const char **str = split_message((const uint8_t *)address, addrlen, rowlen);
|
|
|
|
if (desc) {
|
|
|
|
oledDrawString(0, 0 * 9, desc);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
oledDrawString(0, (i + 1) * 9 + 4, str[i]);
|
|
|
|
}
|
2016-06-30 12:03:12 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2017-07-11 19:30:01 +00:00
|
|
|
if (!qrcode) {
|
|
|
|
static const char *btnNo = _("QR Code");
|
|
|
|
oledDrawString(2, OLED_HEIGHT - 8, btnNo);
|
|
|
|
oledInvert(0, OLED_HEIGHT - 9, oledStringWidth(btnNo) + 3, OLED_HEIGHT - 1);
|
2015-02-18 17:30:54 +00:00
|
|
|
}
|
2014-08-08 17:09:54 +00:00
|
|
|
|
2017-06-18 20:22:33 +00:00
|
|
|
static const char *btnYes = _("Continue");
|
2015-02-13 16:42:23 +00:00
|
|
|
oledDrawString(OLED_WIDTH - fontCharWidth('\x06') - 1, OLED_HEIGHT - 8, "\x06");
|
|
|
|
oledDrawString(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 3, OLED_HEIGHT - 8, btnYes);
|
|
|
|
oledInvert(OLED_WIDTH - oledStringWidth(btnYes) - fontCharWidth('\x06') - 4, OLED_HEIGHT - 9, OLED_WIDTH - 1, OLED_HEIGHT - 1);
|
2014-08-08 17:09:54 +00:00
|
|
|
|
|
|
|
oledRefresh();
|
|
|
|
}
|
2015-02-20 19:22:05 +00:00
|
|
|
|
2015-11-19 10:48:26 +00:00
|
|
|
void layoutPublicKey(const uint8_t *pubkey)
|
|
|
|
{
|
|
|
|
char hex[32*2+1], desc[16];
|
|
|
|
strlcpy(desc, "Public Key: 00", sizeof(desc));
|
|
|
|
data2hex(pubkey, 1, desc + 12);
|
|
|
|
data2hex(pubkey + 1, 32, hex);
|
|
|
|
const char **str = split_message((const uint8_t *)hex, 32*2, 16);
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, NULL, _("Continue"), NULL,
|
2015-11-19 10:48:26 +00:00
|
|
|
desc, str[0], str[1], str[2], str[3], NULL);
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:22:05 +00:00
|
|
|
void layoutSignIdentity(const IdentityType *identity, const char *challenge)
|
|
|
|
{
|
2015-04-02 14:48:50 +00:00
|
|
|
char row_proto[8 + 11 + 1];
|
2015-03-02 20:33:06 +00:00
|
|
|
char row_hostport[64 + 6 + 1];
|
|
|
|
char row_user[64 + 8 + 1];
|
|
|
|
|
2016-11-26 19:16:15 +00:00
|
|
|
bool is_gpg = (strcmp(identity->proto, "gpg") == 0);
|
|
|
|
|
2015-03-02 20:33:06 +00:00
|
|
|
if (identity->has_proto && identity->proto[0]) {
|
2015-08-21 15:04:38 +00:00
|
|
|
if (strcmp(identity->proto, "https") == 0) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("Web sign in to:"), sizeof(row_proto));
|
2016-11-26 19:16:15 +00:00
|
|
|
} else if (is_gpg) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("GPG sign for:"), sizeof(row_proto));
|
2015-08-21 15:04:38 +00:00
|
|
|
} else {
|
|
|
|
strlcpy(row_proto, identity->proto, sizeof(row_proto));
|
|
|
|
char *p = row_proto;
|
|
|
|
while (*p) { *p = toupper((int)*p); p++; }
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcat(row_proto, _(" login to:"), sizeof(row_proto));
|
2015-08-21 15:04:38 +00:00
|
|
|
}
|
2015-03-02 20:33:06 +00:00
|
|
|
} else {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("Login to:"), sizeof(row_proto));
|
2015-03-02 20:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_host && identity->host[0]) {
|
|
|
|
strlcpy(row_hostport, identity->host, sizeof(row_hostport));
|
|
|
|
if (identity->has_port && identity->port[0]) {
|
|
|
|
strlcat(row_hostport, ":", sizeof(row_hostport));
|
2015-03-03 16:42:25 +00:00
|
|
|
strlcat(row_hostport, identity->port, sizeof(row_hostport));
|
2015-03-02 20:33:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row_hostport[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_user && identity->user[0]) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_user, _("user: "), sizeof(row_user));
|
2015-03-02 20:33:06 +00:00
|
|
|
strlcat(row_user, identity->user, sizeof(row_user));
|
|
|
|
} else {
|
|
|
|
row_user[0] = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-26 19:16:15 +00:00
|
|
|
if (is_gpg) {
|
|
|
|
// Split "First Last <first@last.com>" into 2 lines:
|
|
|
|
// "First Last"
|
|
|
|
// "first@last.com"
|
|
|
|
char *email_start = strchr(row_hostport, '<');
|
|
|
|
if (email_start) {
|
|
|
|
strlcpy(row_user, email_start + 1, sizeof(row_user));
|
|
|
|
*email_start = 0;
|
|
|
|
char *email_end = strchr(row_user, '>');
|
|
|
|
if (email_end) {
|
|
|
|
*email_end = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
_("Do you want to sign in?"),
|
2015-03-02 20:33:06 +00:00
|
|
|
row_proto[0] ? row_proto : NULL,
|
|
|
|
row_hostport[0] ? row_hostport : NULL,
|
|
|
|
row_user[0] ? row_user : NULL,
|
2015-02-20 19:22:05 +00:00
|
|
|
challenge,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
2016-05-16 16:58:13 +00:00
|
|
|
|
2016-07-14 16:11:20 +00:00
|
|
|
void layoutDecryptIdentity(const IdentityType *identity)
|
|
|
|
{
|
|
|
|
char row_proto[8 + 11 + 1];
|
|
|
|
char row_hostport[64 + 6 + 1];
|
|
|
|
char row_user[64 + 8 + 1];
|
|
|
|
|
|
|
|
if (identity->has_proto && identity->proto[0]) {
|
|
|
|
strlcpy(row_proto, identity->proto, sizeof(row_proto));
|
|
|
|
char *p = row_proto;
|
|
|
|
while (*p) { *p = toupper((int)*p); p++; }
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcat(row_proto, _(" decrypt for:"), sizeof(row_proto));
|
2016-07-14 16:11:20 +00:00
|
|
|
} else {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_proto, _("Decrypt for:"), sizeof(row_proto));
|
2016-07-14 16:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_host && identity->host[0]) {
|
|
|
|
strlcpy(row_hostport, identity->host, sizeof(row_hostport));
|
|
|
|
if (identity->has_port && identity->port[0]) {
|
|
|
|
strlcat(row_hostport, ":", sizeof(row_hostport));
|
|
|
|
strlcat(row_hostport, identity->port, sizeof(row_hostport));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
row_hostport[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (identity->has_user && identity->user[0]) {
|
2017-06-18 20:22:33 +00:00
|
|
|
strlcpy(row_user, _("user: "), sizeof(row_user));
|
2016-07-14 16:11:20 +00:00
|
|
|
strlcat(row_user, identity->user, sizeof(row_user));
|
|
|
|
} else {
|
|
|
|
row_user[0] = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"),
|
|
|
|
_("Do you want to decrypt?"),
|
2016-07-14 16:11:20 +00:00
|
|
|
row_proto[0] ? row_proto : NULL,
|
|
|
|
row_hostport[0] ? row_hostport : NULL,
|
|
|
|
row_user[0] ? row_user : NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-06-09 16:11:19 +00:00
|
|
|
void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appicon) {
|
|
|
|
if (!appicon) {
|
|
|
|
appicon = &bmp_icon_question;
|
|
|
|
}
|
2017-06-18 20:22:33 +00:00
|
|
|
layoutDialog(appicon, NULL, verb, NULL, verb, _("U2F security key?"), NULL, appname, NULL, NULL);
|
2016-05-16 16:58:13 +00:00
|
|
|
}
|