1
/* -*-mode:java; c-basic-offset:2; -*- */
3
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
8
1. Redistributions of source code must retain the above copyright notice,
9
this list of conditions and the following disclaimer.
11
2. Redistributions in binary form must reproduce the above copyright
12
notice, this list of conditions and the following disclaimer in
13
the documentation and/or other materials provided with the distribution.
15
3. The names of the authors may not be used to endorse or promote products
16
derived from this software without specific prior written permission.
18
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package com.jcraft.jsch;
33
private static final byte[] sshdss="ssh-dss".getBytes();
34
private static final byte[] sshrsa="ssh-rsa".getBytes();
36
public static final int SSHDSS=0;
37
public static final int SSHRSA=1;
38
static final int UNKNOWN=2;
43
public HostKey(String host, byte[] key) throws JSchException {
44
this.host=host; this.key=key;
45
if(key[8]=='d'){ this.type=SSHDSS; }
46
else if(key[8]=='r'){ this.type=SSHRSA; }
47
else { throw new JSchException("invalid key type");}
49
HostKey(String host, int type, byte[] key){
50
this.host=host; this.type=type; this.key=key;
52
public String getHost(){ return host; }
53
public String getType(){
54
if(type==SSHDSS){ return new String(sshdss); }
55
if(type==SSHRSA){ return new String(sshrsa);}
58
public String getKey(){
59
return new String(Util.toBase64(key, 0, key.length));
61
public String getFingerPrint(JSch jsch){
64
Class c=Class.forName(jsch.getConfig("md5"));
65
hash=(HASH)(c.newInstance());
67
catch(Exception e){ System.err.println("getFingerPrint: "+e); }
68
return Util.getFingerPrint(hash, key);