Newer
Older
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
/*
This file is part of SLC.
Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
SLC 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; version 2 of the License.
SLC 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 SLC; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "slc.hh"
#include "sll/connection.hh"
#include "sll/cypher.hh"
#include "engine.hh"
#include "screen.hh"
#include "options.hh"
#include <string.h>
#include <openssl/sha.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include <openssl/md5.h>
void Engine::on() {
// Create graphic env
S.init();
// Show login screen
S.login();
// Showing dialog screen
S.dialog();
// connect and auth
login();
// Treat keyboards events
S.eventsloop();
}
void Engine::off() {
// Close connection
try { C.disconnect(); }
catch (...) {}
}
/**
* Connect and auth to server
*
*/
void Engine::login() {
try {
S << INF_DATA << "Trying to connect to " << O.server << " on " << O.port << ".\n";
C.connect(O.server.c_str(), O.port);
S << INF_DATA << "Trying to auth as " << O.login << ".\n";
auth();
}
catch (const Error &e) {
try {C.disconnect(); }
catch (...) {}
if (e.code() == ERR_NET || e.code() == ERR_AUTH)
S << WAR_DATA << e.message() << ".\n";
else
throw;
}
}
/**
* Try authenticate to server
*
*/
void Engine::auth() {
char buf[MAX_LINE_SIZE];
snprintf(buf, MAX_LINE_SIZE, "USER %s", O.login.c_str());
C.sendln(buf);
snprintf(buf, MAX_LINE_SIZE, "PASS %s",
Cypher::sha1_64(O.pass.c_str(), O.pass.length()).c_str());
C.sendln(buf);
string valid = C.recvln();
if (valid != "OK")
throw Error(ERR_AUTH, "Authentication refused");
}