Commit Graph

1051 Commits

Author SHA1 Message Date
Evan Hahn
836a891204
Use #unavailable where possible, fixing SwiftLint violation
This fixes violations of [SwiftLint's `unavailable_condition` rule][0].
We can now do this because we're on Xcode 14.

[0]: https://realm.github.io/SwiftLint/unavailable_condition.html

Co-Authored-By: Sasha Weiss <sasha@signal.org>
2022-10-06 17:14:49 -05:00
Evan Hahn
349681ff85
Attempt to recover corrupted databases
If a user's database is corrupted, we now try to fix it. I recommend
reviewing `DatabaseRecovery` to see how this works, and
`DatabaseRecoveryViewController` for the bulk of the UI.
2022-10-06 16:42:19 -05:00
Evan Hahn
760e5c1c97
Add PNI registration ID to account attributes
Like "regular" registration IDs, this attaches a PNI registration ID to
account attributes. It's already synced at the right times (see
[`updateAccountAttributesIfNecessaryAttempt`][0]).

Tested this by registering and seeing the payload correctly sent to the
server.

See also: [Android's implementation][1].

[0]: 487405ef08/SignalServiceKit/src/Account/TSAccountManager.swift (L137)
[1]: 6e5f28339d/libsignal/service/src/main/java/org/whispersystems/signalservice/internal/push/PushServiceSocket.java (L378)
2022-10-05 16:13:33 -05:00
Nora Trapp
433d63f003 Flag on websocket and REST message requests that stories are enabled 2022-10-05 12:24:13 -07:00
Nora Trapp
1e613fe438 Use unrestricted sealed sender for story sends 2022-10-05 12:24:13 -07:00
Evan Hahn
56589799cb
Clean up registration ID generation
_This change should have no user impact._

This cleans up the way we generate registration IDs. It:

- Rewrites the generation code in Swift
- Removes the "sneaky transaction" method. I did this for clarity, and
  because we won't use it for much longer
- Turns a log warning into a regular log—generating a registration ID is
  not a problem
- Adds tests

I think this is a useful change on its own, but will be handy for an
upcoming change, too.
2022-10-05 14:09:07 +00:00
Max Radermacher
02ca8e2a99
Include http headers on web socket connections
Once initialized, a URLSession’s configuration can’t be changed. In
order to transfer the headers, assign them to the configuration before
assigning the configuration to the session.
2022-09-29 16:36:42 -07:00
Nora Trapp
dd37ca526d Allow NSE to manage lifetime of proxy relay server 2022-09-27 17:05:05 -07:00
Sasha Weiss
ac97aeba92
Migrate to using ExpiredProfileKeyCredentials 2022-09-26 14:33:57 -07:00
Nora Trapp
5e277b6eb4 Reduce logging 2022-09-26 13:48:00 -07:00
Nora Trapp
323bbb5a4b Add some doc comments and make restart clearer 2022-09-26 13:48:00 -07:00
Nora Trapp
9d021f50fe Allow specifying a port for a proxy to connect to 2022-09-26 13:48:00 -07:00
Nora Trapp
fb31679cc7 Validate proxy address and that we can connect to it 2022-09-26 13:48:00 -07:00
Evan Hahn
7a357a9cd3 Harden isValidProxyLink against strange URLs 2022-09-26 13:48:00 -07:00
Nora Trapp
e05a19d962 Handle backgrounding in relay server 2022-09-26 13:48:00 -07:00
Nora Trapp
8d1e038611 Fix bug with link previews 2022-09-26 13:48:00 -07:00
Nora Trapp
e5e9e544b3 Add UI for configuring proxy connection 2022-09-26 13:48:00 -07:00
Nora Trapp
286a930a79 Add support the Signal TLS Proxy 2022-09-26 13:48:00 -07:00
Max Radermacher
084a2b2274 Fix crash when toggling censorship circumvention
Changing the setting updates whether or not it’s enabled, which resulted
in a lock being re-entrantly acquired to check the current value.
2022-09-26 11:40:38 -07:00
Michelle Linington
4ada6b3a3f Derive bundle ID from an Xcode build setting
See [#5423][5423].

[5423]: https://github.com/signalapp/Signal-iOS/pull/5423
2022-09-21 18:10:42 +00:00
Evan Hahn
4d55d95869 Autofix SwiftLint whitespace issues
I recommend reviewing this with whitespace changes disabled.
2022-09-15 16:37:44 +00:00
Nora Trapp
54be3e5e21 Add API to lookup safety number changes for a batch of addresses 2022-09-08 09:42:43 -07:00
Sasha Weiss
f37a0040ad
Replace AuthCredential with AuthCredentialWithPni 2022-09-07 15:39:50 -07:00
Nora Trapp
09598d2e7a Add remote flag for stories 2022-08-31 13:34:24 -07:00
Sasha Weiss
569cdb2aad
Durable jobs for leaving groups 2022-08-26 13:13:23 -07:00
Evan Hahn
5a0f836f0d Use "timestamp" instead of "timeStamp"
This change should have no user impact.

We use "timestamp", all lowercase, in most of the codebase. This makes
it consistent.
2022-08-26 14:17:12 -05:00
Harry
33e26b6c4c
Migrate OWSSignalService from objc to swift, and split it into a protocol and implementation
* Split OWSSignalService into a swift protocol and implementation, migrated from objc

* Put OWSSignalService under SSKEnvironment and use mock in mock environment

* Rename from basename + impl to protocol + basename

* extend mock functionality a bit

* pr feedback
2022-08-24 14:36:52 -07:00
Harry
2950667ac9
Split OWSURLSession into a protocol and implementation
* Split OWSURLSession into a protocol and implementation

* Add OWSURLSessionMock

* Rename from basename + impl to protocol + basename

* add simple init for mock session

* nits from pr comments

* pr comments 2
2022-08-24 13:33:27 -07:00
Jordan Rose
11cf13a255 Avoid intermediate copies when using dictionary keys as collections
The non-lazy map and filter always make a new array or dictionary,
which is often consumed immediately into a Set. Using `lazy` avoids
that intermediate allocation, as well as the need to loop over the
array or dictionary a second time.

This is a micro-optimization, but several of these accessors are
accessed fairly frequently, so we might as well make them faster.
2022-08-23 10:42:11 -07:00
Evan Hahn
48c3c08c10 Fix vertical_parameter_alignment SwiftLint violations
This fixes violations of [SwiftLint's `vertical_parameter_alignment`
rule][0]. This should have no user impact.

[0]: https://realm.github.io/SwiftLint/vertical_parameter_alignment.html
2022-08-18 10:37:09 -05:00
Evan Hahn
da322d3bf9 Add "urgent" boolean to outgoing messages
To improve message reliability, we're adding an urgency flag to outgoing
messages. For example, outgoing calls are urgent, but delivery receipts
are not. [Android][] and [Desktop][] have already done this work.

At a high level, I added an `isUrgent` property to `TSOutgoingMessage`s.
It defaults to `true`. Some subclasses, like
`OWSReceiptsForSenderMessage`, override it to return `false`.

Builds off of a few other commits (not necessary to understand this
commit, but might be useful for posterity):

- e858a0d916
- 8c6d2ebe8c
- 402b117221
- 2ba0cd764d
- 266a4663e9
- 8e5009bbf7

[Android]: dc04c8ed98
[Desktop]: 06190b1434
2022-08-18 07:35:41 -05:00
Evan Hahn
2ba0cd764d Update comments that reference server code
This change should have no user impact because it only changes
comments.

We had some comments that referenced the Signal server repo. They
referenced a commit that was a little out of date (from March 2022).
This updates the links.
2022-08-15 11:54:48 -05:00
Jordan Rose
094c8290ce Remove unnecessary NotificationCenter.removeObserver calls
As of iOS 9, selector-based observers in NotificationCenter do not
need to be explicitly unregistered.
2022-08-02 17:43:52 -07:00
Evan Hahn
028d97c2cb
Use remote config for gift badges
This removes `FeatureFlags.giftBadgeReceiving` and
`FeatureFlags.giftBadgeSending`, replacing them with
`RemoteConfig.canReceiveGiftBadges` and
`RemoteConfig.canSendGiftBadges`.
2022-07-20 08:50:58 -05:00
Max Radermacher
e4e21cab8c Fix outage detector error when there’s no network
If DNS resolution fails, then it’s expected that there won’t be any
addresses. Fail gracefully in this case.

If DNS resolution succeeds and provides a non-nil but empty list of
addresses, report an error. This shouldn’t happen.
2022-07-19 11:48:58 -07:00
Evan Hahn
bf8fd72fba
Improve Accept-Language header value, fixing registration bug
Some users [are unable to register][1] because the server [returns a 400
error][2] if passed an invalid `Accept-Language` header.

This commit helps prevent two possible error modes:

- Filters out invalid language tags. Some users reported a "Workshopx"
  language, which the server would reject because it's syntactically
  invalid. Deleting this language (at the OS level) let them register.
- If no languages are valid, we should send `*` instead of the empty
  string. There's no evidence that this happened in practice.

In addition, this commit:

- Adds tests.
- Sends a maximum of 10 languages instead of 6.
- Omits the `q` value when it's 1 because [that's the default][3].
- Marginally improves performance by iterating lazily.

[1]: https://github.com/signalapp/Signal-iOS/issues/5261
[2]: bf6d3aa324/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java (L271-L275)
[3]: https://www.rfc-editor.org/rfc/rfc9110.html#section-12.4.2

Co-authored-by: Nora Trapp <nora@signal.org>
2022-07-11 12:20:24 -05:00
Evan Hahn
f5556d1857
Use durable job for sending badge gifts
Previously, sending a gift badge was not a durable operation, which
meant that crashes/failures could cause users to have their payment
methods charged without actually sending the badge.

Now, the flow is split up into two steps: non-durable parts before the
charge is attempted, and durable parts afterward.

The high-level flow is:

1. Prepare the payment, which involves a couple of repeatable network
   requests.
2. Enqueue a job with the prepared payment, that:
   1. Charges the payment method (idempotently)
   2. Requests a receipt credential (idempotently)
   3. Enqueues a gift message, and optionally a text message
3. When the job completes, open the conversation in the UI.
2022-07-01 17:10:31 -05:00
Evan Hahn
f4714b1a83 Basic support for sending gift badges
If you've got the `giftBadgeSending` flag enabled, you can now send gift
badges to anyone who has the capability.

This commit doesn't complete the feature, though. It is missing:

- Proper durability and error handling (to be addressed separately)
- Saving of receipts
- A few other cleanups
2022-06-22 15:50:51 +00:00
Evan Hahn
a1eb9e3042 Clean up boostCreatePaymentIntent()
This makes a few small changes to `OWSRequestFactory.boostCreatePaymentIntent()`:

- Adds tests
- Rewrites the function in Swift

I made sure I could do a boost (in staging) in the simulator.
2022-06-21 17:33:28 +00:00
Nora Trapp
7bd167f815
Initial story sending support
* Little fix for context menu

* Add 'My Stories' section to stories tab

* Add new story thread types

* Show stories in conversation picker

* Support for sending stories

* Update story list when sending stories

* Add basic 'My Stories' view controller

* Initial stories settings screens

* Consolidate TSPrivateStoryThread and TSMyStoryThread into one class

* Require an explicit read transaction to initialize an outgoing message

* Fix linting

* Allow enabling group story from internal settings

* Fix tests

* PR Feedback
2022-06-10 22:28:03 -04:00
Evan Hahn
8009206c18 Respect recipient capabilities when sending gift badges
This respects the `giftBadges` capability when trying to send gift
badges. In other words, it prevents you from sending gift badges to
someone who lacks the capability.

The bulk of this change involves fetching and saving of this new
capability. The rest of the code involves showing it on the "choose
recipient" screen (and some debug screens).
2022-06-10 22:37:22 +00:00
Evan Hahn
e679707038 Fix SwiftLint shorthand_operator violations
The gist is:

```diff
-foo = foo + 1
+foo += 1
```

Most of the violations were in generated files, so I changed and re-ran the generator.

A few of these violations required implementing some new methods, which I added tests for.

See [the docs for this rule][0].

[0]: https://realm.github.io/SwiftLint/shorthand_operator.html
2022-06-07 14:51:57 +00:00
Jordan Rose
4e05dfde5c Don't generate a new PushChallenge for every failed operation
We sometimes attempt to do N operations at once where up to N of them
end up getting caught by the rate limiter. This should *not* turn into
N push challenges, or else we'll get rate limited for that too.
2022-05-31 18:05:22 -07:00
Jordan Rose
534035fa80 Check whether we actually get ping responses from our websockets
In at least one instance (iOS 14.6), we've seen pings go out that
never get responses and never report timeouts. Check for that
explicitly to make sure we cycle the socket if we're not getting ping
responses.
2022-05-26 16:01:43 -07:00
Jordan Rose
42c18bcc0b Use a mock reachability manager for testing
The normal reachability manager would never get configured during
testing because it waited for AppReadiness. However, it still created
an OWSURLSession, and if between tests the previous reachability
manager wasn't destroyed fast enough, trying to set up a new one would
create a second URL session with the same background identifier, which
isn't allowed.

Fix this by providing a MockSSKReachabilityManager, which is never
reachable by default, and while here update the background identifier
to be something descriptive.
2022-05-25 13:09:14 -07:00
Max Radermacher
c404773145 Add giftBadge capability 2022-05-23 15:25:19 +00:00
Evan Hahn
baddc85564 Add first gift badge screen
This adds the first screen for badge gifting. It lets you see the gift
badge, pick the currency, and advance to the next screen.

It also adds a skeleton for the next screen, so there's somewhere to
advance to, but that screen is unfinished.

All of this is behind disabled flags, so this should have no user
impact.
2022-05-19 14:07:23 +00:00
Evan Hahn
29c0ddf60e Fix violations of SwiftLint's attributes rule
_I recommend reviewing this with whitespace changes disabled._

Most of these were `@objc` being on the same line, which I fixed with [a
silly script][1]—probably could've used `sed` if I were wiser. The rest
were manual fixes.

See [the SwiftLint documentation for this rule][0].

[0]: https://realm.github.io/SwiftLint/attributes.html
[1]: https://gist.github.com/EvanHahn-Signal/d353c93fa269c82b96baca0a1086521f
2022-05-14 09:07:42 -05:00
Max Radermacher
385ae60bc8
Fix some codegen designated initializers
* Ignore `exclusiveProcessIdentifier` parameter

This was added in fee1bbddad, but the `NS_UNAVAILABLE` declarations
weren’t updated, which led to warnings in Xcode.

* Ignore `TSThread` initializer in subclasses

* Fix `TSAttachmentPointer` ignored initializer

* Add missing initializers to `TSMessage` subclasses

This only handles the immediate subclasses. There’s still more warnings
in the extended hierarchy, but those don’t seem to have been handled as
consistently in the first place, so updating them is more involved.
2022-05-09 13:59:38 -07:00
Max Radermacher
f7f129cdc5 Remove unnecessary error handler wrapper
This only calls the block, and the formatting in the old design made it
particularly difficult to read. (It also makes this path and the success
path more similar in their construction.)
2022-05-09 09:41:25 -07:00