@@ -289,6 +289,57 @@ arc_key_hashesok(ARC_LIB *lib, u_char *hashlist)
289
289
/* NOTREACHED */
290
290
}
291
291
292
+ /*
293
+ ** ARC_PARSE_ALGORITHM -- parse an algorithm and set the msg hash and key,
294
+ ** as well as set the message digest algorithm for
295
+ ** RSA_verify in the variable nid
296
+ **
297
+ ** Parameters:
298
+ ** msg -- ARC_MESSAGE handle
299
+ ** alg -- string containing the algorithm to parse
300
+ ** nid -- variable to write the message digest algorithm
301
+ **
302
+ ** Return value:
303
+ ** An ARC_STAT_* constant.
304
+ */
305
+
306
+ ARC_STAT
307
+ arc_parse_algorithm (ARC_MESSAGE * msg , u_char * alg , int * nid )
308
+ {
309
+ arc_alg_t algtype ;
310
+
311
+ assert (msg != NULL );
312
+ assert (nid != NULL );
313
+
314
+ if (alg == NULL )
315
+ {
316
+ arc_error (msg , "missing algorithm passed to arc_parse_algorithm" );
317
+ return ARC_STAT_BADALG ;
318
+ }
319
+
320
+ algtype = arc_name_to_code (algorithms , alg );
321
+
322
+ if (algtype == ARC_SIGN_RSASHA1 )
323
+ {
324
+ msg -> arc_hashtype = ARC_HASHTYPE_SHA1 ;
325
+ msg -> arc_keytype = ARC_KEYTYPE_RSA ;
326
+ * nid = NID_sha1 ;
327
+ }
328
+ else if (algtype == ARC_SIGN_RSASHA256 )
329
+ {
330
+ msg -> arc_hashtype = ARC_HASHTYPE_SHA256 ;
331
+ msg -> arc_keytype = ARC_KEYTYPE_RSA ;
332
+ * nid = NID_sha256 ;
333
+ }
334
+ else
335
+ {
336
+ arc_error (msg , "unknown or invalid algorithm: %s" , alg );
337
+ return ARC_STAT_BADALG ;
338
+ }
339
+
340
+ return ARC_STAT_OK ;
341
+ }
342
+
292
343
/*
293
344
** ARC_GENAMSHDR -- generate a signature or seal header field
294
345
**
@@ -1964,6 +2015,13 @@ arc_validate_msg(ARC_MESSAGE *msg, u_int setnum)
1964
2015
msg -> arc_selector = arc_param_get (kvset , "s" );
1965
2016
msg -> arc_domain = arc_param_get (kvset , "d" );
1966
2017
2018
+ /* store algorithm in msg, needed for arc_get_key() */
2019
+ alg = arc_param_get (kvset , "a" );
2020
+ status = arc_parse_algorithm (msg , alg , & nid );
2021
+ if (status != ARC_STAT_OK )
2022
+ // arc_error already set by arc_parse_algorithm()
2023
+ return status ;
2024
+
1967
2025
/* get the key from DNS (or wherever) */
1968
2026
status = arc_get_key (msg , FALSE);
1969
2027
if (status != ARC_STAT_OK )
@@ -2038,11 +2096,6 @@ arc_validate_msg(ARC_MESSAGE *msg, u_int setnum)
2038
2096
return ARC_STAT_CANTVRFY ;
2039
2097
}
2040
2098
2041
- alg = arc_param_get (kvset , "a" );
2042
- nid = NID_sha1 ;
2043
- if (alg != NULL && strcmp (alg , "rsa-sha256" ) == 0 )
2044
- nid = NID_sha256 ;
2045
-
2046
2099
rsastat = RSA_verify (nid , hh , hhlen , sig , siglen , rsa );
2047
2100
2048
2101
RSA_free (rsa );
@@ -2118,6 +2171,13 @@ arc_validate_seal(ARC_MESSAGE *msg, u_int setnum)
2118
2171
msg -> arc_selector = arc_param_get (kvset , "s" );
2119
2172
msg -> arc_domain = arc_param_get (kvset , "d" );
2120
2173
2174
+ /* store algorithm in msg, needed for arc_get_key() */
2175
+ alg = arc_param_get (kvset , "a" );
2176
+ status = arc_parse_algorithm (msg , alg , & nid );
2177
+ if (status != ARC_STAT_OK )
2178
+ // arc_error already set by arc_parse_algorithm()
2179
+ return status ;
2180
+
2121
2181
if (msg -> arc_selector == NULL )
2122
2182
{
2123
2183
arc_error (msg , "seal at i=%u has no selector" , setnum );
@@ -2190,11 +2250,6 @@ arc_validate_seal(ARC_MESSAGE *msg, u_int setnum)
2190
2250
return ARC_STAT_INTERNAL ;
2191
2251
}
2192
2252
2193
- alg = arc_param_get (kvset , "a" );
2194
- nid = NID_sha1 ;
2195
- if (alg != NULL && strcmp (alg , "rsa-sha256" ) == 0 )
2196
- nid = NID_sha256 ;
2197
-
2198
2253
rsastat = RSA_verify (nid , sh , shlen , sig , siglen , rsa );
2199
2254
2200
2255
RSA_free (rsa );
0 commit comments