Skip to content

Commit

Permalink
Allow iOS to connect to servers without SSL (#7881) (#7885)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattermost-build authored Mar 28, 2024
1 parent 26896eb commit 2b1dfff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
10 changes: 0 additions & 10 deletions .github/actions/prepare-ios-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ description: Action to prepare environment for ios build
runs:
using: composite
steps:
- name: ci/install-os-deps
env:
HOMEBREW_NO_AUTO_UPDATE: "1"
shell: bash
run: |
echo "::group::install-os-deps"
brew install --overwrite [email protected]
brew install watchman
echo "::endgroup::"
- name: ci/prepare-mobile-build
uses: ./.github/actions/prepare-mobile-build

Expand Down
33 changes: 18 additions & 15 deletions app/screens/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,31 +290,34 @@ const Server = ({
cancelPing = undefined;
};

const serverUrl = await getServerUrlAfterRedirect(pingUrl, !retryWithHttp);
if (!serverUrl) {
const ping = await getServerUrlAfterRedirect(pingUrl, !retryWithHttp);
if (!ping.url) {
cancelPing();
if (retryWithHttp) {
const nurl = pingUrl.replace('https:', 'http:');
pingServer(nurl, false);
} else {
setUrlError(getErrorMessage(ping.error, intl));
setButtonDisabled(true);
setConnecting(false);
}
return;
}
const result = await doPing(serverUrl, true, managedConfig?.timeout ? parseInt(managedConfig?.timeout, 10) : undefined);
const result = await doPing(ping.url, true, managedConfig?.timeout ? parseInt(managedConfig?.timeout, 10) : undefined);

if (canceled) {
return;
}

if (result.error) {
if (retryWithHttp) {
const nurl = serverUrl.replace('https:', 'http:');
pingServer(nurl, false);
} else {
setUrlError(getErrorMessage(result.error, intl));
setButtonDisabled(true);
setConnecting(false);
}
setUrlError(getErrorMessage(result.error, intl));
setButtonDisabled(true);
setConnecting(false);
return;
}

canReceiveNotifications(serverUrl, result.canReceiveNotifications as string, intl);
const data = await fetchConfigAndLicense(serverUrl, true);
canReceiveNotifications(ping.url, result.canReceiveNotifications as string, intl);
const data = await fetchConfigAndLicense(ping.url, true);
if (data.error) {
setButtonDisabled(true);
setUrlError(getErrorMessage(data.error, intl));
Expand All @@ -332,7 +335,7 @@ const Server = ({
}

const server = await getServerByIdentifier(data.config.DiagnosticId);
const credentials = await getServerCredentials(serverUrl);
const credentials = await getServerCredentials(ping.url);
setConnecting(false);

if (server && server.lastActiveAt > 0 && credentials?.token) {
Expand All @@ -344,7 +347,7 @@ const Server = ({
return;
}

displayLogin(serverUrl, data.config!, data.license!);
displayLogin(ping.url, data.config!, data.license!);
};

const transform = useAnimatedStyle(() => {
Expand Down
12 changes: 7 additions & 5 deletions app/utils/url/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import urlParse from 'url-parse';

import {Files} from '@constants';
import {emptyFunction} from '@utils/general';
import {logDebug} from '@utils/log';

import {latinise} from './latinise';

Expand All @@ -25,8 +26,10 @@ export function sanitizeUrl(url: string, useHttp = false) {
preUrl = urlParse('https://' + stripTrailingSlashes(url), true);
}

if (!protocol || (preUrl.protocol === 'http:' && !useHttp)) {
if (preUrl.protocol === 'http:' && !useHttp) {
protocol = 'https:';
} else if (!protocol) {
protocol = useHttp ? 'http:' : 'https:';
}

return stripTrailingSlashes(
Expand All @@ -43,12 +46,11 @@ export async function getServerUrlAfterRedirect(serverUrl: string, useHttp = fal
url = resp.redirectUrls[resp.redirectUrls.length - 1];
}
} catch (error) {
if (useHttp) {
return undefined;
}
logDebug('getServerUrlAfterRedirect error', url, error);
return {error};
}

return sanitizeUrl(url, useHttp);
return {url: sanitizeUrl(url, useHttp)};
}

export function stripTrailingSlashes(url = '') {
Expand Down
10 changes: 8 additions & 2 deletions ios/Mattermost/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>Enabling access to your media library means you can attach files from your media library to your messages in $(PRODUCT_NAME).</string>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b1dfff

Please sign in to comment.