-
-
Notifications
You must be signed in to change notification settings - Fork 40.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement XAP 'secure' core requirements (#16843)
Co-authored-by: Drashna Jaelre <[email protected]> Co-authored-by: Stefan Kerkmann <[email protected]>
- Loading branch information
1 parent
ae4d518
commit 92a61aa
Showing
15 changed files
with
312 additions
and
13 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
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
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
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
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,39 @@ | ||
// Copyright 2022 QMK | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "secure.h" | ||
#include "process_secure.h" | ||
#include "quantum_keycodes.h" | ||
|
||
bool preprocess_secure(uint16_t keycode, keyrecord_t *record) { | ||
if (secure_is_unlocking()) { | ||
if (!record->event.pressed) { | ||
secure_keypress_event(record->event.key.row, record->event.key.col); | ||
} | ||
|
||
// Normal keypresses should be disabled until the sequence is completed | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool process_secure(uint16_t keycode, keyrecord_t *record) { | ||
#ifndef SECURE_DISABLE_KEYCODES | ||
if (!record->event.pressed) { | ||
if (keycode == SECURE_LOCK) { | ||
secure_lock(); | ||
return false; | ||
} | ||
if (keycode == SECURE_UNLOCK) { | ||
secure_unlock(); | ||
return false; | ||
} | ||
if (keycode == SECURE_TOGGLE) { | ||
secure_is_locked() ? secure_unlock() : secure_lock(); | ||
return false; | ||
} | ||
} | ||
#endif | ||
return true; | ||
} |
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,15 @@ | ||
// Copyright 2022 QMK | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include "action.h" | ||
|
||
/** \brief Intercept keycodes and detect unlock sequences | ||
*/ | ||
bool preprocess_secure(uint16_t keycode, keyrecord_t *record); | ||
|
||
/** \brief Handle any secure specific keycodes | ||
*/ | ||
bool process_secure(uint16_t keycode, keyrecord_t *record); |
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
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,87 @@ | ||
// Copyright 2022 QMK | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "secure.h" | ||
#include "timer.h" | ||
|
||
#ifndef SECURE_UNLOCK_TIMEOUT | ||
# define SECURE_UNLOCK_TIMEOUT 5000 | ||
#endif | ||
|
||
#ifndef SECURE_IDLE_TIMEOUT | ||
# define SECURE_IDLE_TIMEOUT 60000 | ||
#endif | ||
|
||
#ifndef SECURE_UNLOCK_SEQUENCE | ||
# define SECURE_UNLOCK_SEQUENCE \ | ||
{ \ | ||
{ 0, 0 } \ | ||
} | ||
#endif | ||
|
||
static secure_status_t secure_status = SECURE_LOCKED; | ||
static uint32_t unlock_time = 0; | ||
static uint32_t idle_time = 0; | ||
|
||
secure_status_t secure_get_status(void) { | ||
return secure_status; | ||
} | ||
|
||
void secure_lock(void) { | ||
secure_status = SECURE_LOCKED; | ||
} | ||
|
||
void secure_unlock(void) { | ||
secure_status = SECURE_UNLOCKED; | ||
idle_time = timer_read32(); | ||
} | ||
|
||
void secure_request_unlock(void) { | ||
if (secure_status == SECURE_LOCKED) { | ||
secure_status = SECURE_PENDING; | ||
unlock_time = timer_read32(); | ||
} | ||
} | ||
|
||
void secure_activity_event(void) { | ||
if (secure_status == SECURE_UNLOCKED) { | ||
idle_time = timer_read32(); | ||
} | ||
} | ||
|
||
void secure_keypress_event(uint8_t row, uint8_t col) { | ||
static const uint8_t sequence[][2] = SECURE_UNLOCK_SEQUENCE; | ||
static const uint8_t sequence_len = sizeof(sequence) / sizeof(sequence[0]); | ||
|
||
static uint8_t offset = 0; | ||
if ((sequence[offset][0] == row) && (sequence[offset][1] == col)) { | ||
offset++; | ||
if (offset == sequence_len) { | ||
offset = 0; | ||
secure_unlock(); | ||
} | ||
} else { | ||
offset = 0; | ||
secure_lock(); | ||
} | ||
} | ||
|
||
void secure_task(void) { | ||
#if SECURE_UNLOCK_TIMEOUT != 0 | ||
// handle unlock timeout | ||
if (secure_status == SECURE_PENDING) { | ||
if (timer_elapsed32(unlock_time) >= SECURE_UNLOCK_TIMEOUT) { | ||
secure_lock(); | ||
} | ||
} | ||
#endif | ||
|
||
#if SECURE_IDLE_TIMEOUT != 0 | ||
// handle idle timeout | ||
if (secure_status == SECURE_UNLOCKED) { | ||
if (timer_elapsed32(idle_time) >= SECURE_IDLE_TIMEOUT) { | ||
secure_lock(); | ||
} | ||
} | ||
#endif | ||
} |
Oops, something went wrong.