summaryrefslogtreecommitdiff
path: root/src/protocol/internal/fqterm_ssh_auth.h
blob: 6152a710ca4259bd307be0bc3c42f096dc059248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/***************************************************************************
 *   fqterm, a terminal emulator for both BBS and *nix.                    *
 *   Copyright (C) 2008 fqterm development group.                          *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.               *
 ***************************************************************************/

#ifndef FQTERM_SSH_AUTH_H
#define FQTERM_SSH_AUTH_H

#include <QObject>

class QString;

namespace FQTerm {

class FQTermSSHPacketReceiver;
class FQTermSSHPacketSender;

class FQTermSSHAuth: public QObject {

  Q_OBJECT;
protected:
  QString user_name_;
  FQTermSSHPacketReceiver *packet_receiver_;
  FQTermSSHPacketSender *packet_sender_;

public:
  FQTermSSHAuth(const char *sshuser = NULL)
    : user_name_(sshuser) {
  }

  ~FQTermSSHAuth() {}

  virtual void initAuth(FQTermSSHPacketReceiver *packet,
                        FQTermSSHPacketSender *output) = 0;
public slots:
  virtual void handlePacket(int type) = 0;

signals:
  void requestUserPwd(QString *user, QString *pwd, bool *isOK);
  void authOK();
  void authError(QString);
};

class FQTermSSHPasswdAuth: public FQTermSSHAuth {
  Q_OBJECT;
protected:
  QString passwd_;
  bool is_tried_;

  QString default_user_;
  QString default_passwd_;
  
public:
  FQTermSSHPasswdAuth(const char *sshuser, const char *sshpasswd)
    : FQTermSSHAuth(sshuser),
      passwd_(sshpasswd),
      default_user_(sshuser),
      default_passwd_(sshpasswd) {
  }
};

class FQTermSSH1PasswdAuth: public FQTermSSHPasswdAuth {
  Q_OBJECT;
private:
  enum FQTermSSH1PasswdAuthState {
    BEFORE_AUTH, USER_SENT, PASS_SENT, AUTH_OK
  }	ssh_pw_auth_state_;

public:
  FQTermSSH1PasswdAuth(const char *sshuser, const char *sshpasswd);

public slots:
  void handlePacket(int type);
  void initAuth(FQTermSSHPacketReceiver *packet, FQTermSSHPacketSender *output);
};

class FQTermSSH2PasswdAuth: public FQTermSSHPasswdAuth {
  Q_OBJECT;
private:
  enum FQTermSSH2PasswdAuthState {
    SERVICE_ACCEPTED, USER_PASSWD_SENT, PASS_SENT, AUTH_OK
  }	ssh_pw_auth_state_;

  void sendUserPasswd();
  bool check();

public:
  FQTermSSH2PasswdAuth(const char *sshuser, const char *sshpasswd);

public slots:
  void handlePacket(int type);
  void initAuth(FQTermSSHPacketReceiver *packet, FQTermSSHPacketSender *output);
};

}  // namespace FQTerm

#endif  // FQTERM_SSH_AUTH_H