Merge pull request #2 from Nitrokey/initial-refacto

Initial refactor
This commit is contained in:
sosthene-nitrokey
2022-12-02 15:41:17 +01:00
committed by GitHub
31 changed files with 2338 additions and 1813 deletions
+3
View File
@@ -1,2 +1,5 @@
# Copyright (C) 2022 Nicolas Stalder
# SPDX-License-Identifier: Apache-2.0 OR MIT
[net]
git-fetch-with-cli = true
+5
View File
@@ -1,2 +1,7 @@
# Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
# SPDX-License-Identifier: Apache-2.0 OR MIT
/target
Cargo.lock
tarpaulin-report.html
cobertura.xml
+50
View File
@@ -0,0 +1,50 @@
# Copyright (C) 2022 Nitrokey GmbH
# SPDX-License-Identifier: CC0-1.0
include: 'https://raw.githubusercontent.com/Nitrokey/common-ci-jobs/master/common_jobs.yml'
stages:
- pull-github
- build
- deploy
variables:
GIT_STRATEGY: clone
GIT_DEPTH: 0
GIT_SUBMODULE_STRATEGY: recursive
REPO_NAME: piv-authenticator
MAIN_BRANCH: initial-refacto
COMMON_PULL: "true"
COMMON_UPLOAD_NIGHTLY: "false"
COMMON_GITHUB_RELEASE: "false"
COMMON_UPLOAD_FILES: "false"
build:
image: registry.git.nitrokey.com/nitrokey/piv-authenticator/piv-authenticator-build:latest
rules:
- if: '$CI_PIPELINE_SHOULD_NOT_BUILD == "true"'
when: never
- if: '$CI_PIPELINE_SOURCE == "push"'
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_PIPELINE_SOURCE == "schedule"'
tags:
- docker
stage: build
before_script:
- cargo --version
script:
- make ci
after_script:
- wget $icon_server/checkmark/$CI_COMMIT_REF_NAME/$CI_COMMIT_SHA/$CI_JOB_NAME/$CI_JOB_STATUS/${CI_JOB_URL#*/*/*/}
- cp /app/.cache/scdaemon.log scdaemon.log
coverage: '/^\d+.\d+% coverage/'
artifacts:
when: always
paths:
- "scdaemon.log"
- "cobertura.xml"
- "tarpaulin-report.html"
reports:
coverage_report:
coverage_format: cobertura
path: cobertura.xml
+31 -11
View File
@@ -1,34 +1,51 @@
# Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
# SPDX-License-Identifier: Apache-2.0 OR MIT
[package]
name = "piv-authenticator"
version = "0.0.0-unreleased"
authors = ["Nicolas Stalder <n@stalder.io>"]
edition = "2018"
license = "Apache-2.0 OR MIT"
authors = ["Nicolas Stalder <n@stalder.io>", "Nitrokey GmbH"]
edition = "2021"
license = "LGPL-3.0-only"
repository = "https://github.com/solokeys/piv-authenticator"
documentation = "https://docs.rs/piv-authenticator"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[example]]
name = "virtual"
required-features = ["virtual"]
[dependencies]
apdu-dispatch = { version = "0.1", optional = true }
delog = "0.1.0"
delog = { version = "0.1.5", optional = true }
flexiber = { version = "0.1", features = ["derive", "heapless"] }
heapless = "0.7"
hex-literal = "0.3"
interchange = "0.2.0"
interchange = "0.2.2"
iso7816 = "0.1"
serde = { version = "1", default-features = false }
trussed = { git = "https://github.com/trussed-dev/trussed" }
# trussed = { path = "../../../trussed" }
untrusted = "0.7"
serde = { version = "1", default-features = false, features = ["derive"] }
trussed = "0.1"
untrusted = "0.9"
vpicc = { version = "0.1.0", optional = true }
log = "0.4"
heapless-bytes = "0.3.0"
[dev-dependencies]
littlefs2 = "0.3.1"
littlefs2 = "0.3.2"
rand_core = { version = "0.6", features = ["getrandom"] }
trussed = { version = "0.1.0", features = ["virt"] }
env_logger = "0.9"
serde = { version = "1", features = ["derive"] }
serde_cbor = { version = "0.11", features = ["std"] }
hex = "0.4"
test-log = "0.2"
ron = "0.8"
[features]
default = []
strict-pin = []
std = []
virtual = ["std", "vpicc","trussed/virt"]
log-all = []
log-none = []
@@ -36,3 +53,6 @@ log-info = []
log-debug = []
log-warn = []
log-error = []
[patch.crates-io]
trussed = { git = "https://github.com/trussed-dev/trussed", rev = "28478f8abed11d78c51e6a6a32326821ed61957a"}
+121
View File
@@ -0,0 +1,121 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
+304
View File
@@ -0,0 +1,304 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License.
"The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version".
The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed 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 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 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 price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for 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 free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
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 modification follow.
TERMS AND CONDITIONS
0. Definitions.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on the Program.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you 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 License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have 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 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, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
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 be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
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, 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 <http://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 <http://www.gnu.org/philosophy/why-not-lgpl.html>.
View File
+32
View File
@@ -1,2 +1,34 @@
# Copyright (C) 2022 Nitrokey GmbH
# SPDX-License-Identifier: CC0-1.0
.NOTPARALLEL:
export RUST_LOG ?= info,cargo_tarpaulin=off
.PHONY: build-cortex-m4
build-cortex-m4:
cargo build --target thumbv7em-none-eabi
.PHONY: test
test:
cargo test --features virtual
.PHONY: check
check:
cargo fmt --check
cargo check --all-targets --all-features
cargo clippy --all-targets --all-features -- -Dwarnings
RUSTDOCFLAGS='-Dwarnings' cargo doc --all-features
reuse lint
.PHONY: tarpaulin
tarpaulin:
cargo tarpaulin --features virtual -o Html -o Xml
.PHONY: example
example:
cargo run --example virtual --features virtual
.PHONY: ci
ci: check tarpaulin
+35
View File
@@ -0,0 +1,35 @@
<!--
Copyright (C) 2022 Nitrokey GmbH
SPDX-License-Identifier: CC0-1.0
-->
PIV-Authenticator
=================
`piv-authenticator` is a Rust implematation of the [Personnal Identity Verification](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-73-4.pdf) smartcard.
Supported features
------------------
`piv-authenticator` is still under heavy development and currently doesn't support most of PIV's features.
See the [tracking issue for command support](https://github.com/Nitrokey/piv-authenticator/issues/1) for more information.
License
-------
This project is licensed under the [GNU Lesser General Public License (LGPL)
version 3][LGPL-3.0]. Configuration files and examples are licensed under the
[CC0 1.0 license][CC0-1.0]. The [original work][original] by [Solokeys][solokeys] from which this repository is forked from is licensed under [Apache-2.0][Apache-2.0] OR [MIT][MIT] For more information, see the license header in
each file. You can find a copy of the license texts in the
[`LICENSES`](./LICENSES) directory.
[LGPL-3.0]: https://opensource.org/licenses/LGPL-3.0
[CC0-1.0]: https://creativecommons.org/publicdomain/zero/1.0/
[Apache-2.0]: https://www.apache.org/licenses/LICENSE-2.0.html
[MIT]: https://en.wikipedia.org/wiki/MIT_License
[solokeys]: https://solokeys.com/
[original]: https://github.com/solokeys/piv-authenticator
This project complies with [version 3.0 of the REUSE specification][reuse].
[reuse]: https://reuse.software/practices/3.0/
+2
View File
@@ -1,3 +1,5 @@
# Copyright (C) 2022 Nicolas Stalder
# SPDX-License-Identifier: Apache-2.0 OR MIT
# This is a configuration file for the bacon tool
# More info at https://github.com/Canop/bacon
+20
View File
@@ -0,0 +1,20 @@
# Copyright (C) 2022 Nitrokey GmbH
# SPDX-License-Identifier: CC0-1.0
FROM docker.io/rust:latest
RUN apt update && apt install --yes scdaemon libclang-dev llvm python3-pip vsmartcard-vpcd pkg-config nettle-dev libpcsclite-dev
RUN python3 -m pip install reuse
RUN rustup component add clippy rustfmt && rustup target add thumbv7em-none-eabi
RUN cargo install cargo-tarpaulin --profile release && rm -rf "$CARGO_HOME"/registry
# initialize cargo cache
RUN cargo search
ENV CARGO_HOME=/app/.cache/cargo
WORKDIR /app
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
+29
View File
@@ -0,0 +1,29 @@
# Copyright (C) 2022 Nitrokey GmbH
# SPDX-License-Identifier: CC0-1.0
-include config.mk
TAG := registry.git.nitrokey.com/nitrokey/piv-authenticator/piv-authenticator-build
DOCKER ?= docker
FUZZ_JOBS?=$(shell nproc)
FUZZ_DURATION?="0"
.PHONY: build
build:
$(DOCKER) build . --tag $(TAG)
.PHONY: push
push:
$(DOCKER) push $(TAG)
.PHONY: run
run:
$(DOCKER) run --interactive --rm --volume "$(PWD)/..:/app" --env RUST_LOG $(TAG) make ci
.PHONY: test
test:
$(DOCKER) run --interactive --rm --volume "$(PWD)/..:/app" --env RUST_LOG $(TAG) make test
.PHONY: fuzz
fuzz:
$(DOCKER) run --interactive --rm --volume "$(PWD)/..:/app" --env RUST_LOG $(TAG) make fuzz FUZZ_JOBS=${FUZZ_JOBS} FUZZ_DURATION=${FUZZ_DURATION}
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
# Copyright (C) 2022 Nitrokey GmbH
# SPDX-License-Identifier: CC0-1.0
set -e
mkdir -p /app/.cache
if [ ! -e "$CARGO_HOME" ]
then
cp -r /usr/local/cargo $CARGO_HOME
fi
pcscd
exec "$@"
+25
View File
@@ -0,0 +1,25 @@
// Copyright (C) 2022 Nitrokey GmbH
// SPDX-License-Identifier: CC0-1.0
// To use this, make sure that you have vpcd from vsmartcard installed and configured (e. g.
// install vsmartcard-vpcd on Debian). You might have to restart your pcscd, e. g.
// `systemctl restart pcscd pcscd.socket`.
//
// Now you should be able to see the card in `pcsc_scan` and talk to it with `piv-tool`r
//
// Set `RUST_LOG=piv_authenticator::card=info` to see the executed commands.
// TODO: add CLI
fn main() {
env_logger::init();
trussed::virt::with_ram_client("piv-authenticator", |client| {
let card = piv_authenticator::Authenticator::new(client);
let mut virtual_card = piv_authenticator::vpicc::VirtualCard::new(card);
let vpicc = vpicc::connect().expect("failed to connect to vpicc");
vpicc
.run(&mut virtual_card)
.expect("failed to run virtual smartcard");
});
}
+121 -203
View File
@@ -1,3 +1,6 @@
// Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
//! Parsed PIV commands.
//!
//! The types here should enforce all restrictions in the spec (such as padded_piv_pin.len() == 8),
@@ -8,7 +11,27 @@ use core::convert::{TryFrom, TryInto};
// use flexiber::Decodable;
use iso7816::{Instruction, Status};
pub use crate::{container as containers, piv_types, Pin, Puk};
use crate::state::TouchPolicy;
pub use crate::{
container::{
self as containers, AttestKeyReference, AuthenticateKeyReference,
ChangeReferenceKeyReference, GenerateAsymmetricKeyReference, VerifyKeyReference,
},
piv_types, Pin, Puk,
};
// https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum YubicoPivExtension {
SetManagementKey(TouchPolicy),
ImportAsymmetricKey,
GetVersion,
Reset,
SetPinRetries,
Attest(AttestKeyReference),
GetSerial, // also used via 0x01
GetMetadata,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Command<'l> {
@@ -32,10 +55,19 @@ pub enum Command<'l> {
/// The most general purpose method, performing actual cryptographic operations
///
/// In particular, this can also decrypt or similar.
Authenticate(Authenticate),
GeneralAuthenticate(GeneralAuthenticate),
/// Store a data object / container.
PutData(PutData),
GenerateAsymmetric(GenerateAsymmetric),
GenerateAsymmetric(GenerateAsymmetricKeyReference),
/* Yubico commands */
YkExtension(YubicoPivExtension),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GeneralAuthenticate {
algorithm: piv_types::Algorithms,
key_reference: AuthenticateKeyReference,
}
impl<'l> Command<'l> {
@@ -66,7 +98,6 @@ impl<'l> TryFrom<&'l [u8]> for Select<'l> {
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GetData(containers::Container);
@@ -74,7 +105,9 @@ impl TryFrom<&[u8]> for GetData {
type Error = Status;
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
let mut decoder = flexiber::Decoder::new(data);
let tagged_slice: flexiber::TaggedSlice = decoder.decode().map_err(|_| Status::IncorrectDataParameter)?;
let tagged_slice: flexiber::TaggedSlice = decoder
.decode()
.map_err(|_| Status::IncorrectDataParameter)?;
if tagged_slice.tag() != flexiber::Tag::application(0x1C) {
return Err(Status::IncorrectDataParameter);
}
@@ -82,41 +115,11 @@ impl TryFrom<&[u8]> for GetData {
.try_into()
.map_err(|_| Status::IncorrectDataParameter)?;
info_now!("request to GetData for container {:?}", container);
info!("request to GetData for container {:?}", container);
Ok(Self(container))
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum VerifyKeyReference {
GlobalPin = 0x00,
PivPin = 0x80,
PrimaryFingerOcc = 0x96,
SecondaryFingerOcc = 0x97,
PairingCode = 0x98,
}
impl TryFrom<u8> for VerifyKeyReference {
type Error = Status;
fn try_from(p2: u8) -> Result<Self, Self::Error> {
// If the PIV Card Application does not contain the Discovery Object as described in Part 1,
// then no other key reference shall be able to be verified by the PIV Card Application VERIFY command.
match p2 {
0x00 => Ok(Self::GlobalPin),
// 0x00 => Err(Status::FunctionNotSupported),
0x80 => Ok(Self::PivPin),
0x96 => Ok(Self::PrimaryFingerOcc),
0x97 => Ok(Self::SecondaryFingerOcc),
0x98 => Ok(Self::PairingCode),
// 0x96 => Err(Status::FunctionNotSupported),
// 0x97 => Err(Status::FunctionNotSupported),
// 0x98 => Err(Status::FunctionNotSupported),
_ => Err(Status::KeyReferenceNotFound),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct VerifyLogout(bool);
@@ -130,7 +133,6 @@ impl TryFrom<u8> for VerifyLogout {
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct VerifyArguments<'l> {
pub key_reference: VerifyKeyReference,
@@ -155,13 +157,20 @@ pub enum Verify {
impl TryFrom<VerifyArguments<'_>> for Verify {
type Error = Status;
fn try_from(arguments: VerifyArguments<'_>) -> Result<Self, Self::Error> {
let VerifyArguments { key_reference, logout, data } = arguments;
if key_reference != VerifyKeyReference::PivPin {
let VerifyArguments {
key_reference,
logout,
data,
} = arguments;
if key_reference != VerifyKeyReference::ApplicationPin {
return Err(Status::FunctionNotSupported);
}
Ok(match (logout.0, data.len()) {
(false, 0) => Verify::Status(key_reference),
(false, 8) => Verify::Login(VerifyLogin::PivPin(data.try_into().map_err(|_| Status::IncorrectDataParameter)?)),
(false, 8) => Verify::Login(VerifyLogin::PivPin(
data.try_into()
.map_err(|_| Status::IncorrectDataParameter)?,
)),
(false, _) => return Err(Status::IncorrectDataParameter),
(true, 0) => Verify::Logout(key_reference),
(true, _) => return Err(Status::IncorrectDataParameter),
@@ -169,26 +178,6 @@ impl TryFrom<VerifyArguments<'_>> for Verify {
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum ChangeReferenceKeyReference {
GlobalPin = 0x00,
PivPin = 0x80,
Puk = 0x81,
}
impl TryFrom<u8> for ChangeReferenceKeyReference {
type Error = Status;
fn try_from(p2: u8) -> Result<Self, Self::Error> {
match p2 {
0x00 => Ok(Self::GlobalPin),
0x80 => Ok(Self::PivPin),
0x81 => Ok(Self::Puk),
_ => Err(Status::KeyReferenceNotFound),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ChangeReferenceArguments<'l> {
pub key_reference: ChangeReferenceKeyReference,
@@ -204,24 +193,26 @@ pub enum ChangeReference {
impl TryFrom<ChangeReferenceArguments<'_>> for ChangeReference {
type Error = Status;
fn try_from(arguments: ChangeReferenceArguments<'_>) -> Result<Self, Self::Error> {
let ChangeReferenceArguments { key_reference, data } = arguments;
let ChangeReferenceArguments {
key_reference,
data,
} = arguments;
use ChangeReferenceKeyReference::*;
Ok(match (key_reference, data) {
(GlobalPin, _) => return Err(Status::FunctionNotSupported),
(PivPin, data) => {
ChangeReference::ChangePin {
old_pin: Pin::try_from(&data[..8]).map_err(|_| Status::IncorrectDataParameter)?,
new_pin: Pin::try_from(&data[8..]).map_err(|_| Status::IncorrectDataParameter)?,
}
}
(Puk, data) => {
use crate::commands::Puk;
ChangeReference::ChangePuk {
old_puk: Puk(data[..8].try_into().map_err(|_| Status::IncorrectDataParameter)?),
new_puk: Puk(data[8..].try_into().map_err(|_| Status::IncorrectDataParameter)?),
}
}
(ApplicationPin, data) => ChangeReference::ChangePin {
old_pin: Pin::try_from(&data[..8]).map_err(|_| Status::IncorrectDataParameter)?,
new_pin: Pin::try_from(&data[8..]).map_err(|_| Status::IncorrectDataParameter)?,
},
(PinUnblockingKey, data) => ChangeReference::ChangePuk {
old_puk: Puk(data[..8]
.try_into()
.map_err(|_| Status::IncorrectDataParameter)?),
new_puk: Puk(data[8..]
.try_into()
.map_err(|_| Status::IncorrectDataParameter)?),
},
})
}
}
@@ -229,7 +220,7 @@ impl TryFrom<ChangeReferenceArguments<'_>> for ChangeReference {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ResetPinRetries {
pub padded_pin: [u8; 8],
pub puk: [u8; 8],
pub puk: [u8; 8],
}
impl TryFrom<&[u8]> for ResetPinRetries {
@@ -245,72 +236,6 @@ impl TryFrom<&[u8]> for ResetPinRetries {
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum AuthenticateKeyReference {
SecureMessaging = 0x04,
Authentication = 0x9a,
Administration = 0x9b,
Signature = 0x9c,
Management = 0x9d,
CardAuthentication = 0x9e,
Retired01 = 0x82,
Retired02 = 0x83,
Retired03 = 0x84,
Retired04 = 0x85,
Retired05 = 0x86,
Retired06 = 0x87,
Retired07 = 0x88,
Retired08 = 0x89,
Retired09 = 0x8A,
Retired10 = 0x8B,
Retired11 = 0x8C,
Retired12 = 0x8D,
Retired13 = 0x8E,
Retired14 = 0x8F,
Retired15 = 0x90,
Retired16 = 0x91,
Retired17 = 0x92,
Retired18 = 0x93,
Retired19 = 0x94,
Retired20 = 0x95,
}
impl TryFrom<u8> for AuthenticateKeyReference {
type Error = Status;
fn try_from(p2: u8) -> Result<Self, Self::Error> {
match p2 {
0x04 => Ok(Self::SecureMessaging),
0x9a => Ok(Self::Authentication),
0x9b => Ok(Self::Administration),
0x9c => Ok(Self::Signature),
0x9d => Ok(Self::Management),
0x9e => Ok(Self::CardAuthentication),
0x82 => Ok(Self::Retired01),
0x83 => Ok(Self::Retired02),
0x84 => Ok(Self::Retired03),
0x85 => Ok(Self::Retired04),
0x86 => Ok(Self::Retired05),
0x87 => Ok(Self::Retired06),
0x88 => Ok(Self::Retired07),
0x89 => Ok(Self::Retired08),
0x8A => Ok(Self::Retired09),
0x8B => Ok(Self::Retired10),
0x8C => Ok(Self::Retired11),
0x8D => Ok(Self::Retired12),
0x8E => Ok(Self::Retired13),
0x8F => Ok(Self::Retired14),
0x90 => Ok(Self::Retired15),
0x91 => Ok(Self::Retired16),
0x92 => Ok(Self::Retired17),
0x93 => Ok(Self::Retired18),
0x94 => Ok(Self::Retired19),
0x95 => Ok(Self::Retired20),
_ => Err(Status::KeyReferenceNotFound),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct AuthenticateArguments<'l> {
/// To allow the authenticator to have additional algorithms beyond NIST SP 800-78-4,
@@ -321,19 +246,7 @@ pub struct AuthenticateArguments<'l> {
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Authenticate {
}
impl TryFrom<AuthenticateArguments<'_>> for Authenticate {
type Error = Status;
fn try_from(_arguments: AuthenticateArguments<'_>) -> Result<Self, Self::Error> {
todo!();
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct PutData {
}
pub struct PutData {}
impl TryFrom<&[u8]> for PutData {
type Error = Status;
@@ -342,47 +255,6 @@ impl TryFrom<&[u8]> for PutData {
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u8)]
pub enum GenerateAsymmetricKeyReference {
SecureMessaging = 0x04,
Authentication = 0x9a,
Signature = 0x9c,
Management = 0x9d,
CardAuthentication = 0x9e,
}
impl TryFrom<u8> for GenerateAsymmetricKeyReference {
type Error = Status;
fn try_from(p2: u8) -> Result<Self, Self::Error> {
match p2 {
0x04 => Err(Status::FunctionNotSupported),
0x9a => Ok(Self::Authentication),
0x9c => Ok(Self::Signature),
0x9d => Ok(Self::Management),
0x9e => Ok(Self::CardAuthentication),
_ => Err(Status::KeyReferenceNotFound),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GenerateAsymmetricArguments<'l> {
pub key_reference: GenerateAsymmetricKeyReference,
pub data: &'l [u8],
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum GenerateAsymmetric {
}
impl TryFrom<GenerateAsymmetricArguments<'_>> for GenerateAsymmetric {
type Error = Status;
fn try_from(_arguments: GenerateAsymmetricArguments<'_>) -> Result<Self, Self::Error> {
todo!();
}
}
impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
type Error = Status;
/// The first layer of unraveling the iso7816::Command onion.
@@ -392,7 +264,12 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
///
/// The individual piv::Command TryFroms then further interpret these validated parameters.
fn try_from(command: &'l iso7816::Command<C>) -> Result<Self, Self::Error> {
let (class, instruction, p1, p2) = (command.class(), command.instruction(), command.p1, command.p2);
let (class, instruction, p1, p2) = (
command.class(),
command.instruction(),
command.p1,
command.p2,
);
let data = command.data();
if !class.secure_messaging().none() {
@@ -406,7 +283,6 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
// TODO: should we check `command.expected() == 0`, where specified?
Ok(match (class.into_inner(), instruction, p1, p2) {
(0x00, Instruction::Select, 0x04, 0x00) => {
Self::Select(Select::try_from(data.as_slice())?)
}
@@ -418,12 +294,19 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
(0x00, Instruction::Verify, p1, p2) => {
let logout = VerifyLogout::try_from(p1)?;
let key_reference = VerifyKeyReference::try_from(p2)?;
Self::Verify(Verify::try_from(VerifyArguments { key_reference, logout, data })?)
Self::Verify(Verify::try_from(VerifyArguments {
key_reference,
logout,
data,
})?)
}
(0x00, Instruction::ChangeReferenceData, 0x00, p2) => {
let key_reference = ChangeReferenceKeyReference::try_from(p2)?;
Self::ChangeReference(ChangeReference::try_from(ChangeReferenceArguments { key_reference, data })?)
Self::ChangeReference(ChangeReference::try_from(ChangeReferenceArguments {
key_reference,
data,
})?)
}
(0x00, Instruction::ResetRetryCounter, 0x00, 0x80) => {
@@ -431,9 +314,12 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
}
(0x00, Instruction::GeneralAuthenticate, p1, p2) => {
let unparsed_algorithm = p1;
let algorithm = p1.try_into()?;
let key_reference = AuthenticateKeyReference::try_from(p2)?;
Self::Authenticate(Authenticate::try_from(AuthenticateArguments { unparsed_algorithm, key_reference, data })?)
Self::GeneralAuthenticate(GeneralAuthenticate {
algorithm,
key_reference,
})
}
(0x00, Instruction::PutData, 0x3F, 0xFF) => {
@@ -441,8 +327,40 @@ impl<'l, const C: usize> TryFrom<&'l iso7816::Command<C>> for Command<'l> {
}
(0x00, Instruction::GenerateAsymmetricKeyPair, 0x00, p2) => {
let key_reference = GenerateAsymmetricKeyReference::try_from(p2)?;
Self::GenerateAsymmetric(GenerateAsymmetric::try_from(GenerateAsymmetricArguments { key_reference, data })?)
Self::GenerateAsymmetric(GenerateAsymmetricKeyReference::try_from(p2)?)
}
// (0x00, 0x01, 0x10, 0x00)
(0x00, Instruction::Unknown(0x01), 0x00, 0x00) => {
Self::YkExtension(YubicoPivExtension::GetSerial)
}
(0x00, Instruction::Unknown(0xff), 0xFF, 0xFE) => {
Self::YkExtension(YubicoPivExtension::SetManagementKey(TouchPolicy::Never))
}
(0x00, Instruction::Unknown(0xff), 0xFF, 0xFF) => {
Self::YkExtension(YubicoPivExtension::SetManagementKey(TouchPolicy::Always))
}
(0x00, Instruction::Unknown(0xfe), 0x00, 0x00) => {
Self::YkExtension(YubicoPivExtension::ImportAsymmetricKey)
}
(0x00, Instruction::Unknown(0xfd), 0x00, 0x00) => {
Self::YkExtension(YubicoPivExtension::GetVersion)
}
(0x00, Instruction::Unknown(0xfb), 0x00, 0x00) => {
Self::YkExtension(YubicoPivExtension::Reset)
}
(0x00, Instruction::Unknown(0xfa), 0x00, 0x00) => {
Self::YkExtension(YubicoPivExtension::SetPinRetries)
}
// (0x00, 0xf9, 0x9a, 0x00)
(0x00, Instruction::Unknown(0xf9), _, 0x00) => Self::YkExtension(
YubicoPivExtension::Attest(AttestKeyReference::try_from(p1)?),
),
// (0x00, 0xf8, 0x00, 0x00)
(0x00, Instruction::Unknown(0xf8), _, _) => {
Self::YkExtension(YubicoPivExtension::GetSerial)
}
(0x00, Instruction::Unknown(0xf7), _, _) => {
Self::YkExtension(YubicoPivExtension::GetMetadata)
}
_ => return Err(Status::FunctionNotSupported),
+141 -299
View File
@@ -1,5 +1,10 @@
// Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
// https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
use hex_literal::hex;
pub const RID_LENGTH: usize = 5;
// top nibble of first byte is "category", here "A" = International
@@ -19,7 +24,8 @@ pub const DERIVED_PIV_PIX: [u8; 6] = hex!("0000 2000 0100");
pub const PIV_TRUNCATED_AID: [u8; 9] = hex!("A000000308 00001000");
// pub const PIV_AID: &[u8] = &hex!("A000000308 00001000 0100");
pub const PIV_AID: iso7816::Aid = iso7816::Aid::new_truncatable(&hex!("A000000308 00001000 0100"), 9);
pub const PIV_AID: iso7816::Aid =
iso7816::Aid::new_truncatable(&hex!("A000000308 00001000 0100"), 9);
pub const DERIVED_PIV_AID: [u8; 11] = hex!("A000000308 00002000 0100");
@@ -27,7 +33,6 @@ pub const APPLICATION_LABEL: &[u8] = b"SoloKeys PIV";
pub const APPLICATION_URL: &[u8] = b"https://github.com/solokeys/piv-authenticator";
// pub const APPLICATION_URL: &[u8] = b"https://piv.is/SoloKeys/PIV/1.0.0-alpha1";
// https://git.io/JfWuD
pub const YUBICO_OTP_PIX: [u8; 3] = hex!("200101");
pub const YUBICO_OTP_AID: iso7816::Aid = iso7816::Aid::new(&hex!("A000000527 200101"));
@@ -84,7 +89,7 @@ pub const SELECT: (u8, u8, u8, u8) = (
// p2: i think this is dummy here
0x00, // b2, b1 zero means "file occurence": first/only occurence,
// b4, b3 zero means "file control information": return FCI template
// 256,
// 256,
);
//
@@ -101,149 +106,14 @@ pub const SELECT: (u8, u8, u8, u8) = (
pub const GET_DATA: (u8, u8, u8, u8) = (
0x00, // as before, would be 0x0C for secure messaging
0xCB, // GET DATA. There's also `CA`, setting bit 1 here
// means (7816-4, sec. 5.1.2): use BER-TLV, as opposed
// to "no indication provided".
// means (7816-4, sec. 5.1.2): use BER-TLV, as opposed
// to "no indication provided".
// P1, P2: 7816-4, sec. 7.4.1: bit 1 of INS set => P1,P2 identifies
// a file. And 0x3FFF identifies current DF
0x3F,
0xFF,
0x3F, 0xFF,
// 256,
);
// SW (SP 800-73 Part 1, Table 6)
// == == == == == == == == == == ==
// 61, xx success, more response data bytes
//
// 63, 00 verification failed
// 63, Cx verification failed, x furtehr retries or resets
//
// 68, 82 secure messaging not supported
//
// 69, 82 security status not satisfied
// 69, 83 authn method blocked
// : (more secure messaging stuff)
//
//// ISO/IEC 7816-4, 5.1.3 "Status bytes"
//#[derive(Copy, Clone, Debug, Eq, PartialEq)]
//pub enum StatusWord {
////////////////////////////////
//// Normal processing (90, 61)
////////////////////////////////
// // 9000
// Success,
// // 61XX
// MoreAvailable(u8),
/////////////////////////////////
//// Warning processing (62, 63)
/////////////////////////////////
// // 62XX: state of non-volatile memory unchanged (cf. SW2)
// // 63XX: state of non-volatile memory changed (cf. SW2)
// VerificationFailed,
// FailedRetries(u8),
//////////////////////////////////
//// Execution error (64, 65, 66)
//////////////////////////////////
// // 64XX: persistent memory unchanged (cf. SW2)
// // 65XX: persistent memory changed (cf. SW2)
// // 66XX: security related issues
/////////////////////////////////
//// Checking error (67 - 6F)
/////////////////////////////////
// // 6700: wrong length, no further indication
// // 68XX: functions in CLA not supported (cf. SW2)
// SecureMessagingNotSupported,
// CommandChainingNotSupported,
// // 69xx: command not allowed (cf. SW2)
// SecurityStatusNotSatisfied,
// OperationBlocked,
// // 6Axx: wrong parameters P1-P2 (cf. SW2)
// IncorrectDataParameter,
// FunctionNotSupported,
// NotFound,
// NotEnoughMemory,
// IncorrectP1OrP2Parameter,
// KeyReferenceNotFound,
// // 6BXX: wrong parameters P1-P2
// // 6CXX: wrong Le field, SW2 encodes available bytes
// // 6D00: instruction code not supported or invalid
// InstructionNotSupportedOrInvalid,
// // 6E00: class not supported
// ClassNotSupported,
// // 6F00: no precise diagnosis
// UnspecifiedCheckingError,
//}
//impl Into<u16> for StatusWord {
// #[inline]
// fn into(self) -> u16 {
// match self {
// Self::VerificationFailed => 0x6300,
// Self::FailedRetries(x) => {
// assert!(x < 16);
// u16::from_be_bytes([0x63, 0xc0 + x])
// }
// Self::SecureMessagingNotSupported => 0x6882,
// Self::CommandChainingNotSupported => 0x6884,
// Self::SecurityStatusNotSatisfied => 0x6982,
// Self::OperationBlocked => 0x6983,
// Self::IncorrectDataParameter => 0x6a80,
// Self::FunctionNotSupported => 0x6a81,
// Self::NotFound => 0x6a82,
// Self::NotEnoughMemory => 0x6a84,
// Self::IncorrectP1OrP2Parameter => 0x6a86,
// Self::KeyReferenceNotFound => 0x6a88,
// Self::InstructionNotSupportedOrInvalid => 0x6d00,
// Self::ClassNotSupported => 0x6e00,
// Self::UnspecifiedCheckingError => 0x6f00,
// Self::Success => 0x9000,
// Self::MoreAvailable(x) => u16::from_be_bytes([0x61, x]),
// }
// }
//}
//impl Into<[u8; 2]> for StatusWord {
// #[inline]
// fn into(self) -> [u8; 2] {
// let sw: u16 = self.into();
// sw.to_be_bytes()
// }
//}
// 6A, 80 incorrect parameter in command data field
// 6A, 81 function not supported
// 6A, 82 data object not found ( = NOT FOUND for files, e.g. certificate, e.g. after GET-DATA)
// 6A, 84 not enough memory
// 6A, 86 incorrect parameter in P1/P2
// 6A, 88 reference(d) data not found ( = NOT FOUND for keys, e.g. global PIN, e.g. after VERIFY)
//
// 90, 00 SUCCESS!
// == == == == == == == == == == ==
// #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct DataObjects {}
#[allow(non_upper_case_globals)]
@@ -265,168 +135,140 @@ impl DataObjects {
pub struct YubicoObjects {}
#[allow(non_upper_case_globals)]
impl YubicoObjects {
pub const AttestationCertificate: &'static [u8] = b"\x5f\xff\x01";
pub const AttestationCertificate: &'static [u8] = &hex!("5fff01");
}
// https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum YubicoPivExtension {
SetManagementKey = 0xff,
ImportAsymmetricKey = 0xfe,
GetVersion = 0xfd,
Reset = 0xfb,
SetPinRetries = 0xfa,
Attest = 0xf9,
GetSerial = 0xf8, // also used via 0x01
GetMetadata = 0xf7,
}
pub const YUBICO_PIV_AUTHENTICATION_CERTIFICATE: &[u8; 351] = &hex!(
"
5382 015b 7082 0152 3082 014e 3081 f5a0
0302 0102 0211 008e 4632 d8f0 c1f7 c14d
67d1 4bfd e364 8e30 0a06 082a 8648 ce3d
0403 0230 2a31 1630 1406 0355 040a 130d
7975 6269 6b65 792d 6167 656e 7431 1030
0e06 0355 040b 1307 2864 6576 656c 2930
2017 0d32 3030 3530 3931 3230 3034 395a
180f 3230 3632 3035 3039 3133 3030 3439
5a30 1231 1030 0e06 0355 0403 1307 5353
4820 6b65 7930 5930 1306 072a 8648 ce3d
0201 0608 2a86 48ce 3d03 0107 0342 0004
832a 9247 8b4e b57a 461b 2a5e 0e44 2503
9bfb 2794 5678 ed48 2b1c f221 616d dabd
3d8f b62b 75c6 ac3f 834a 594e 5adf ede7
3ae4 991a e733 2f61 2bcf 6c0e d678 72eb
a312 3010 300e 0603 551d 0f01 01ff 0404
0302 0388 300a 0608 2a86 48ce 3d04 0302
0348 0030 4502 2003 09e2 8447 dcb7 c532
ee97 5b9e 44fa 4206 f226 67c1 a6c6 4adc
6a0b 5da9 8763 8b02 2100 bb4e cb18 72cc
1239 d3d4 1836 1418 e4a9 f383 814b 740f
9333 b847 a973 c282 923e 7101 00fe 00
"
);
impl core::convert::TryFrom<u8> for YubicoPivExtension {
type Error = ();
fn try_from(ins: u8) -> core::result::Result<Self, Self::Error> {
Ok(match ins {
// (0x00, 0x01, 0x10, 0x00)
0x01 => YubicoPivExtension::GetSerial,
0xff => YubicoPivExtension::SetManagementKey,
0xfe => YubicoPivExtension::ImportAsymmetricKey,
0xfd => YubicoPivExtension::GetVersion,
0xfb => YubicoPivExtension::Reset,
0xfa => YubicoPivExtension::SetPinRetries,
// (0x00, 0xf9, 0x9a, 0x00)
0xf9 => YubicoPivExtension::Attest,
// (0x00, 0xf8, 0x00, 0x00)
0xf8 => YubicoPivExtension::GetSerial,
0xf7 => YubicoPivExtension::GetMetadata,
_ => return Err(()),
})
}
}
pub const YUBICO_ATTESTATION_CERTIFICATE: &[u8; 754] = &hex!(
"
5382 02ee 7082 02ea 3082 02e6 3082 01ce
a003 0201 0202 0900 a485 22aa 34af ae4f
300d 0609 2a86 4886 f70d 0101 0b05 0030
2b31 2930 2706 0355 0403 0c20 5975 6269
636f 2050 4956 2052 6f6f 7420 4341 2053
6572 6961 6c20 3236 3337 3531 3020 170d
3136 3033 3134 3030 3030 3030 5a18 0f32
3035 3230 3431 3730 3030 3030 305a 3021
311f 301d 0603 5504 030c 1659 7562 6963
6f20 5049 5620 4174 7465 7374 6174 696f
6e30 8201 2230 0d06 092a 8648 86f7 0d01
0101 0500 0382 010f 0030 8201 0a02 8201
0100 aba9 0b16 9bef 31cc 3eac 185a 2d45
8075 70c7 58b0 6c3f 1b59 0d49 b989 e86f
cebb 276f d83c 603a 8500 ef5c bc40 993d
41ee eac0 817f 7648 e4a9 4cbc d56b e11f
0a60 93c6 feaa d28d 8ee2 b7cd 8b2b f79b
dd5a ab2f cfb9 0e54 ceec 8df5 5ed7 7b91
c3a7 569c dcc1 0686 7636 4453 fb08 25d8
06b9 068c 81fd 6367 ca3c a8b8 ea1c a6ca
db44 7b12 cab2 3401 7e73 e436 83df ebf9
2300 0701 6a07 198a 6456 9d10 8ac5 7302
3d18 6eaf 3fc3 02a7 c0f7 a2fd 6d5a 4276
4ed6 c01e d6c0 c6aa 5da7 1a9f 10db 3057
185c b5b5 fd0c be49 2422 af1e 564a 3444
d4aa d4e1 ae95 4c75 c088 61f4 8c7e 54f3
13eb 0fe5 2b52 605a 6eba d7e5 8c63 da51
1abb 225c 372b d7d1 7057 4c2e dc35 3c22
989b 0203 0100 01a3 1530 1330 1106 0a2b
0601 0401 82c4 0a03 0304 0304 0303 300d
0609 2a86 4886 f70d 0101 0b05 0003 8201
0100 5280 5a6d c39e df47 a8f1 b2a5 9ca3
8081 3b1d 6aeb 6a12 624b 11fd 8d30 f17b
fc71 10c9 b208 fcd1 4e35 7f45 f210 a252
b9d4 b302 1a01 5607 6bfa 64a7 08f0 03fb
27a9 608d 0dd3 ac5a 10cf 2096 4e82 bc9d
e337 dac1 4c50 e13d 16b4 caf4 1bff 0864
c974 4f2a 3a43 e0de 4279 f213 ae77 a1e2
ae6b df72 a5b6 ced7 4c90 13df dedb f28b
3445 8b30 dc51 aba9 34f8 a9e5 0c47 29aa
2f42 54f2 f819 5ab4 89fe 1b9f 197a 16c8
c8ba 8f18 177a 07a9 97a1 56b9 525d a121
c081 672d e80e a651 b908 b09d d360 1c70
a30f fad8 62d8 792b 0ae6 42fc f82d f5e4
cdfb 1596 23ff b6c0 a7a7 e285 83f9 70c8
196b f3c1 3f37 4465 27fb 6788 c883 b72f
851f 8044 bb72 ce06 8259 2d83 00e1 948d
a085
"
);
pub const YUBICO_PIV_AUTHENTICATION_CERTIFICATE: &'static [u8; 351] = &[
0x53, 0x82, 0x01, 0x5b, 0x70, 0x82, 0x01, 0x52, 0x30, 0x82, 0x01, 0x4e, 0x30, 0x81, 0xf5, 0xa0,
0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00, 0x8e, 0x46, 0x32, 0xd8, 0xf0, 0xc1, 0xf7, 0xc1, 0x4d,
0x67, 0xd1, 0x4b, 0xfd, 0xe3, 0x64, 0x8e, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
0x04, 0x03, 0x02, 0x30, 0x2a, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d,
0x79, 0x75, 0x62, 0x69, 0x6b, 0x65, 0x79, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x31, 0x10, 0x30,
0x0e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x07, 0x28, 0x64, 0x65, 0x76, 0x65, 0x6c, 0x29, 0x30,
0x20, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x35, 0x30, 0x39, 0x31, 0x32, 0x30, 0x30, 0x34, 0x39, 0x5a,
0x18, 0x0f, 0x32, 0x30, 0x36, 0x32, 0x30, 0x35, 0x30, 0x39, 0x31, 0x33, 0x30, 0x30, 0x34, 0x39,
0x5a, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x07, 0x53, 0x53,
0x48, 0x20, 0x6b, 0x65, 0x79, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d,
0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04,
0x83, 0x2a, 0x92, 0x47, 0x8b, 0x4e, 0xb5, 0x7a, 0x46, 0x1b, 0x2a, 0x5e, 0x0e, 0x44, 0x25, 0x03,
0x9b, 0xfb, 0x27, 0x94, 0x56, 0x78, 0xed, 0x48, 0x2b, 0x1c, 0xf2, 0x21, 0x61, 0x6d, 0xda, 0xbd,
0x3d, 0x8f, 0xb6, 0x2b, 0x75, 0xc6, 0xac, 0x3f, 0x83, 0x4a, 0x59, 0x4e, 0x5a, 0xdf, 0xed, 0xe7,
0x3a, 0xe4, 0x99, 0x1a, 0xe7, 0x33, 0x2f, 0x61, 0x2b, 0xcf, 0x6c, 0x0e, 0xd6, 0x78, 0x72, 0xeb,
0xa3, 0x12, 0x30, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,
0x03, 0x02, 0x03, 0x88, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02,
0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x03, 0x09, 0xe2, 0x84, 0x47, 0xdc, 0xb7, 0xc5, 0x32,
0xee, 0x97, 0x5b, 0x9e, 0x44, 0xfa, 0x42, 0x06, 0xf2, 0x26, 0x67, 0xc1, 0xa6, 0xc6, 0x4a, 0xdc,
0x6a, 0x0b, 0x5d, 0xa9, 0x87, 0x63, 0x8b, 0x02, 0x21, 0x00, 0xbb, 0x4e, 0xcb, 0x18, 0x72, 0xcc,
0x12, 0x39, 0xd3, 0xd4, 0x18, 0x36, 0x14, 0x18, 0xe4, 0xa9, 0xf3, 0x83, 0x81, 0x4b, 0x74, 0x0f,
0x93, 0x33, 0xb8, 0x47, 0xa9, 0x73, 0xc2, 0x82, 0x92, 0x3e, 0x71, 0x01, 0x00, 0xfe, 0x00,
];
pub const YUBICO_ATTESTATION_CERTIFICATE_FOR_9A: &[u8; 584] = &hex!(
"
3082 0244 3082 012c a003 0201 0202 1100
c636 e7b3 a5a5 a498 5d13 6e43 362d 13f7
300d 0609 2a86 4886 f70d 0101 0b05 0030
2131 1f30 1d06 0355 0403 0c16 5975 6269
636f 2050 4956 2041 7474 6573 7461 7469
6f6e 3020 170d 3136 3033 3134 3030 3030
3030 5a18 0f32 3035 3230 3431 3730 3030
3030 305a 3025 3123 3021 0603 5504 030c
1a59 7562 694b 6579 2050 4956 2041 7474
6573 7461 7469 6f6e 2039 6130 5930 1306
072a 8648 ce3d 0201 0608 2a86 48ce 3d03
0107 0342 0004 832a 9247 8b4e b57a 461b
2a5e 0e44 2503 9bfb 2794 5678 ed48 2b1c
f221 616d dabd 3d8f b62b 75c6 ac3f 834a
594e 5adf ede7 3ae4 991a e733 2f61 2bcf
6c0e d678 72eb a33c 303a 3011 060a 2b06
0104 0182 c40a 0303 0403 0403 0430 1306
0a2b 0601 0401 82c4 0a03 0704 0502 0352
f743 3010 060a 2b06 0104 0182 c40a 0308
0402 0202 300d 0609 2a86 4886 f70d 0101
0b05 0003 8201 0100 0217 38a8 f61d 1735
e130 9dd2 d5c4 d4d0 0de1 9f37 9abe cf63
6a0e 2bd0 d7a4 045c 407d f743 9be4 ee7d
9655 d291 dc32 8254 fe2d 9f19 2354 bbdd
7d6b e961 2a1d c813 65e2 049f a287 de61
92d5 de46 d4a4 c2a6 b480 5d4a a4d1 1ba7
34f2 977b 7a5a ad9a a85d 2ad4 7fb1 57bf
261d 3da6 b3ea 3d3d f794 cd16 3640 24cd
7c8e 7adb 2df9 22da 26b3 c1c8 00a3 4797
5210 1273 4baf 12fe b70d 9e91 30a7 52cf
12d8 2bdf 126a b62f 3924 c604 a26f ed70
b5f2 0d2a 73e3 38a9 9cfe 353e dc17 4055
d595 7f05 8e24 c2b3 b105 2d69 0ccf 5bf7
0640 1736 0ac3 a5db 3cda 62f8 532d f13f
0455 700c 437b 1fa3 63b1 a05e 8928 5b4f
76a7 05e1 4c45 5514 ff10 1089 696a 133d
89f2 cafd 149a c4d0
"
);
pub const YUBICO_ATTESTATION_CERTIFICATE: &'static [u8; 754] = &[
0x53, 0x82, 0x02, 0xee, 0x70, 0x82, 0x02, 0xea, 0x30, 0x82, 0x02, 0xe6, 0x30, 0x82, 0x01, 0xce,
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xa4, 0x85, 0x22, 0xaa, 0x34, 0xaf, 0xae, 0x4f,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x2b, 0x31, 0x29, 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x20, 0x59, 0x75, 0x62, 0x69,
0x63, 0x6f, 0x20, 0x50, 0x49, 0x56, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x20, 0x53,
0x65, 0x72, 0x69, 0x61, 0x6c, 0x20, 0x32, 0x36, 0x33, 0x37, 0x35, 0x31, 0x30, 0x20, 0x17, 0x0d,
0x31, 0x36, 0x30, 0x33, 0x31, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x32,
0x30, 0x35, 0x32, 0x30, 0x34, 0x31, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x21,
0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x59, 0x75, 0x62, 0x69, 0x63,
0x6f, 0x20, 0x50, 0x49, 0x56, 0x20, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01,
0x01, 0x00, 0xab, 0xa9, 0x0b, 0x16, 0x9b, 0xef, 0x31, 0xcc, 0x3e, 0xac, 0x18, 0x5a, 0x2d, 0x45,
0x80, 0x75, 0x70, 0xc7, 0x58, 0xb0, 0x6c, 0x3f, 0x1b, 0x59, 0x0d, 0x49, 0xb9, 0x89, 0xe8, 0x6f,
0xce, 0xbb, 0x27, 0x6f, 0xd8, 0x3c, 0x60, 0x3a, 0x85, 0x00, 0xef, 0x5c, 0xbc, 0x40, 0x99, 0x3d,
0x41, 0xee, 0xea, 0xc0, 0x81, 0x7f, 0x76, 0x48, 0xe4, 0xa9, 0x4c, 0xbc, 0xd5, 0x6b, 0xe1, 0x1f,
0x0a, 0x60, 0x93, 0xc6, 0xfe, 0xaa, 0xd2, 0x8d, 0x8e, 0xe2, 0xb7, 0xcd, 0x8b, 0x2b, 0xf7, 0x9b,
0xdd, 0x5a, 0xab, 0x2f, 0xcf, 0xb9, 0x0e, 0x54, 0xce, 0xec, 0x8d, 0xf5, 0x5e, 0xd7, 0x7b, 0x91,
0xc3, 0xa7, 0x56, 0x9c, 0xdc, 0xc1, 0x06, 0x86, 0x76, 0x36, 0x44, 0x53, 0xfb, 0x08, 0x25, 0xd8,
0x06, 0xb9, 0x06, 0x8c, 0x81, 0xfd, 0x63, 0x67, 0xca, 0x3c, 0xa8, 0xb8, 0xea, 0x1c, 0xa6, 0xca,
0xdb, 0x44, 0x7b, 0x12, 0xca, 0xb2, 0x34, 0x01, 0x7e, 0x73, 0xe4, 0x36, 0x83, 0xdf, 0xeb, 0xf9,
0x23, 0x00, 0x07, 0x01, 0x6a, 0x07, 0x19, 0x8a, 0x64, 0x56, 0x9d, 0x10, 0x8a, 0xc5, 0x73, 0x02,
0x3d, 0x18, 0x6e, 0xaf, 0x3f, 0xc3, 0x02, 0xa7, 0xc0, 0xf7, 0xa2, 0xfd, 0x6d, 0x5a, 0x42, 0x76,
0x4e, 0xd6, 0xc0, 0x1e, 0xd6, 0xc0, 0xc6, 0xaa, 0x5d, 0xa7, 0x1a, 0x9f, 0x10, 0xdb, 0x30, 0x57,
0x18, 0x5c, 0xb5, 0xb5, 0xfd, 0x0c, 0xbe, 0x49, 0x24, 0x22, 0xaf, 0x1e, 0x56, 0x4a, 0x34, 0x44,
0xd4, 0xaa, 0xd4, 0xe1, 0xae, 0x95, 0x4c, 0x75, 0xc0, 0x88, 0x61, 0xf4, 0x8c, 0x7e, 0x54, 0xf3,
0x13, 0xeb, 0x0f, 0xe5, 0x2b, 0x52, 0x60, 0x5a, 0x6e, 0xba, 0xd7, 0xe5, 0x8c, 0x63, 0xda, 0x51,
0x1a, 0xbb, 0x22, 0x5c, 0x37, 0x2b, 0xd7, 0xd1, 0x70, 0x57, 0x4c, 0x2e, 0xdc, 0x35, 0x3c, 0x22,
0x98, 0x9b, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x15, 0x30, 0x13, 0x30, 0x11, 0x06, 0x0a, 0x2b,
0x06, 0x01, 0x04, 0x01, 0x82, 0xc4, 0x0a, 0x03, 0x03, 0x04, 0x03, 0x04, 0x03, 0x03, 0x30, 0x0d,
0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01,
0x01, 0x00, 0x52, 0x80, 0x5a, 0x6d, 0xc3, 0x9e, 0xdf, 0x47, 0xa8, 0xf1, 0xb2, 0xa5, 0x9c, 0xa3,
0x80, 0x81, 0x3b, 0x1d, 0x6a, 0xeb, 0x6a, 0x12, 0x62, 0x4b, 0x11, 0xfd, 0x8d, 0x30, 0xf1, 0x7b,
0xfc, 0x71, 0x10, 0xc9, 0xb2, 0x08, 0xfc, 0xd1, 0x4e, 0x35, 0x7f, 0x45, 0xf2, 0x10, 0xa2, 0x52,
0xb9, 0xd4, 0xb3, 0x02, 0x1a, 0x01, 0x56, 0x07, 0x6b, 0xfa, 0x64, 0xa7, 0x08, 0xf0, 0x03, 0xfb,
0x27, 0xa9, 0x60, 0x8d, 0x0d, 0xd3, 0xac, 0x5a, 0x10, 0xcf, 0x20, 0x96, 0x4e, 0x82, 0xbc, 0x9d,
0xe3, 0x37, 0xda, 0xc1, 0x4c, 0x50, 0xe1, 0x3d, 0x16, 0xb4, 0xca, 0xf4, 0x1b, 0xff, 0x08, 0x64,
0xc9, 0x74, 0x4f, 0x2a, 0x3a, 0x43, 0xe0, 0xde, 0x42, 0x79, 0xf2, 0x13, 0xae, 0x77, 0xa1, 0xe2,
0xae, 0x6b, 0xdf, 0x72, 0xa5, 0xb6, 0xce, 0xd7, 0x4c, 0x90, 0x13, 0xdf, 0xde, 0xdb, 0xf2, 0x8b,
0x34, 0x45, 0x8b, 0x30, 0xdc, 0x51, 0xab, 0xa9, 0x34, 0xf8, 0xa9, 0xe5, 0x0c, 0x47, 0x29, 0xaa,
0x2f, 0x42, 0x54, 0xf2, 0xf8, 0x19, 0x5a, 0xb4, 0x89, 0xfe, 0x1b, 0x9f, 0x19, 0x7a, 0x16, 0xc8,
0xc8, 0xba, 0x8f, 0x18, 0x17, 0x7a, 0x07, 0xa9, 0x97, 0xa1, 0x56, 0xb9, 0x52, 0x5d, 0xa1, 0x21,
0xc0, 0x81, 0x67, 0x2d, 0xe8, 0x0e, 0xa6, 0x51, 0xb9, 0x08, 0xb0, 0x9d, 0xd3, 0x60, 0x1c, 0x70,
0xa3, 0x0f, 0xfa, 0xd8, 0x62, 0xd8, 0x79, 0x2b, 0x0a, 0xe6, 0x42, 0xfc, 0xf8, 0x2d, 0xf5, 0xe4,
0xcd, 0xfb, 0x15, 0x96, 0x23, 0xff, 0xb6, 0xc0, 0xa7, 0xa7, 0xe2, 0x85, 0x83, 0xf9, 0x70, 0xc8,
0x19, 0x6b, 0xf3, 0xc1, 0x3f, 0x37, 0x44, 0x65, 0x27, 0xfb, 0x67, 0x88, 0xc8, 0x83, 0xb7, 0x2f,
0x85, 0x1f, 0x80, 0x44, 0xbb, 0x72, 0xce, 0x06, 0x82, 0x59, 0x2d, 0x83, 0x00, 0xe1, 0x94, 0x8d,
0xa0, 0x85,
];
pub const YUBICO_ATTESTATION_CERTIFICATE_FOR_9A: &'static [u8; 584] = &[
0x30, 0x82, 0x02, 0x44, 0x30, 0x82, 0x01, 0x2c, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00,
0xc6, 0x36, 0xe7, 0xb3, 0xa5, 0xa5, 0xa4, 0x98, 0x5d, 0x13, 0x6e, 0x43, 0x36, 0x2d, 0x13, 0xf7,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x21, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x59, 0x75, 0x62, 0x69,
0x63, 0x6f, 0x20, 0x50, 0x49, 0x56, 0x20, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x33, 0x31, 0x34, 0x30, 0x30, 0x30, 0x30,
0x30, 0x30, 0x5a, 0x18, 0x0f, 0x32, 0x30, 0x35, 0x32, 0x30, 0x34, 0x31, 0x37, 0x30, 0x30, 0x30,
0x30, 0x30, 0x30, 0x5a, 0x30, 0x25, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
0x1a, 0x59, 0x75, 0x62, 0x69, 0x4b, 0x65, 0x79, 0x20, 0x50, 0x49, 0x56, 0x20, 0x41, 0x74, 0x74,
0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x39, 0x61, 0x30, 0x59, 0x30, 0x13, 0x06,
0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03,
0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x83, 0x2a, 0x92, 0x47, 0x8b, 0x4e, 0xb5, 0x7a, 0x46, 0x1b,
0x2a, 0x5e, 0x0e, 0x44, 0x25, 0x03, 0x9b, 0xfb, 0x27, 0x94, 0x56, 0x78, 0xed, 0x48, 0x2b, 0x1c,
0xf2, 0x21, 0x61, 0x6d, 0xda, 0xbd, 0x3d, 0x8f, 0xb6, 0x2b, 0x75, 0xc6, 0xac, 0x3f, 0x83, 0x4a,
0x59, 0x4e, 0x5a, 0xdf, 0xed, 0xe7, 0x3a, 0xe4, 0x99, 0x1a, 0xe7, 0x33, 0x2f, 0x61, 0x2b, 0xcf,
0x6c, 0x0e, 0xd6, 0x78, 0x72, 0xeb, 0xa3, 0x3c, 0x30, 0x3a, 0x30, 0x11, 0x06, 0x0a, 0x2b, 0x06,
0x01, 0x04, 0x01, 0x82, 0xc4, 0x0a, 0x03, 0x03, 0x04, 0x03, 0x04, 0x03, 0x04, 0x30, 0x13, 0x06,
0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xc4, 0x0a, 0x03, 0x07, 0x04, 0x05, 0x02, 0x03, 0x52,
0xf7, 0x43, 0x30, 0x10, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xc4, 0x0a, 0x03, 0x08,
0x04, 0x02, 0x02, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x02, 0x17, 0x38, 0xa8, 0xf6, 0x1d, 0x17, 0x35,
0xe1, 0x30, 0x9d, 0xd2, 0xd5, 0xc4, 0xd4, 0xd0, 0x0d, 0xe1, 0x9f, 0x37, 0x9a, 0xbe, 0xcf, 0x63,
0x6a, 0x0e, 0x2b, 0xd0, 0xd7, 0xa4, 0x04, 0x5c, 0x40, 0x7d, 0xf7, 0x43, 0x9b, 0xe4, 0xee, 0x7d,
0x96, 0x55, 0xd2, 0x91, 0xdc, 0x32, 0x82, 0x54, 0xfe, 0x2d, 0x9f, 0x19, 0x23, 0x54, 0xbb, 0xdd,
0x7d, 0x6b, 0xe9, 0x61, 0x2a, 0x1d, 0xc8, 0x13, 0x65, 0xe2, 0x04, 0x9f, 0xa2, 0x87, 0xde, 0x61,
0x92, 0xd5, 0xde, 0x46, 0xd4, 0xa4, 0xc2, 0xa6, 0xb4, 0x80, 0x5d, 0x4a, 0xa4, 0xd1, 0x1b, 0xa7,
0x34, 0xf2, 0x97, 0x7b, 0x7a, 0x5a, 0xad, 0x9a, 0xa8, 0x5d, 0x2a, 0xd4, 0x7f, 0xb1, 0x57, 0xbf,
0x26, 0x1d, 0x3d, 0xa6, 0xb3, 0xea, 0x3d, 0x3d, 0xf7, 0x94, 0xcd, 0x16, 0x36, 0x40, 0x24, 0xcd,
0x7c, 0x8e, 0x7a, 0xdb, 0x2d, 0xf9, 0x22, 0xda, 0x26, 0xb3, 0xc1, 0xc8, 0x00, 0xa3, 0x47, 0x97,
0x52, 0x10, 0x12, 0x73, 0x4b, 0xaf, 0x12, 0xfe, 0xb7, 0x0d, 0x9e, 0x91, 0x30, 0xa7, 0x52, 0xcf,
0x12, 0xd8, 0x2b, 0xdf, 0x12, 0x6a, 0xb6, 0x2f, 0x39, 0x24, 0xc6, 0x04, 0xa2, 0x6f, 0xed, 0x70,
0xb5, 0xf2, 0x0d, 0x2a, 0x73, 0xe3, 0x38, 0xa9, 0x9c, 0xfe, 0x35, 0x3e, 0xdc, 0x17, 0x40, 0x55,
0xd5, 0x95, 0x7f, 0x05, 0x8e, 0x24, 0xc2, 0xb3, 0xb1, 0x05, 0x2d, 0x69, 0x0c, 0xcf, 0x5b, 0xf7,
0x06, 0x40, 0x17, 0x36, 0x0a, 0xc3, 0xa5, 0xdb, 0x3c, 0xda, 0x62, 0xf8, 0x53, 0x2d, 0xf1, 0x3f,
0x04, 0x55, 0x70, 0x0c, 0x43, 0x7b, 0x1f, 0xa3, 0x63, 0xb1, 0xa0, 0x5e, 0x89, 0x28, 0x5b, 0x4f,
0x76, 0xa7, 0x05, 0xe1, 0x4c, 0x45, 0x55, 0x14, 0xff, 0x10, 0x10, 0x89, 0x69, 0x6a, 0x13, 0x3d,
0x89, 0xf2, 0xca, 0xfd, 0x14, 0x9a, 0xc4, 0xd0,
];
// pub const YUBICO_DEFAULT_MANAGEMENT_KEY: &'static [u8; 24] = b"123456781234567812345678";
pub const YUBICO_DEFAULT_MANAGEMENT_KEY: &'static [u8; 24] = &[
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
];
// pub const YUBICO_DEFAULT_MANAGEMENT_KEY: & [u8; 24] = b"123456781234567812345678";
pub const YUBICO_DEFAULT_MANAGEMENT_KEY: &[u8; 24] = &hex!(
"
0102030405060708
0102030405060708
0102030405060708
"
);
// stolen from le yubico
pub const DISCOVERY_OBJECT: &'static [u8; 20] = b"~\x12O\x0b\xa0\x00\x00\x03\x08\x00\x00\x10\x00\x01\x00_/\x02@\x00";
// import secrets; secrets.token_bytes(16)
pub const GUID: &'static [u8; 16] = b"\x0c\x92\xc9\x04\xd0\xdeL\xd9\xf6\xd1\xa2\x9fE3\xca\xeb";
pub const DISCOVERY_OBJECT: &[u8; 20] =
b"~\x12O\x0b\xa0\x00\x00\x03\x08\x00\x00\x10\x00\x01\x00_/\x02@\x00";
+164 -98
View File
@@ -1,5 +1,64 @@
// Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
use core::convert::TryFrom;
// use flexiber::{Decodable, Encodable};
use hex_literal::hex;
macro_rules! enum_subset {
(
$(#[$outer:meta])*
$vis:vis enum $name:ident: $sup:ident {
$($var:ident),+
$(,)*
}
) => {
$(#[$outer])*
#[repr(u8)]
$vis enum $name {
$(
$var,
)*
}
impl TryFrom<$sup> for $name
{
type Error = ::iso7816::Status;
fn try_from(val: $sup) -> ::core::result::Result<Self, Self::Error> {
match val {
$(
$sup::$var => Ok($name::$var),
)*
_ => Err(::iso7816::Status::KeyReferenceNotFound)
}
}
}
impl From<$name> for $sup
{
fn from(v: $name) -> $sup {
match v {
$(
$name::$var => $sup::$var,
)*
}
}
}
impl TryFrom<u8> for $name {
type Error = ::iso7816::Status;
fn try_from(tag: u8) -> ::core::result::Result<Self, Self::Error> {
let v: $sup = tag.try_into()?;
match v {
$(
$sup::$var => Ok($name::$var),
)*
_ => Err(::iso7816::Status::KeyReferenceNotFound)
}
}
}
}
}
pub struct Tag<'a>(&'a [u8]);
impl<'a> Tag<'a> {
@@ -11,46 +70,115 @@ impl<'a> Tag<'a> {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RetiredIndex(u8);
// #[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum KeyReference {
GlobalPin,
ApplicationPin,
PinUnblockingKey,
PrimaryFinger,
SecondaryFinger,
PairingCode,
crate::enum_u8! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum KeyReference {
GlobalPin = 0x00,
SecureMessaging = 0x04,
ApplicationPin = 0x80,
PinUnblockingKey = 0x81,
PrimaryFinger = 0x96,
SecondaryFinger = 0x97,
PairingCode = 0x98,
PivAuthentication,
PivCardApplicationAdministration,
DigitalSignature,
KeyManagement,
CardAuthentication,
// 20x
RetiredKeyManagement(RetiredIndex),
PivAuthentication = 0x9A,
PivCardApplicationAdministration = 0x9B,
DigitalSignature = 0x9C,
KeyManagement = 0x9D,
CardAuthentication = 0x9E,
Retired01 = 0x82,
Retired02 = 0x83,
Retired03 = 0x84,
Retired04 = 0x85,
Retired05 = 0x86,
Retired06 = 0x87,
Retired07 = 0x88,
Retired08 = 0x89,
Retired09 = 0x8A,
Retired10 = 0x8B,
Retired11 = 0x8C,
Retired12 = 0x8D,
Retired13 = 0x8E,
Retired14 = 0x8F,
Retired15 = 0x90,
Retired16 = 0x91,
Retired17 = 0x92,
Retired18 = 0x93,
Retired19 = 0x94,
Retired20 = 0x95,
}
}
impl From<KeyReference> for u8 {
fn from(reference: KeyReference) -> Self {
use KeyReference::*;
match reference {
GlobalPin => 0x00,
ApplicationPin => 0x80,
PinUnblockingKey => 0x81,
PrimaryFinger => 0x96,
SecondaryFinger => 0x97,
PairingCode => 0x98,
enum_subset! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AttestKeyReference: KeyReference {
PivAuthentication,
}
}
PivAuthentication => 0x9A,
PivCardApplicationAdministration => 0x9B,
DigitalSignature => 0x9C,
KeyManagement => 0x9D,
CardAuthentication => 0x9E,
enum_subset! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum GenerateAsymmetricKeyReference: KeyReference {
SecureMessaging,
PivAuthentication,
DigitalSignature,
KeyManagement,
CardAuthentication,
}
}
RetiredKeyManagement(RetiredIndex(i)) => (0x82 - 1) + i,
}
enum_subset! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ChangeReferenceKeyReference: KeyReference {
GlobalPin,
ApplicationPin,
PinUnblockingKey,
}
}
enum_subset! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VerifyKeyReference: KeyReference {
GlobalPin,
ApplicationPin,
PrimaryFinger,
SecondaryFinger,
PairingCode,
}
}
enum_subset! {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AuthenticateKeyReference: KeyReference {
SecureMessaging,
PivAuthentication,
PivCardApplicationAdministration,
DigitalSignature,
KeyManagement,
CardAuthentication,
Retired01,
Retired02,
Retired03,
Retired04,
Retired05,
Retired06,
Retired07,
Retired08,
Retired09,
Retired10,
Retired11,
Retired12,
Retired13,
Retired14,
Retired15,
Retired16,
Retired17,
Retired18,
Retired19,
Retired20,
}
}
@@ -85,7 +213,7 @@ impl From<Container> for ContainerId {
use Container::*;
Self(match container {
CardCapabilityContainer => 0xDB00,
CardHolderUniqueIdentifier =>0x3000,
CardHolderUniqueIdentifier => 0x3000,
X509CertificateFor9A => 0x0101,
CardholderFingerprints => 0x6010,
SecurityObject => 0x9000,
@@ -193,65 +321,3 @@ impl TryFrom<Tag<'_>> for Container {
})
}
}
// #[derive(Clone, Copy, PartialEq)]
// pub struct CertInfo {
// compressed: bool,
// }
// impl From<CertInfo> for u8 {
// fn from(cert_info: CertInfo) -> Self {
// cert_info.compressed as u8
// }
// }
// impl Encodable for CertInfo {
// fn encoded_len(&self) -> der::Result<der::Length> {
// Length::from(1)
// }
// fn encode(&self, encoder: &mut Encoder<'_>) -> der::Result<()> {
// encoder.encode(der::Any::new(0x71, &[u8::from(self)]))
// }
// }
// pub struct Certificate<'a> {
// // max bytes: 1856
// certificate: &'a [u8], // tag: 0x70
// // 1B
// cert_info: CertInfo, // tag: 0x71
// // 38
// // mscuid: ?, // tag: 0x72
// error_detection_code: [u8; 0], // tag: 0xFE
// }
// impl Encodable for CertInfo {
// fn encoded_len(&self) -> der::Result<der::Length> {
// Length::from(1)
// }
// fn encode(&self, encoder: &mut Encoder<'_>) -> der::Result<()> {
// encoder.encode(der::Any::new(0x71, &[u8::from(self)]))
// }
// }
// #[derive(Encodable)]
// pub struct DiscoveryObject<'a> {
// #[tlv(tag = "0x4F")]
// piv_card_application_aid: &'a [u8; 11], // tag: 0x4F, max bytes = 12,
// #[tlv(tag = 0x5F2f)]
// pin_usage_policy: [u8; 2], // tag: 0x5F2F, max bytes = 2,
// }
// impl Encodable for CertInfo {
// fn encoded_len(&self) -> der::Result<der::Length> {
// Length::from(1)
// }
// fn encode(&self, encoder: &mut Encoder<'_>) -> der::Result<()> {
// encoder.encode(der::Any::new(0x71, &[u8::from(self)]))
// }
// }
// }
+3
View File
@@ -1,3 +1,6 @@
// Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
pub use untrusted::{Input, Reader};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+17 -7
View File
@@ -1,20 +1,30 @@
// Copyright (C) 2022 Nicolas Stalder AND Nitrokey GmbH
// SPDX-License-Identifier: LGPL-3.0-only
use crate::{Authenticator, /*constants::PIV_AID,*/ Result};
use apdu_dispatch::{app::App, command, Command, response};
use apdu_dispatch::{app::App, command, response, Command};
use trussed::client;
#[cfg(feature = "apdu-dispatch")]
impl<T> App<{command::SIZE}, {response::SIZE}> for Authenticator<T, {command::SIZE}>
impl<T> App<{ command::SIZE }, { response::SIZE }> for Authenticator<T>
where
T: client::Client + client::Ed255 + client::Tdes
T: client::Client + client::Ed255 + client::Tdes,
{
fn select(&mut self, apdu: &Command, reply: &mut response::Data) -> Result {
self.select(apdu, reply)
fn select(&mut self, _apdu: &Command, reply: &mut response::Data) -> Result {
self.select(reply)
}
fn deselect(&mut self) { self.deselect() }
fn deselect(&mut self) {
self.deselect()
}
fn call(&mut self, _: iso7816::Interface, apdu: &Command, reply: &mut response::Data) -> Result {
fn call(
&mut self,
_: iso7816::Interface,
apdu: &Command,
reply: &mut response::Data,
) -> Result {
self.respond(apdu, reply)
}
}

Some files were not shown because too many files have changed in this diff Show More