| 30 | package com.jcraft.jsch; |
| 31 | |
| 32 | public class HostKey{ |
| 33 | |
| 34 | private static final byte[][] names = { |
| 35 | Util.str2byte("ssh-dss"), |
| 36 | Util.str2byte("ssh-rsa"), |
| 37 | Util.str2byte("ecdsa-sha2-nistp256"), |
| 38 | Util.str2byte("ecdsa-sha2-nistp384"), |
| 39 | Util.str2byte("ecdsa-sha2-nistp521") |
| 40 | }; |
| 41 | |
| 42 | protected static final int GUESS=0; |
| 43 | public static final int SSHDSS=1; |
| 44 | public static final int SSHRSA=2; |
| 45 | public static final int ECDSA256=3; |
| 46 | public static final int ECDSA384=4; |
| 47 | public static final int ECDSA521=5; |
| 48 | static final int UNKNOWN=6; |
| 49 | |
| 50 | protected String marker; |
| 51 | protected String host; |
| 52 | protected int type; |
| 53 | protected byte[] key; |
| 54 | protected String comment; |
| 55 | |
| 56 | public HostKey(String host, byte[] key) throws JSchException { |
| 57 | this(host, GUESS, key); |
| 58 | } |
| 59 | |
| 60 | public HostKey(String host, int type, byte[] key) throws JSchException { |
| 61 | this(host, type, key, null); |
| 62 | } |
| 63 | public HostKey(String host, int type, byte[] key, String comment) throws JSchException { |
| 64 | this("", host, type, key, comment); |
| 65 | } |
| 66 | public HostKey(String marker, String host, int type, byte[] key, String comment) throws JSchException { |
| 67 | this.marker=marker; |
| 68 | this.host=host; |
| 69 | if(type==GUESS){ |
| 70 | if(key[8]=='d'){ this.type=SSHDSS; } |
| 71 | else if(key[8]=='r'){ this.type=SSHRSA; } |
| 72 | else if(key[8]=='a' && key[20]=='2'){ this.type=ECDSA256; } |
| 73 | else if(key[8]=='a' && key[20]=='3'){ this.type=ECDSA384; } |
| 74 | else if(key[8]=='a' && key[20]=='5'){ this.type=ECDSA521; } |
| 75 | else { throw new JSchException("invalid key type");} |
| 76 | } |
| 77 | else{ |
| 78 | this.type=type; |
| 79 | } |
| 80 | this.key=key; |
| 81 | this.comment=comment; |
| 82 | } |
| 83 | |
| 84 | public String getHost(){ return host; } |
| 85 | public String getType(){ |
| 86 | if(type==SSHDSS || |
| 87 | type==SSHRSA || |
| 88 | type==ECDSA256 || |
| 89 | type==ECDSA384 || |