Skip to content

Commit

Permalink
allow user to override HTTP User-Agent
Browse files Browse the repository at this point in the history
Latest LibOpenConnect has two constructors, one of which accepts a User-Agent string.
  • Loading branch information
dlenski committed Aug 7, 2018
1 parent dd3af87 commit 41e740f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ private void acceptCert(String hash, boolean save) {
}

private class AndroidOC extends LibOpenConnect {
AndroidOC() {
super();
}

AndroidOC(String userAgent) {
super(userAgent);
}

private String getPeerCertSHA1() {
MessageDigest md;
try {
Expand Down Expand Up @@ -699,9 +707,14 @@ private boolean runVPN() {
mCacheDir = mContext.getCacheDir().getPath();
extractBinaries();

String userAgent = getStringPref("reported_user_agent");

setState(STATE_CONNECTING);
synchronized (mMainloopLock) {
mOC = new AndroidOC();
if (userAgent.length() > 0)
mOC = new AndroidOC(userAgent);
else
mOC = new AndroidOC();
}

if (setPreferences() == false) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
<string name="unknown">Unknown</string>
<string name="batch_mode">Batch mode</string>
<string name="reported_os">Reported OS</string>
<string name="reported_user_agent">Reported User-Agent</string>
<string name="reported_user_agent_summary">Override the HTTP User-Agent header.\n\nSome Cisco servers accept &quot;Cisco AnyConnect VPN Agent&quot;; some Juniper servers accept &quot;ncsvc&quot;</string>
<string name="custom_csd_wrapper">Custom CSD wrapper</string>
<string name="split_tunnel_mode">Split tunnel mode</string>
<string name="split_tunnel_networks">Split tunnel networks</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/pref_openconnect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
android:entries="@array/reported_os_entries"
android:entryValues="@array/reported_os_values"
android:defaultValue="android" />
<EditTextPreference
android:key="reported_user_agent"
android:title="@string/reported_user_agent"
android:dialogTitle="@string/reported_user_agent"
android:dialogMessage="@string/reported_user_agent_summary"
android:defaultValue="" />
<app.openconnect.ShowTextPreference
android:key="custom_csd_wrapper"
android:title="@string/custom_csd_wrapper"
Expand Down

0 comments on commit 41e740f

Please sign in to comment.