@@ -958,7 +958,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
958
958
}
959
959
960
960
// Test invalid divisor lengths.
961
- for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 ] ) {
961
+ for ( const divisorLength of [ 'a' , true , { } , [ ] , 4096.1 , 2147483648 , - 1 ] ) {
962
962
assert . throws ( ( ) => generateKeyPair ( 'dsa' , {
963
963
modulusLength : 2048 ,
964
964
divisorLength
@@ -1081,6 +1081,52 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
1081
1081
message : 'Unknown DH group'
1082
1082
} ) ;
1083
1083
1084
+ assert . throws ( ( ) => {
1085
+ generateKeyPair ( 'dh' , {
1086
+ primeLength : 2147483648
1087
+ } , common . mustNotCall ( ) ) ;
1088
+ } , {
1089
+ name : 'TypeError' ,
1090
+ code : 'ERR_INVALID_ARG_VALUE' ,
1091
+ message : "The property 'options.primeLength' is invalid. " +
1092
+ 'Received 2147483648' ,
1093
+ } ) ;
1094
+
1095
+ assert . throws ( ( ) => {
1096
+ generateKeyPair ( 'dh' , {
1097
+ primeLength : - 1
1098
+ } , common . mustNotCall ( ) ) ;
1099
+ } , {
1100
+ name : 'TypeError' ,
1101
+ code : 'ERR_INVALID_ARG_VALUE' ,
1102
+ message : "The property 'options.primeLength' is invalid. " +
1103
+ 'Received -1' ,
1104
+ } ) ;
1105
+
1106
+ assert . throws ( ( ) => {
1107
+ generateKeyPair ( 'dh' , {
1108
+ primeLength : 2 ,
1109
+ generator : 2147483648 ,
1110
+ } , common . mustNotCall ( ) ) ;
1111
+ } , {
1112
+ name : 'TypeError' ,
1113
+ code : 'ERR_INVALID_ARG_VALUE' ,
1114
+ message : "The property 'options.generator' is invalid. " +
1115
+ 'Received 2147483648' ,
1116
+ } ) ;
1117
+
1118
+ assert . throws ( ( ) => {
1119
+ generateKeyPair ( 'dh' , {
1120
+ primeLength : 2 ,
1121
+ generator : - 1 ,
1122
+ } , common . mustNotCall ( ) ) ;
1123
+ } , {
1124
+ name : 'TypeError' ,
1125
+ code : 'ERR_INVALID_ARG_VALUE' ,
1126
+ message : "The property 'options.generator' is invalid. " +
1127
+ 'Received -1' ,
1128
+ } ) ;
1129
+
1084
1130
// Test incompatible options.
1085
1131
const allOpts = {
1086
1132
group : 'modp5' ,
@@ -1142,6 +1188,35 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
1142
1188
} ) ;
1143
1189
}
1144
1190
1191
+ // too long salt length
1192
+ assert . throws ( ( ) => {
1193
+ generateKeyPair ( 'rsa-pss' , {
1194
+ modulusLength : 512 ,
1195
+ saltLength : 2147483648 ,
1196
+ hash : 'sha256' ,
1197
+ mgf1Hash : 'sha256'
1198
+ } , common . mustNotCall ( ) ) ;
1199
+ } , {
1200
+ name : 'TypeError' ,
1201
+ code : 'ERR_INVALID_ARG_VALUE' ,
1202
+ message : "The property 'options.saltLength' is invalid. " +
1203
+ 'Received 2147483648'
1204
+ } ) ;
1205
+
1206
+ assert . throws ( ( ) => {
1207
+ generateKeyPair ( 'rsa-pss' , {
1208
+ modulusLength : 512 ,
1209
+ saltLength : - 1 ,
1210
+ hash : 'sha256' ,
1211
+ mgf1Hash : 'sha256'
1212
+ } , common . mustNotCall ( ) ) ;
1213
+ } , {
1214
+ name : 'TypeError' ,
1215
+ code : 'ERR_INVALID_ARG_VALUE' ,
1216
+ message : "The property 'options.saltLength' is invalid. " +
1217
+ 'Received -1'
1218
+ } ) ;
1219
+
1145
1220
// Invalid private key type.
1146
1221
for ( const type of [ 'foo' , 'spki' ] ) {
1147
1222
assert . throws ( ( ) => {
0 commit comments