mirror of
https://github.com/polhenarejos/pico-openpgp.git
synced 2026-05-30 10:01:23 +02:00
Compare commits
5 Commits
v3.6
...
f34cdac00b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f34cdac00b | ||
|
|
f9c1178f4d | ||
|
|
68ac692de6 | ||
|
|
4480e29ecc | ||
|
|
fccc48de43 |
@@ -67,6 +67,7 @@ set(SOURCES ${SOURCES}
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/cmd_keypair_gen.c
|
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/cmd_keypair_gen.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/cmd_reset_retry.c
|
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/cmd_reset_retry.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/do.c
|
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/do.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/defs.c
|
||||||
)
|
)
|
||||||
|
|
||||||
set(USB_ITF_CCID 1)
|
set(USB_ITF_CCID 1)
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ int cmd_change_pin() {
|
|||||||
}
|
}
|
||||||
uint8_t pin_len = file_get_data(pw)[0];
|
uint8_t pin_len = file_get_data(pw)[0];
|
||||||
uint16_t r = 0;
|
uint16_t r = 0;
|
||||||
|
r = check_pin(pw, apdu.data, pin_len);
|
||||||
|
if (r != 0x9000) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
if ((r = load_dek()) != PICOKEY_OK) {
|
if ((r = load_dek()) != PICOKEY_OK) {
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
@@ -38,10 +42,6 @@ int cmd_change_pin() {
|
|||||||
dek[IV_SIZE + i] ^= otp_key_1[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];
|
uint8_t dhash[33];
|
||||||
dhash[0] = apdu.nc - pin_len;
|
dhash[0] = apdu.nc - pin_len;
|
||||||
double_hash_pin(apdu.data + pin_len, apdu.nc - pin_len, dhash + 1);
|
double_hash_pin(apdu.data + pin_len, apdu.nc - pin_len, dhash + 1);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ int cmd_internal_aut() {
|
|||||||
if (!ef) {
|
if (!ef) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
if (wait_button_pressed(EF_UIF_AUT) == true) {
|
if (wait_button_pressed_fid(EF_UIF_AUT) == true) {
|
||||||
return SW_SECURE_MESSAGE_EXEC_ERROR();
|
return SW_SECURE_MESSAGE_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
int r = PICOKEY_OK;
|
int r = PICOKEY_OK;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ int cmd_pso() {
|
|||||||
if (!ef) {
|
if (!ef) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
if (wait_button_pressed(pk_fid == EF_PK_SIG ? EF_UIF_SIG : EF_UIF_DEC) == true) {
|
if (wait_button_pressed_fid(pk_fid == EF_PK_SIG ? EF_UIF_SIG : EF_UIF_DEC) == true) {
|
||||||
return SW_SECURE_MESSAGE_EXEC_ERROR();
|
return SW_SECURE_MESSAGE_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
int r = PICOKEY_OK;
|
int r = PICOKEY_OK;
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ int cmd_terminate_df() {
|
|||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
initialize_flash(true);
|
initialize_flash(true);
|
||||||
scan_files();
|
scan_files_openpgp();
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
int cmd_version() {
|
int cmd_version_openpgp() {
|
||||||
res_APDU[res_APDU_size++] = PIPGP_VERSION_MAJOR;
|
res_APDU[res_APDU_size++] = PIPGP_VERSION_MAJOR;
|
||||||
res_APDU[res_APDU_size++] = PIPGP_VERSION_MINOR;
|
res_APDU[res_APDU_size++] = PIPGP_VERSION_MINOR;
|
||||||
res_APDU[res_APDU_size++] = 0x0;
|
res_APDU[res_APDU_size++] = 0x0;
|
||||||
|
|||||||
20
src/openpgp/defs.c
Normal file
20
src/openpgp/defs.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
uint8_t PICO_PRODUCT = 3;
|
||||||
@@ -34,8 +34,6 @@
|
|||||||
#include "mbedtls/eddsa.h"
|
#include "mbedtls/eddsa.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t PICO_PRODUCT = 3;
|
|
||||||
|
|
||||||
bool has_pw1 = false;
|
bool has_pw1 = false;
|
||||||
bool has_pw2 = false;
|
bool has_pw2 = false;
|
||||||
bool has_pw3 = false;
|
bool has_pw3 = false;
|
||||||
@@ -67,7 +65,7 @@ int openpgp_process_apdu();
|
|||||||
|
|
||||||
extern uint32_t board_button_read(void);
|
extern uint32_t board_button_read(void);
|
||||||
|
|
||||||
bool wait_button_pressed(uint16_t fid) {
|
bool wait_button_pressed_fid(uint16_t fid) {
|
||||||
uint32_t val = EV_PRESS_BUTTON;
|
uint32_t val = EV_PRESS_BUTTON;
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
file_t *ef = search_by_fid(fid, NULL, SPECIFY_ANY);
|
file_t *ef = search_by_fid(fid, NULL, SPECIFY_ANY);
|
||||||
@@ -99,7 +97,7 @@ void select_file(file_t *pe) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_files() {
|
void scan_files_openpgp() {
|
||||||
scan_flash();
|
scan_flash();
|
||||||
file_t *ef;
|
file_t *ef;
|
||||||
if ((ef = search_by_fid(EF_FULL_AID, NULL, SPECIFY_ANY))) {
|
if ((ef = search_by_fid(EF_FULL_AID, NULL, SPECIFY_ANY))) {
|
||||||
@@ -288,7 +286,7 @@ void init_openpgp() {
|
|||||||
algo_aut = EF_ALGO_PRIV3;
|
algo_aut = EF_ALGO_PRIV3;
|
||||||
pk_dec = EF_PK_DEC;
|
pk_dec = EF_PK_DEC;
|
||||||
pk_aut = EF_PK_AUT;
|
pk_aut = EF_PK_AUT;
|
||||||
scan_files();
|
scan_files_openpgp();
|
||||||
//cmd_select();
|
//cmd_select();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,7 +778,7 @@ extern int cmd_get_next_data();
|
|||||||
extern int cmd_put_data();
|
extern int cmd_put_data();
|
||||||
extern int cmd_verify();
|
extern int cmd_verify();
|
||||||
extern int cmd_select_data();
|
extern int cmd_select_data();
|
||||||
extern int cmd_version();
|
extern int cmd_version_openpgp();
|
||||||
extern int cmd_import_data();
|
extern int cmd_import_data();
|
||||||
extern int cmd_change_pin();
|
extern int cmd_change_pin();
|
||||||
extern int cmd_mse();
|
extern int cmd_mse();
|
||||||
@@ -825,7 +823,7 @@ static const cmd_t cmds[] = {
|
|||||||
{ INS_INTERNAL_AUT, cmd_internal_aut },
|
{ INS_INTERNAL_AUT, cmd_internal_aut },
|
||||||
{ INS_MSE, cmd_mse },
|
{ INS_MSE, cmd_mse },
|
||||||
{ INS_IMPORT_DATA, cmd_import_data },
|
{ INS_IMPORT_DATA, cmd_import_data },
|
||||||
{ INS_VERSION, cmd_version },
|
{ INS_VERSION, cmd_version_openpgp },
|
||||||
{ INS_SELECT_DATA, cmd_select_data },
|
{ INS_SELECT_DATA, cmd_select_data },
|
||||||
{ INS_GET_NEXT_DATA, cmd_get_next_data },
|
{ INS_GET_NEXT_DATA, cmd_get_next_data },
|
||||||
{ 0x00, 0x0 }
|
{ 0x00, 0x0 }
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ extern int check_pin(const file_t *pin, const uint8_t *data, size_t len);
|
|||||||
extern mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_len);
|
extern mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_len);
|
||||||
extern int reset_sig_count();
|
extern int reset_sig_count();
|
||||||
extern uint16_t algo_dec, algo_aut, pk_dec, pk_aut;
|
extern uint16_t algo_dec, algo_aut, pk_dec, pk_aut;
|
||||||
extern bool wait_button_pressed(uint16_t fid);
|
extern bool wait_button_pressed_fid(uint16_t fid);
|
||||||
extern void scan_files();
|
extern void scan_files_openpgp();
|
||||||
extern int load_aes_key(uint8_t *aes_key, file_t *fkey);
|
extern int load_aes_key(uint8_t *aes_key, file_t *fkey);
|
||||||
extern int inc_sig_count();
|
extern int inc_sig_count();
|
||||||
extern int dek_encrypt(uint8_t *data, size_t len);
|
extern int dek_encrypt(uint8_t *data, size_t len);
|
||||||
|
|||||||
Reference in New Issue
Block a user