Browse code

Allow management client to announce pss padding support

The --management-external-key option can currently indicate support
for 'nopadding' or 'pkcs1' signatures in the client. Add 'pss' as an
option to announce that PSS signing requests are accepted.

To match, extend the algorithm string in PK_SIGN request to
include the following format:

- RSA_PKCS1_PSS_PADDING,hashalg=name,saltlen=[max|digest]

Here 'name' is the short common name of the hash algorithm.
E.g., SHA1, SHA256 etc.

Existing formats 'ECDSA' and 'RSA_PKCS1_PADDING' are unchanged.

v2 changes: Fix typos and other sloppiness in documentation and
commit message.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20211214165928.30676-10-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg23430.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Selva Nair authored on 2021/12/15 01:59:19
Showing 4 changed files
... ...
@@ -85,9 +85,15 @@ server and client mode operations.
85 85
      management-external-key
86 86
      management-external-key nopadding
87 87
      management-external-key pkcs1
88
+     management-external-key pss
89
+
90
+  or any combination like:
91
+  ::
92
+
88 93
      management-external-key nopadding pkcs1
94
+     management-external-key pkcs1 pss
89 95
 
90
-  The optional parameters :code:`nopadding` and :code:`pkcs1` signal
96
+  The optional parameters :code:`nopadding` :code:`pkcs1` and :code:`pss` signal
91 97
   support for different padding algorithms. See
92 98
   :code:`doc/mangement-notes.txt` for a complete description of this
93 99
   feature.
... ...
@@ -907,10 +907,24 @@ can be indicated in the signing request only if the client version is > 2"
907 907
 
908 908
 The currently defined padding algorithms are:
909 909
 
910
- - RSA_PKCS1_PADDING  -  PKCS1 padding and RSA signature
911
- - RSA_NO_PADDING     -  No padding may be added for the signature
912
- - ECDSA              -  EC signature.
913
-
910
+ - RSA_PKCS1_PADDING            -  PKCS1 padding and RSA signature
911
+ - RSA_NO_PADDING               -  No padding may be added for the signature
912
+ - ECDSA                        -  EC signature.
913
+ - RSA_PKCS1_PSS_PADDING,params -  RSA signature with PSS padding
914
+
915
+   The params for PSS are specified as 'hashalg=name,saltlen=[max|digest]'.
916
+
917
+   The hashalg names are short common names such as SHA256, SHA224, etc.
918
+   PSS saltlen="digest" means use the same size as the hash to sign, while
919
+   "max" indicates maximum possible saltlen which is
920
+   '(nbits-1)/8 - hlen - 2'. Here 'nbits' is the number of bits in the
921
+   key modulus and 'hlen' the size in octets of the hash.
922
+   (See: RFC 8017 sec 8.1.1 and 9.1.1)
923
+
924
+   In the case of PKCS1_PADDING, when the hash algorithm is not legacy
925
+   MD5-SHA1, the hash is encoded with DigestInfo header before presenting
926
+   to the management interface. This is identical to CKM_RSA_PKCS in Cryptoki
927
+   as well as what RSA_private_encrypt() in OpenSSL expects.
914 928
 
915 929
 COMMAND -- certificate (OpenVPN 2.4 or higher)
916 930
 ----------------------------------------------
... ...
@@ -339,6 +339,7 @@ struct management *management_init(void);
339 339
 #define MF_QUERY_REMOTE             (1<<13)
340 340
 #define MF_QUERY_PROXY              (1<<14)
341 341
 #define MF_EXTERNAL_CERT            (1<<15)
342
+#define MF_EXTERNAL_KEY_PSSPAD      (1<<16)
342 343
 
343 344
 bool management_open(struct management *man,
344 345
                      const char *addr,
... ...
@@ -60,6 +60,7 @@
60 60
 #include "forward.h"
61 61
 #include "ssl_verify.h"
62 62
 #include "platform.h"
63
+#include "xkey_common.h"
63 64
 #include <ctype.h>
64 65
 
65 66
 #include "memdbg.h"
... ...
@@ -2207,14 +2208,14 @@ options_postprocess_verify_ce(const struct options *options,
2207 2207
 
2208 2208
 #endif /* ifdef ENABLE_MANAGEMENT */
2209 2209
 
2210
-#if  defined(ENABLE_MANAGEMENT)
2210
+#if defined(ENABLE_MANAGEMENT) && !defined(HAVE_XKEY_PROVIDER)
2211 2211
     if ((tls_version_max() >= TLS_VER_1_3)
2212 2212
         && (options->management_flags & MF_EXTERNAL_KEY)
2213 2213
         && !(options->management_flags & (MF_EXTERNAL_KEY_NOPADDING))
2214 2214
         )
2215 2215
     {
2216
-        msg(M_ERR, "management-external-key with OpenSSL 1.1.1 requires "
2217
-            "the nopadding argument/support");
2216
+        msg(M_FATAL, "management-external-key with TLS 1.3 or later requires "
2217
+            "nopadding argument/support");
2218 2218
     }
2219 2219
 #endif
2220 2220
     /*
... ...
@@ -5520,6 +5521,10 @@ add_option(struct options *options,
5520 5520
             {
5521 5521
                 options->management_flags |= MF_EXTERNAL_KEY_PKCS1PAD;
5522 5522
             }
5523
+            else if (streq(p[j], "pss"))
5524
+            {
5525
+                options->management_flags |= MF_EXTERNAL_KEY_PSSPAD;
5526
+            }
5523 5527
             else
5524 5528
             {
5525 5529
                 msg(msglevel, "Unknown management-external-key flag: %s", p[j]);