comparison app/src/main/java/ch/ethz/ssh2/Connection.java @ 510:7953570e5210

update to ganymed-ssh2 tag 263 and fix hmac-sha2-512
author Carl Byington <carl@five-ten-sg.com>
date Wed, 01 Feb 2023 17:55:29 -0700
parents d29cce60f393
children
comparison
equal deleted inserted replaced
509:2eb4fa13b9ef 510:7953570e5210
1240 cryptoWishList.c2s_comp_algos = new String[] {"none"}; 1240 cryptoWishList.c2s_comp_algos = new String[] {"none"};
1241 cryptoWishList.s2c_comp_algos = new String[] {"none"}; 1241 cryptoWishList.s2c_comp_algos = new String[] {"none"};
1242 } 1242 }
1243 1243
1244 /** 1244 /**
1245 * Removes duplicates from a String array, keeps only first occurence
1246 * of each element. Does not destroy order of elements; can handle nulls.
1247 * Uses a very efficient O(N^2) algorithm =)
1248 *
1249 * @param list a String array.
1250 * @return a cleaned String array.
1251 */
1252 private String[] removeDuplicates(String[] list) {
1253 if((list == null) || (list.length < 2)) {
1254 return list;
1255 }
1256
1257 String[] list2 = new String[list.length];
1258
1259 int count = 0;
1260
1261 for(final String element : list) {
1262 boolean duplicate = false;
1263 for(int j = 0; j < count; j++) {
1264 if(((element == null) && (list2[j] == null)) || ((element != null) && (element.equals(list2[j])))) {
1265 duplicate = true;
1266 break;
1267 }
1268 }
1269 if(duplicate) {
1270 continue;
1271 }
1272 list2[count++] = element;
1273 }
1274
1275 if(count == list2.length) {
1276 return list2;
1277 }
1278
1279 String[] tmp = new String[count];
1280 System.arraycopy(list2, 0, tmp, 0, count);
1281
1282 return tmp;
1283 }
1284
1285 /**
1245 * Unless you know what you are doing, you will never need this. 1286 * Unless you know what you are doing, you will never need this.
1246 */ 1287 */
1247 1288
1248 public synchronized void setClient2ServerCiphers(final String[] ciphers) { 1289 public synchronized void setClient2ServerCiphers(String[] ciphers) {
1249 if ((ciphers == null) || (ciphers.length == 0)) { 1290 if ((ciphers == null) || (ciphers.length == 0)) {
1250 throw new IllegalArgumentException(); 1291 throw new IllegalArgumentException();
1251 } 1292 }
1252 1293 ciphers = removeDuplicates(ciphers);
1253 BlockCipherFactory.checkCipherList(ciphers); 1294 BlockCipherFactory.checkCipherList(ciphers);
1254 cryptoWishList.c2s_enc_algos = ciphers; 1295 cryptoWishList.c2s_enc_algos = ciphers;
1255 } 1296 }
1256 1297
1257 /** 1298 /**
1258 * Unless you know what you are doing, you will never need this. 1299 * Unless you know what you are doing, you will never need this.
1259 */ 1300 */
1260 1301
1261 public synchronized void setClient2ServerMACs(final String[] macs) { 1302 public synchronized void setClient2ServerMACs(String[] macs) {
1303 if((macs == null) || (macs.length == 0)) {
1304 throw new IllegalArgumentException();
1305 }
1306 macs = removeDuplicates(macs);
1262 MAC.checkMacList(macs); 1307 MAC.checkMacList(macs);
1263 cryptoWishList.c2s_mac_algos = macs; 1308 cryptoWishList.c2s_mac_algos = macs;
1264 } 1309 }
1265 1310
1266 /** 1311 /**
1281 1326
1282 /** 1327 /**
1283 * Unless you know what you are doing, you will never need this. 1328 * Unless you know what you are doing, you will never need this.
1284 */ 1329 */
1285 1330
1286 public synchronized void setServer2ClientCiphers(final String[] ciphers) { 1331 public synchronized void setServer2ClientCiphers(String[] ciphers) {
1332 if((ciphers == null) || (ciphers.length == 0)) {
1333 throw new IllegalArgumentException();
1334 }
1335 ciphers = removeDuplicates(ciphers);
1287 BlockCipherFactory.checkCipherList(ciphers); 1336 BlockCipherFactory.checkCipherList(ciphers);
1288 cryptoWishList.s2c_enc_algos = ciphers; 1337 cryptoWishList.s2c_enc_algos = ciphers;
1289 } 1338 }
1290 1339
1291 /** 1340 /**
1292 * Unless you know what you are doing, you will never need this. 1341 * Unless you know what you are doing, you will never need this.
1293 */ 1342 */
1294 1343
1295 public synchronized void setServer2ClientMACs(final String[] macs) { 1344 public synchronized void setServer2ClientMACs(String[] macs) {
1345 if((macs == null) || (macs.length == 0)) {
1346 throw new IllegalArgumentException();
1347 }
1348 macs = removeDuplicates(macs);
1296 MAC.checkMacList(macs); 1349 MAC.checkMacList(macs);
1297 cryptoWishList.s2c_mac_algos = macs; 1350 cryptoWishList.s2c_mac_algos = macs;
1298 } 1351 }
1299 1352
1300 /** 1353 /**
1308 * The entries of the array must be ordered after preference, i.e., 1361 * The entries of the array must be ordered after preference, i.e.,
1309 * the entry at index 0 is the most preferred one. You must specify 1362 * the entry at index 0 is the most preferred one. You must specify
1310 * at least one entry. 1363 * at least one entry.
1311 */ 1364 */
1312 1365
1313 public synchronized void setServerHostKeyAlgorithms(final String[] algos) { 1366 public synchronized void setServerHostKeyAlgorithms(String[] algos) {
1367 if ((algos == null) || (algos.length == 0)) {
1368 throw new IllegalArgumentException();
1369 }
1370 algos = removeDuplicates(algos);
1314 KexManager.checkServerHostkeyAlgorithmsList(algos); 1371 KexManager.checkServerHostkeyAlgorithmsList(algos);
1315 cryptoWishList.serverHostKeyAlgorithms = algos; 1372 cryptoWishList.serverHostKeyAlgorithms = algos;
1373 }
1374
1375 /**
1376 * Define the set of allowed key exchange methods.
1377 *
1378 * @param algos An array of allowed key exchange methods. The following are supported:
1379 * diffie-hellman-group14-sha256,
1380 * diffie-hellman-group16-sha512,
1381 * diffie-hellman-group18-sha512,
1382 * diffie-hellman-group14-sha1,
1383 * diffie-hellman-group1-sha1,
1384 * diffie-hellman-group-exchange-sha1
1385 */
1386 public synchronized void setClientKexAlgorithms(String[] algos) {
1387 if ((algos == null) || (algos.length == 0)) {
1388 throw new IllegalArgumentException();
1389 }
1390 algos = removeDuplicates(algos);
1391 KexManager.checkClientKexAlgorithmList(algos);
1392 cryptoWishList.kexAlgorithms = algos;
1316 } 1393 }
1317 1394
1318 /** 1395 /**
1319 * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm) on the underlying socket. 1396 * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm) on the underlying socket.
1320 * <p/> 1397 * <p/>