~ubuntu-branches/ubuntu/wily/jsch/wily

« back to all changes in this revision

Viewing changes to src/main/java/com/jcraft/jsch/HostKey.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-07-08 15:43:26 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20150708154326-er7o49qy0wgfr6xd
Tags: 0.1.53-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop dependency on libjzlib-java for continued main inclusion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2
2
/*
3
 
Copyright (c) 2002-2014 ymnk, JCraft,Inc. All rights reserved.
 
3
Copyright (c) 2002-2015 ymnk, JCraft,Inc. All rights reserved.
4
4
 
5
5
Redistribution and use in source and binary forms, with or without
6
6
modification, are permitted provided that the following conditions are met:
30
30
package com.jcraft.jsch;
31
31
 
32
32
public class HostKey{
33
 
  private static final byte[] sshdss=Util.str2byte("ssh-dss");
34
 
  private static final byte[] sshrsa=Util.str2byte("ssh-rsa");
 
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
  };
35
41
 
36
42
  protected static final int GUESS=0;
37
43
  public static final int SSHDSS=1;
38
44
  public static final int SSHRSA=2;
39
 
  static final int UNKNOWN=3;
 
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;
40
49
 
41
50
  protected String marker;
42
51
  protected String host;
60
69
    if(type==GUESS){
61
70
      if(key[8]=='d'){ this.type=SSHDSS; }
62
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; }
63
75
      else { throw new JSchException("invalid key type");}
64
76
    }
65
77
    else{
71
83
 
72
84
  public String getHost(){ return host; }
73
85
  public String getType(){
74
 
    if(type==SSHDSS){ return Util.byte2str(sshdss); }
75
 
    if(type==SSHRSA){ return Util.byte2str(sshrsa);}
 
86
    if(type==SSHDSS ||
 
87
       type==SSHRSA ||
 
88
       type==ECDSA256 ||
 
89
       type==ECDSA384 ||
 
90
       type==ECDSA521){
 
91
      return Util.byte2str(names[type-1]);
 
92
    }
76
93
    return "UNKNOWN";
77
94
  }
 
95
  protected static int name2type(String name){
 
96
    for(int i = 0; i < names.length; i++){
 
97
      if(Util.byte2str(names[i]).equals(name)){
 
98
        return i + 1;
 
99
      }
 
100
    }
 
101
    return UNKNOWN;
 
102
  }
78
103
  public String getKey(){
79
104
    return Util.byte2str(Util.toBase64(key, 0, key.length));
80
105
  }