SSH2Util.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:3k
源码类别:

Telnet服务器

开发平台:

C#

  1. /* ---------------------------------------------------------------------------
  2.  *
  3.  * Copyright (c) Granados Networks, Inc.    All Rights Reserved..
  4.  * 
  5.  * This file is a part of the Granados SSH Client Library that is subject to
  6.  * the license included in the distributed package.
  7.  * You may not use this file except in compliance with the license.
  8.  * 
  9.  * $Id: SSH2Util.cs,v 1.2 2005/04/20 09:00:56 okajima Exp $
  10.  */
  11. using System;
  12. using Granados.SSHC;
  13. using Granados.PKI;
  14. namespace Granados.SSHCV2
  15. {
  16. public enum PacketType {
  17. SSH_MSG_DISCONNECT          =   1,
  18. SSH_MSG_IGNORE              =   2,
  19. SSH_MSG_UNIMPLEMENTED       =   3,
  20. SSH_MSG_DEBUG               =   4,
  21. SSH_MSG_SERVICE_REQUEST     =   5,
  22. SSH_MSG_SERVICE_ACCEPT      =   6,
  23. SSH_MSG_KEXINIT             =   20,
  24. SSH_MSG_NEWKEYS             =   21,
  25. SSH_MSG_KEXDH_INIT          =   30,
  26. SSH_MSG_KEXDH_REPLY         =   31,
  27. SSH_MSG_USERAUTH_REQUEST    =   50,
  28. SSH_MSG_USERAUTH_FAILURE    =   51,
  29. SSH_MSG_USERAUTH_SUCCESS    =   52,
  30. SSH_MSG_USERAUTH_BANNER     =   53,
  31. SSH_MSG_USERAUTH_INFO_REQUEST   = 60,
  32. SSH_MSG_USERAUTH_INFO_RESPONSE  = 61,
  33. SSH_MSG_GLOBAL_REQUEST =                 80,
  34. SSH_MSG_REQUEST_SUCCESS =                81,
  35. SSH_MSG_REQUEST_FAILURE =                82,
  36. SSH_MSG_CHANNEL_OPEN              =      90,
  37. SSH_MSG_CHANNEL_OPEN_CONFIRMATION =      91,
  38. SSH_MSG_CHANNEL_OPEN_FAILURE      =      92,
  39. SSH_MSG_CHANNEL_WINDOW_ADJUST     =      93,
  40. SSH_MSG_CHANNEL_DATA              =      94,
  41. SSH_MSG_CHANNEL_EXTENDED_DATA     =      95,
  42. SSH_MSG_CHANNEL_EOF               =      96,
  43. SSH_MSG_CHANNEL_CLOSE             =      97,
  44. SSH_MSG_CHANNEL_REQUEST           =      98,
  45. SSH_MSG_CHANNEL_SUCCESS           =      99,
  46. SSH_MSG_CHANNEL_FAILURE           =      100
  47. }
  48. public enum DisconnectReason {
  49. SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT =     1,
  50. SSH_DISCONNECT_PROTOCOL_ERROR              =     2,
  51. SSH_DISCONNECT_KEY_EXCHANGE_FAILED         =     3,
  52. SSH_DISCONNECT_RESERVED                    =     4,
  53. SSH_DISCONNECT_MAC_ERROR                   =     5,
  54. SSH_DISCONNECT_COMPRESSION_ERROR           =     6,
  55. SSH_DISCONNECT_SERVICE_NOT_AVAILABLE       =     7,
  56. SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED=   8,
  57. SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE     =     9,
  58. SSH_DISCONNECT_CONNECTION_LOST             =    10,
  59. SSH_DISCONNECT_BY_APPLICATION              =    11,
  60. SSH_DISCONNECT_TOO_MANY_CONNECTIONS        =    12,
  61. SSH_DISCONNECT_AUTH_CANCELLED_BY_USER      =    13,
  62. SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE=  14,
  63. SSH_DISCONNECT_ILLEGAL_USER_NAME           =    15
  64. }
  65. public enum ChannelOpenFailureReason {
  66. SSH_OPEN_ADMINISTRATIVELY_PROHIBITED =   1,
  67. SSH_OPEN_CONNECT_FAILED              =   2,
  68. SSH_OPEN_UNKNOWN_CHANNEL_TYPE        =   3,
  69. SSH_OPEN_RESOURCE_SHORTAGE           =   4
  70. }
  71. internal class SSH2Util : SSHUtil {
  72. public static string PublicKeyAlgorithmName(PublicKeyAlgorithm algorithm) {
  73. switch(algorithm) {
  74. case PublicKeyAlgorithm.DSA:
  75. return "ssh-dss";
  76. case PublicKeyAlgorithm.RSA:
  77. return "ssh-rsa";
  78. default:
  79. throw new SSHException("unknown HostKeyAlgorithm " + algorithm);
  80. }
  81. }
  82. }
  83. }