pki: Unify parsing of RSA padding scheme and fix disabling PSS

If PSS padding is enabled by default, not all commands allowed disabling
it explicitly.
This commit is contained in:
Tobias Brunner
2023-03-31 09:11:17 +02:00
parent 47d9590556
commit e2a2674476
8 changed files with 37 additions and 37 deletions
+1 -5
View File
@@ -64,11 +64,7 @@ static int acert()
}
continue;
case 'R':
if (streq(arg, "pss"))
{
pss = TRUE;
}
else if (!streq(arg, "pkcs1"))
if (!parse_rsa_padding(arg, &pss))
{
error = "invalid RSA padding";
goto usage;
+1 -5
View File
@@ -185,11 +185,7 @@ static int issue()
}
continue;
case 'R':
if (streq(arg, "pss"))
{
pss = TRUE;
}
else if (!streq(arg, "pkcs1"))
if (!parse_rsa_padding(arg, &pss))
{
error = "invalid RSA padding";
goto usage;
+1 -6
View File
@@ -105,12 +105,7 @@ static int req()
}
continue;
case 'R': /* --rsa-padding */
if (streq(arg, "pss"))
{
pss = TRUE;
}
else if (!streq(arg, "pkcs1"))
if (!parse_rsa_padding(arg, &pss))
{
error = "invalid RSA padding";
goto usage;
+1 -9
View File
@@ -162,15 +162,7 @@ static int scep()
}
continue;
case 'R': /* --rsa-padding */
if (streq(arg, "pss"))
{
pss = TRUE;
}
else if (streq(arg, "pkcs1"))
{
pss = FALSE;
}
else
if (!parse_rsa_padding(arg, &pss))
{
error = "invalid RSA padding";
goto usage;
+1 -5
View File
@@ -129,11 +129,7 @@ static int self()
}
continue;
case 'R':
if (streq(arg, "pss"))
{
pss = TRUE;
}
else if (!streq(arg, "pkcs1"))
if (!parse_rsa_padding(arg, &pss))
{
error = "invalid RSA padding";
goto usage;
+1 -5
View File
@@ -146,11 +146,7 @@ static int sign_crl()
}
continue;
case 'R':
if (streq(arg, "pss"))
{
pss = TRUE;
}
else if (!streq(arg, "pkcs1"))
if (!parse_rsa_padding(arg, &pss))
{
error = "invalid RSA padding";
goto usage;
+21 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2018 Tobias Brunner
* Copyright (C) 2012-2023 Tobias Brunner
* Copyright (C) 2009 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -238,6 +238,26 @@ void set_file_mode(FILE *stream, cred_encoding_type_t enc)
#endif
}
/*
* Described in header
*/
bool parse_rsa_padding(char *padding, bool *pss)
{
if (streq(padding, "pss"))
{
*pss = TRUE;
}
else if (streq(padding, "pkcs1"))
{
*pss = FALSE;
}
else
{
return FALSE;
}
return TRUE;
}
/**
* Determine a default hash algorithm for the given key
*/
+10 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2017 Tobias Brunner
* Copyright (C) 2015-2023 Tobias Brunner
* Copyright (C) 2009 Martin Willi
*
* Copyright (C) secunet Security Networks AG
@@ -58,6 +58,15 @@ bool calculate_lifetime(char *format, char *nbstr, char *nastr, time_t span,
*/
void set_file_mode(FILE *stream, cred_encoding_type_t enc);
/**
* Parse RSA padding configuration.
*
* @param padding input string to parse
* @param pss set to TRUE if PSS padding should be used, FALSE otherwise
* @return TRUE if successfully parsed
*/
bool parse_rsa_padding(char *padding, bool *pss);
/**
* Determine the signature scheme and parameters for the given private key and
* hash algorithm and whether to use PSS padding for RSA.