Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable RSA-PSS signatures in pkcs11-tool #1146

Merged
merged 20 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a7a4e6c
Add missing SHA224 RSA algorithms
Jakuje Sep 6, 2017
811a6b9
Fix wrong replacement in pkcs11-tool manual page
Jakuje Sep 6, 2017
6d37b6c
Add MGF and PSS_PARAMS definitions in PKCS#11 header file
Jakuje Sep 6, 2017
89309a5
Inspect PSS signature parameters in pkcs11-spy
Jakuje Sep 6, 2017
1efb774
Enable RSA-PSS signatures in pkcs11-tool
Jakuje Sep 6, 2017
c2d8ee5
Added short names to RSA-PSS methods
Sep 7, 2017
ec8dd42
Change RSA-PSS salt length default to OpenSSL-compatible, aka digest …
Sep 7, 2017
aaecfdb
Fixed hashAlg but in pkcs11-tool for RSA-PSS
Sep 7, 2017
da9bae0
CHanged opt_salt to salt_len
mouse07410 Sep 8, 2017
7513ec2
Fixed type of salt length from unsigned long to long
mouse07410 Sep 9, 2017
cedbd3e
RSA-PSS: made sure special values for salt length from OpenSSL ("-1" …
mouse07410 Sep 9, 2017
0b7e5f0
Refactored dealing with salt length, and added input check
mouse07410 Sep 10, 2017
f2f53c1
Fix introduced incompatibility with C90 standard (declaration of vari…
mouse07410 Sep 11, 2017
ebd3ca2
Whitespace cleanup of mouse07410 commits
Jakuje Sep 11, 2017
55f0616
Add SHA-224 hash algorithm for RSA-PSS
Jakuje Sep 11, 2017
15659fb
Do not fallback to zero-length salt on unknown hash algorithms
Jakuje Sep 11, 2017
375e1c2
Add SHA224 definitions in pkcs11.h (for completenes)
Jakuje Sep 11, 2017
4450c2c
Reintroduce portable NORETURN indication for functions and use it to …
Jakuje Sep 13, 2017
e870706
Use default SHA-1 mechanisms, use --salt-len, improve wording of docu…
Jakuje Sep 15, 2017
63ae2f9
Check the mechanism type before dereferencing generic parameter
Jakuje Sep 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use default SHA-1 mechanisms, use --salt-len, improve wording of docu…
…mentation
  • Loading branch information
Jakuje committed Sep 15, 2017
commit e87070646f20ae2d17cfd6b63759a5b0ecd9729e
15 changes: 10 additions & 5 deletions doc/tools/pkcs11-tool.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
<term>
<option>--hash-algorithm</option> <replaceable>mechanism</replaceable>
</term>
<listitem><para>Specify hash algorithm used with generic RSA-PSS signature</para></listitem>
<listitem><para>Specify hash algorithm used with
RSA-PKCS-PSS signature. Default is SHA-1.</para></listitem>
</varlistentry>

<varlistentry>
Expand Down Expand Up @@ -226,7 +227,8 @@
<listitem><para>Use the specified Message Generation
Function (MGF) <replaceable>function</replaceable>
for RSA-PSS signatures. Supported arguments are MGF1-SHA1
to MGF1-SHA512 if supported by the driver.</para></listitem>
to MGF1-SHA512 if supported by the driver.
The default is based on the hash selection.</para></listitem>
</varlistentry>

<varlistentry>
Expand Down Expand Up @@ -328,10 +330,13 @@

<varlistentry>
<term>
<option>--salt</option> <replaceable>bytes</replaceable>
<option>--salt-len</option> <replaceable>bytes</replaceable>
</term>
<listitem><para>Specify how many bytes should be used in
RSA-PSS signatures. Can be zero (no salt). Accepts two special values: "-1" means salt length equals to digest length, "-2" means use maximum permissible length. Default is digest length.</para></listitem>
<listitem><para>Specify how many bytes of salt should
be used in RSA-PSS signatures. Accepts two special values:
"-1" means salt length equals to digest length,
"-2" means use maximum permissible length.
Default is digest length (-1).</para></listitem>
</varlistentry>

<varlistentry>
Expand Down
20 changes: 11 additions & 9 deletions src/tools/pkcs11-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static const struct option options[] = {
{ "mechanism", 1, NULL, 'm' },
{ "hash-algorithm", 1, NULL, OPT_HASH_ALGORITHM },
{ "mgf", 1, NULL, OPT_MGF },
{ "salt", 1, NULL, OPT_SALT },
{ "salt-len", 1, NULL, OPT_SALT },

{ "login", 0, NULL, 'l' },
{ "login-type", 1, NULL, OPT_LOGIN_TYPE },
Expand Down Expand Up @@ -233,9 +233,9 @@ static const char *option_help[] = {
"Derive a secret key using another key and some data",
"Derive ECDHpass DER encoded pubkey for compatibility with some PKCS#11 implementations",
"Specify mechanism (use -M for a list of supported mechanisms)",
"Specify hash algorithm used with generic RSA-PSS signature",
"Specify hash algorithm used with RSA-PKCS-PSS signature",
"Specify MGF (Message Generation Function) used for RSA-PSS signatures (possible values are MGF1-SHA1 to MGF1-SHA512)",
"Specify how many bytes should be used for salt in RSA-PSS signatures (default equals to digest size)",
"Specify how many bytes should be used for salt in RSA-PSS signatures (default is digest size)",

"Log into the token first",
"Specify login type ('so', 'user', 'context-specific'; default:'user')",
Expand Down Expand Up @@ -1676,16 +1676,15 @@ static void sign_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
pss_params.hashAlg = 0;

if (opt_hash_alg != 0 && opt_mechanism != CKM_RSA_PKCS_PSS)
util_fatal("The hash-algorithm is applicable only to generic"
util_fatal("The hash-algorithm is applicable only to "
"RSA-PKCS-PSS mechanism");

/* set "default" MGF and hash algorithms. We can overwrite MGF later */
switch (opt_mechanism) {
case CKM_RSA_PKCS_PSS:
pss_params.hashAlg = opt_hash_alg;

switch (opt_hash_alg) {
case CKM_SHA_1:
pss_params.mgf = CKG_MGF1_SHA1;
break;
case CKM_SHA256:
pss_params.mgf = CKG_MGF1_SHA256;
break;
Expand All @@ -1696,9 +1695,12 @@ static void sign_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session,
pss_params.mgf = CKG_MGF1_SHA512;
break;
default:
util_fatal("RSA-PKCS-PSS requires explicit hash mechanism");
/* the PSS should use SHA-1 if not specified */
pss_params.hashAlg = CKM_SHA_1;
/* fallthrough */
case CKM_SHA_1:
pss_params.mgf = CKG_MGF1_SHA1;
}
pss_params.hashAlg = opt_hash_alg;
break;

case CKM_SHA1_RSA_PKCS_PSS:
Expand Down