Moved repository to Git and fixed support for adding keys
This commit is contained in:
commit
6d37b980cd
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="com.ibm.bluez.jcop.eclipse.containers.cardconfig/com.ibm.bluez.jcop.eclipse.cardconfigs.njcop"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1 @@
|
|||
bin/
|
||||
|
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><jcop.project debug_comp="2" version="2"><package debug_comp="0" exportmap="false" jcop.id=""><aid jcop.id="package"/><version jcop.id="package">1.0</version></package><package debug_comp="0" exportmap="false" jcop.id="openpgpcard"><aid jcop.id="package">D27600012401</aid><version jcop.id="package">1.0</version><cunit jcop.id="OpenPGPApplet.java"><applet jcop.id="OpenPGPApplet"><aid jcop.id="applet">D2760001240102000000000000010000</aid></applet></cunit><cunit jcop.id="PGPKey.java"/><cunit jcop.id="OpenPGPSecureMessaging.java"/></package></jcop.project>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>OpenPGP JavaCard</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.ibm.bluez.jcop.eclipse.jcopbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>com.ibm.bluez.jcop.eclipse.jcopnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.3
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
|
||||
org.eclipse.jdt.core.compiler.source=1.3
|
||||
|
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) 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
|
||||
this service 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 make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. 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.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the 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 a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE 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.
|
||||
|
||||
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
|
||||
convey 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 2 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, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision 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, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This 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.
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
project.name=OpenPGP JavaCard
|
||||
|
||||
base.dir=.
|
||||
bin.dir=bin
|
||||
lib.dir=lib
|
||||
src.dir=src
|
||||
|
||||
jar.jctasks=jctasks.jar
|
||||
jar.gpj=gpj.jar
|
||||
|
||||
cap.package=openpgpcard
|
||||
cap.package_aid=0xD2:0x76:0x00:0x01:0x24:0x01
|
||||
cap.applet=openpgpcard.OpenPGPApplet
|
||||
cap.applet_aid=0xD2:0x76:0x00:0x01:0x24:0x01:0x02:0x00:0x00:0x00:0x00:0x00:0x00:0x01:0x00:0x00
|
||||
|
||||
gpj.sd_aid=0xA0:0x00:0x00:0x00:0x03:0x00:0x00:0x00
|
||||
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project name="${project.name}" default="applet">
|
||||
|
||||
<property file="build.properties" />
|
||||
|
||||
<!-- Definitions for tasks for Java Card tools -->
|
||||
<taskdef name="apdutool" classname="com.sun.javacard.ant.tasks.APDUToolTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="capgen" classname="com.sun.javacard.ant.tasks.CapgenTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="maskgen" classname="com.sun.javacard.ant.tasks.MaskgenTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="deploycap" classname="com.sun.javacard.ant.tasks.DeployCapTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="exp2text" classname="com.sun.javacard.ant.tasks.Exp2TextTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="convert" classname="com.sun.javacard.ant.tasks.ConverterTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="verifyexport" classname="com.sun.javacard.ant.tasks.VerifyExpTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="verifycap" classname="com.sun.javacard.ant.tasks.VerifyCapTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="verifyrevision" classname="com.sun.javacard.ant.tasks.VerifyRevTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<taskdef name="scriptgen" classname="com.sun.javacard.ant.tasks.ScriptgenTask" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<typedef name="appletnameaid" classname="com.sun.javacard.ant.types.AppletNameAID" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<typedef name="jcainputfile" classname="com.sun.javacard.ant.types.JCAInputFile" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
<typedef name="exportfiles" classname="org.apache.tools.ant.types.FileSet" classpath="${lib.dir}/${jar.jctasks}" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="${lib.dir}" includes="*.jar" />
|
||||
</path>
|
||||
|
||||
<pathconvert property="cap.dir">
|
||||
<path path="${bin.dir}/${cap.package}" />
|
||||
<unpackagemapper from="*" to="*/javacard" />
|
||||
</pathconvert>
|
||||
|
||||
<pathconvert property="cap.file">
|
||||
<path path="${cap.package}" />
|
||||
<chainedmapper>
|
||||
<unpackagemapper from="*" to="*.cap" />
|
||||
<flattenmapper />
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${bin.dir}" />
|
||||
<delete dir="${base.dir}" includes="*.zip *.tar.*" />
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="${bin.dir}" />
|
||||
<javac srcdir="${src.dir}" destdir="${bin.dir}" includeantruntime="false" source="1.3" target="1.2">
|
||||
<classpath refid="classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="applet" depends="compile">
|
||||
<convert dir="${bin.dir}" JCA="true" EXP="true" CAP="true" nobanner="true" majorminorversion="1.0"
|
||||
packagename="${cap.package}" packageaid="${cap.package_aid}"
|
||||
ExportPath="${lib.dir}/api_export_files:${lib.dir}/jcopx_export_files:${bin.dir}">
|
||||
<AppletNameAID appletname="${cap.applet}" aid="${cap.applet_aid}" />
|
||||
<classpath refid="classpath" />
|
||||
</convert>
|
||||
</target>
|
||||
|
||||
<target name="release" depends="clean,compile,applet">
|
||||
<zip destfile="${base.dir}/${project.name}.zip">
|
||||
<fileset dir="${base.dir}" excludes="*.zip *.tar.*" />
|
||||
</zip>
|
||||
<tar destfile="${base.dir}/${project.name}.tar.gz" compression="gzip">
|
||||
<fileset dir="${base.dir}" excludes="*.zip *.tar.*" />
|
||||
</tar>
|
||||
<tar destfile="${base.dir}/${project.name}.tar.bz2" compression="bzip2">
|
||||
<fileset dir="${base.dir}" excludes="*.zip *.tar.*" />
|
||||
</tar>
|
||||
</target>
|
||||
|
||||
<target name="install" depends="applet">
|
||||
<java classname="net.sourceforge.gpj.cardservices.GlobalPlatformService">
|
||||
<classpath refid="classpath" />
|
||||
<arg line="-sdaid ${gpj.sd_aid}" />
|
||||
<arg line="-deletedeps -delete ${cap.package_aid}" />
|
||||
<arg line="-load '${cap.dir}/${cap.file}'" />
|
||||
<arg line="-install -list" />
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="uninstall">
|
||||
<java classname="net.sourceforge.gpj.cardservices.GlobalPlatformService">
|
||||
<classpath refid="classpath" />
|
||||
<arg line="-sdaid ${gpj.sd_aid}" />
|
||||
<arg line="-deletedeps -delete ${cap.package_aid} -list" />
|
||||
</java>
|
||||
</target>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,415 @@
|
|||
/**
|
||||
* Java Card implementation of the OpenPGP card
|
||||
*
|
||||
* Copyright (C) 2011 Joeri de Ruiter
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* OpenPGPSecureMessaging.java is based on OVSecureMessaging.java which is part
|
||||
* of OVchip-ng
|
||||
*
|
||||
* Copyright (C) Pim Vullers, Radboud University Nijmegen, February 2011.
|
||||
*/
|
||||
|
||||
package openpgpcard;
|
||||
|
||||
import javacard.framework.APDU;
|
||||
import javacard.framework.ISO7816;
|
||||
import javacard.framework.ISOException;
|
||||
import javacard.framework.JCSystem;
|
||||
import javacard.framework.Util;
|
||||
import javacard.security.DESKey;
|
||||
import javacard.security.KeyBuilder;
|
||||
import javacard.security.Signature;
|
||||
import javacardx.crypto.Cipher;
|
||||
|
||||
/**
|
||||
* OV secure messaging functionality.
|
||||
*
|
||||
* <p>OVSecureMessaging is based on PassportCrypto which is part of the
|
||||
* e-passport Java Card applet from the JMRTD project (http://jmrtd.org/).
|
||||
*
|
||||
* @author Pim Vullers
|
||||
* @version $Revision: 12 $ by $Author: joeridr $
|
||||
* $LastChangedDate: 2012-02-23 15:31:33 +0100 (Thu, 23 Feb 2012) $
|
||||
*/
|
||||
public class OpenPGPSecureMessaging {
|
||||
private static final short SW_INTERNAL_ERROR = (short) 0x6D66;
|
||||
private static final byte[] PAD_DATA = {(byte) 0x80, 0, 0, 0, 0, 0, 0, 0};
|
||||
private static final short SSC_SIZE = 8;
|
||||
private static final short TMP_SIZE = 256;
|
||||
private static final short MAC_SIZE = 8;
|
||||
private static final short KEY_SIZE = 16;
|
||||
private static final byte[] EMPTY_KEY = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
/**
|
||||
* The needed cryptographic functionality.
|
||||
*/
|
||||
private Signature signer;
|
||||
private Signature verifier;
|
||||
private Cipher cipher;
|
||||
private Cipher decipher;
|
||||
|
||||
/**
|
||||
* The needed keys.
|
||||
*/
|
||||
private DESKey keyMAC;
|
||||
private DESKey keyENC;
|
||||
|
||||
/**
|
||||
* The send sequence counter.
|
||||
*/
|
||||
private byte[] ssc;
|
||||
|
||||
/**
|
||||
* Storage for temporary data.
|
||||
*/
|
||||
private byte[] tmp;
|
||||
|
||||
private boolean[] ssc_set;
|
||||
|
||||
/**
|
||||
* Construct a new secure messaging wrapper.
|
||||
*/
|
||||
public OpenPGPSecureMessaging() {
|
||||
ssc = JCSystem.makeTransientByteArray(SSC_SIZE,
|
||||
JCSystem.CLEAR_ON_DESELECT);
|
||||
tmp = JCSystem.makeTransientByteArray(TMP_SIZE,
|
||||
JCSystem.CLEAR_ON_DESELECT);
|
||||
signer = Signature.getInstance(
|
||||
Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
|
||||
verifier = Signature.getInstance(
|
||||
Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false);
|
||||
cipher = Cipher.getInstance(
|
||||
Cipher.ALG_DES_CBC_ISO9797_M2, false);
|
||||
decipher = Cipher.getInstance(
|
||||
Cipher.ALG_DES_CBC_ISO9797_M2, false);
|
||||
|
||||
keyMAC = (DESKey) KeyBuilder.buildKey(
|
||||
KeyBuilder.TYPE_DES_TRANSIENT_DESELECT,
|
||||
KeyBuilder.LENGTH_DES3_2KEY, false);
|
||||
keyENC = (DESKey) KeyBuilder.buildKey(
|
||||
KeyBuilder.TYPE_DES_TRANSIENT_DESELECT,
|
||||
KeyBuilder.LENGTH_DES3_2KEY, false);
|
||||
|
||||
ssc_set = JCSystem.makeTransientBooleanArray((short)1, JCSystem.CLEAR_ON_DESELECT);
|
||||
ssc_set[0] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAC and encryption (and decryption) session keys. Each key is a
|
||||
* 16 byte 3DES EDE key. This method may be called at any time and will
|
||||
* immediately replace the session key.
|
||||
*
|
||||
* @param buffer byte array containing the session keys.
|
||||
* @param offset location of the session keys in the buffer.
|
||||
*/
|
||||
public void setSessionKeys(byte[] buffer, short offset) {
|
||||
// Check for empty keys
|
||||
if(Util.arrayCompare(buffer, (short)0, EMPTY_KEY, (short)0, KEY_SIZE) == 0 ||
|
||||
Util.arrayCompare(buffer, KEY_SIZE, EMPTY_KEY, (short)0, KEY_SIZE) == 0) {
|
||||
keyMAC.clearKey();
|
||||
keyENC.clearKey();
|
||||
}
|
||||
else {
|
||||
keyMAC.setKey(buffer, offset);
|
||||
keyENC.setKey(buffer, (short) (offset + KEY_SIZE));
|
||||
|
||||
signer.init(keyMAC, Signature.MODE_SIGN);
|
||||
verifier.init(keyMAC, Signature.MODE_VERIFY);
|
||||
|
||||
cipher.init(keyENC, Cipher.MODE_ENCRYPT);
|
||||
decipher.init(keyENC, Cipher.MODE_DECRYPT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAC session key. Each key is a 16 byte 3DES EDE key. This method
|
||||
* may be called at any time and will immediately replace the session key.
|
||||
*
|
||||
* @param buffer byte array containing the session key.
|
||||
* @param offset location of the session key in the buffer.
|
||||
*/
|
||||
public void setSessionKeyMAC(byte[] buffer, short offset) {
|
||||
// Check for empty keys
|
||||
if(Util.arrayCompare(buffer, (short)0, EMPTY_KEY, (short)0, KEY_SIZE) == 0) {
|
||||
keyMAC.clearKey();
|
||||
keyENC.clearKey();
|
||||
}
|
||||
else {
|
||||
keyMAC.setKey(buffer, offset);
|
||||
|
||||
signer.init(keyMAC, Signature.MODE_SIGN);
|
||||
verifier.init(keyMAC, Signature.MODE_VERIFY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the encryption session key. Each key is a 16 byte 3DES EDE key. This method
|
||||
* may be called at any time and will immediately replace the session key.
|
||||
*
|
||||
* @param buffer byte array containing the session key.
|
||||
* @param offset location of the session key in the buffer.
|
||||
*/
|
||||
public void setSessionKeyEncryption(byte[] buffer, short offset) {
|
||||
// Check for empty keys
|
||||
if(Util.arrayCompare(buffer, (short)0, EMPTY_KEY, (short)0, KEY_SIZE) == 0) {
|
||||
keyMAC.clearKey();
|
||||
keyENC.clearKey();
|
||||
}
|
||||
else {
|
||||
keyENC.setKey(buffer, (short) (offset + KEY_SIZE));
|
||||
|
||||
cipher.init(keyENC, Cipher.MODE_ENCRYPT);
|
||||
decipher.init(keyENC, Cipher.MODE_DECRYPT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MAC and encryption (and decryption) 3DES session keys to zero.
|
||||
*/
|
||||
public void clearSessionKeys() {
|
||||
keyMAC.clearKey();
|
||||
keyENC.clearKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwraps (verify and decrypt) the command APDU located in the APDU buffer.
|
||||
* The command buffer has to be filled by the APDU.setIncomingAndReceive()
|
||||
* method beforehand. The verified and decrypted command data get placed at
|
||||
* the start of the APDU buffer.
|
||||
*
|
||||
* @return the length value encoded by DO97, 0 if this object is missing.
|
||||
*/
|
||||
public short unwrapCommandAPDU() {
|
||||
byte[] buf = APDU.getCurrentAPDUBuffer();
|
||||
short apdu_p = (short) (ISO7816.OFFSET_CDATA & 0xff);
|
||||
short start_p = apdu_p;
|
||||
short le = 0;
|
||||
short do87DataLen = 0;
|
||||
short do87Data_p = 0;
|
||||
short do87LenBytes = 0;
|
||||
short hdrLen = 4;
|
||||
short hdrPadLen = (short) (8 - hdrLen);
|
||||
|
||||
incrementSSC();
|
||||
|
||||
if (buf[apdu_p] == (byte) 0x87) {
|
||||
apdu_p++;
|
||||
// do87
|
||||
if ((buf[apdu_p] & 0xff) > 0x80) {
|
||||
do87LenBytes = (short) (buf[apdu_p] & 0x7f);
|
||||
apdu_p++;
|
||||
} else {
|
||||
do87LenBytes = 1;
|
||||
}
|
||||
if (do87LenBytes > 2) { // sanity check
|
||||
ISOException.throwIt(SW_INTERNAL_ERROR);
|
||||
}
|
||||
for (short i = 0; i < do87LenBytes; i++) {
|
||||
do87DataLen += (short) ((buf[(short)(apdu_p + i)] & 0xff) << (short) ((do87LenBytes - 1 - i) * 8));
|
||||
}
|
||||
apdu_p += do87LenBytes;
|
||||
|
||||
if (buf[apdu_p] != 1) {
|
||||
ISOException.throwIt(SW_INTERNAL_ERROR);
|
||||
}
|
||||
// store pointer to data and defer decrypt to after mac check (do8e)
|
||||
do87Data_p = (short) (apdu_p + 1);
|
||||
apdu_p += do87DataLen;
|
||||
do87DataLen--; // compensate for 0x01 marker
|
||||
}
|
||||
|
||||
if (buf[apdu_p] == (byte) 0x97) {
|
||||
// do97
|
||||
if (buf[++apdu_p] != 1)
|
||||
ISOException.throwIt(SW_INTERNAL_ERROR);
|
||||
le = (short) (buf[++apdu_p] & 0xff);
|
||||
apdu_p++;
|
||||
}
|
||||
|
||||
// do8e
|
||||
if (buf[apdu_p] != (byte) 0x8e) {
|
||||
ISOException.throwIt(SW_INTERNAL_ERROR);
|
||||
}
|
||||
if (buf[++apdu_p] != 8) {
|
||||
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
|
||||
}
|
||||
|
||||
// verify mac
|
||||
verifier.update(ssc, (short)0, (short)ssc.length);
|
||||
verifier.update(buf, (short)0, hdrLen);
|
||||
verifier.update(PAD_DATA, (short)0, hdrPadLen);
|
||||
if (!verifier.verify(buf, start_p, (short) (apdu_p - 1 - start_p), buf,
|
||||
(short)(apdu_p + 1), MAC_SIZE)) {
|
||||
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
|
||||
}
|
||||
|
||||
short lc = 0;
|
||||
if (do87DataLen != 0) {
|
||||
// decrypt data, and leave room for lc
|
||||
lc = decipher.doFinal(buf, do87Data_p, do87DataLen, buf,
|
||||
(short) (hdrLen + 1));
|
||||
buf[hdrLen] = (byte) (lc & 0xff);
|
||||
}
|
||||
|
||||
return le;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps (encrypts and build MAC) the response data and places it in the
|
||||
* APDU buffer starting at offset 0. The buffer can be any buffer including
|
||||
* the APDU buffer itself. If the length is zero the buffer will not be
|
||||
* addressed and no response data will be present in the wrapped output.
|
||||
*
|
||||
* @param buffer byte array containing the data which needs to be wrapped.
|
||||
* @param offset location of the data in the buffer.
|
||||
* @param length of the data in the buffer (in bytes).
|
||||
* @param status word which has to be wrapped in the response APDU.
|
||||
* @return the length of the wrapped data in the <apdu> buffer
|
||||
*/
|
||||
public short wrapResponseAPDU(byte[] buffer, short offset, short length,
|
||||
short status) {
|
||||
byte[] apdu = APDU.getCurrentAPDUBuffer();
|
||||
short apdu_p = 0;
|
||||
// smallest multiple of 8 strictly larger than plaintextLen (length + padding)
|
||||
short do87DataLen = (short) ((((short) (length + 8)) / 8) * 8);
|
||||
// for 0x01 marker (indicating padding is used)
|
||||
do87DataLen++;
|
||||
short do87DataLenBytes = (short)(do87DataLen > 0xff? 2 : 1);
|
||||
short do87HeaderBytes = getApduBufferOffset(length);
|
||||
short do87Bytes = (short)(do87HeaderBytes + do87DataLen - 1); // 0x01 is counted twice
|
||||
boolean hasDo87 = length > 0;
|
||||
|
||||
incrementSSC();
|
||||
|
||||
short ciphertextLength=0;
|
||||
if(hasDo87) {
|
||||
// Copy the plain text to temporary buffer to avoid data corruption.
|
||||
Util.arrayCopyNonAtomic(buffer, offset, tmp, (short) 0, length);
|
||||
// Put the cipher text in the proper position.
|
||||
ciphertextLength = cipher.doFinal(tmp, (short) 0, length, apdu,
|
||||
do87HeaderBytes);
|
||||
}
|
||||
//sanity check
|
||||
//note that this check
|
||||
// (possiblyPaddedPlaintextLength != (short)(do87DataLen -1))
|
||||
//does not always hold because some algs do the padding in the final, some in the init.
|
||||
if (hasDo87 && (((short) (do87DataLen - 1) != ciphertextLength)))
|
||||
ISOException.throwIt(SW_INTERNAL_ERROR);
|
||||
|
||||
if (hasDo87) {
|
||||
// build do87
|
||||
apdu[apdu_p++] = (byte) 0x87;
|
||||
if(do87DataLen < 0x80) {
|
||||
apdu[apdu_p++] = (byte)do87DataLen;
|
||||
} else {
|
||||
apdu[apdu_p++] = (byte) (0x80 + do87DataLenBytes);
|
||||
for(short i = (short) (do87DataLenBytes - 1); i >= 0; i--) {
|
||||
apdu[apdu_p++] = (byte) ((do87DataLen >>> (i * 8)) & 0xff);
|
||||
}
|
||||
}
|
||||
apdu[apdu_p++] = 0x01;
|
||||
}
|
||||
|
||||
if(hasDo87) {
|
||||
apdu_p = do87Bytes;
|
||||
}
|
||||
|
||||
// build do99
|
||||
apdu[apdu_p++] = (byte) 0x99;
|
||||
apdu[apdu_p++] = 0x02;
|
||||
Util.setShort(apdu, apdu_p, status);
|
||||
apdu_p += 2;
|
||||
|
||||
// calculate and write mac
|
||||
signer.update(ssc, (short) 0, (short) ssc.length);
|
||||
signer.sign(apdu, (short) 0, apdu_p, apdu, (short) (apdu_p + 2));
|
||||
|
||||
// write do8e
|
||||
apdu[apdu_p++] = (byte) 0x8e;
|
||||
apdu[apdu_p++] = 0x08;
|
||||
apdu_p += 8; // for mac written earlier
|
||||
|
||||
return apdu_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the send sequence counter.
|
||||
*/
|
||||
private void incrementSSC() {
|
||||
if (ssc == null || ssc.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (short s = (short) (ssc.length - 1); s >= 0; s--) {
|
||||
if ((short) ((ssc[s] & 0xff) + 1) > 0xff) {
|
||||
ssc[s] = 0;
|
||||
} else {
|
||||
ssc[s]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Get the amount of space to reserve in the buffer when using secure
|
||||
* messaging.
|
||||
*
|
||||
* @param length length of plain text in which this offset depends.
|
||||
* @return the amount of space to reserve.
|
||||
*/
|
||||
private short getApduBufferOffset(short length) {
|
||||
short do87Bytes = 2; // 0x87 length data 0x01
|
||||
// smallest multiple of 8 strictly larger than plaintextLen + 1
|
||||
// byte is probably the length of the cipher text (including do87 0x01)
|
||||
short do87DataLen = (short) ((((short) (length + 8) / 8) * 8) + 1);
|
||||
|
||||
if (do87DataLen < 0x80) {
|
||||
do87Bytes++;
|
||||
} else if (do87DataLen <= 0xff) {
|
||||
do87Bytes += 2;
|
||||
} else {
|
||||
do87Bytes += (short) (length > 0xff ? 2 : 1);
|
||||
}
|
||||
|
||||
return do87Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SSC
|
||||
*
|
||||
* @param buffer byte array containing the SSC
|
||||
* @param offset location of the data in the buffer
|
||||
*/
|
||||
public void setSSC(byte[] buffer, short offset) {
|
||||
Util.arrayCopy(buffer, offset, ssc, (short)0, SSC_SIZE);
|
||||
ssc_set[0] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return size in bytes of the SSC
|
||||
*/
|
||||
public short getSSCSize() {
|
||||
return SSC_SIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean indicating whether SSC has been set
|
||||
*/
|
||||
public boolean isSetSSC() {
|
||||
return ssc_set[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
/**
|
||||
* Java Card implementation of the OpenPGP card
|
||||
* Copyright (C) 2011 Joeri de Ruiter
|
||||
*
|
||||
* 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 2
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package openpgpcard;
|
||||
|
||||
import javacard.framework.*;
|
||||
import javacard.security.*;
|
||||
|
||||
/**
|
||||
* @author Joeri de Ruiter (joeri@cs.ru.nl)
|
||||
* @version $Revision: 12 $ by $Author: joeridr $
|
||||
* $LastChangedDate: 2012-02-23 15:31:33 +0100 (Thu, 23 Feb 2012) $
|
||||
*/
|
||||
public class PGPKey implements ISO7816 {
|
||||
public static final short KEY_SIZE = 2048;// 2368;
|
||||
public static final short KEY_SIZE_BYTES = KEY_SIZE / 8;
|
||||
public static final short EXPONENT_SIZE = 17;
|
||||
public static final short EXPONENT_SIZE_BYTES = 3;
|
||||
public static final short FP_SIZE = 20;
|
||||
|
||||
private KeyPair key;
|
||||
private byte[] fp;
|
||||
private byte[] time = { 0x00, 0x00, 0x00, 0x00 };
|
||||
private byte[] attributes = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x02 };
|
||||
|
||||
public PGPKey() {
|
||||
key = new KeyPair(KeyPair.ALG_RSA_CRT, KEY_SIZE);
|
||||
|
||||
fp = new byte[FP_SIZE];
|
||||
Util.arrayFillNonAtomic(fp, (short) 0, (short) fp.length, (byte) 0);
|
||||
|
||||
Util.setShort(attributes, (short) 1, KEY_SIZE);
|
||||
Util.setShort(attributes, (short) 3, EXPONENT_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the key pair.
|
||||
*/
|
||||
public void genKeyPair() {
|
||||
key.genKeyPair();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fingerprint for the public key.
|
||||
*
|
||||
* @param data
|
||||
* Byte array
|
||||
* @param offset
|
||||
* Offset within byte array containing first byte
|
||||
*/
|
||||
public void setFingerprint(byte[] data, short offset) {
|
||||
// Check whether there are enough bytes to copy
|
||||
if ((short) (offset + fp.length) > data.length)
|
||||
ISOException.throwIt(SW_UNKNOWN);
|
||||
|
||||
Util.arrayCopy(data, offset, fp, (short) 0, (short) fp.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the generation time for the key pair.
|
||||
*
|
||||
* @param data
|
||||
* Byte array
|
||||
* @param offset
|
||||
* Offset within byte array containing first byte
|
||||
*/
|
||||
public void setTime(byte[] data, short offset) {
|
||||
// Check whether there are enough bytes to copy
|
||||
if ((short) (offset + time.length) > data.length)
|
||||
ISOException.throwIt(SW_UNKNOWN);
|
||||
|
||||
Util.arrayCopy(data, offset, time, (short) 0, (short) 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fingerprint for the public key.
|
||||
*
|
||||
* @param data
|
||||
* Byte array
|
||||
* @param offset
|
||||
* Offset within byte array indicating first byte
|
||||
*/
|
||||
public short getFingerprint(byte[] data, short offset) {
|
||||
Util.arrayCopyNonAtomic(fp, (short) 0, data, offset, (short) fp.length);
|
||||
return (short) (offset + fp.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the generation time for the key pair.
|
||||
*
|
||||
* @param data
|
||||
* Byte array
|
||||
* @param offset
|
||||
* Offset within byte array indicating first byte
|
||||
*/
|
||||
public short getTime(byte[] data, short offset) {
|
||||
Util.arrayCopyNonAtomic(time, (short) 0, data, offset,
|
||||
(short) time.length);
|
||||
return (short) (offset + time.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the algorithm attributes for the key pair.
|
||||
*
|
||||
* @param data
|
||||
* Byte array
|
||||
* @param offset
|
||||
* Offset within byte array indicating first byte
|
||||
*/
|
||||
public short getAttributes(byte[] data, short offset) {
|
||||
Util.arrayCopyNonAtomic(attributes, (short) 0, data, offset,
|
||||
(short) attributes.length);
|
||||
return (short) (offset + attributes.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Public key of the key pair
|
||||
*/
|
||||
public RSAPublicKey getPublic() {
|
||||
return (RSAPublicKey) key.getPublic();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Private key of the key pair
|
||||
*/
|
||||
public RSAPrivateCrtKey getPrivate() {
|
||||
return (RSAPrivateCrtKey) key.getPrivate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Length in bytes of the exponent
|
||||
*/
|
||||
public short getExponentLength() {
|
||||
// Fixed value of 65537 for exponent
|
||||
return EXPONENT_SIZE_BYTES;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Length in bytes of the modulus
|
||||
*/
|
||||
public short getModulusLength() {
|
||||
return KEY_SIZE_BYTES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the DP1 parameter. The plain text data format is
|
||||
* big-endian and right-aligned (the least significant bit is the least
|
||||
* significant bit of last byte). Input DP1 parameter data is copied into
|
||||
* the internal representation.
|
||||
*
|
||||
* @param buffer
|
||||
* The input buffer
|
||||
* @param offset
|
||||
* The offset into the input buffer at which the parameter value
|
||||
* begins
|
||||
* @param length
|
||||
* The length of the parameter
|
||||
*/
|
||||
public void setDP1(byte[] buffer, short offset, short length) {
|
||||
((RSAPrivateCrtKey) key.getPrivate()).setDP1(buffer, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the DQ1 parameter. The plain text data format is
|
||||
* big-endian and right-aligned (the least significant bit is the least
|
||||
* significant bit of last byte). Input DQ1 parameter data is copied into
|
||||
* the internal representation.
|
||||
*
|
||||
* @param buffer
|
||||
* The input buffer
|
||||
* @param offset
|
||||
* The offset into the input buffer at which the parameter value
|
||||
* begins
|
||||
* @param length
|
||||
* The length of the parameter
|
||||
*/
|
||||
public void setDQ1(byte[] buffer, short offset, short length) {
|
||||
((RSAPrivateCrtKey) key.getPrivate()).setDQ1(buffer, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the P parameter. The plain text data format is
|
||||
* big-endian and right-aligned (the least significant bit is the least
|
||||
* significant bit of last byte). Input P parameter data is copied into the
|
||||
* internal representation.
|
||||
*
|
||||
* @param buffer
|
||||
* The input buffer
|
||||
* @param offset
|
||||
* The offset into the input buffer at which the parameter value
|
||||
* begins
|
||||
* @param length
|
||||
* The length of the parameter
|
||||
*/
|
||||
public void setP(byte[] buffer, short offset, short length) {
|
||||
((RSAPrivateCrtKey) key.getPrivate()).setP(buffer, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the PQ parameter. The plain text data format is
|
||||
* big-endian and right-aligned (the least significant bit is the least
|
||||
* significant bit of last byte). Input PQ parameter data is copied into the
|
||||
* internal representation.
|
||||
*
|
||||
* @param buffer
|
||||
* The input buffer
|
||||
* @param offset
|
||||
* The offset into the input buffer at which the parameter value
|
||||
* begins
|
||||
* @param length
|
||||
* The length of the parameter
|
||||
*/
|
||||
public void setPQ(byte[] buffer, short offset, short length) {
|
||||
((RSAPrivateCrtKey) key.getPrivate()).setPQ(buffer, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the Q parameter. The plain text data format is
|
||||
* big-endian and right-aligned (the least significant bit is the least
|
||||
* significant bit of last byte). Input Q parameter data is copied into the
|
||||
* internal representation.
|
||||
*
|
||||
* @param buffer
|
||||
* The input buffer
|
||||
* @param offset
|
||||
* The offset into the input buffer at which the parameter value
|
||||
* begins
|
||||
* @param length
|
||||
* The length of the parameter
|
||||
*/
|
||||
public void setQ(byte[] buffer, short offset, short length) {
|
||||
((RSAPrivateCrtKey) key.getPrivate()).setQ(buffer, offset, length);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue