Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
fb1eef05
Commit
fb1eef05
authored
Jan 16, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
App connects to insecure servers.
parent
2bec0df7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
27 deletions
+90
-27
DDPClientWrapper.java
...c/main/java/chat/rocket/android/api/DDPClientWrapper.java
+4
-2
InputHostnameFragment.java
...android/fragment/server_config/InputHostnameFragment.java
+10
-3
ServerPolicyHelper.java
...n/java/chat/rocket/android/helper/ServerPolicyHelper.java
+64
-21
ServerConfig.java
...src/main/java/chat/rocket/android/model/ServerConfig.java
+10
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+1
-1
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/chat/rocket/android/api/DDPClientWrapper.java
View file @
fb1eef05
...
...
@@ -38,8 +38,10 @@ public class DDPClientWrapper {
/**
* Connect to WebSocket server with DDP client.
*/
public
Task
<
DDPClientCallback
.
Connect
>
connect
(
@Nullable
String
session
)
{
return
ddpClient
.
connect
(
"wss://"
+
hostname
+
"/websocket"
,
session
);
public
Task
<
DDPClientCallback
.
Connect
>
connect
(
@Nullable
String
session
,
boolean
usesSecureConnection
)
{
final
String
protocol
=
usesSecureConnection
?
"wss://"
:
"ws://"
;
return
ddpClient
.
connect
(
protocol
+
hostname
+
"/websocket"
,
session
);
}
/**
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/InputHostnameFragment.java
View file @
fb1eef05
...
...
@@ -44,8 +44,8 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
ServerPolicyHelper
.
isApiVersionValid
(
OkHttpHelper
.
getClientForUploadFile
(),
hostname
,
new
ServerPolicyHelper
.
Callback
()
{
@Override
public
void
isValid
()
{
getActivity
().
runOnUiThread
(()
->
onServerValid
(
hostname
));
public
void
isValid
(
boolean
usesSecureConnection
)
{
getActivity
().
runOnUiThread
(()
->
onServerValid
(
hostname
,
usesSecureConnection
));
}
@Override
...
...
@@ -53,6 +53,12 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
getActivity
().
runOnUiThread
(()
->
showError
(
getString
(
R
.
string
.
input_hostname_invalid_server_message
)));
}
@Override
public
void
onNetworkError
()
{
getActivity
().
runOnUiThread
(()
->
showError
(
getString
(
R
.
string
.
connection_error_try_later
)));
}
});
}
...
...
@@ -68,7 +74,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
return
TextUtils
.
or
(
TextUtils
.
or
(
editor
.
getText
(),
editor
.
getHint
()),
""
).
toString
();
}
private
void
onServerValid
(
final
String
hostname
)
{
private
void
onServerValid
(
final
String
hostname
,
boolean
usesSecureConnection
)
{
RocketChatCache
.
get
(
getContext
()).
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_CONFIG_ID
,
serverConfigId
)
.
apply
();
...
...
@@ -79,6 +85,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
.
put
(
ServerConfig
.
HOSTNAME
,
hostname
)
.
put
(
ServerConfig
.
ERROR
,
JSONObject
.
NULL
)
.
put
(
ServerConfig
.
SESSION
,
JSONObject
.
NULL
)
.
put
(
ServerConfig
.
SECURE_CONNECTION
,
usesSecureConnection
)
.
put
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_READY
)))
.
continueWith
(
new
LogcatIfError
());
}
...
...
app/src/main/java/chat/rocket/android/helper/ServerPolicyHelper.java
View file @
fb1eef05
...
...
@@ -27,32 +27,20 @@ public class ServerPolicyHelper {
public
static
void
isApiVersionValid
(
@NonNull
OkHttpClient
client
,
@NonNull
String
host
,
@NonNull
Callback
callback
)
{
Request
request
;
try
{
request
=
new
Request
.
Builder
()
.
url
(
"https://"
+
host
+
API_INFO_PATH
)
.
get
()
.
build
();
}
catch
(
Exception
e
)
{
callback
.
isNotValid
();
return
;
}
trySecureValidation
(
client
,
host
,
new
Callback
()
{
@Override
public
void
isValid
(
boolean
usesSecureConnection
)
{
callback
.
isValid
(
usesSecureConnection
);
}
client
.
newCall
(
request
).
enqueue
(
new
okhttp3
.
Callback
()
{
@Override
public
void
onFailure
(
Call
call
,
IOException
exception
)
{
// some connection error
public
void
isNotValid
()
{
callback
.
isNotValid
();
}
@Override
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
if
(!
response
.
isSuccessful
()
||
!
isValid
(
response
.
body
()))
{
callback
.
isNotValid
();
return
;
}
callback
.
isValid
();
public
void
onNetworkError
()
{
tryInsecureValidation
(
client
,
host
,
callback
);
}
});
}
...
...
@@ -104,9 +92,64 @@ public class ServerPolicyHelper {
return
versionParts
.
length
>=
3
&&
Integer
.
parseInt
(
versionParts
[
1
])
>=
49
;
}
private
static
void
trySecureValidation
(
@NonNull
OkHttpClient
client
,
@NonNull
String
host
,
@NonNull
Callback
callback
)
{
Request
request
;
try
{
request
=
createRequest
(
"https://"
,
host
);
}
catch
(
Exception
e
)
{
callback
.
isNotValid
();
return
;
}
validate
(
request
,
client
,
callback
,
true
);
}
private
static
void
tryInsecureValidation
(
@NonNull
OkHttpClient
client
,
@NonNull
String
host
,
@NonNull
Callback
callback
)
{
Request
request
;
try
{
request
=
createRequest
(
"http://"
,
host
);
}
catch
(
Exception
e
)
{
callback
.
isNotValid
();
return
;
}
validate
(
request
,
client
,
callback
,
false
);
}
private
static
Request
createRequest
(
@NonNull
String
protocol
,
@NonNull
String
host
)
{
return
new
Request
.
Builder
()
.
url
(
protocol
+
host
+
API_INFO_PATH
)
.
get
()
.
build
();
}
private
static
void
validate
(
@NonNull
Request
request
,
@NonNull
OkHttpClient
client
,
@NonNull
Callback
callback
,
boolean
usesSecureConnection
)
{
client
.
newCall
(
request
).
enqueue
(
new
okhttp3
.
Callback
()
{
@Override
public
void
onFailure
(
Call
call
,
IOException
exception
)
{
callback
.
onNetworkError
();
}
@Override
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
if
(!
response
.
isSuccessful
()
||
!
isValid
(
response
.
body
()))
{
callback
.
isNotValid
();
return
;
}
callback
.
isValid
(
usesSecureConnection
);
}
});
}
public
interface
Callback
{
void
isValid
();
void
isValid
(
boolean
usesSecureConnection
);
void
isNotValid
();
void
onNetworkError
();
}
}
app/src/main/java/chat/rocket/android/model/ServerConfig.java
View file @
fb1eef05
...
...
@@ -19,6 +19,7 @@ public class ServerConfig extends RealmObject {
public
static
final
String
HOSTNAME
=
"hostname"
;
public
static
final
String
STATE
=
"state"
;
public
static
final
String
SESSION
=
"session"
;
public
static
final
String
SECURE_CONNECTION
=
"secureConnection"
;
public
static
final
String
ERROR
=
"error"
;
public
static
final
int
STATE_READY
=
0
;
...
...
@@ -30,6 +31,7 @@ public class ServerConfig extends RealmObject {
private
String
hostname
;
private
int
state
;
private
String
session
;
private
boolean
secureConnection
;
private
String
error
;
/**
...
...
@@ -93,6 +95,14 @@ public class ServerConfig extends RealmObject {
this
.
session
=
session
;
}
public
boolean
usesSecureConnection
()
{
return
secureConnection
;
}
public
void
setSecureConnection
(
boolean
usesSecureConnection
)
{
this
.
secureConnection
=
usesSecureConnection
;
}
public
String
getError
()
{
return
error
;
}
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
fb1eef05
...
...
@@ -170,7 +170,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
());
prepareWebSocket
(
config
.
getHostname
());
return
ddpClient
.
connect
(
config
.
getSession
())
return
ddpClient
.
connect
(
config
.
getSession
()
,
config
.
usesSecureConnection
()
)
.
onSuccessTask
(
task
->
{
final
String
session
=
task
.
getResult
().
session
;
defaultRealm
.
executeTransaction
(
realm
->
...
...
app/src/main/res/values/strings.xml
View file @
fb1eef05
...
...
@@ -41,4 +41,5 @@
<string
name=
"video_upload_message_spec_title"
>
Attach video
</string>
<string
name=
"input_hostname_invalid_server_message"
>
Invalid server version
</string>
<string
name=
"connection_error_try_later"
>
There\'s a connection error. Please try later.
</string>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment