-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
28 changed files
with
1,901 additions
and
1,475 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
Version=2.2 | ||
Version=3.2 |
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
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,22 @@ | ||
/* | ||
* This file is part of the Pico OpenPGP distribution (https://github.com/polhenarejos/pico-openpgp). | ||
* Copyright (c) 2022 Pol Henarejos. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program 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 | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "openpgp.h" | ||
|
||
int cmd_activate_file() { | ||
return SW_OK(); | ||
} |
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,29 @@ | ||
/* | ||
* This file is part of the Pico OpenPGP distribution (https://github.com/polhenarejos/pico-openpgp). | ||
* Copyright (c) 2022 Pol Henarejos. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program 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 | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "openpgp.h" | ||
#include "random.h" | ||
|
||
int cmd_challenge() { | ||
uint8_t *rb = (uint8_t *) random_bytes_get(apdu.ne); | ||
if (!rb) { | ||
return SW_WRONG_LENGTH(); | ||
} | ||
memcpy(res_APDU, rb, apdu.ne); | ||
res_APDU_size = apdu.ne; | ||
return SW_OK(); | ||
} |
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,69 @@ | ||
/* | ||
* This file is part of the Pico OpenPGP distribution (https://github.com/polhenarejos/pico-openpgp). | ||
* Copyright (c) 2022 Pol Henarejos. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program 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 | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "openpgp.h" | ||
#include "otp.h" | ||
|
||
int cmd_change_pin() { | ||
if (P1(apdu) != 0x0) { | ||
return SW_WRONG_P1P2(); | ||
} | ||
uint16_t fid = 0x1000 | P2(apdu); | ||
file_t *pw; | ||
if (!(pw = search_by_fid(fid, NULL, SPECIFY_EF))) { | ||
return SW_REFERENCE_NOT_FOUND(); | ||
} | ||
uint8_t pin_len = file_get_data(pw)[0]; | ||
uint16_t r = 0; | ||
if ((r = load_dek()) != PICOKEY_OK) { | ||
return SW_EXEC_ERROR(); | ||
} | ||
|
||
if (otp_key_1) { | ||
for (int i = 0; i < 32; i++) { | ||
dek[IV_SIZE + i] ^= otp_key_1[i]; | ||
} | ||
} | ||
r = check_pin(pw, apdu.data, pin_len); | ||
if (r != 0x9000) { | ||
return r; | ||
} | ||
uint8_t dhash[33]; | ||
dhash[0] = apdu.nc - pin_len; | ||
double_hash_pin(apdu.data + pin_len, apdu.nc - pin_len, dhash + 1); | ||
file_put_data(pw, dhash, sizeof(dhash)); | ||
|
||
file_t *tf = search_by_fid(EF_DEK, NULL, SPECIFY_EF); | ||
if (!tf) { | ||
return SW_REFERENCE_NOT_FOUND(); | ||
} | ||
uint8_t def[IV_SIZE + 32 + 32 + 32 + 32] = {0}; | ||
memcpy(def, file_get_data(tf), file_get_size(tf)); | ||
if (P2(apdu) == 0x81) { | ||
hash_multi(apdu.data + pin_len, apdu.nc - pin_len, session_pw1); | ||
memcpy(def + IV_SIZE, dek + IV_SIZE, 32); | ||
aes_encrypt_cfb_256(session_pw1, def, def + IV_SIZE, 32); | ||
} | ||
else if (P2(apdu) == 0x83) { | ||
hash_multi(apdu.data + pin_len, apdu.nc - pin_len, session_pw3); | ||
memcpy(def + IV_SIZE + 32 + 32, dek + IV_SIZE, 32); | ||
aes_encrypt_cfb_256(session_pw3, def, def + IV_SIZE + 32 + 32, 32); | ||
} | ||
file_put_data(tf, def, sizeof(def)); | ||
low_flash_available(); | ||
return SW_OK(); | ||
} |
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,91 @@ | ||
/* | ||
* This file is part of the Pico OpenPGP distribution (https://github.com/polhenarejos/pico-openpgp). | ||
* Copyright (c) 2022 Pol Henarejos. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program 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 | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "openpgp.h" | ||
#include "asn1.h" | ||
|
||
int cmd_get_data() { | ||
if (apdu.nc > 0) { | ||
return SW_WRONG_LENGTH(); | ||
} | ||
uint16_t fid = (P1(apdu) << 8) | P2(apdu); | ||
file_t *ef; | ||
if (!(ef = search_by_fid(fid, NULL, SPECIFY_EF))) { | ||
return SW_REFERENCE_NOT_FOUND(); | ||
} | ||
if (!authenticate_action(ef, ACL_OP_READ_SEARCH)) { | ||
return SW_SECURITY_STATUS_NOT_SATISFIED(); | ||
} | ||
if (currentEF && (currentEF->fid & 0x1FF0) == (fid & 0x1FF0)) { //previously selected | ||
ef = currentEF; | ||
} | ||
else { | ||
select_file(ef); | ||
} | ||
if (ef->data) { | ||
uint16_t fids[] = { 1, fid }; | ||
uint16_t data_len = parse_do(fids, 1); | ||
uint8_t *p = NULL; | ||
uint16_t tg = 0; | ||
uint16_t tg_len = 0; | ||
asn1_ctx_t ctxi; | ||
asn1_ctx_init(res_APDU, data_len, &ctxi); | ||
if (walk_tlv(&ctxi, &p, &tg, &tg_len, NULL)) { | ||
uint8_t dec = 2; | ||
if ((tg & 0x1f) == 0x1f) { | ||
dec++; | ||
} | ||
if ((res_APDU[dec - 1] & 0xF0) == 0x80) { | ||
dec += (res_APDU[dec - 1] & 0x0F); | ||
} | ||
if (tg_len + dec == data_len) { | ||
memmove(res_APDU, res_APDU + dec, data_len - dec); | ||
data_len -= dec; | ||
res_APDU_size -= dec; | ||
} | ||
} | ||
//if (apdu.ne > data_len) | ||
// apdu.ne = data_len; | ||
} | ||
return SW_OK(); | ||
} | ||
|
||
int cmd_get_next_data() { | ||
file_t *ef = NULL; | ||
if (apdu.nc > 0) { | ||
return SW_WRONG_LENGTH(); | ||
} | ||
if (!currentEF) { | ||
return SW_RECORD_NOT_FOUND(); | ||
} | ||
uint16_t fid = (P1(apdu) << 8) | P2(apdu); | ||
if (!(ef = search_by_fid(fid, NULL, SPECIFY_EF))) { | ||
return SW_REFERENCE_NOT_FOUND(); | ||
} | ||
if (!authenticate_action(ef, ACL_OP_UPDATE_ERASE)) { | ||
return SW_SECURITY_STATUS_NOT_SATISFIED(); | ||
} | ||
if ((currentEF->fid & 0x1FF0) != (fid & 0x1FF0)) { | ||
return SW_WRONG_P1P2(); | ||
} | ||
fid = currentEF->fid + 1; //curentEF contains private DO. so, we select the next one | ||
if (!(ef = search_by_fid(fid, NULL, SPECIFY_EF))) { | ||
return SW_REFERENCE_NOT_FOUND(); | ||
} | ||
select_file(ef); | ||
return cmd_get_data(); | ||
} |
Oops, something went wrong.