Diffstat (limited to 'noncore/comm/keypebble/krfblogin.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/krfblogin.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/noncore/comm/keypebble/krfblogin.cpp b/noncore/comm/keypebble/krfblogin.cpp index 2bbd110..92005d2 100644 --- a/noncore/comm/keypebble/krfblogin.cpp +++ b/noncore/comm/keypebble/krfblogin.cpp | |||
@@ -1,23 +1,28 @@ | |||
1 | #include <assert.h> | 1 | #include "krfblogin.h" |
2 | #include "krfbconnection.h" | ||
2 | 3 | ||
4 | /* OPIE */ | ||
5 | #include <opie2/odebug.h> | ||
6 | using namespace Opie::Core; | ||
7 | |||
8 | /* QT */ | ||
9 | #include <qtimer.h> | ||
3 | 10 | ||
11 | /* STD */ | ||
12 | #include <assert.h> | ||
4 | extern "C" { | 13 | extern "C" { |
5 | #include "vncauth.h" | 14 | #include "vncauth.h" |
6 | } | 15 | } |
7 | 16 | ||
8 | #include "krfblogin.h" | ||
9 | #include "krfbconnection.h" | ||
10 | #include <qtimer.h> | ||
11 | |||
12 | // The length of the various messages (used to decide how many bytes to | 17 | // The length of the various messages (used to decide how many bytes to |
13 | // wait for). | 18 | // wait for). |
14 | const int ServerVersionLength = 12; | 19 | const int ServerVersionLength = 12; |
15 | const int ClientVersionLength = 12; | 20 | const int ClientVersionLength = 12; |
16 | const int AuthSchemeLength = 4; | 21 | const int AuthSchemeLength = 4; |
17 | const int FailureReasonSizeLength = 4; | 22 | const int FailureReasonSizeLength = 4; |
18 | const int ChallengeLength = 16; | 23 | const int ChallengeLength = 16; |
19 | const int AuthResultLength = 4; | 24 | const int AuthResultLength = 4; |
20 | 25 | ||
21 | // Authentication results | 26 | // Authentication results |
22 | enum AuthResult { | 27 | enum AuthResult { |
23 | AuthOk, | 28 | AuthOk, |
@@ -43,154 +48,154 @@ const int endianTest = 1; | |||
43 | 48 | ||
44 | KRFBLogin::KRFBLogin( KRFBConnection *con ) | 49 | KRFBLogin::KRFBLogin( KRFBConnection *con ) |
45 | : QObject( con, "RFB login manager" ) | 50 | : QObject( con, "RFB login manager" ) |
46 | { | 51 | { |
47 | assert( con ); | 52 | assert( con ); |
48 | this->con = con; | 53 | this->con = con; |
49 | currentState = AwaitingServerVersion; | 54 | currentState = AwaitingServerVersion; |
50 | 55 | ||
51 | connect( this, SIGNAL( error(const QString&) ), | 56 | connect( this, SIGNAL( error(const QString&) ), |
52 | con, SIGNAL( error(const QString&) ) ); | 57 | con, SIGNAL( error(const QString&) ) ); |
53 | 58 | ||
54 | 59 | ||
55 | qWarning( "Waiting for server version..." ); | 60 | owarn << "Waiting for server version..." << oendl; |
56 | 61 | ||
57 | static QString statusMsg = tr( "Waiting for server version..." ); | 62 | static QString statusMsg = tr( "Waiting for server version..." ); |
58 | emit status( statusMsg ); | 63 | emit status( statusMsg ); |
59 | 64 | ||
60 | // Kick off the state machine | 65 | // Kick off the state machine |
61 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) ); | 66 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) ); |
62 | con->waitForData( ServerVersionLength ); | 67 | con->waitForData( ServerVersionLength ); |
63 | } | 68 | } |
64 | 69 | ||
65 | KRFBLogin::~KRFBLogin() | 70 | KRFBLogin::~KRFBLogin() |
66 | { | 71 | { |
67 | 72 | ||
68 | } | 73 | } |
69 | 74 | ||
70 | KRFBLogin::State KRFBLogin::state() const | 75 | KRFBLogin::State KRFBLogin::state() const |
71 | { | 76 | { |
72 | return currentState; | 77 | return currentState; |
73 | } | 78 | } |
74 | 79 | ||
75 | void KRFBLogin::gotServerVersion() | 80 | void KRFBLogin::gotServerVersion() |
76 | { | 81 | { |
77 | qWarning( "Got server version" ); | 82 | owarn << "Got server version" << oendl; |
78 | 83 | ||
79 | disconnect( con, SIGNAL( gotEnoughData() ), | 84 | disconnect( con, SIGNAL( gotEnoughData() ), |
80 | this, SLOT( gotServerVersion() ) ); | 85 | this, SLOT( gotServerVersion() ) ); |
81 | 86 | ||
82 | // Read the server's version message | 87 | // Read the server's version message |
83 | char serverVersion[ ServerVersionLength + 1 ]; | 88 | char serverVersion[ ServerVersionLength + 1 ]; |
84 | con->read( serverVersion, ServerVersionLength ); | 89 | con->read( serverVersion, ServerVersionLength ); |
85 | serverVersion[ ServerVersionLength ] = '\0'; | 90 | serverVersion[ ServerVersionLength ] = '\0'; |
86 | 91 | ||
87 | QCString rfbString( serverVersion, ServerVersionLength + 1 ); | 92 | QCString rfbString( serverVersion, ServerVersionLength + 1 ); |
88 | versionString = rfbString; | 93 | versionString = rfbString; |
89 | 94 | ||
90 | QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" ); | 95 | QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" ); |
91 | 96 | ||
92 | if ( rfbString.find( regexp ) == -1 ) { | 97 | if ( rfbString.find( regexp ) == -1 ) { |
93 | static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString ); | 98 | static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString ); |
94 | 99 | ||
95 | qWarning( msg ); | 100 | owarn << msg << oendl; |
96 | emit error( msg ); | 101 | emit error( msg ); |
97 | currentState = Error; | 102 | currentState = Error; |
98 | return; | 103 | return; |
99 | } | 104 | } |
100 | 105 | ||
101 | // Calculate the actual version number | 106 | // Calculate the actual version number |
102 | serverMajor = (serverVersion[4] - '0') * 100 | 107 | serverMajor = (serverVersion[4] - '0') * 100 |
103 | + (serverVersion[5] - '0') * 10 | 108 | + (serverVersion[5] - '0') * 10 |
104 | + (serverVersion[6] - '0'); | 109 | + (serverVersion[6] - '0'); |
105 | serverMinor = (serverVersion[8] - '0') * 100 | 110 | serverMinor = (serverVersion[8] - '0') * 100 |
106 | + (serverVersion[9] - '0') * 10 | 111 | + (serverVersion[9] - '0') * 10 |
107 | + (serverVersion[10] - '0'); | 112 | + (serverVersion[10] - '0'); |
108 | 113 | ||
109 | qWarning("Server Version: %03d.%03d", serverMajor, serverMinor ); | 114 | owarn << "Server Version: " << serverMajor << "." << serverMinor << "" << oendl; |
110 | 115 | ||
111 | if ( serverMajor != 3 ) { | 116 | if ( serverMajor != 3 ) { |
112 | QString msg = tr( "Error: Unsupported server version, %1" ) | 117 | QString msg = tr( "Error: Unsupported server version, %1" ) |
113 | .arg( rfbString ); | 118 | .arg( rfbString ); |
114 | 119 | ||
115 | qWarning( msg ); | 120 | owarn << msg << oendl; |
116 | emit error( msg ); | 121 | emit error( msg ); |
117 | currentState = Error; | 122 | currentState = Error; |
118 | return; | 123 | return; |
119 | } | 124 | } |
120 | 125 | ||
121 | if ( serverMinor != 3 ) { | 126 | if ( serverMinor != 3 ) { |
122 | qWarning( "Minor version mismatch: %d", serverMinor ); | 127 | owarn << "Minor version mismatch: " << serverMinor << "" << oendl; |
123 | } | 128 | } |
124 | 129 | ||
125 | // Setup for the next state | 130 | // Setup for the next state |
126 | sendClientVersion(); | 131 | sendClientVersion(); |
127 | 132 | ||
128 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) ); | 133 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) ); |
129 | con->waitForData( AuthSchemeLength ); | 134 | con->waitForData( AuthSchemeLength ); |
130 | } | 135 | } |
131 | 136 | ||
132 | void KRFBLogin::gotAuthScheme() | 137 | void KRFBLogin::gotAuthScheme() |
133 | { | 138 | { |
134 | disconnect( con, SIGNAL( gotEnoughData() ), | 139 | disconnect( con, SIGNAL( gotEnoughData() ), |
135 | this, SLOT( gotAuthScheme() ) ); | 140 | this, SLOT( gotAuthScheme() ) ); |
136 | 141 | ||
137 | // Got data | 142 | // Got data |
138 | CARD32 scheme; | 143 | CARD32 scheme; |
139 | con->read( &scheme, AuthSchemeLength ); | 144 | con->read( &scheme, AuthSchemeLength ); |
140 | scheme = Swap32IfLE( scheme ); | 145 | scheme = Swap32IfLE( scheme ); |
141 | 146 | ||
142 | static QString statusMsgOk = tr( "Logged in" ); | 147 | static QString statusMsgOk = tr( "Logged in" ); |
143 | 148 | ||
144 | switch ( scheme ) { | 149 | switch ( scheme ) { |
145 | case 0: | 150 | case 0: |
146 | qWarning( "Failed" ); | 151 | owarn << "Failed" << oendl; |
147 | // Handle failure | 152 | // Handle failure |
148 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) ); | 153 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) ); |
149 | con->waitForData( FailureReasonSizeLength ); | 154 | con->waitForData( FailureReasonSizeLength ); |
150 | break; | 155 | break; |
151 | case 1: | 156 | case 1: |
152 | // Handle no auth | 157 | // Handle no auth |
153 | emit status( statusMsgOk ); | 158 | emit status( statusMsgOk ); |
154 | con->gotRFBConnection(); | 159 | con->gotRFBConnection(); |
155 | break; | 160 | break; |
156 | case 2: | 161 | case 2: |
157 | // Handle VNC auth | 162 | // Handle VNC auth |
158 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) ); | 163 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) ); |
159 | con->waitForData( ChallengeLength ); | 164 | con->waitForData( ChallengeLength ); |
160 | break; | 165 | break; |
161 | default: | 166 | default: |
162 | qWarning( "Unknown authentication scheme, 0x%08lx", scheme ); | 167 | owarn << "Unknown authentication scheme, 0x" << scheme << "" << oendl; |
163 | currentState = Error; | 168 | currentState = Error; |
164 | break; | 169 | break; |
165 | }; | 170 | }; |
166 | } | 171 | } |
167 | 172 | ||
168 | void KRFBLogin::gotChallenge() | 173 | void KRFBLogin::gotChallenge() |
169 | { | 174 | { |
170 | disconnect( con, SIGNAL( gotEnoughData() ), | 175 | disconnect( con, SIGNAL( gotEnoughData() ), |
171 | this, SLOT( gotChallenge() ) ); | 176 | this, SLOT( gotChallenge() ) ); |
172 | 177 | ||
173 | QTimer::singleShot( 0, this, SLOT(getPassword()) ); | 178 | QTimer::singleShot( 0, this, SLOT(getPassword()) ); |
174 | } | 179 | } |
175 | 180 | ||
176 | void KRFBLogin::getPassword() | 181 | void KRFBLogin::getPassword() |
177 | { | 182 | { |
178 | // Got data | 183 | // Got data |
179 | CARD8 challenge[ ChallengeLength ]; | 184 | CARD8 challenge[ ChallengeLength ]; |
180 | con->read( challenge, ChallengeLength ); | 185 | con->read( challenge, ChallengeLength ); |
181 | 186 | ||
182 | // Last chance to enter a password | 187 | // Last chance to enter a password |
183 | if ( con->options_->password.isNull() ) { | 188 | if ( con->options_->password.isNull() ) { |
184 | qWarning( "krfblogin needs a password" ); | 189 | owarn << "krfblogin needs a password" << oendl; |
185 | emit passwordRequired( con ); | 190 | emit passwordRequired( con ); |
186 | } | 191 | } |
187 | 192 | ||
188 | if ( con->options_->password.isNull() ) { | 193 | if ( con->options_->password.isNull() ) { |
189 | QString msg = tr( "Error: This server requires a password, but none " | 194 | QString msg = tr( "Error: This server requires a password, but none " |
190 | "has been specified.\n" ); | 195 | "has been specified.\n" ); |
191 | 196 | ||
192 | emit error( msg ); | 197 | emit error( msg ); |
193 | return; | 198 | return; |
194 | } | 199 | } |
195 | 200 | ||
196 | vncEncryptBytes( (unsigned char *) challenge, QCString(con->options_->password.latin1()).data() ); | 201 | vncEncryptBytes( (unsigned char *) challenge, QCString(con->options_->password.latin1()).data() ); |
@@ -207,47 +212,47 @@ void KRFBLogin::gotFailureReasonSize() | |||
207 | } | 212 | } |
208 | 213 | ||
209 | void KRFBLogin::gotAuthResult() | 214 | void KRFBLogin::gotAuthResult() |
210 | { | 215 | { |
211 | // Got data | 216 | // Got data |
212 | disconnect( con, SIGNAL( gotEnoughData() ), this, | 217 | disconnect( con, SIGNAL( gotEnoughData() ), this, |
213 | SLOT( gotAuthResult() ) ); | 218 | SLOT( gotAuthResult() ) ); |
214 | 219 | ||
215 | long result; | 220 | long result; |
216 | con->read( &result, AuthResultLength ); | 221 | con->read( &result, AuthResultLength ); |
217 | result = Swap32IfLE( result ); | 222 | result = Swap32IfLE( result ); |
218 | 223 | ||
219 | qWarning( "Authentication Result is 0x%08lx", result ); | 224 | owarn << "Authentication Result is 0x" << result << "" << oendl; |
220 | 225 | ||
221 | static QString failed = tr( "Error: The password you specified was incorrect." ); | 226 | static QString failed = tr( "Error: The password you specified was incorrect." ); |
222 | static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n" | 227 | static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n" |
223 | "to this account, please try later." ); | 228 | "to this account, please try later." ); |
224 | 229 | ||
225 | static QString statusMsgOk = tr( "Logged in" ); | 230 | static QString statusMsgOk = tr( "Logged in" ); |
226 | static QString statusMsgFailed = tr( "Login Failed" ); | 231 | static QString statusMsgFailed = tr( "Login Failed" ); |
227 | static QString statusMsgTooMany = tr( "Too many failures" ); | 232 | static QString statusMsgTooMany = tr( "Too many failures" ); |
228 | 233 | ||
229 | switch( result ) { | 234 | switch( result ) { |
230 | case AuthOk: | 235 | case AuthOk: |
231 | emit status( statusMsgOk ); | 236 | emit status( statusMsgOk ); |
232 | con->gotRFBConnection(); | 237 | con->gotRFBConnection(); |
233 | break; | 238 | break; |
234 | case AuthFailed: | 239 | case AuthFailed: |
235 | qWarning( "Dammit" ); | 240 | owarn << "Dammit" << oendl; |
236 | emit status( statusMsgFailed ); | 241 | emit status( statusMsgFailed ); |
237 | emit error( failed ); | 242 | emit error( failed ); |
238 | break; | 243 | break; |
239 | case AuthTooMany: | 244 | case AuthTooMany: |
240 | emit status( statusMsgTooMany ); | 245 | emit status( statusMsgTooMany ); |
241 | emit error( tooMany ); | 246 | emit error( tooMany ); |
242 | break; | 247 | break; |
243 | default: | 248 | default: |
244 | qWarning( "Invalid authentication result, %lx", result ); | 249 | owarn << "Invalid authentication result, " << result << "" << oendl; |
245 | break; | 250 | break; |
246 | } | 251 | } |
247 | } | 252 | } |
248 | 253 | ||
249 | void KRFBLogin::sendClientVersion() | 254 | void KRFBLogin::sendClientVersion() |
250 | { | 255 | { |
251 | qWarning( "Sending client version" ); | 256 | owarn << "Sending client version" << oendl; |
252 | con->write( (void*)"RFB 003.003\n", ClientVersionLength ); | 257 | con->write( (void*)"RFB 003.003\n", ClientVersionLength ); |
253 | } | 258 | } |