4067 |
02 Sep 16 |
nicklas |
1 |
package net.sf.basedb.opengrid; |
4067 |
02 Sep 16 |
nicklas |
2 |
|
4067 |
02 Sep 16 |
nicklas |
3 |
import java.util.regex.Pattern; |
4067 |
02 Sep 16 |
nicklas |
4 |
|
4067 |
02 Sep 16 |
nicklas |
5 |
import net.schmizz.sshj.Config; |
4067 |
02 Sep 16 |
nicklas |
6 |
import net.schmizz.sshj.DefaultConfig; |
4450 |
10 Apr 17 |
nicklas |
7 |
import net.sf.basedb.core.FileServer; |
4067 |
02 Sep 16 |
nicklas |
8 |
|
4067 |
02 Sep 16 |
nicklas |
9 |
/** |
4067 |
02 Sep 16 |
nicklas |
Interal class with utility functions for SSH connections. |
4067 |
02 Sep 16 |
nicklas |
11 |
|
4067 |
02 Sep 16 |
nicklas |
@author nicklas |
4067 |
02 Sep 16 |
nicklas |
@since 1.0 |
4067 |
02 Sep 16 |
nicklas |
14 |
*/ |
4254 |
25 Nov 16 |
nicklas |
15 |
public final class SshUtil |
4067 |
02 Sep 16 |
nicklas |
16 |
{ |
4067 |
02 Sep 16 |
nicklas |
17 |
|
4067 |
02 Sep 16 |
nicklas |
18 |
/** |
4067 |
02 Sep 16 |
nicklas |
Default configuration for SSH connections. |
4067 |
02 Sep 16 |
nicklas |
We save this as a static to avoid expensive |
4067 |
02 Sep 16 |
nicklas |
initialization each time a connection is |
4067 |
02 Sep 16 |
nicklas |
needed. |
4067 |
02 Sep 16 |
nicklas |
23 |
*/ |
4067 |
02 Sep 16 |
nicklas |
24 |
static final Config SSH_CONFIG; |
4067 |
02 Sep 16 |
nicklas |
25 |
|
4067 |
02 Sep 16 |
nicklas |
26 |
static |
4067 |
02 Sep 16 |
nicklas |
27 |
{ |
4067 |
02 Sep 16 |
nicklas |
28 |
SSH_CONFIG = new DefaultConfig(); |
4067 |
02 Sep 16 |
nicklas |
29 |
} |
4067 |
02 Sep 16 |
nicklas |
30 |
|
4067 |
02 Sep 16 |
nicklas |
31 |
/** |
4067 |
02 Sep 16 |
nicklas |
Pattern that matches a SSH fingerprint: 16 pairs of hexadecimal numbers separated with colon. |
4450 |
10 Apr 17 |
nicklas |
@deprecated In 1.1, use {@link FileServer#MD5_FINGERPRINT_PATTERN} instead |
4067 |
02 Sep 16 |
nicklas |
34 |
*/ |
4450 |
10 Apr 17 |
nicklas |
35 |
@Deprecated |
4067 |
02 Sep 16 |
nicklas |
36 |
public static final Pattern FINGERPRINT_PATTERN = Pattern.compile("[0-9a-f]{2}(\\:[0-9a-f]{2}){15}"); |
4067 |
02 Sep 16 |
nicklas |
37 |
|
4450 |
10 Apr 17 |
nicklas |
38 |
|
4450 |
10 Apr 17 |
nicklas |
39 |
/** |
4450 |
10 Apr 17 |
nicklas |
Check if the given fingerprint is valid and what type it is. |
4450 |
10 Apr 17 |
nicklas |
@param fingerprint The fingerprint to check |
4450 |
10 Apr 17 |
nicklas |
@return MD5 or SHA256 or null |
4450 |
10 Apr 17 |
nicklas |
@since 1.1 |
4450 |
10 Apr 17 |
nicklas |
44 |
*/ |
4450 |
10 Apr 17 |
nicklas |
45 |
public static final String getFingerPrintType(String fingerprint) |
4450 |
10 Apr 17 |
nicklas |
46 |
{ |
4450 |
10 Apr 17 |
nicklas |
47 |
String type = null; |
4450 |
10 Apr 17 |
nicklas |
48 |
if (FileServer.SHA256_FINGERPRINT_PATTERN.matcher(fingerprint).matches()) |
4450 |
10 Apr 17 |
nicklas |
49 |
{ |
4450 |
10 Apr 17 |
nicklas |
50 |
type = FileServer.FINGERPRINT_TYPE_SHA256; |
4450 |
10 Apr 17 |
nicklas |
51 |
} |
4450 |
10 Apr 17 |
nicklas |
52 |
else if (FileServer.MD5_FINGERPRINT_PATTERN.matcher(fingerprint).matches()) |
4450 |
10 Apr 17 |
nicklas |
53 |
{ |
4450 |
10 Apr 17 |
nicklas |
54 |
type = FileServer.FINGERPRINT_TYPE_MD5; |
4450 |
10 Apr 17 |
nicklas |
55 |
} |
4450 |
10 Apr 17 |
nicklas |
56 |
return type; |
4450 |
10 Apr 17 |
nicklas |
57 |
} |
4450 |
10 Apr 17 |
nicklas |
58 |
|
4067 |
02 Sep 16 |
nicklas |
59 |
} |