Compare commits
91 Commits
v3.4-eddsa
...
nightly-ma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b7beeec8c | ||
|
|
1f037da326 | ||
|
|
ffbdef14b6 | ||
|
|
ad59aa8c1a | ||
|
|
fcca95715e | ||
|
|
704df76499 | ||
|
|
e6cc190c4f | ||
|
|
615737807a | ||
|
|
e563bb3379 | ||
|
|
374cff588c | ||
|
|
ca8d81fd20 | ||
|
|
5d71e69c1d | ||
|
|
75691b6a42 | ||
|
|
811f33e282 | ||
|
|
90b62f067d | ||
|
|
2e0f9d6b36 | ||
|
|
6ef122528f | ||
|
|
9c1dc102ce | ||
|
|
a94603b9e2 | ||
|
|
6af4cef91b | ||
|
|
551334a447 | ||
|
|
2ce4f22622 | ||
|
|
822038aba2 | ||
|
|
70b5e35bde | ||
|
|
4638a1c926 | ||
|
|
b6366ef1c0 | ||
|
|
d4d8ad86d5 | ||
|
|
c51d3e7d5e | ||
|
|
757d163ce9 | ||
|
|
2513608ba9 | ||
|
|
3710146074 | ||
|
|
5462458622 | ||
|
|
353471c599 | ||
|
|
b2538cf2b6 | ||
|
|
e136bb26e3 | ||
|
|
b1421e176b | ||
|
|
2a14c771cb | ||
|
|
90e77f7c61 | ||
|
|
504d90a2b3 | ||
|
|
c35d6f73d9 | ||
|
|
595455bbbc | ||
|
|
7a27dde253 | ||
|
|
e4fec2ab22 | ||
|
|
45d174b8bf | ||
|
|
73053bdc6d | ||
|
|
7936e20b9a | ||
|
|
9606e34630 | ||
|
|
81b012c0dd | ||
|
|
42a13b2777 | ||
|
|
9742991deb | ||
|
|
d938720ab5 | ||
|
|
b80a4693c6 | ||
|
|
321d02eb0d | ||
|
|
296fbd142f | ||
|
|
b606b75a12 | ||
|
|
331f4f1c4e | ||
|
|
abb432dd31 | ||
|
|
f3b7f3b42d | ||
|
|
d76e53f80b | ||
|
|
fc663cfdd6 | ||
|
|
47ac55abd1 | ||
|
|
286893bdb6 | ||
|
|
41ae81067c | ||
|
|
9c878cc5b6 | ||
|
|
31ac28c7de | ||
|
|
33ce1c50aa | ||
|
|
edfcd087c1 | ||
|
|
a713eb4e03 | ||
|
|
f2fe6dd5c2 | ||
|
|
1a24a9ed1b | ||
|
|
b62573a6bd | ||
|
|
58a9d9cf97 | ||
|
|
bc9681e7b0 | ||
|
|
c39b87019e | ||
|
|
f34cdac00b | ||
|
|
f9c1178f4d | ||
|
|
68ac692de6 | ||
|
|
4480e29ecc | ||
|
|
fccc48de43 | ||
|
|
d5a0d85b71 | ||
|
|
6dbc8f8f56 | ||
|
|
11840f1471 | ||
|
|
fc4391b433 | ||
|
|
b8a3969fad | ||
|
|
0cf673ac6d | ||
|
|
142511c494 | ||
|
|
6de499e435 | ||
|
|
ddb6b4b936 | ||
|
|
5ec7402e81 | ||
|
|
153c60fb47 | ||
|
|
3e5f882071 |
50
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
50
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
## Summary
|
||||||
|
|
||||||
|
Describe in plain language what this PR does and why.
|
||||||
|
|
||||||
|
- What problem does it solve?
|
||||||
|
- Is it a bug fix, a new feature, a cleanup/refactor…?
|
||||||
|
|
||||||
|
|
||||||
|
## Details / Impact
|
||||||
|
|
||||||
|
Please include any relevant details:
|
||||||
|
|
||||||
|
- Hardware / board(s) tested:
|
||||||
|
- Firmware / commit/base version:
|
||||||
|
- Security impact (if any):
|
||||||
|
- e.g. changes PIN handling, touches key storage, affects attestation, etc.
|
||||||
|
- Behavior changes:
|
||||||
|
- e.g. new command, new API surface, different defaults, etc.
|
||||||
|
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
How did you test this change?
|
||||||
|
|
||||||
|
- Steps to reproduce / validate:
|
||||||
|
- Expected vs actual results:
|
||||||
|
- Any logs / traces (please remove secrets):
|
||||||
|
|
||||||
|
|
||||||
|
## Licensing confirmation (required)
|
||||||
|
|
||||||
|
By checking the box below, you confirm ALL of the following:
|
||||||
|
|
||||||
|
- You are the author of this contribution, or you have the right to contribute it.
|
||||||
|
- You have read `CONTRIBUTING.md`.
|
||||||
|
- You agree that this contribution may be merged, used, modified, and redistributed:
|
||||||
|
- under the AGPLv3 Community Edition, **and**
|
||||||
|
- under any proprietary / commercial / Enterprise editions of this project,
|
||||||
|
now or in the future.
|
||||||
|
- You understand that submitting this PR does not create any support obligation,
|
||||||
|
SLA, or guarantee of merge.
|
||||||
|
|
||||||
|
**I confirm the above licensing terms:**
|
||||||
|
|
||||||
|
- [ ] Yes, I agree
|
||||||
|
|
||||||
|
|
||||||
|
## Anything else?
|
||||||
|
|
||||||
|
Optional: mention known limitations, follow-ups, or if this is related to an existing Issue.
|
||||||
11
.github/workflows/nightly.yml
vendored
11
.github/workflows/nightly.yml
vendored
@@ -19,15 +19,22 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ matrix.refs }}
|
ref: ${{ matrix.refs }}
|
||||||
submodules: 'recursive'
|
submodules: 'recursive'
|
||||||
|
- name: Restore private key
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.PRIVATE_KEY_B64 }}" | base64 -d > private.pem
|
||||||
|
chmod 600 private.pem
|
||||||
- name : Build
|
- name : Build
|
||||||
env:
|
env:
|
||||||
PICO_SDK_PATH: ../pico-sdk
|
PICO_SDK_PATH: ../pico-sdk
|
||||||
|
SECURE_BOOT_PKEY: ../private.pem
|
||||||
run: |
|
run: |
|
||||||
./workflows/autobuild.sh pico
|
./workflows/autobuild.sh pico
|
||||||
./build_pico_openpgp.sh
|
./build_pico_openpgp.sh --no-eddsa
|
||||||
./workflows/autobuild.sh esp32
|
./workflows/autobuild.sh esp32
|
||||||
|
- name: Delete private key
|
||||||
|
run: rm private.pem
|
||||||
- name: Update nightly release
|
- name: Update nightly release
|
||||||
uses: pyTooling/Actions/releaser@main
|
uses: pyTooling/Actions/releaser@v6.7.0
|
||||||
with:
|
with:
|
||||||
tag: nightly-${{ matrix.refs }}
|
tag: nightly-${{ matrix.refs }}
|
||||||
rm: true
|
rm: true
|
||||||
|
|||||||
@@ -17,8 +17,11 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
|
set(USB_VID 0x2E8A)
|
||||||
|
set(USB_PID 0x10FF)
|
||||||
|
|
||||||
if(ESP_PLATFORM)
|
if(ESP_PLATFORM)
|
||||||
set(EXTRA_COMPONENT_DIRS src pico-keys-sdk/src)
|
set(EXTRA_COMPONENT_DIRS pico-keys-sdk/config/esp32/components src/openpgp)
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
else()
|
else()
|
||||||
if(NOT ENABLE_EMULATION)
|
if(NOT ENABLE_EMULATION)
|
||||||
@@ -31,10 +34,6 @@ else()
|
|||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
if(NOT ENABLE_EMULATION)
|
|
||||||
pico_sdk_init()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT DEFINED __FOR_CI)
|
if(NOT DEFINED __FOR_CI)
|
||||||
set(__FOR_CI 0)
|
set(__FOR_CI 0)
|
||||||
endif()
|
endif()
|
||||||
@@ -45,6 +44,13 @@ else()
|
|||||||
add_executable(pico_openpgp)
|
add_executable(pico_openpgp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(USB_ITF_CCID 1)
|
||||||
|
set(USB_ITF_WCID 1)
|
||||||
|
include(pico-keys-sdk/pico_keys_sdk_import.cmake)
|
||||||
|
|
||||||
|
if(NOT ESP_PLATFORM)
|
||||||
|
set(SOURCES ${PICO_KEYS_SOURCES})
|
||||||
|
endif()
|
||||||
set(SOURCES ${SOURCES}
|
set(SOURCES ${SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c
|
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/files.c
|
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/files.c
|
||||||
@@ -67,13 +73,10 @@ 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_VERSION(ver_major ver_minor "${CMAKE_CURRENT_LIST_DIR}/src/openpgp/version.h")
|
||||||
set(USB_ITF_WCID 1)
|
|
||||||
include(pico-keys-sdk/pico_keys_sdk_import.cmake)
|
|
||||||
|
|
||||||
SET_VERSION(ver_major ver_minor "${CMAKE_CURRENT_LIST_DIR}/src/openpgp/version.h" 1)
|
|
||||||
|
|
||||||
if(ESP_PLATFORM)
|
if(ESP_PLATFORM)
|
||||||
project(pico_openpgp)
|
project(pico_openpgp)
|
||||||
@@ -117,7 +120,7 @@ if(NOT ESP_PLATFORM)
|
|||||||
-Wl,--gc-sections
|
-Wl,--gc-sections
|
||||||
)
|
)
|
||||||
endif(APPLE)
|
endif(APPLE)
|
||||||
target_link_libraries(pico_openpgp PRIVATE pthread m)
|
target_link_libraries(pico_openpgp PRIVATE pico_keys_sdk mbedtls pthread m)
|
||||||
else()
|
else()
|
||||||
pico_add_extra_outputs(${CMAKE_PROJECT_NAME})
|
pico_add_extra_outputs(${CMAKE_PROJECT_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
105
CONTRIBUTING.md
Normal file
105
CONTRIBUTING.md
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Thank you for your interest in contributing to this project.
|
||||||
|
|
||||||
|
This repository is published in two forms:
|
||||||
|
- a Community Edition released under AGPLv3, and
|
||||||
|
- a proprietary / commercial / Enterprise Edition offered to organizations.
|
||||||
|
|
||||||
|
To keep that model legally clean, we need to be explicit about how contributions can be used.
|
||||||
|
|
||||||
|
By opening a pull request, you agree to all of the following:
|
||||||
|
|
||||||
|
1. **You have the right to contribute this code.**
|
||||||
|
You are either the original author of the contribution, or you have obtained the necessary rights/permissions to contribute it under these terms.
|
||||||
|
|
||||||
|
2. **Dual licensing permission.**
|
||||||
|
You agree that your contribution may be:
|
||||||
|
- merged into this repository, and
|
||||||
|
- used, copied, modified, sublicensed, and redistributed
|
||||||
|
- under the AGPLv3 Community Edition, and
|
||||||
|
- under any proprietary / commercial / Enterprise editions of this project,
|
||||||
|
now or in the future.
|
||||||
|
|
||||||
|
In other words: you are granting the project maintainer(s) the right to include
|
||||||
|
your contribution in both the open-source (AGPLv3) codebase and in closed-source /
|
||||||
|
commercially licensed builds, without any additional approval or payment.
|
||||||
|
|
||||||
|
3. **Attribution.**
|
||||||
|
The maintainers may keep or add attribution lines such as
|
||||||
|
`Copyright (c) <your name>` or an AUTHORS / CONTRIBUTORS list.
|
||||||
|
The maintainers may also make changes for clarity, style, security, refactoring,
|
||||||
|
or integration reasons.
|
||||||
|
|
||||||
|
4. **No automatic SLA.**
|
||||||
|
Submitting a pull request does *not* create any support obligation,
|
||||||
|
service-level agreement, warranty, or guarantee that the contribution
|
||||||
|
will be reviewed, merged, or maintained.
|
||||||
|
|
||||||
|
5. **Potential rejection for business reasons.**
|
||||||
|
Features that fall under "Enterprise / Commercial" functionality
|
||||||
|
(e.g. multi-tenant provisioning at scale, centralized audit trails,
|
||||||
|
corporate policy enforcement, attestation/branding flows, key escrow / dual-control,
|
||||||
|
etc.) may be declined for the public AGPLv3 tree even if technically valid.
|
||||||
|
That is normal: some functionality is intentionally offered only
|
||||||
|
under commercial terms.
|
||||||
|
|
||||||
|
If you are not comfortable with these terms, **do not open a pull request yet.**
|
||||||
|
Instead, please open an Issue to start a discussion.
|
||||||
|
|
||||||
|
## How to contribute (technical side)
|
||||||
|
|
||||||
|
### 1. Bug reports / issues
|
||||||
|
- Please include:
|
||||||
|
- hardware / board revision
|
||||||
|
- firmware / commit hash
|
||||||
|
- exact steps to reproduce
|
||||||
|
- expected vs actual behavior
|
||||||
|
- logs / traces if available (strip secrets)
|
||||||
|
|
||||||
|
Security-sensitive findings: do **not** post publicly.
|
||||||
|
Send a short report by email instead so it can be triaged responsibly.
|
||||||
|
|
||||||
|
### 2. Small fixes / minor improvements
|
||||||
|
- You can open a PR directly for:
|
||||||
|
- bug fixes
|
||||||
|
- portability fixes / new board definitions
|
||||||
|
- clarifications in code comments
|
||||||
|
- build / tooling cleanup
|
||||||
|
- documentation of existing behavior
|
||||||
|
|
||||||
|
Please keep PRs focused (one logical change per PR if possible).
|
||||||
|
|
||||||
|
### 3. Larger features / behavior changes
|
||||||
|
- Please open an Issue first and describe:
|
||||||
|
- what problem you're solving (not just "add feature X")
|
||||||
|
- impact on existing flows / security model
|
||||||
|
- any new dependencies
|
||||||
|
|
||||||
|
This helps avoid doing a bunch of work on something that won't be accepted
|
||||||
|
in the Community Edition.
|
||||||
|
|
||||||
|
### 4. Coding style / security posture
|
||||||
|
- Aim for clarity and small, auditable changes. This code runs in places
|
||||||
|
where secrets live.
|
||||||
|
- No debug backdoors, no "just for testing" shortcuts left enabled.
|
||||||
|
- Keep external dependencies minimal and license-compatible
|
||||||
|
(MIT / Apache 2.0 / similarly permissive is usually fine).
|
||||||
|
|
||||||
|
### 5. Commit / PR format
|
||||||
|
- Use descriptive commit messages ("Fix PIN retry counter wrap" is better than "fix stuff").
|
||||||
|
- In the PR description, please include a short summary of what was changed and why.
|
||||||
|
- At the bottom of the PR description, **copy/paste and confirm the licensing line below**:
|
||||||
|
|
||||||
|
> I confirm that I have read `CONTRIBUTING.md` and I agree that this contribution may be used under both the AGPLv3 Community Edition and any proprietary / commercial / Enterprise editions of this project, now or in the future.
|
||||||
|
|
||||||
|
A PR without that confirmation may be delayed or closed without merge.
|
||||||
|
|
||||||
|
## Thank you
|
||||||
|
|
||||||
|
This project exists because people build on it, break it, fix it,
|
||||||
|
and push it into places it wasn't originally designed to go.
|
||||||
|
|
||||||
|
Whether you are here for research, hacking on hardware,
|
||||||
|
rolling out secure keys for a team, or building a commercial product:
|
||||||
|
thank you for helping improve it.
|
||||||
116
ENTERPRISE.md
Normal file
116
ENTERPRISE.md
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
# Enterprise / Commercial Edition
|
||||||
|
|
||||||
|
This project is offered under two editions:
|
||||||
|
|
||||||
|
## 1. Community Edition (FOSS)
|
||||||
|
|
||||||
|
The Community Edition is released under the GNU Affero General Public License v3 (AGPLv3).
|
||||||
|
|
||||||
|
Intended for:
|
||||||
|
- individual users and researchers
|
||||||
|
- evaluation / prototyping
|
||||||
|
- internal lab / security testing
|
||||||
|
|
||||||
|
You are allowed to:
|
||||||
|
- read and study the source code
|
||||||
|
- modify it
|
||||||
|
- run it internally
|
||||||
|
|
||||||
|
Obligations under AGPLv3:
|
||||||
|
- If you distribute modified firmware/binaries/libraries to third parties, you must provide the corresponding source code of your modifications.
|
||||||
|
- If you run a modified version of this project as a network-accessible service (internal or external), you must offer the source code of those modifications to the users of that service.
|
||||||
|
- No warranty, no support, no SLA.
|
||||||
|
- Enterprise features (bulk provisioning, multi-user policy enforcement, device inventory / revocation, corporate PIN rules, custom attestation/identity, etc.) are NOT included.
|
||||||
|
|
||||||
|
The Community Edition will continue to exist.
|
||||||
|
|
||||||
|
## 2. Enterprise / Commercial Edition
|
||||||
|
|
||||||
|
The Enterprise / Commercial Edition is a proprietary license for organizations that need to:
|
||||||
|
|
||||||
|
- deploy this in production at scale (multiple devices / multiple users / multiple teams)
|
||||||
|
- integrate it into their own physical product or appliance
|
||||||
|
- run it as an internal service (VM / container / private cloud "HSM / auth backend") for multiple internal teams or tenants
|
||||||
|
- enforce internal security policy (admin vs user roles, mandatory PIN rules, secure offboarding / revocation)
|
||||||
|
- avoid any AGPLv3 disclosure obligations for their own modifications and integration code
|
||||||
|
|
||||||
|
### What the Enterprise Edition provides
|
||||||
|
|
||||||
|
**Base license package (always included):**
|
||||||
|
- **Commercial license (proprietary).**
|
||||||
|
You may run and integrate the software/firmware in production — including virtualized / internal-cloud style deployments — without being required to disclose derivative source code under AGPLv3.
|
||||||
|
- **Official signed builds.**
|
||||||
|
You receive signed builds from the original developer so you can prove integrity and provenance.
|
||||||
|
- **Onboarding call (up to 1 hour).**
|
||||||
|
A live remote session to get you from "we have it" to "it’s actually running in our environment" with minimal guesswork.
|
||||||
|
|
||||||
|
**Optional enterprise components (available on demand, scoped and priced per customer):**
|
||||||
|
- **Production / multi-user readiness.**
|
||||||
|
Permission to operate the system with multiple users, multiple devices and multiple teams in real environments.
|
||||||
|
- **Bulk / fleet provisioning.**
|
||||||
|
Automated enrollment for many tokens/devices/users at once (CSV / directory import), scripted onboarding of new users, initial PIN assignment / reset workflows, and role-based access (admin vs user).
|
||||||
|
- **Policy & lifecycle tooling.**
|
||||||
|
Corporate PIN policy enforcement, per-user / per-team access control, device inventory / traceability, and secure revocation / retirement when someone leaves.
|
||||||
|
- **Custom attestation / per-organization identity.**
|
||||||
|
Per-company certificate chains and attestation keys so devices can prove "this token/HSM is officially ours," including anti-cloning / unique device identity for OEM and fleet use.
|
||||||
|
- **Virtualization / internal cloud deployment support.**
|
||||||
|
Guidance and components to run this as an internal service (VM, container, private-cloud HSM/auth backend) serving multiple internal teams or tenants under your brand.
|
||||||
|
- **Post-quantum (PQC) key material handling.**
|
||||||
|
Integration/roadmap support for PQC algorithms (auth / signing) and secure PQC key storage inside the device or service.
|
||||||
|
- **Hierarchical deterministic key derivation (HD).**
|
||||||
|
Wallet-style hierarchical key trees (BIP32-like concepts adapted to this platform) for issuing per-user / per-tenant / per-purpose subkeys without exporting the root secret — e.g. embedded wallet logic, tenant isolation, firmware signing trees, large fleets.
|
||||||
|
- **Cryptographically signed audit trail / tamper-evident event logging.**
|
||||||
|
High-assurance logging of sensitive actions (key use, provisioning, PIN resets, revocations) with integrity protection for forensic / compliance needs.
|
||||||
|
- **Dual-control / two-person approval ("four-eyes").**
|
||||||
|
Require multi-party authorization for high-risk actions such as firmware signing, key export, or critical configuration changes — standard in high-assurance / regulated environments.
|
||||||
|
- **Secure key escrow / disaster recovery design.**
|
||||||
|
Split-secret or escrowed backup strategies so you don’t lose critical signing keys if a single admin disappears or hardware is lost.
|
||||||
|
- **Release-signing / supply-chain hardening pipeline.**
|
||||||
|
Reference tooling and process so every production firmware/binary is signed with hardware-backed keys, proving origin and preventing tampering in transit or at manufacturing.
|
||||||
|
- **Policy-locked hardened mode ("FIPS-style profile").**
|
||||||
|
Restricted algorithms, debug disabled, no raw key export, tamper-evident configuration for regulated / high-assurance deployments.
|
||||||
|
- **Priority support / security response SLA.**
|
||||||
|
A direct line and guaranteed response window for production-impacting security issues.
|
||||||
|
- **White-label demo / pre-sales bundle.**
|
||||||
|
Branded demo firmware + safe onboarding script so you can show "your product" to your own customers without exposing real production secrets.
|
||||||
|
|
||||||
|
These components are NOT automatically bundled. They are available case-by-case depending on your use case and are priced separately.
|
||||||
|
|
||||||
|
### Licensing models
|
||||||
|
|
||||||
|
- **Internal Use License**
|
||||||
|
Internal production use within one legal entity (your company), including internal private cloud / virtualized deployments for multiple internal teams.
|
||||||
|
Optional enterprise components can be added as needed.
|
||||||
|
|
||||||
|
- **OEM / Redistribution / Service License**
|
||||||
|
Integration into a product/appliance you ship to customers, OR operating this as a managed service / hosted feature for external clients or third parties.
|
||||||
|
Optional enterprise components (attestation branding, PQC support, HD key derivation, multi-tenant service hardening, audit trail, etc.) can be added as required.
|
||||||
|
|
||||||
|
Pricing depends on scope, fleet size, number of users/tenants, regulatory requirements, and which optional components you select.
|
||||||
|
|
||||||
|
### Request a quote
|
||||||
|
|
||||||
|
Email: pol@henarejos.me
|
||||||
|
Subject: `ENTERPRISE LICENSE <your company name>`
|
||||||
|
|
||||||
|
Please include:
|
||||||
|
- Company name and country
|
||||||
|
- Intended use:
|
||||||
|
- Internal private deployment
|
||||||
|
- OEM / external service to third parties
|
||||||
|
- Approximate scale (number of devices/tokens, number of users/tenants)
|
||||||
|
- Which optional components you are interested in (bulk provisioning, policy & lifecycle tooling, attestation branding / anti-cloning, virtualization/cloud, PQC, HD key derivation, audit trail, dual-control, key escrow, supply-chain signing, hardened mode, SLA, white-label demo)
|
||||||
|
|
||||||
|
You will receive:
|
||||||
|
1. A short commercial license agreement naming your company.
|
||||||
|
2. Access to the base package (and any optional components agreed).
|
||||||
|
3. Scheduling of the onboarding call.
|
||||||
|
|
||||||
|
## Why Enterprise exists
|
||||||
|
|
||||||
|
- Companies often need hardware-backed security (HSM, FIDO2, OpenPGP, etc.) under their own control, but cannot or will not open-source their internal security workflows.
|
||||||
|
- They also need multi-user / fleet-management features that hobby users do not.
|
||||||
|
- The commercial license funds continued development, maintenance and new hardware support.
|
||||||
|
|
||||||
|
The Community Edition remains AGPLv3.
|
||||||
|
The Enterprise Edition is for production, scale, and legal clarity.
|
||||||
141
LICENSE
141
LICENSE
@@ -1,5 +1,5 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
@@ -7,17 +7,15 @@
|
|||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
software and other kinds of works.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
share and change all versions of a program--to make sure it remains free
|
share and change all versions of a program--to make sure it remains free
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
software for all its users.
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
@@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
|
|||||||
want it, that you can change the software or use pieces of it in new
|
want it, that you can change the software or use pieces of it in new
|
||||||
free programs, and that you know you can do these things.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
Developers that use our General Public Licenses protect your rights
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
you this License which gives you legal permission to copy, distribute
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
and/or modify the software.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
A secondary benefit of defending all users' freedom is that
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
improvements made in alternate versions of the program, if they
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
receive widespread use, become available for other developers to
|
||||||
or can get the source code. And you must show them these terms so they
|
incorporate. Many developers of free software are heartened and
|
||||||
know their rights.
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
The GNU Affero General Public License is designed specifically to
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
ensure that, in such cases, the modified source code becomes available
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
An older license, called the Affero General Public License and
|
||||||
that there is no warranty for this free software. For both users' and
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
changed, so that their problems will not be attributed erroneously to
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
authors of previous versions.
|
this license.
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
@@ -72,7 +60,7 @@ modification follow.
|
|||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
works, such as semiconductor masks.
|
works, such as semiconductor masks.
|
||||||
@@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
|
|||||||
the Program, the only way you could satisfy both those terms and this
|
the Program, the only way you could satisfy both those terms and this
|
||||||
License would be to refrain entirely from conveying the Program.
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
Notwithstanding any other provision of this License, you have
|
||||||
permission to link or combine any covered work with a work licensed
|
permission to link or combine any covered work with a work licensed
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
under version 3 of the GNU General Public License into a single
|
||||||
combined work, and to convey the resulting work. The terms of this
|
combined work, and to convey the resulting work. The terms of this
|
||||||
License will continue to apply to the part which is the covered work,
|
License will continue to apply to the part which is the covered work,
|
||||||
but the special requirements of the GNU Affero General Public License,
|
but the work with which it is combined will remain governed by version
|
||||||
section 13, concerning interaction through a network will apply to the
|
3 of the GNU General Public License.
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
the GNU General Public License from time to time. Such new versions will
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the
|
||||||
Program specifies that a certain numbered version of the GNU General
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
Public License "or any later version" applies to it, you have the
|
Public License "or any later version" applies to it, you have the
|
||||||
option of following the terms and conditions either of that numbered
|
option of following the terms and conditions either of that numbered
|
||||||
version or of any later version published by the Free Software
|
version or of any later version published by the Free Software
|
||||||
Foundation. If the Program does not specify a version number of the
|
Foundation. If the Program does not specify a version number of the
|
||||||
GNU General Public License, you may choose any version ever published
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
by the Free Software Foundation.
|
by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
public statement of acceptance of a version permanently authorizes you
|
public statement of acceptance of a version permanently authorizes you
|
||||||
to choose that version for the Program.
|
to choose that version for the Program.
|
||||||
|
|
||||||
@@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
Copyright (C) <year> <name of author>
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
If your software can interact with users remotely through a computer
|
||||||
notice like this when it starts in an interactive mode:
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
<program> Copyright (C) <year> <name of author>
|
interface could display a "Source" link that leads users to an archive
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
of the code. There are many ways you could offer source, and different
|
||||||
This is free software, and you are welcome to redistribute it
|
solutions will be better for different programs; see section 13 for the
|
||||||
under certain conditions; type `show c' for details.
|
specific requirements.
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
<https://www.gnu.org/licenses/>.
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
|
|||||||
69
README.md
69
README.md
@@ -3,6 +3,8 @@ This project aims at transforming your Raspberry Pico or ESP32 microcontroller i
|
|||||||
|
|
||||||
OpenPGP cards are used to manage PGP keys and do cryptographic operations, such as keypair generation, signing and asymmetric deciphering. Pico OpenPGP follows the [**OpenPGP 3.4.1** specifications](https://gnupg.org/ftp/specs/OpenPGP-smart-card-application-3.4.pdf "**OpenPGP 3.4.1** specifications"), available at [GnuPG](http://gnupg.org "GnuPG").
|
OpenPGP cards are used to manage PGP keys and do cryptographic operations, such as keypair generation, signing and asymmetric deciphering. Pico OpenPGP follows the [**OpenPGP 3.4.1** specifications](https://gnupg.org/ftp/specs/OpenPGP-smart-card-application-3.4.pdf "**OpenPGP 3.4.1** specifications"), available at [GnuPG](http://gnupg.org "GnuPG").
|
||||||
|
|
||||||
|
If you are looking for a OpenPGP + Fido, see: https://github.com/polhenarejos/pico-fido2. Available through [PicoKey App](https://www.picokeys.com/picokeyapp/ "PicoKey App").
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
Pico OpenPGP has implemented the following features:
|
Pico OpenPGP has implemented the following features:
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ Pico OpenPGP has implemented the following features:
|
|||||||
- Secure Boot and Secure Lock in RP2350 and ESP32-S3 MCUs.
|
- Secure Boot and Secure Lock in RP2350 and ESP32-S3 MCUs.
|
||||||
- One Time Programming to store the master key that encrypts all resident keys and seeds.
|
- One Time Programming to store the master key that encrypts all resident keys and seeds.
|
||||||
- Rescue interface to allow recovery of the device if it becomes unresponsive or undetectable.
|
- Rescue interface to allow recovery of the device if it becomes unresponsive or undetectable.
|
||||||
- LED customization with Pico Commissioner.
|
- LED customization with PicoKey App.
|
||||||
|
|
||||||
All these features are compliant with the specification. Therefore, if you detect some behaviour that is not expected or it does not follow the rules of specs, please open an issue.
|
All these features are compliant with the specification. Therefore, if you detect some behaviour that is not expected or it does not follow the rules of specs, please open an issue.
|
||||||
|
|
||||||
@@ -60,26 +62,16 @@ If the Pico is stolen the contents of private and secret keys cannot be read wit
|
|||||||
### RP2350 and ESP32-S3
|
### RP2350 and ESP32-S3
|
||||||
RP2350 and ESP32-S3 microcontrollers are equipped with advanced security features, including Secure Boot and Secure Lock, ensuring that firmware integrity and authenticity are tightly controlled. Both devices support the storage of the Device Encryption Key (DEK) in an OTP (One-Time Programmable) memory region, making it permanently inaccessible for external access or tampering. This secure, non-volatile region guarantees that critical security keys are embedded into the hardware, preventing unauthorized access and supporting robust defenses against code injection or firmware modification. Together, Secure Boot and Secure Lock enforce firmware authentication, while the DEK in OTP memory solidifies the foundation for secure operations.
|
RP2350 and ESP32-S3 microcontrollers are equipped with advanced security features, including Secure Boot and Secure Lock, ensuring that firmware integrity and authenticity are tightly controlled. Both devices support the storage of the Device Encryption Key (DEK) in an OTP (One-Time Programmable) memory region, making it permanently inaccessible for external access or tampering. This secure, non-volatile region guarantees that critical security keys are embedded into the hardware, preventing unauthorized access and supporting robust defenses against code injection or firmware modification. Together, Secure Boot and Secure Lock enforce firmware authentication, while the DEK in OTP memory solidifies the foundation for secure operations.
|
||||||
|
|
||||||
### Secure Boot
|
|
||||||
Secure Boot is a security feature that ensures that only trusted firmware, verified through digital signatures, can be loaded onto the device during the boot process. Once enabled, Secure Boot checks every piece of firmware against a cryptographic signature before execution, rejecting any unauthorized or modified code. This prevents malicious firmware from compromising the device’s operation and integrity. With Secure Boot activated, only firmware versions signed by a trusted authority, such as the device manufacturer, will be accepted, ensuring the device remains protected from unauthorized software modifications. **This is irreversible. Once enabled, it CANNOT be disabled.**
|
|
||||||
|
|
||||||
**IMPORTANT:** For users wishing to develop and compile custom firmware, a private-public key pair is essential. Activating Secure Boot requires users to generate and manage their own unique private-public key pair. The public key from this pair must be embedded into the device to validate all firmware. Firmware will not boot without a proper digital signature from this key pair. This means that users must sign all future firmware versions with their private key and embed the public key in the device to ensure compatibility.
|
|
||||||
|
|
||||||
### Secure Lock
|
|
||||||
Secure Lock builds on Secure Boot by imposing an even stricter security model. Once activated, Secure Lock prevents any further installation of new boot keys, effectively locking the device to only run firmware that is authorized by the device's primary vendor—in this case, Pico Keys. In addition to preventing additional keys, Secure Lock disables debugging interfaces and puts additional safeguards in place to resist tampering and intrusion attempts. This ensures that the device operates exclusively with the original vendor’s firmware and resists unauthorized access, making it highly secure against external threats. **This is irreversible. Once enabled, it CANNOT be disabled.**
|
|
||||||
|
|
||||||
**IMPORTANT:** Activating Secure Lock not only enables Secure Boot but also invalidates all keys except the official Pico Key. This means that only firmware signed by Pico Key will be recognized, and custom code will no longer be allowed. Once enabled, the Pico Key device will run solely on the official firmware available on the website, with no option for generating or compiling new code for the device.
|
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
**If you own an ESP32-S3 board, go to [ESP32 Flasher](https://www.picokeys.com/esp32-flasher/) for flashing your Pico OpenPGP.**
|
**If you own an ESP32-S3 board, go to [ESP32 Flasher](https://www.picokeys.com/esp32-flasher/) for flashing your Pico OpenPGP.**
|
||||||
|
|
||||||
If you own a Raspberry Pico (RP2040 or RP2350), go to [Download page](https://www.picokeys.com/getting-started/), select your vendor and model and download the proper firmware; or go to [Release page](https://www.github.com/polhenarejos/pico-openpgp/releases/) and download the UF2 file for your board.
|
If you own a Raspberry Pico (RP2040 or RP2350), go to [Download page](https://www.picokeys.com/getting-started/), select your vendor and model and download the proper firmware; or go to [Release page](https://www.github.com/polhenarejos/pico-openpgp/releases/) and download the UF2 file for your board.
|
||||||
|
|
||||||
Note that UF2 files are shiped with a dummy VID/PID to avoid license issues (FEFF:FCFD). If you plan to use it with OpenSC or similar tools, you should modify Info.plist of CCID driver to add these VID/PID or use the [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner").
|
UF2 files are shiped with a VID/PID granted by RaspberryPi (2E8A:10FF). If you plan to use it with OpenSC or similar tools, you should modify Info.plist of CCID driver to add these VID/PID or use the [PicoKey App](https://www.picokeys.com/picokeyapp/ "PicoKey App").
|
||||||
|
|
||||||
You can use whatever VID/PID (i.e., 234b:0000 from FISJ), but remember that you are not authorized to distribute the binary with a VID/PID that you do not own.
|
You can use whatever VID/PID for internal purposes, but remember that you are not authorized to distribute the binary with a VID/PID that you do not own.
|
||||||
|
|
||||||
Note that the pure-browser option [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner") is the most recommended.
|
Note that the [PicoKey App](https://www.picokeys.com/picokeyapp/ "PicoKey App") is the most recommended.
|
||||||
|
|
||||||
## Build for Raspberry Pico
|
## Build for Raspberry Pico
|
||||||
Before building, ensure you have installed the toolchain for the Pico and the Pico SDK is properly located in your drive.
|
Before building, ensure you have installed the toolchain for the Pico and the Pico SDK is properly located in your drive.
|
||||||
@@ -167,9 +159,56 @@ The way to communicate is exactly the same as with other cards, such as OpenPGP
|
|||||||
|
|
||||||
### Important
|
### Important
|
||||||
OpenSC relies on PCSC driver, which reads a list (`Info.plist`) that contains a pair of VID/PID of supported readers. In order to be detectable, you have several options:
|
OpenSC relies on PCSC driver, which reads a list (`Info.plist`) that contains a pair of VID/PID of supported readers. In order to be detectable, you have several options:
|
||||||
- Use the pure-browser online [Pico Commissioner](https://www.picokeys.com/pico-commissioner/ "Pico Commissioner") that commissions the Pico Key on-the-fly without external tools.
|
- Use the [PicoKey App](https://www.picokeys.com/picokeyapp/ "PicoKey App") that commissions the PicoKey on-the-fly without external tools.
|
||||||
- Build and configure the project with the proper VID/PID with `USB_VID` and `USB_PID` parameters in `CMake` (see [Build section](#build "Build section")). Note that you cannot distribute the patched/compiled binary if you do not own the VID/PID or have an explicit authorization.
|
- Build and configure the project with the proper VID/PID with `USB_VID` and `USB_PID` parameters in `CMake` (see [Build section](#build "Build section")). Note that you cannot distribute the patched/compiled binary if you do not own the VID/PID or have an explicit authorization.
|
||||||
|
|
||||||
|
## License and Commercial Use
|
||||||
|
|
||||||
|
This project is available under two editions:
|
||||||
|
|
||||||
|
**Community Edition (FOSS)**
|
||||||
|
- Released under the GNU Affero General Public License v3 (AGPLv3).
|
||||||
|
- You are free to study, modify, and run the code, including for internal evaluation.
|
||||||
|
- If you distribute modified binaries/firmware, OR if you run a modified version of this project as a network-accessible service, you must provide the corresponding source code to the users of that binary or service, as required by AGPLv3.
|
||||||
|
- No warranty. No SLA. No guaranteed support.
|
||||||
|
|
||||||
|
**Enterprise / Commercial Edition**
|
||||||
|
- Proprietary license for organizations that want to:
|
||||||
|
- run this in production with multiple users/devices,
|
||||||
|
- integrate it into their own product/appliance,
|
||||||
|
- enforce corporate policies (PIN policy, admin/user roles, revocation),
|
||||||
|
- deploy it as an internal virtualized / cloud-style service,
|
||||||
|
- and *not* be required to publish derivative source code.
|
||||||
|
- Base package includes:
|
||||||
|
- commercial license (no AGPLv3 disclosure obligation for your modifications / integration)
|
||||||
|
- onboarding call
|
||||||
|
- access to officially signed builds
|
||||||
|
- Optional / on-demand enterprise components that can be added case-by-case:
|
||||||
|
- ability to operate in multi-user / multi-device environments
|
||||||
|
- device inventory, traceability and secure revocation/offboarding
|
||||||
|
- custom attestation, per-organization device identity / anti-cloning
|
||||||
|
- virtualization / internal "HSM or auth backend" service for multiple teams or tenants
|
||||||
|
- post-quantum (PQC) key material handling and secure PQC credential storage
|
||||||
|
- hierarchical deterministic key derivation (HD wallet–style key trees for per-user / per-tenant keys, firmware signing trees, etc.)
|
||||||
|
- cryptographically signed audit trail / tamper-evident logging
|
||||||
|
- dual-control / two-person approval for high-risk operations
|
||||||
|
- secure key escrow / disaster recovery strategy
|
||||||
|
- release-signing / supply-chain hardening toolchain
|
||||||
|
- policy-locked hardened mode ("FIPS-style profile")
|
||||||
|
- priority security-response SLA
|
||||||
|
- white-label demo / pre-sales bundle
|
||||||
|
|
||||||
|
Typical licensing models:
|
||||||
|
- Internal use (single legal entity, including internal private cloud / virtualized deployments).
|
||||||
|
- OEM / Redistribution / Service (ship in your product OR offer it as a service to third parties).
|
||||||
|
|
||||||
|
These options are scoped and priced individually depending on which components you actually need.
|
||||||
|
|
||||||
|
For commercial licensing and enterprise features, email pol@henarejos.me
|
||||||
|
Subject: `ENTERPRISE LICENSE <your company name>`
|
||||||
|
|
||||||
|
See `ENTERPRISE.md` for details.
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
Pico OpenPGP uses the following libraries or portion of code:
|
Pico OpenPGP uses the following libraries or portion of code:
|
||||||
- MbedTLS for cryptographic operations.
|
- MbedTLS for cryptographic operations.
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
VERSION_MAJOR="3"
|
VERSION_MAJOR="4"
|
||||||
VERSION_MINOR="4-eddsa1"
|
VERSION_MINOR="4"
|
||||||
SUFFIX="${VERSION_MAJOR}.${VERSION_MINOR}"
|
SUFFIX="${VERSION_MAJOR}.${VERSION_MINOR}"
|
||||||
#if ! [[ -z "${GITHUB_SHA}" ]]; then
|
#if ! [[ -z "${GITHUB_SHA}" ]]; then
|
||||||
# SUFFIX="${SUFFIX}.${GITHUB_SHA}"
|
# SUFFIX="${SUFFIX}.${GITHUB_SHA}"
|
||||||
#fi
|
#fi
|
||||||
|
|
||||||
rm -rf release/*
|
|
||||||
mkdir -p build_release
|
mkdir -p build_release
|
||||||
mkdir -p release
|
mkdir -p release
|
||||||
|
rm -rf -- release/*
|
||||||
cd build_release
|
cd build_release
|
||||||
|
|
||||||
PICO_SDK_PATH="${PICO_SDK_PATH:-../../pico-sdk}"
|
PICO_SDK_PATH="${PICO_SDK_PATH:-../../pico-sdk}"
|
||||||
board_dir=${PICO_SDK_PATH}/src/boards/include/boards
|
SECURE_BOOT_PKEY="${SECURE_BOOT_PKEY:-../../ec_private_key.pem}"
|
||||||
for board in "$board_dir"/*
|
boards=("pico" "pico2")
|
||||||
|
|
||||||
|
for board_name in "${boards[@]}"
|
||||||
do
|
do
|
||||||
board_name="$(basename -- $board .h)"
|
rm -rf -- ./*
|
||||||
rm -rf *
|
PICO_SDK_PATH="${PICO_SDK_PATH}" cmake .. -DPICO_BOARD=$board_name -DSECURE_BOOT_PKEY=${SECURE_BOOT_PKEY}
|
||||||
PICO_SDK_PATH="${PICO_SDK_PATH}" cmake .. -DPICO_BOARD=$board_name
|
|
||||||
make -j`nproc`
|
make -j`nproc`
|
||||||
mv pico_openpgp.uf2 ../release/pico_openpgp_$board_name-$SUFFIX.uf2
|
mv pico_openpgp.uf2 ../release/pico_openpgp_$board_name-$SUFFIX.uf2
|
||||||
done
|
done
|
||||||
|
|||||||
Submodule pico-keys-sdk updated: 4120a8c1a6...6b483029a5
@@ -10,6 +10,8 @@ CONFIG_PARTITION_TABLE_CUSTOM=y
|
|||||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="pico-keys-sdk/config/esp32/partitions.csv"
|
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="pico-keys-sdk/config/esp32/partitions.csv"
|
||||||
CONFIG_PARTITION_TABLE_FILENAME="pico-keys-sdk/config/esp32/partitions.csv"
|
CONFIG_PARTITION_TABLE_FILENAME="pico-keys-sdk/config/esp32/partitions.csv"
|
||||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
|
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
|
||||||
|
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
|
||||||
CONFIG_WL_SECTOR_SIZE_512=y
|
CONFIG_WL_SECTOR_SIZE_512=y
|
||||||
CONFIG_WL_SECTOR_MODE_PERF=y
|
CONFIG_WL_SECTOR_MODE_PERF=y
|
||||||
COMPILER_OPTIMIZATION="Performance"
|
COMPILER_OPTIMIZATION="Performance"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS ${SOURCES}
|
SRCS ${SOURCES}
|
||||||
INCLUDE_DIRS . ../../pico-keys-sdk/src ../../pico-keys-sdk/src/fs ../../pico-keys-sdk/src/rng ../../pico-keys-sdk/src/usb ../../pico-keys-sdk/tinycbor/src
|
INCLUDE_DIRS .
|
||||||
REQUIRES bootloader_support esp_partition esp_tinyusb zorxx__neopixel mbedtls efuse
|
REQUIRES mbedtls efuse pico-keys-sdk
|
||||||
)
|
)
|
||||||
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)
|
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -3,21 +3,23 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
#include "asn1.h"
|
#include "asn1.h"
|
||||||
|
|
||||||
|
extern bool is_gpg;
|
||||||
|
|
||||||
int cmd_get_data() {
|
int cmd_get_data() {
|
||||||
if (apdu.nc > 0) {
|
if (apdu.nc > 0) {
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
@@ -27,39 +29,88 @@ int cmd_get_data() {
|
|||||||
if (!(ef = search_by_fid(fid, NULL, SPECIFY_EF))) {
|
if (!(ef = search_by_fid(fid, NULL, SPECIFY_EF))) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
if (!authenticate_action(ef, ACL_OP_READ_SEARCH)) {
|
if (fid == EF_PRIV_DO_3) {
|
||||||
|
if (!has_pw2 && !has_pw3) {
|
||||||
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fid == EF_PRIV_DO_4) {
|
||||||
|
if (!has_pw3) {
|
||||||
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!authenticate_action(ef, ACL_OP_READ_SEARCH)) {
|
||||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
}
|
}
|
||||||
if (currentEF && (currentEF->fid & 0x1FF0) == (fid & 0x1FF0)) { //previously selected
|
if (currentEF && currentEF->fid == fid) { // previously selected same EF
|
||||||
ef = currentEF;
|
ef = currentEF;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
select_file(ef);
|
select_file(ef);
|
||||||
}
|
}
|
||||||
if (ef->data) {
|
if (ef->data) {
|
||||||
|
if (fid == EF_PW_STATUS || fid == EF_HIST_BYTES || fid == EF_FULL_AID || fid == EF_SEC_TPL) {
|
||||||
|
is_gpg = true;
|
||||||
|
}
|
||||||
uint16_t fids[] = { 1, fid };
|
uint16_t fids[] = { 1, fid };
|
||||||
uint16_t data_len = parse_do(fids, 1);
|
uint16_t data_len = parse_do(fids, 1);
|
||||||
uint8_t *p = NULL;
|
if (!(ef->type & FILE_DATA_FLASH)) {
|
||||||
uint16_t tg = 0;
|
uint8_t *p = NULL;
|
||||||
uint16_t tg_len = 0;
|
uint16_t tg = 0;
|
||||||
asn1_ctx_t ctxi;
|
uint16_t tg_len = 0;
|
||||||
asn1_ctx_init(res_APDU, data_len, &ctxi);
|
asn1_ctx_t ctxi;
|
||||||
if (walk_tlv(&ctxi, &p, &tg, &tg_len, NULL)) {
|
asn1_ctx_init(res_APDU, data_len, &ctxi);
|
||||||
uint8_t dec = 2;
|
if (walk_tlv(&ctxi, &p, &tg, &tg_len, NULL)) {
|
||||||
if ((tg & 0x1f) == 0x1f) {
|
uint8_t dec = 2;
|
||||||
dec++;
|
if ((tg & 0x1f) == 0x1f) {
|
||||||
}
|
dec++;
|
||||||
if ((res_APDU[dec - 1] & 0xF0) == 0x80) {
|
}
|
||||||
dec += (res_APDU[dec - 1] & 0x0F);
|
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);
|
if (tg_len + dec == data_len) {
|
||||||
data_len -= dec;
|
memmove(res_APDU, res_APDU + dec, data_len - dec);
|
||||||
res_APDU_size -= dec;
|
data_len -= dec;
|
||||||
|
res_APDU_size -= dec;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if (apdu.ne > data_len)
|
if (is_gpg == false) {
|
||||||
// apdu.ne = data_len;
|
uint8_t off = 2;
|
||||||
|
if (P1(apdu) > 0x0) {
|
||||||
|
off++;
|
||||||
|
}
|
||||||
|
if (data_len >= 128) {
|
||||||
|
off++;
|
||||||
|
}
|
||||||
|
if (data_len >= 256) {
|
||||||
|
off++;
|
||||||
|
}
|
||||||
|
memmove(res_APDU + off, res_APDU, data_len);
|
||||||
|
off = 0;
|
||||||
|
if (P1(apdu) > 0x0) {
|
||||||
|
res_APDU[off++] = P1(apdu);
|
||||||
|
res_APDU[off++] = P2(apdu);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res_APDU[off++] = P2(apdu);
|
||||||
|
}
|
||||||
|
if (data_len >= 256) {
|
||||||
|
res_APDU[off++] = 0x82;
|
||||||
|
res_APDU[off++] = (data_len >> 8) & 0xff;
|
||||||
|
res_APDU[off++] = data_len & 0xff;
|
||||||
|
}
|
||||||
|
else if (data_len >= 128) {
|
||||||
|
res_APDU[off++] = 0x81;
|
||||||
|
res_APDU[off++] = data_len;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res_APDU[off++] = data_len;
|
||||||
|
}
|
||||||
|
res_APDU_size += off;
|
||||||
|
}
|
||||||
|
// if (apdu.ne > data_len)
|
||||||
|
// apdu.ne = data_len;
|
||||||
}
|
}
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
@@ -89,3 +140,10 @@ int cmd_get_next_data() {
|
|||||||
select_file(ef);
|
select_file(ef);
|
||||||
return cmd_get_data();
|
return cmd_get_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cmd_get_bulk_data() {
|
||||||
|
if (apdu.nc < 3) {
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
}
|
||||||
|
return bulk_cmd(cmd_get_data);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
@@ -177,10 +177,13 @@ int cmd_import_data() {
|
|||||||
mbedtls_ecp_keypair_free(&ecdsa);
|
mbedtls_ecp_keypair_free(&ecdsa);
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
if (ecdsa.grp.id == MBEDTLS_ECP_DP_ED25519) {
|
if (ecdsa.grp.id == MBEDTLS_ECP_DP_ED25519) {
|
||||||
r = mbedtls_ecp_point_edwards(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, random_gen, NULL);
|
r = mbedtls_ecp_point_edwards(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, random_gen, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
r = mbedtls_ecp_mul(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, &ecdsa.grp.G, random_gen, NULL);
|
r = mbedtls_ecp_mul(&ecdsa.grp, &ecdsa.Q, &ecdsa.d, &ecdsa.grp.G, random_gen, NULL);
|
||||||
}
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
@@ -127,7 +127,7 @@ int cmd_keypair_gen() {
|
|||||||
}
|
}
|
||||||
else if (P1(apdu) == 0x81) { //read
|
else if (P1(apdu) == 0x81) { //read
|
||||||
file_t *ef = search_by_fid(fid + 3, NULL, SPECIFY_EF);
|
file_t *ef = search_by_fid(fid + 3, NULL, SPECIFY_EF);
|
||||||
if (!ef || !ef->data) {
|
if (!file_has_data(ef)) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
res_APDU_size = file_get_size(ef);
|
res_APDU_size = file_get_size(ef);
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
@@ -32,43 +32,54 @@ int cmd_put_data() {
|
|||||||
if (!authenticate_action(ef, ACL_OP_UPDATE_ERASE)) {
|
if (!authenticate_action(ef, ACL_OP_UPDATE_ERASE)) {
|
||||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
}
|
}
|
||||||
|
if ((fid == EF_PRIV_DO_1 || fid == EF_PRIV_DO_3) && (!has_pw2 && !has_pw3)) {
|
||||||
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
|
}
|
||||||
|
if (!(fid == EF_PRIV_DO_1 || fid == EF_PRIV_DO_3) && !has_pw3) {
|
||||||
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
|
}
|
||||||
if (fid == EF_PW_STATUS) {
|
if (fid == EF_PW_STATUS) {
|
||||||
fid = EF_PW_PRIV;
|
fid = EF_PW_PRIV;
|
||||||
apdu.nc = 4; //we silently ommit the reset parameters
|
apdu.nc = 4; //we silently ommit the reset parameters
|
||||||
}
|
}
|
||||||
if (currentEF && (currentEF->fid & 0x1FF0) == (fid & 0x1FF0)) { //previously selected
|
if (currentEF && currentEF->fid == fid) { // previously selected same EF
|
||||||
ef = currentEF;
|
ef = currentEF;
|
||||||
}
|
}
|
||||||
if (apdu.nc > 0 && (ef->type & FILE_DATA_FLASH)) {
|
if (ef->type & FILE_DATA_FLASH) {
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (fid == EF_RC) {
|
if (apdu.nc > 0) {
|
||||||
has_rc = false;
|
if (fid == EF_RC) {
|
||||||
if ((r = load_dek()) != PICOKEY_OK) {
|
has_rc = false;
|
||||||
return SW_EXEC_ERROR();
|
if ((r = load_dek()) != PICOKEY_OK) {
|
||||||
}
|
return SW_EXEC_ERROR();
|
||||||
uint8_t dhash[33];
|
}
|
||||||
dhash[0] = apdu.nc;
|
uint8_t dhash[33];
|
||||||
double_hash_pin(apdu.data, apdu.nc, dhash + 1);
|
dhash[0] = apdu.nc;
|
||||||
r = file_put_data(ef, dhash, sizeof(dhash));
|
double_hash_pin(apdu.data, apdu.nc, dhash + 1);
|
||||||
|
r = file_put_data(ef, dhash, sizeof(dhash));
|
||||||
|
|
||||||
file_t *tf = search_by_fid(EF_DEK, NULL, SPECIFY_EF);
|
file_t *tf = search_by_fid(EF_DEK, NULL, SPECIFY_EF);
|
||||||
if (!tf) {
|
if (!tf) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
|
}
|
||||||
|
uint8_t def[IV_SIZE + 32 + 32 + 32 + 32];
|
||||||
|
memcpy(def, file_get_data(tf), file_get_size(tf));
|
||||||
|
hash_multi(apdu.data, apdu.nc, session_rc);
|
||||||
|
memcpy(def + IV_SIZE + 32, dek + IV_SIZE, 32);
|
||||||
|
aes_encrypt_cfb_256(session_rc, def, def + IV_SIZE + 32, 32);
|
||||||
|
r = file_put_data(tf, def, sizeof(def));
|
||||||
}
|
}
|
||||||
uint8_t def[IV_SIZE + 32 + 32 + 32 + 32];
|
else {
|
||||||
memcpy(def, file_get_data(tf), file_get_size(tf));
|
r = file_put_data(ef, apdu.data, apdu.nc);
|
||||||
hash_multi(apdu.data, apdu.nc, session_rc);
|
}
|
||||||
memcpy(def + IV_SIZE + 32, dek + IV_SIZE, 32);
|
if (r != PICOKEY_OK) {
|
||||||
aes_encrypt_cfb_256(session_rc, def, def + IV_SIZE + 32, 32);
|
return SW_MEMORY_FAILURE();
|
||||||
r = file_put_data(tf, def, sizeof(def));
|
}
|
||||||
|
low_flash_available();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
r = file_put_data(ef, apdu.data, apdu.nc);
|
delete_file(ef);
|
||||||
}
|
}
|
||||||
if (r != PICOKEY_OK) {
|
|
||||||
return SW_MEMORY_FAILURE();
|
|
||||||
}
|
|
||||||
low_flash_available();
|
|
||||||
}
|
}
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,20 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
#include "otp.h"
|
||||||
|
|
||||||
int cmd_reset_retry() {
|
int cmd_reset_retry() {
|
||||||
if (P2(apdu) != 0x81) {
|
if (P2(apdu) != 0x81) {
|
||||||
@@ -44,6 +45,8 @@ int cmd_reset_retry() {
|
|||||||
newpin_len = apdu.nc - pin_len;
|
newpin_len = apdu.nc - pin_len;
|
||||||
has_rc = true;
|
has_rc = true;
|
||||||
hash_multi(apdu.data, pin_len, session_rc);
|
hash_multi(apdu.data, pin_len, session_rc);
|
||||||
|
has_pw1 = has_pw3 = false;
|
||||||
|
isUserAuthenticated = false;
|
||||||
}
|
}
|
||||||
else if (P1(apdu) == 0x2) {
|
else if (P1(apdu) == 0x2) {
|
||||||
if (!has_pw3) {
|
if (!has_pw3) {
|
||||||
@@ -59,6 +62,11 @@ int cmd_reset_retry() {
|
|||||||
if (!tf) {
|
if (!tf) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
|
if (otp_key_1) {
|
||||||
|
for (int i = 0; i < 32; i++) {
|
||||||
|
dek[IV_SIZE + i] ^= otp_key_1[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
uint8_t def[IV_SIZE + 32 + 32 + 32 + 32];
|
uint8_t def[IV_SIZE + 32 + 32 + 32 + 32];
|
||||||
memcpy(def, file_get_data(tf), file_get_size(tf));
|
memcpy(def, file_get_data(tf), file_get_size(tf));
|
||||||
hash_multi(apdu.data + (apdu.nc - newpin_len), newpin_len, session_pw1);
|
hash_multi(apdu.data + (apdu.nc - newpin_len), newpin_len, session_pw1);
|
||||||
@@ -74,6 +82,9 @@ int cmd_reset_retry() {
|
|||||||
return SW_MEMORY_FAILURE();
|
return SW_MEMORY_FAILURE();
|
||||||
}
|
}
|
||||||
low_flash_available();
|
low_flash_available();
|
||||||
|
if ((r = load_dek()) != PICOKEY_OK) {
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
return SW_INCORRECT_P1P2();
|
return SW_INCORRECT_P1P2();
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
|
|||||||
@@ -3,22 +3,22 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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;
|
||||||
|
|||||||
23
src/openpgp/defs.c
Normal file
23
src/openpgp/defs.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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 Affero 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
|
||||||
|
* Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "openpgp.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
uint8_t PICO_PRODUCT = 3;
|
||||||
|
uint8_t PICO_VERSION_MAJOR = PIPGP_VERSION_MAJOR;
|
||||||
|
uint8_t PICO_VERSION_MINOR = PIPGP_VERSION_MINOR;
|
||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "openpgp.h"
|
#include "openpgp.h"
|
||||||
@@ -28,12 +28,7 @@ int parse_do(uint16_t *fids, int mode) {
|
|||||||
data_len = ((int (*)(const file_t *, int))(ef->data))((const file_t *) ef, mode);
|
data_len = ((int (*)(const file_t *, int))(ef->data))((const file_t *) ef, mode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ef->data) {
|
data_len = file_get_size(ef);
|
||||||
data_len = file_get_size(ef);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
data_len = 0;
|
|
||||||
}
|
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
if (fids[0] > 1 && res_APDU_size > 0) {
|
if (fids[0] > 1 && res_APDU_size > 0) {
|
||||||
if (fids[i + 1] < 0x0100) {
|
if (fids[i + 1] < 0x0100) {
|
||||||
@@ -45,7 +40,7 @@ int parse_do(uint16_t *fids, int mode) {
|
|||||||
}
|
}
|
||||||
res_APDU_size += format_tlv_len(data_len, res_APDU + res_APDU_size);
|
res_APDU_size += format_tlv_len(data_len, res_APDU + res_APDU_size);
|
||||||
}
|
}
|
||||||
if (ef->data) {
|
if (file_has_data(ef)) {
|
||||||
memcpy(res_APDU + res_APDU_size, file_get_data(ef), data_len);
|
memcpy(res_APDU + res_APDU_size, file_get_data(ef), data_len);
|
||||||
}
|
}
|
||||||
res_APDU_size += data_len;
|
res_APDU_size += data_len;
|
||||||
@@ -174,20 +169,6 @@ int parse_pw_status(const file_t *f, int mode) {
|
|||||||
return res_APDU_size - init_len;
|
return res_APDU_size - init_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ALGO_RSA_1K 0
|
|
||||||
#define ALGO_RSA_2k 1
|
|
||||||
#define ALGO_RSA_3K 2
|
|
||||||
#define ALGO_RSA_4K 3
|
|
||||||
#define ALGO_X448 4
|
|
||||||
#define ALGO_P256K1 5
|
|
||||||
#define ALGO_P256R1 6
|
|
||||||
#define ALGO_P384R1 7
|
|
||||||
#define ALGO_P521R1 8
|
|
||||||
#define ALGO_BP256R1 9
|
|
||||||
#define ALGO_BP384R1 10
|
|
||||||
#define ALGO_BP512R1 11
|
|
||||||
#define ALGO_CV22519 12
|
|
||||||
|
|
||||||
const uint8_t algorithm_attr_x448[] = {
|
const uint8_t algorithm_attr_x448[] = {
|
||||||
4,
|
4,
|
||||||
ALGO_ECDH,
|
ALGO_ECDH,
|
||||||
@@ -275,12 +256,20 @@ const uint8_t algorithm_attr_cv25519[] = {
|
|||||||
0x2b, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01
|
0x2b, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
const uint8_t algorithm_attr_ed25519[] = {
|
const uint8_t algorithm_attr_ed25519[] = {
|
||||||
10,
|
10,
|
||||||
ALGO_EDDSA,
|
ALGO_EDDSA,
|
||||||
0x2b, 0x06, 0x01, 0x04, 0x01, 0xda, 0x47, 0x0f, 0x01
|
0x2b, 0x06, 0x01, 0x04, 0x01, 0xda, 0x47, 0x0f, 0x01
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uint8_t algorithm_attr_ed448[] = {
|
||||||
|
4,
|
||||||
|
ALGO_EDDSA,
|
||||||
|
0x2b, 0x65, 0x71
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
int parse_algo(const uint8_t *algo, uint16_t tag) {
|
int parse_algo(const uint8_t *algo, uint16_t tag) {
|
||||||
res_APDU[res_APDU_size++] = tag & 0xff;
|
res_APDU[res_APDU_size++] = tag & 0xff;
|
||||||
memcpy(res_APDU + res_APDU_size, algo, algo[0] + 1);
|
memcpy(res_APDU + res_APDU_size, algo, algo[0] + 1);
|
||||||
@@ -306,7 +295,10 @@ int parse_algoinfo(const file_t *f, int mode) {
|
|||||||
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_SIG);
|
||||||
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_SIG);
|
||||||
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_SIG);
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
datalen += parse_algo(algorithm_attr_ed25519, EF_ALGO_SIG);
|
datalen += parse_algo(algorithm_attr_ed25519, EF_ALGO_SIG);
|
||||||
|
datalen += parse_algo(algorithm_attr_ed448, EF_ALGO_SIG);
|
||||||
|
#endif
|
||||||
|
|
||||||
datalen += parse_algo(algorithm_attr_rsa1k, EF_ALGO_DEC);
|
datalen += parse_algo(algorithm_attr_rsa1k, EF_ALGO_DEC);
|
||||||
datalen += parse_algo(algorithm_attr_rsa2k, EF_ALGO_DEC);
|
datalen += parse_algo(algorithm_attr_rsa2k, EF_ALGO_DEC);
|
||||||
@@ -333,7 +325,10 @@ int parse_algoinfo(const file_t *f, int mode) {
|
|||||||
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_bp256r1, EF_ALGO_AUT);
|
||||||
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_bp384r1, EF_ALGO_AUT);
|
||||||
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_bp512r1, EF_ALGO_AUT);
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
datalen += parse_algo(algorithm_attr_ed25519, EF_ALGO_AUT);
|
datalen += parse_algo(algorithm_attr_ed25519, EF_ALGO_AUT);
|
||||||
|
datalen += parse_algo(algorithm_attr_ed448, EF_ALGO_AUT);
|
||||||
|
#endif
|
||||||
uint16_t lpdif = res_APDU + res_APDU_size - lp - 2;
|
uint16_t lpdif = res_APDU + res_APDU_size - lp - 2;
|
||||||
*lp++ = lpdif >> 8;
|
*lp++ = lpdif >> 8;
|
||||||
*lp++ = lpdif & 0xff;
|
*lp++ = lpdif & 0xff;
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern const uint8_t algorithm_attr_p256k1[];
|
extern const uint8_t algorithm_attr_p256k1[];
|
||||||
@@ -26,4 +26,7 @@ extern const uint8_t algorithm_attr_cv25519[];
|
|||||||
extern const uint8_t algorithm_attr_x448[];
|
extern const uint8_t algorithm_attr_x448[];
|
||||||
extern const uint8_t algorithm_attr_rsa2k[];
|
extern const uint8_t algorithm_attr_rsa2k[];
|
||||||
extern const uint8_t algorithm_attr_rsa4096[];
|
extern const uint8_t algorithm_attr_rsa4096[];
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
extern const uint8_t algorithm_attr_ed25519[];
|
extern const uint8_t algorithm_attr_ed25519[];
|
||||||
|
extern const uint8_t algorithm_attr_ed448[];
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
@@ -55,12 +55,12 @@ uint8_t historical_bytes[] = {
|
|||||||
|
|
||||||
uint8_t extended_capabilities[] = {
|
uint8_t extended_capabilities[] = {
|
||||||
10, 0,
|
10, 0,
|
||||||
0x77, /*
|
0x7f, /*
|
||||||
* No Secure Messaging supported
|
* No Secure Messaging supported
|
||||||
* GET CHALLENGE supported
|
* GET CHALLENGE supported
|
||||||
* Key import supported
|
* Key import supported
|
||||||
* PW status byte can be put
|
* PW status byte can be put
|
||||||
* No private_use_DO
|
* private_use_DO
|
||||||
* Algorithm attrs are changable
|
* Algorithm attrs are changable
|
||||||
* ENC/DEC with AES
|
* ENC/DEC with AES
|
||||||
* KDF-DO available
|
* KDF-DO available
|
||||||
@@ -68,7 +68,7 @@ uint8_t extended_capabilities[] = {
|
|||||||
0, /* Secure Messaging Algorithm: N/A (TDES=0, AES=1) */
|
0, /* Secure Messaging Algorithm: N/A (TDES=0, AES=1) */
|
||||||
0x00, 128, /* Max size of GET CHALLENGE */
|
0x00, 128, /* Max size of GET CHALLENGE */
|
||||||
0x08, 0x00, /* max. length of cardholder certificate (2KiB) */
|
0x08, 0x00, /* max. length of cardholder certificate (2KiB) */
|
||||||
0x00, 0xff,
|
0x08, 0x00, /* max. length of private DO (2KiB) */
|
||||||
0x00, 0x1
|
0x00, 0x1
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ file_t file_entries[] = {
|
|||||||
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
||||||
/* 10 */ { .fid = EF_CH_CERT, .parent = 0, .name = NULL,
|
/* 10 */ { .fid = EF_CH_CERT, .parent = 0, .name = NULL,
|
||||||
.type = FILE_TYPE_WORKING_EF | FILE_DATA_FUNC, .data = (uint8_t *) parse_ch_cert,
|
.type = FILE_TYPE_WORKING_EF | FILE_DATA_FUNC, .data = (uint8_t *) parse_ch_cert,
|
||||||
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
||||||
/* 11 */ { .fid = EF_EXLEN_INFO, .parent = 0, .name = NULL, .type = FILE_TYPE_WORKING_EF,
|
/* 11 */ { .fid = EF_EXLEN_INFO, .parent = 0, .name = NULL, .type = FILE_TYPE_WORKING_EF,
|
||||||
.data = exlen_info, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
.data = exlen_info, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
||||||
/* 12 */ { .fid = EF_GFM, .parent = 0, .name = NULL, .type = FILE_TYPE_WORKING_EF,
|
/* 12 */ { .fid = EF_GFM, .parent = 0, .name = NULL, .type = FILE_TYPE_WORKING_EF,
|
||||||
@@ -476,10 +476,28 @@ file_t file_entries[] = {
|
|||||||
/* 131 */ { .fid = EF_PW_RETRIES, .parent = 0, .name = NULL,
|
/* 131 */ { .fid = EF_PW_RETRIES, .parent = 0, .name = NULL,
|
||||||
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
||||||
|
/* 131 */ { .fid = EF_PRIV_DO_1, .parent = 0, .name = NULL,
|
||||||
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
||||||
|
/* 132 */ { .fid = EF_PRIV_DO_2, .parent = 0, .name = NULL,
|
||||||
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
||||||
|
/* 133 */ { .fid = EF_PRIV_DO_3, .parent = 0, .name = NULL,
|
||||||
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
|
||||||
|
/* 134 */ { .fid = EF_PRIV_DO_4, .parent = 0, .name = NULL,
|
||||||
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_WP },
|
||||||
|
/* 135 */ { .fid = EF_PW_RETRIES, .parent = 0, .name = NULL,
|
||||||
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
||||||
|
/* 136 */ { .fid = EF_PW_STATUS, .parent = 0, .name = NULL,
|
||||||
|
.type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL,
|
||||||
|
.ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_R_WP },
|
||||||
|
|
||||||
/* 132 */ { .fid = 0x0000, .parent = 0, .name = openpgp_aid, .type = FILE_TYPE_WORKING_EF,
|
/* 137 */ { .fid = 0x0000, .parent = 0, .name = openpgp_aid, .type = FILE_TYPE_WORKING_EF,
|
||||||
.data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
.data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_RO },
|
||||||
/* 133 */ { .fid = 0x0000, .parent = 0xff, .name = NULL, .type = FILE_TYPE_NOT_KNOWN, .data = NULL,
|
/* 138 */ { .fid = 0x0000, .parent = 0xff, .name = NULL, .type = FILE_TYPE_NOT_KNOWN, .data = NULL,
|
||||||
.ef_structure = 0, .acl = ACL_NONE } //end
|
.ef_structure = 0, .acl = ACL_NONE } //end
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -163,4 +163,9 @@
|
|||||||
|
|
||||||
#define EF_DEV_CONF 0x1122
|
#define EF_DEV_CONF 0x1122
|
||||||
|
|
||||||
|
#define EF_PRIV_DO_1 0x0101
|
||||||
|
#define EF_PRIV_DO_2 0x0102
|
||||||
|
#define EF_PRIV_DO_3 0x0103
|
||||||
|
#define EF_PRIV_DO_4 0x0104
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pico_keys.h"
|
#include "pico_keys.h"
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "asn1.h"
|
#include "asn1.h"
|
||||||
#include "management.h"
|
#include "management.h"
|
||||||
|
|
||||||
|
bool is_gpg = true;
|
||||||
|
|
||||||
int man_process_apdu();
|
int man_process_apdu();
|
||||||
int man_unload();
|
int man_unload();
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ int man_select(app_t *a, uint8_t force) {
|
|||||||
res_APDU_size = strlen((char *) res_APDU);
|
res_APDU_size = strlen((char *) res_APDU);
|
||||||
apdu.ne = res_APDU_size;
|
apdu.ne = res_APDU_size;
|
||||||
init_piv();
|
init_piv();
|
||||||
|
is_gpg = false;
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _MANAGEMENT_H_
|
#ifndef _MANAGEMENT_H_
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
@@ -30,9 +30,9 @@
|
|||||||
#include "ccid/ccid.h"
|
#include "ccid/ccid.h"
|
||||||
#include "otp.h"
|
#include "otp.h"
|
||||||
#include "do.h"
|
#include "do.h"
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
#include "mbedtls/eddsa.h"
|
#include "mbedtls/eddsa.h"
|
||||||
|
#endif
|
||||||
uint8_t PICO_PRODUCT = 3;
|
|
||||||
|
|
||||||
bool has_pw1 = false;
|
bool has_pw1 = false;
|
||||||
bool has_pw2 = false;
|
bool has_pw2 = false;
|
||||||
@@ -65,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);
|
||||||
@@ -97,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))) {
|
||||||
@@ -219,6 +219,10 @@ void scan_files() {
|
|||||||
low_flash_available();
|
low_flash_available();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void release_dek() {
|
||||||
|
memset(dek, 0, sizeof(dek));
|
||||||
|
}
|
||||||
|
|
||||||
extern bool has_pwpiv;
|
extern bool has_pwpiv;
|
||||||
extern uint8_t session_pwpiv[32];
|
extern uint8_t session_pwpiv[32];
|
||||||
int load_dek() {
|
int load_dek() {
|
||||||
@@ -245,6 +249,7 @@ int load_dek() {
|
|||||||
r = aes_decrypt_cfb_256(session_pwpiv, dek, dek + IV_SIZE, 32);
|
r = aes_decrypt_cfb_256(session_pwpiv, dek, dek + IV_SIZE, 32);
|
||||||
}
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
|
release_dek();
|
||||||
return PICOKEY_EXEC_ERROR;
|
return PICOKEY_EXEC_ERROR;
|
||||||
}
|
}
|
||||||
if (otp_key_1) {
|
if (otp_key_1) {
|
||||||
@@ -255,10 +260,6 @@ int load_dek() {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void release_dek() {
|
|
||||||
memset(dek, 0, sizeof(dek));
|
|
||||||
}
|
|
||||||
|
|
||||||
int dek_encrypt(uint8_t *data, size_t len) {
|
int dek_encrypt(uint8_t *data, size_t len) {
|
||||||
int r;
|
int r;
|
||||||
if ((r = load_dek()) != PICOKEY_OK) {
|
if ((r = load_dek()) != PICOKEY_OK) {
|
||||||
@@ -281,18 +282,18 @@ int dek_decrypt(uint8_t *data, size_t len) {
|
|||||||
|
|
||||||
void init_openpgp() {
|
void init_openpgp() {
|
||||||
isUserAuthenticated = false;
|
isUserAuthenticated = false;
|
||||||
has_pw1 = has_pw3 = false;
|
has_pw1 = has_pw2 = has_pw3 = false;
|
||||||
algo_dec = EF_ALGO_PRIV2;
|
algo_dec = EF_ALGO_PRIV2;
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
int openpgp_unload() {
|
int openpgp_unload() {
|
||||||
isUserAuthenticated = false;
|
isUserAuthenticated = false;
|
||||||
has_pw1 = has_pw3 = false;
|
has_pw1 = has_pw2 = has_pw3 = false;
|
||||||
algo_dec = EF_ALGO_PRIV2;
|
algo_dec = EF_ALGO_PRIV2;
|
||||||
algo_aut = EF_ALGO_PRIV3;
|
algo_aut = EF_ALGO_PRIV3;
|
||||||
pk_dec = EF_PK_DEC;
|
pk_dec = EF_PK_DEC;
|
||||||
@@ -573,10 +574,13 @@ int load_private_key_ecdsa(mbedtls_ecp_keypair *ctx, file_t *fkey, bool use_dek)
|
|||||||
return PICOKEY_EXEC_ERROR;
|
return PICOKEY_EXEC_ERROR;
|
||||||
}
|
}
|
||||||
mbedtls_platform_zeroize(kdata, sizeof(kdata));
|
mbedtls_platform_zeroize(kdata, sizeof(kdata));
|
||||||
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519) {
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
|
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519 || ctx->grp.id == MBEDTLS_ECP_DP_ED448) {
|
||||||
r = mbedtls_ecp_point_edwards(&ctx->grp, &ctx->Q, &ctx->d, random_gen, NULL);
|
r = mbedtls_ecp_point_edwards(&ctx->grp, &ctx->Q, &ctx->d, random_gen, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
r = mbedtls_ecp_mul(&ctx->grp, &ctx->Q, &ctx->d, &ctx->grp.G, random_gen, NULL);
|
r = mbedtls_ecp_mul(&ctx->grp, &ctx->Q, &ctx->d, &ctx->grp.G, random_gen, NULL);
|
||||||
}
|
}
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
@@ -623,9 +627,14 @@ mbedtls_ecp_group_id get_ec_group_id_from_attr(const uint8_t *algo, size_t algo_
|
|||||||
else if (memcmp(algorithm_attr_x448 + 2, algo, algo_len) == 0) {
|
else if (memcmp(algorithm_attr_x448 + 2, algo, algo_len) == 0) {
|
||||||
return MBEDTLS_ECP_DP_CURVE448;
|
return MBEDTLS_ECP_DP_CURVE448;
|
||||||
}
|
}
|
||||||
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
else if (memcmp(algorithm_attr_ed25519 + 2, algo, algo_len) == 0) {
|
else if (memcmp(algorithm_attr_ed25519 + 2, algo, algo_len) == 0) {
|
||||||
return MBEDTLS_ECP_DP_ED25519;
|
return MBEDTLS_ECP_DP_ED25519;
|
||||||
}
|
}
|
||||||
|
else if (memcmp(algorithm_attr_ed448 + 2, algo, algo_len) == 0) {
|
||||||
|
return MBEDTLS_ECP_DP_ED448;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return MBEDTLS_ECP_DP_NONE;
|
return MBEDTLS_ECP_DP_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,10 +753,13 @@ int ecdsa_sign(mbedtls_ecp_keypair *ctx,
|
|||||||
size_t *out_len) {
|
size_t *out_len) {
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519) {
|
#ifdef MBEDTLS_EDDSA_C
|
||||||
r = mbedtls_eddsa_write_signature(ctx, data, data_len, out, 64, out_len, MBEDTLS_EDDSA_PURE, NULL, 0, random_gen, NULL);
|
if (ctx->grp.id == MBEDTLS_ECP_DP_ED25519 || ctx->grp.id == MBEDTLS_ECP_DP_ED448) {
|
||||||
|
r = mbedtls_eddsa_write_signature(ctx, data, data_len, out, 114, out_len, MBEDTLS_EDDSA_PURE, NULL, 0, random_gen, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
mbedtls_mpi ri, si;
|
mbedtls_mpi ri, si;
|
||||||
mbedtls_mpi_init(&ri);
|
mbedtls_mpi_init(&ri);
|
||||||
mbedtls_mpi_init(&si);
|
mbedtls_mpi_init(&si);
|
||||||
@@ -770,7 +782,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();
|
||||||
@@ -781,6 +793,7 @@ extern int cmd_terminate_df();
|
|||||||
extern int cmd_pso();
|
extern int cmd_pso();
|
||||||
extern int cmd_keypair_gen();
|
extern int cmd_keypair_gen();
|
||||||
extern int cmd_reset_retry();
|
extern int cmd_reset_retry();
|
||||||
|
extern int cmd_get_bulk_data();
|
||||||
|
|
||||||
#define INS_VERIFY 0x20
|
#define INS_VERIFY 0x20
|
||||||
#define INS_MSE 0x22
|
#define INS_MSE 0x22
|
||||||
@@ -795,6 +808,7 @@ extern int cmd_reset_retry();
|
|||||||
#define INS_SELECT_DATA 0xA5
|
#define INS_SELECT_DATA 0xA5
|
||||||
#define INS_GET_DATA 0xCA
|
#define INS_GET_DATA 0xCA
|
||||||
#define INS_GET_NEXT_DATA 0xCC
|
#define INS_GET_NEXT_DATA 0xCC
|
||||||
|
#define INS_GET_BULK_DATA 0xCE
|
||||||
#define INS_PUT_DATA 0xDA
|
#define INS_PUT_DATA 0xDA
|
||||||
#define INS_IMPORT_DATA 0xDB
|
#define INS_IMPORT_DATA 0xDB
|
||||||
#define INS_TERMINATE_DF 0xE6
|
#define INS_TERMINATE_DF 0xE6
|
||||||
@@ -815,10 +829,11 @@ 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 }
|
{ INS_GET_BULK_DATA, cmd_get_bulk_data },
|
||||||
|
{ 0x00, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
int openpgp_process_apdu() {
|
int openpgp_process_apdu() {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __OPENPGP_H_
|
#ifndef __OPENPGP_H_
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
@@ -124,7 +124,7 @@ static int x509_create_cert(void *pk_ctx, uint8_t algo, uint8_t slot, bool attes
|
|||||||
mbedtls_x509write_crt_set_extension(&ctx, "\x2B\x06\x01\x04\x01\x82\xC4\x0A\x03\x08", 10, 0, &meta[1], 2);
|
mbedtls_x509write_crt_set_extension(&ctx, "\x2B\x06\x01\x04\x01\x82\xC4\x0A\x03\x08", 10, 0, &meta[1], 2);
|
||||||
}
|
}
|
||||||
uint8_t v = 1;
|
uint8_t v = 1;
|
||||||
mbedtls_x509write_crt_set_extension(&ctx, "\x2B\x06\x01\x04\x01\x82\xC4\x0A\x03\x09", 10, 0, &v, sizeof(serial));
|
mbedtls_x509write_crt_set_extension(&ctx, "\x2B\x06\x01\x04\x01\x82\xC4\x0A\x03\x09", 10, 0, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint8_t wslot = slot;
|
uint8_t wslot = slot;
|
||||||
@@ -153,9 +153,7 @@ static int x509_create_cert(void *pk_ctx, uint8_t algo, uint8_t slot, bool attes
|
|||||||
}
|
}
|
||||||
mbedtls_x509write_crt_set_subject_key_identifier(&ctx);
|
mbedtls_x509write_crt_set_subject_key_identifier(&ctx);
|
||||||
mbedtls_x509write_crt_set_authority_key_identifier(&ctx);
|
mbedtls_x509write_crt_set_authority_key_identifier(&ctx);
|
||||||
mbedtls_x509write_crt_set_key_usage(&ctx,
|
mbedtls_x509write_crt_set_key_usage(&ctx, MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN);
|
||||||
MBEDTLS_X509_KU_DIGITAL_SIGNATURE |
|
|
||||||
MBEDTLS_X509_KU_KEY_CERT_SIGN);
|
|
||||||
int ret = mbedtls_x509write_crt_der(&ctx, buffer, buffer_size, random_gen, NULL);
|
int ret = mbedtls_x509write_crt_der(&ctx, buffer, buffer_size, random_gen, NULL);
|
||||||
/* skey cannot be freed, as it is freed later */
|
/* skey cannot be freed, as it is freed later */
|
||||||
if (attestation) {
|
if (attestation) {
|
||||||
@@ -218,7 +216,7 @@ static void scan_files_piv() {
|
|||||||
uint8_t *key = (uint8_t *)"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08";
|
uint8_t *key = (uint8_t *)"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08";
|
||||||
file_t *ef = search_by_fid(EF_PIV_KEY_CARDMGM, NULL, SPECIFY_ANY);
|
file_t *ef = search_by_fid(EF_PIV_KEY_CARDMGM, NULL, SPECIFY_ANY);
|
||||||
file_put_data(ef, key, 24);
|
file_put_data(ef, key, 24);
|
||||||
uint8_t meta[] = { PIV_ALGO_AES192, PINPOLICY_ALWAYS, TOUCHPOLICY_ALWAYS, ORIGIN_GENERATED };
|
uint8_t meta[] = { PIV_ALGO_AES192, PINPOLICY_ALWAYS, TOUCHPOLICY_ALWAYS };
|
||||||
meta_add(EF_PIV_KEY_CARDMGM, meta, sizeof(meta));
|
meta_add(EF_PIV_KEY_CARDMGM, meta, sizeof(meta));
|
||||||
has_pwpiv = false;
|
has_pwpiv = false;
|
||||||
memset(session_pwpiv, 0, sizeof(session_pwpiv));
|
memset(session_pwpiv, 0, sizeof(session_pwpiv));
|
||||||
@@ -458,74 +456,76 @@ static int cmd_get_metadata() {
|
|||||||
res_APDU[res_APDU_size++] = 2;
|
res_APDU[res_APDU_size++] = 2;
|
||||||
res_APDU[res_APDU_size++] = meta[1];
|
res_APDU[res_APDU_size++] = meta[1];
|
||||||
res_APDU[res_APDU_size++] = meta[2];
|
res_APDU[res_APDU_size++] = meta[2];
|
||||||
res_APDU[res_APDU_size++] = 0x3;
|
if (key_ref != EF_PIV_KEY_CARDMGM) {
|
||||||
res_APDU[res_APDU_size++] = 1;
|
res_APDU[res_APDU_size++] = 0x3;
|
||||||
res_APDU[res_APDU_size++] = meta[3];
|
res_APDU[res_APDU_size++] = 1;
|
||||||
if (meta[0] == PIV_ALGO_RSA1024 || meta[0] == PIV_ALGO_RSA2048 || meta[0] == PIV_ALGO_RSA3072 || meta[0] == PIV_ALGO_RSA4096 || meta[0] == PIV_ALGO_ECCP256 || meta[0] == PIV_ALGO_ECCP384) {
|
res_APDU[res_APDU_size++] = meta[3];
|
||||||
res_APDU[res_APDU_size++] = 0x4;
|
if (meta[0] == PIV_ALGO_RSA1024 || meta[0] == PIV_ALGO_RSA2048 || meta[0] == PIV_ALGO_RSA3072 || meta[0] == PIV_ALGO_RSA4096 || meta[0] == PIV_ALGO_ECCP256 || meta[0] == PIV_ALGO_ECCP384) {
|
||||||
res_APDU[res_APDU_size++] = 0; // Filled later
|
res_APDU[res_APDU_size++] = 0x4;
|
||||||
uint8_t *pk = &res_APDU[res_APDU_size];
|
res_APDU[res_APDU_size++] = 0; // Filled later
|
||||||
if (meta[0] == PIV_ALGO_RSA1024 || meta[0] == PIV_ALGO_RSA2048 || meta[0] == PIV_ALGO_RSA3072 || meta[0] == PIV_ALGO_RSA4096) {
|
uint8_t *pk = &res_APDU[res_APDU_size];
|
||||||
mbedtls_rsa_context ctx;
|
if (meta[0] == PIV_ALGO_RSA1024 || meta[0] == PIV_ALGO_RSA2048 || meta[0] == PIV_ALGO_RSA3072 || meta[0] == PIV_ALGO_RSA4096) {
|
||||||
mbedtls_rsa_init(&ctx);
|
mbedtls_rsa_context ctx;
|
||||||
int r = load_private_key_rsa(&ctx, ef_key, false);
|
mbedtls_rsa_init(&ctx);
|
||||||
if (r != PICOKEY_OK) {
|
int r = load_private_key_rsa(&ctx, ef_key, false);
|
||||||
mbedtls_rsa_free(&ctx);
|
if (r != PICOKEY_OK) {
|
||||||
return SW_EXEC_ERROR();
|
mbedtls_rsa_free(&ctx);
|
||||||
}
|
return SW_EXEC_ERROR();
|
||||||
res_APDU[res_APDU_size++] = 0x81;
|
}
|
||||||
res_APDU[res_APDU_size++] = 0x82;
|
|
||||||
put_uint16_t_be(mbedtls_mpi_size(&ctx.N), res_APDU + res_APDU_size); res_APDU_size += 2;
|
|
||||||
mbedtls_mpi_write_binary(&ctx.N, res_APDU + res_APDU_size, mbedtls_mpi_size(&ctx.N));
|
|
||||||
res_APDU_size += mbedtls_mpi_size(&ctx.N);
|
|
||||||
res_APDU[res_APDU_size++] = 0x82;
|
|
||||||
res_APDU[res_APDU_size++] = mbedtls_mpi_size(&ctx.E) & 0xff;
|
|
||||||
mbedtls_mpi_write_binary(&ctx.E, res_APDU + res_APDU_size, mbedtls_mpi_size(&ctx.E));
|
|
||||||
res_APDU_size += mbedtls_mpi_size(&ctx.E);
|
|
||||||
mbedtls_rsa_free(&ctx);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mbedtls_ecdsa_context ctx;
|
|
||||||
mbedtls_ecdsa_init(&ctx);
|
|
||||||
int r = load_private_key_ecdsa(&ctx, ef_key, false);
|
|
||||||
if (r != PICOKEY_OK) {
|
|
||||||
mbedtls_ecdsa_free(&ctx);
|
|
||||||
return SW_EXEC_ERROR();
|
|
||||||
}
|
|
||||||
uint8_t pt[MBEDTLS_ECP_MAX_PT_LEN];
|
|
||||||
size_t plen = 0;
|
|
||||||
mbedtls_ecp_point_write_binary(&ctx.grp, &ctx.Q, MBEDTLS_ECP_PF_UNCOMPRESSED, &plen, pt, sizeof(pt));
|
|
||||||
mbedtls_ecdsa_free(&ctx);
|
|
||||||
res_APDU[res_APDU_size++] = 0x86;
|
|
||||||
if (plen >= 128) {
|
|
||||||
res_APDU[res_APDU_size++] = 0x81;
|
res_APDU[res_APDU_size++] = 0x81;
|
||||||
|
res_APDU[res_APDU_size++] = 0x82;
|
||||||
|
put_uint16_t_be(mbedtls_mpi_size(&ctx.N), res_APDU + res_APDU_size); res_APDU_size += 2;
|
||||||
|
mbedtls_mpi_write_binary(&ctx.N, res_APDU + res_APDU_size, mbedtls_mpi_size(&ctx.N));
|
||||||
|
res_APDU_size += mbedtls_mpi_size(&ctx.N);
|
||||||
|
res_APDU[res_APDU_size++] = 0x82;
|
||||||
|
res_APDU[res_APDU_size++] = mbedtls_mpi_size(&ctx.E) & 0xff;
|
||||||
|
mbedtls_mpi_write_binary(&ctx.E, res_APDU + res_APDU_size, mbedtls_mpi_size(&ctx.E));
|
||||||
|
res_APDU_size += mbedtls_mpi_size(&ctx.E);
|
||||||
|
mbedtls_rsa_free(&ctx);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mbedtls_ecdsa_context ctx;
|
||||||
|
mbedtls_ecdsa_init(&ctx);
|
||||||
|
int r = load_private_key_ecdsa(&ctx, ef_key, false);
|
||||||
|
if (r != PICOKEY_OK) {
|
||||||
|
mbedtls_ecdsa_free(&ctx);
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
|
uint8_t pt[MBEDTLS_ECP_MAX_PT_LEN];
|
||||||
|
size_t plen = 0;
|
||||||
|
mbedtls_ecp_point_write_binary(&ctx.grp, &ctx.Q, MBEDTLS_ECP_PF_UNCOMPRESSED, &plen, pt, sizeof(pt));
|
||||||
|
mbedtls_ecdsa_free(&ctx);
|
||||||
|
res_APDU[res_APDU_size++] = 0x86;
|
||||||
|
if (plen >= 128) {
|
||||||
|
res_APDU[res_APDU_size++] = 0x81;
|
||||||
|
}
|
||||||
|
res_APDU[res_APDU_size++] = plen;
|
||||||
|
memcpy(res_APDU + res_APDU_size, pt, plen);
|
||||||
|
res_APDU_size += plen;
|
||||||
|
}
|
||||||
|
uint16_t pk_len = res_APDU_size - (pk - res_APDU);
|
||||||
|
if (pk_len > 255) {
|
||||||
|
memmove(pk + 2, pk, pk_len);
|
||||||
|
pk[-1] = 0x82;
|
||||||
|
pk[0] = pk_len >> 8;
|
||||||
|
pk[1] = pk_len & 0xff;
|
||||||
|
res_APDU_size += 2;
|
||||||
|
}
|
||||||
|
else if (pk_len > 127) {
|
||||||
|
memmove(pk + 1, pk, pk_len);
|
||||||
|
pk[-1] = 0x81;
|
||||||
|
pk[0] = pk_len;
|
||||||
|
res_APDU_size += 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pk[-1] = pk_len;
|
||||||
}
|
}
|
||||||
res_APDU[res_APDU_size++] = plen;
|
|
||||||
memcpy(res_APDU + res_APDU_size, pt, plen);
|
|
||||||
res_APDU_size += plen;
|
|
||||||
}
|
|
||||||
uint16_t pk_len = res_APDU_size - (pk - res_APDU);
|
|
||||||
if (pk_len > 255) {
|
|
||||||
memmove(pk + 2, pk, pk_len);
|
|
||||||
pk[-1] = 0x82;
|
|
||||||
pk[0] = pk_len >> 8;
|
|
||||||
pk[1] = pk_len & 0xff;
|
|
||||||
res_APDU_size += 2;
|
|
||||||
}
|
|
||||||
else if (pk_len > 127) {
|
|
||||||
memmove(pk + 1, pk, pk_len);
|
|
||||||
pk[-1] = 0x81;
|
|
||||||
pk[0] = pk_len;
|
|
||||||
res_APDU_size += 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pk[-1] = pk_len;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key_ref == EF_PIV_PIN || key_ref == EF_PIV_PUK || key_ref == EF_PIV_KEY_CARDMGM) {
|
if (key_ref == EF_PIV_PIN || key_ref == EF_PIV_PUK || key_ref == EF_PIV_KEY_CARDMGM) {
|
||||||
uint8_t dhash[32];
|
uint8_t dhash[32];
|
||||||
int32_t eq = false;
|
int32_t eq = 0;
|
||||||
if (key_ref == EF_PIV_PIN) {
|
if (key_ref == EF_PIV_PIN) {
|
||||||
double_hash_pin((const uint8_t *)"\x31\x32\x33\x34\x35\x36\xFF\xFF", 8, dhash);
|
double_hash_pin((const uint8_t *)"\x31\x32\x33\x34\x35\x36\xFF\xFF", 8, dhash);
|
||||||
eq = memcmp(dhash, file_get_data(ef_key) + 1, file_get_size(ef_key) - 1);
|
eq = memcmp(dhash, file_get_data(ef_key) + 1, file_get_size(ef_key) - 1);
|
||||||
@@ -539,7 +539,7 @@ static int cmd_get_metadata() {
|
|||||||
}
|
}
|
||||||
res_APDU[res_APDU_size++] = 0x5;
|
res_APDU[res_APDU_size++] = 0x5;
|
||||||
res_APDU[res_APDU_size++] = 1;
|
res_APDU[res_APDU_size++] = 1;
|
||||||
res_APDU[res_APDU_size++] = eq;
|
res_APDU[res_APDU_size++] = eq == 0;
|
||||||
if (key_ref == EF_PIV_PIN || key_ref == EF_PIV_PUK) {
|
if (key_ref == EF_PIV_PIN || key_ref == EF_PIV_PUK) {
|
||||||
file_t *pw_status;
|
file_t *pw_status;
|
||||||
if (!(pw_status = search_by_fid(EF_PW_PRIV, NULL, SPECIFY_EF))) {
|
if (!(pw_status = search_by_fid(EF_PW_PRIV, NULL, SPECIFY_EF))) {
|
||||||
@@ -983,12 +983,13 @@ static int cmd_set_mgmkey() {
|
|||||||
}
|
}
|
||||||
uint8_t touch = P2(apdu);
|
uint8_t touch = P2(apdu);
|
||||||
if (touch != 0xFF && touch != 0xFE) {
|
if (touch != 0xFF && touch != 0xFE) {
|
||||||
if (touch == 0xFF) {
|
return SW_INCORRECT_P1P2();
|
||||||
touch = TOUCHPOLICY_NEVER;
|
}
|
||||||
}
|
if (touch == 0xFF) {
|
||||||
else if (touch == 0xFE) {
|
touch = TOUCHPOLICY_NEVER;
|
||||||
touch = TOUCHPOLICY_ALWAYS;
|
}
|
||||||
}
|
else if (touch == 0xFE) {
|
||||||
|
touch = TOUCHPOLICY_ALWAYS;
|
||||||
}
|
}
|
||||||
uint8_t algo = apdu.data[0], key_ref = apdu.data[1], pinlen = apdu.data[2];
|
uint8_t algo = apdu.data[0], key_ref = apdu.data[1], pinlen = apdu.data[2];
|
||||||
if ((key_ref != EF_PIV_KEY_CARDMGM) || (!(algo == PIV_ALGO_AES128 && pinlen == 16) && !(algo == PIV_ALGO_AES192 && pinlen == 24) && !(algo == PIV_ALGO_AES256 && pinlen == 32) && !(algo == PIV_ALGO_3DES && pinlen == 24))) {
|
if ((key_ref != EF_PIV_KEY_CARDMGM) || (!(algo == PIV_ALGO_AES128 && pinlen == 16) && !(algo == PIV_ALGO_AES192 && pinlen == 24) && !(algo == PIV_ALGO_AES256 && pinlen == 32) && !(algo == PIV_ALGO_3DES && pinlen == 24))) {
|
||||||
@@ -1017,6 +1018,9 @@ static int cmd_move_key() {
|
|||||||
if ((!IS_KEY(to) && to != 0xFF) || !IS_KEY(from)) {
|
if ((!IS_KEY(to) && to != 0xFF) || !IS_KEY(from)) {
|
||||||
return SW_INCORRECT_P1P2();
|
return SW_INCORRECT_P1P2();
|
||||||
}
|
}
|
||||||
|
if (IS_RETIRED(from) && IS_ACTIVE(to)) {
|
||||||
|
return SW_INCORRECT_P1P2();
|
||||||
|
}
|
||||||
if (from == 0x93) {
|
if (from == 0x93) {
|
||||||
from = EF_PIV_KEY_RETIRED18;
|
from = EF_PIV_KEY_RETIRED18;
|
||||||
}
|
}
|
||||||
@@ -1027,9 +1031,85 @@ static int cmd_move_key() {
|
|||||||
if (!(efs = search_by_fid(from, NULL, SPECIFY_EF)) || (!(efd = search_by_fid(to, NULL, SPECIFY_EF)) && to != 0xFF)) {
|
if (!(efs = search_by_fid(from, NULL, SPECIFY_EF)) || (!(efd = search_by_fid(to, NULL, SPECIFY_EF)) && to != 0xFF)) {
|
||||||
return SW_FILE_NOT_FOUND();
|
return SW_FILE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
|
uint16_t cert_from_fid = 0;
|
||||||
|
uint16_t cert_to_fid = 0;
|
||||||
|
if (from == EF_PIV_KEY_AUTHENTICATION) {
|
||||||
|
cert_from_fid = EF_PIV_AUTHENTICATION;
|
||||||
|
}
|
||||||
|
else if (from == EF_PIV_KEY_SIGNATURE) {
|
||||||
|
cert_from_fid = EF_PIV_SIGNATURE;
|
||||||
|
}
|
||||||
|
else if (from == EF_PIV_KEY_KEYMGM) {
|
||||||
|
cert_from_fid = EF_PIV_KEY_MANAGEMENT;
|
||||||
|
}
|
||||||
|
else if (from == EF_PIV_KEY_CARDAUTH) {
|
||||||
|
cert_from_fid = EF_PIV_CARD_AUTH;
|
||||||
|
}
|
||||||
|
else if (from == EF_PIV_KEY_RETIRED18) {
|
||||||
|
cert_from_fid = EF_PIV_RETIRED18;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cert_from_fid = from + 0xC08B;
|
||||||
|
}
|
||||||
|
if (to != 0xFF) {
|
||||||
|
if (to == EF_PIV_KEY_AUTHENTICATION) {
|
||||||
|
cert_to_fid = EF_PIV_AUTHENTICATION;
|
||||||
|
}
|
||||||
|
else if (to == EF_PIV_KEY_SIGNATURE) {
|
||||||
|
cert_to_fid = EF_PIV_SIGNATURE;
|
||||||
|
}
|
||||||
|
else if (to == EF_PIV_KEY_KEYMGM) {
|
||||||
|
cert_to_fid = EF_PIV_KEY_MANAGEMENT;
|
||||||
|
}
|
||||||
|
else if (to == EF_PIV_KEY_CARDAUTH) {
|
||||||
|
cert_to_fid = EF_PIV_CARD_AUTH;
|
||||||
|
}
|
||||||
|
else if (to == EF_PIV_KEY_RETIRED18) {
|
||||||
|
cert_to_fid = EF_PIV_RETIRED18;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cert_to_fid = to + 0xC08B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (to != 0xFF) {
|
if (to != 0xFF) {
|
||||||
file_put_data(efd, file_get_data(efs), file_get_size(efs));
|
file_put_data(efd, file_get_data(efs), file_get_size(efs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_t *ef_cert_from = search_by_fid(cert_from_fid, NULL, SPECIFY_EF);
|
||||||
|
if (to != 0xFF) {
|
||||||
|
file_t *ef_cert_to = search_by_fid(cert_to_fid, NULL, SPECIFY_EF);
|
||||||
|
if (!ef_cert_to) {
|
||||||
|
return SW_FILE_NOT_FOUND();
|
||||||
|
}
|
||||||
|
if (file_has_data(ef_cert_from)) {
|
||||||
|
file_put_data(ef_cert_to, file_get_data(ef_cert_from), file_get_size(ef_cert_from));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
flash_clear_file(ef_cert_to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ef_cert_from) {
|
||||||
|
flash_clear_file(ef_cert_from);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *meta_src = NULL;
|
||||||
|
int meta_len = meta_find(from, &meta_src);
|
||||||
|
if (to != 0xFF) {
|
||||||
|
if (meta_len > 0 && meta_src != NULL) {
|
||||||
|
uint8_t *meta_copy = (uint8_t *)calloc(1, (size_t)meta_len);
|
||||||
|
if (!meta_copy) {
|
||||||
|
return SW_MEMORY_FAILURE();
|
||||||
|
}
|
||||||
|
memcpy(meta_copy, meta_src, (size_t)meta_len);
|
||||||
|
meta_add(to, meta_copy, (uint16_t)meta_len);
|
||||||
|
free(meta_copy);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
meta_delete(to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
meta_delete(from);
|
||||||
flash_clear_file(efs);
|
flash_clear_file(efs);
|
||||||
low_flash_available();
|
low_flash_available();
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
@@ -1151,6 +1231,7 @@ static int cmd_attestation() {
|
|||||||
return SW_INCORRECT_PARAMS();
|
return SW_INCORRECT_PARAMS();
|
||||||
}
|
}
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
uint8_t abuf[2048];
|
||||||
if (meta[0] == PIV_ALGO_RSA1024 || meta[0] == PIV_ALGO_RSA2048) {
|
if (meta[0] == PIV_ALGO_RSA1024 || meta[0] == PIV_ALGO_RSA2048) {
|
||||||
mbedtls_rsa_context ctx;
|
mbedtls_rsa_context ctx;
|
||||||
mbedtls_rsa_init(&ctx);
|
mbedtls_rsa_init(&ctx);
|
||||||
@@ -1159,7 +1240,7 @@ static int cmd_attestation() {
|
|||||||
mbedtls_rsa_free(&ctx);
|
mbedtls_rsa_free(&ctx);
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
r = x509_create_cert(&ctx, meta[0], key_ref, true, res_APDU, 2048);
|
r = x509_create_cert(&ctx, meta[0], key_ref, true, abuf, sizeof(abuf));
|
||||||
mbedtls_rsa_free(&ctx);
|
mbedtls_rsa_free(&ctx);
|
||||||
}
|
}
|
||||||
else if (meta[0] == PIV_ALGO_ECCP256 || meta[0] == PIV_ALGO_ECCP384) {
|
else if (meta[0] == PIV_ALGO_ECCP256 || meta[0] == PIV_ALGO_ECCP384) {
|
||||||
@@ -1170,7 +1251,7 @@ static int cmd_attestation() {
|
|||||||
mbedtls_ecdsa_free(&ctx);
|
mbedtls_ecdsa_free(&ctx);
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
r = x509_create_cert(&ctx, meta[0], key_ref, true, res_APDU, 2048);
|
r = x509_create_cert(&ctx, meta[0], key_ref, true, abuf, sizeof(abuf));
|
||||||
mbedtls_ecdsa_free(&ctx);
|
mbedtls_ecdsa_free(&ctx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1179,7 +1260,7 @@ static int cmd_attestation() {
|
|||||||
if (r <= 0) {
|
if (r <= 0) {
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
memmove(res_APDU, res_APDU + 2048 - r, r);
|
memcpy(res_APDU, abuf + sizeof(abuf) - r, r);
|
||||||
res_APDU_size = r;
|
res_APDU_size = r;
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
* Copyright (c) 2022 Pol Henarejos.
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __VERSION_H_
|
#ifndef __VERSION_H_
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
#define PIV_VERSION_MINOR (PIV_VERSION & 0xff)
|
#define PIV_VERSION_MINOR (PIV_VERSION & 0xff)
|
||||||
|
|
||||||
|
|
||||||
#define PIPGP_VERSION 0x0304
|
#define PIPGP_VERSION 0x0404
|
||||||
|
|
||||||
#define PIPGP_VERSION_MAJOR ((PIPGP_VERSION >> 8) & 0xff)
|
#define PIPGP_VERSION_MAJOR ((PIPGP_VERSION >> 8) & 0xff)
|
||||||
#define PIPGP_VERSION_MINOR (PIPGP_VERSION & 0xff)
|
#define PIPGP_VERSION_MINOR (PIPGP_VERSION & 0xff)
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
source tests/docker_env.sh
|
source tests/docker_env.sh
|
||||||
#run_in_docker rm -rf CMakeFiles
|
#run_in_docker rm -rf CMakeFiles
|
||||||
run_in_docker mkdir -p build_in_docker
|
run_in_docker mkdir -p build_in_docker
|
||||||
run_in_docker -w "$PWD/build_in_docker" cmake -DENABLE_EMULATION=1 ..
|
run_in_docker -w "$PWD/build_in_docker" cmake -DENABLE_EMULATION=1 -DENABLE_EDDSA=1 ..
|
||||||
run_in_docker -w "$PWD/build_in_docker" make -j ${NUM_PROC}
|
run_in_docker -w "$PWD/build_in_docker" make -j ${NUM_PROC}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ def test_extended_capabilities(card):
|
|||||||
pytest.skip("Yubikey returns 6B00 when no key")
|
pytest.skip("Yubikey returns 6B00 when no key")
|
||||||
else:
|
else:
|
||||||
a = get_data_object(card, 0xc0)
|
a = get_data_object(card, 0xc0)
|
||||||
assert a == None or match(b'[\x70\x74\x75\x77]\x00\x00.[\x00\x08]\x00\x00\xff[\x00\x01][\x00\x01]', a)
|
assert a == None or match(b'[\x70\x7F\x75\x77]\x00\x00.[\x00\x08]\x00\x08\x00[\x00\x01][\x00\x01]', a)
|
||||||
|
|
||||||
def test_key_attributes_1(card):
|
def test_key_attributes_1(card):
|
||||||
if card.is_yubikey:
|
if card.is_yubikey:
|
||||||
|
|||||||
@@ -28,6 +28,26 @@ from card_const import *
|
|||||||
from constants_for_test import *
|
from constants_for_test import *
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
PRIVATE_DO_0101 = (0x01, 0x01)
|
||||||
|
PRIVATE_DO_0102 = (0x01, 0x02)
|
||||||
|
PRIVATE_DO_0103 = (0x01, 0x03)
|
||||||
|
PRIVATE_DO_0104 = (0x01, 0x04)
|
||||||
|
|
||||||
|
|
||||||
|
def _assert_sw(e, sw_list):
|
||||||
|
sw = e.args[0]
|
||||||
|
assert sw in sw_list
|
||||||
|
|
||||||
|
|
||||||
|
def _expect_security_error(callable_):
|
||||||
|
try:
|
||||||
|
callable_()
|
||||||
|
except ValueError as e:
|
||||||
|
_assert_sw(e, ["6982", "6985"])
|
||||||
|
return
|
||||||
|
assert False
|
||||||
|
|
||||||
|
|
||||||
class Test_Card_Personalize_Card_2(object):
|
class Test_Card_Personalize_Card_2(object):
|
||||||
def test_verify_pw3_0(self, card):
|
def test_verify_pw3_0(self, card):
|
||||||
v = card.verify(3, PW3_TEST0)
|
v = card.verify(3, PW3_TEST0)
|
||||||
@@ -202,3 +222,112 @@ class Test_Card_Personalize_Card_2(object):
|
|||||||
def test_verify_pw3_2(self, card):
|
def test_verify_pw3_2(self, card):
|
||||||
v = card.verify(3, PW3_TEST0)
|
v = card.verify(3, PW3_TEST0)
|
||||||
assert v
|
assert v
|
||||||
|
|
||||||
|
def test_private_do_0101_write_ok_with_pw3(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(3, PW3_TEST0)
|
||||||
|
assert v
|
||||||
|
r = card.cmd_put_data(PRIVATE_DO_0101[0], PRIVATE_DO_0101[1], b"priv0101_pw3_ok")
|
||||||
|
assert r
|
||||||
|
|
||||||
|
def test_private_do_0101_write_fail_with_pw1_81(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(1, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
_expect_security_error(
|
||||||
|
lambda: card.cmd_put_data(PRIVATE_DO_0101[0], PRIVATE_DO_0101[1], b"priv0101_pw1_81")
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_private_do_0101_write_ok_with_pw1_82(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(2, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
r = card.cmd_put_data(PRIVATE_DO_0101[0], PRIVATE_DO_0101[1], b"priv0101_ok")
|
||||||
|
assert r
|
||||||
|
|
||||||
|
def test_private_do_0101_read_always(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
data = get_data_object(card, 0x0101)
|
||||||
|
assert data == b"priv0101_ok" or data == b"priv0101_pw3_ok"
|
||||||
|
|
||||||
|
def test_private_do_0102_write_fail_with_pw1(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(2, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
_expect_security_error(
|
||||||
|
lambda: card.cmd_put_data(PRIVATE_DO_0102[0], PRIVATE_DO_0102[1], b"priv0102_pw1")
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_private_do_0102_write_ok_with_pw3(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(3, PW3_TEST0)
|
||||||
|
assert v
|
||||||
|
r = card.cmd_put_data(PRIVATE_DO_0102[0], PRIVATE_DO_0102[1], b"priv0102_ok")
|
||||||
|
assert r
|
||||||
|
|
||||||
|
def test_private_do_0102_read_always(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
data = get_data_object(card, 0x0102)
|
||||||
|
assert data == b"priv0102_ok"
|
||||||
|
|
||||||
|
def test_private_do_0103_read_fail_without_auth(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
_expect_security_error(lambda: get_data_object(card, 0x0103))
|
||||||
|
|
||||||
|
def test_private_do_0103_read_fail_with_pw1_81(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(1, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
_expect_security_error(lambda: get_data_object(card, 0x0103))
|
||||||
|
|
||||||
|
def test_private_do_0103_write_ok_with_pw3(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(3, PW3_TEST0)
|
||||||
|
assert v
|
||||||
|
r = card.cmd_put_data(PRIVATE_DO_0103[0], PRIVATE_DO_0103[1], b"priv0103_pw3_ok")
|
||||||
|
assert r
|
||||||
|
|
||||||
|
def test_private_do_0103_read_ok_with_pw3(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(3, PW3_TEST0)
|
||||||
|
assert v
|
||||||
|
data = get_data_object(card, 0x0103)
|
||||||
|
assert data == b"priv0103_pw3_ok"
|
||||||
|
|
||||||
|
def test_private_do_0103_write_ok_with_pw1_82(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(2, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
r = card.cmd_put_data(PRIVATE_DO_0103[0], PRIVATE_DO_0103[1], b"priv0103_ok")
|
||||||
|
assert r
|
||||||
|
|
||||||
|
def test_private_do_0103_read_ok_with_pw1_82(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(2, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
data = get_data_object(card, 0x0103)
|
||||||
|
assert data == b"priv0103_ok"
|
||||||
|
|
||||||
|
def test_private_do_0104_read_fail_without_auth(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
_expect_security_error(lambda: get_data_object(card, 0x0104))
|
||||||
|
|
||||||
|
def test_private_do_0104_read_fail_with_pw1(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(2, PW1_TEST4)
|
||||||
|
assert v
|
||||||
|
_expect_security_error(lambda: get_data_object(card, 0x0104))
|
||||||
|
|
||||||
|
def test_private_do_0104_write_ok_with_pw3(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(3, PW3_TEST0)
|
||||||
|
assert v
|
||||||
|
r = card.cmd_put_data(PRIVATE_DO_0104[0], PRIVATE_DO_0104[1], b"priv0104_ok")
|
||||||
|
assert r
|
||||||
|
|
||||||
|
def test_private_do_0104_read_ok_with_pw3(self, card):
|
||||||
|
card.cmd_select_openpgp()
|
||||||
|
v = card.verify(3, PW3_TEST0)
|
||||||
|
assert v
|
||||||
|
data = get_data_object(card, 0x0104)
|
||||||
|
assert data == b"priv0104_ok"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ sleep 1
|
|||||||
rm -f memory.flash
|
rm -f memory.flash
|
||||||
echo -n "Start Pico OpenPGP..."
|
echo -n "Start Pico OpenPGP..."
|
||||||
./build_in_docker/pico_openpgp > /dev/null 2>&1 &
|
./build_in_docker/pico_openpgp > /dev/null 2>&1 &
|
||||||
|
PID=$!
|
||||||
test $? -eq 0 && echo -n "." || fail
|
test $? -eq 0 && echo -n "." || fail
|
||||||
sleep 1
|
sleep 1
|
||||||
ATR="3b:da:18:ff:81:b1:fe:75:1f:03:00:31:f5:73:c0:01:60:00:90:00:1c"
|
ATR="3b:da:18:ff:81:b1:fe:75:1f:03:00:31:f5:73:c0:01:60:00:90:00:1c"
|
||||||
@@ -27,4 +28,19 @@ test $? -eq 0 && echo -e "${OK}" || fail
|
|||||||
|
|
||||||
pytest tests -W ignore::DeprecationWarning
|
pytest tests -W ignore::DeprecationWarning
|
||||||
|
|
||||||
|
echo -n "Stopping Pico OpenPGP..."
|
||||||
|
kill "$PID" 2>/dev/null || true
|
||||||
|
kill -9 "$PID" 2>/dev/null || true
|
||||||
|
test $? -eq 0 && echo -e "${OK}" || fail
|
||||||
|
sleep 1
|
||||||
|
rm -f memory.flash
|
||||||
|
echo -n "Start Pico OpenPGP..."
|
||||||
|
./build_in_docker/pico_openpgp > /dev/null 2>&1 &
|
||||||
|
PID=$!
|
||||||
|
test $? -eq 0 && echo -n "." || fail
|
||||||
|
sleep 1
|
||||||
|
e=$(opensc-tool -an 2>&1)
|
||||||
|
grep -q "${ATR}" <<< $e && echo -n "." || fail
|
||||||
|
test $? -eq 0 && echo -e "${OK}" || fail
|
||||||
|
|
||||||
./tests/scripts/cli-test.sh
|
./tests/scripts/cli-test.sh
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ if [[ $1 == "pico" ]]; then
|
|||||||
sudo apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
|
sudo apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
|
||||||
git clone https://github.com/raspberrypi/pico-sdk
|
git clone https://github.com/raspberrypi/pico-sdk
|
||||||
cd pico-sdk
|
cd pico-sdk
|
||||||
git checkout tags/2.1.1
|
git checkout tags/2.2.0
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
cd ..
|
cd ..
|
||||||
git clone https://github.com/raspberrypi/picotool
|
git clone https://github.com/raspberrypi/picotool
|
||||||
@@ -28,6 +28,7 @@ elif [[ $1 == "esp32" ]]; then
|
|||||||
sudo apt install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
|
sudo apt install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
|
||||||
git clone --recursive https://github.com/espressif/esp-idf.git
|
git clone --recursive https://github.com/espressif/esp-idf.git
|
||||||
cd esp-idf
|
cd esp-idf
|
||||||
|
git checkout tags/v5.5
|
||||||
./install.sh esp32s3
|
./install.sh esp32s3
|
||||||
. ./export.sh
|
. ./export.sh
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
Reference in New Issue
Block a user