Commit Graph

127 Commits

Author SHA1 Message Date
Harry
a146e18aaf
Set up account state and exit registration
* Go to chat list view after registration

* sync system contacts during registration

* Use explicit local credentials for storage service operations during registration

* fix tests

* Quick hack to get through double pin confirmation

* Finishing touches

* lint

* fix build

* reload phone number discoverability after storage service sync

* fix tests again

* Take chat auth on account and contact record initializers

* Change around branches for clarity in OWSUserProfile

* pr comments

* Split ChatServiceAuth into the same and AuthedAccount

* fix tests

* merge woes
2023-03-09 21:54:51 -08:00
Sasha Weiss
82fad84831
Initial implementation of PNI change-number 2023-03-09 17:13:16 -08:00
Max Radermacher
93d97da82b
Split “in progress” & “saved” voice message drafts 2023-03-08 15:31:56 -08:00
Harry
3d6225060d
Add RegistrationCoordinator
* Add ability to compute registration recovery password

* Add RegistrationCoordinator

* remove repeat nav controller that evan added

* Scaffolding for RegistrationCoodinator test

* Add first round of RegistrationCoordinator tests, some stuff I needed to get them working, and some fixes to RegistrationCoordinator itself I discovered thanks to the tests

* switch to owsFailBeta

* Add auth credential candidate flow tests, related fixes and additions to coordinator and friends

* Add tests for session based registration path and associated fixes

* PR comment nits
2023-02-14 08:50:24 -08:00
Harry
fc4ec188e8
Implement RegistrationSessionManager
* Add RegistrationSession object

* Add RegistrationSessionManager protocol

* Add skeleton RegistrationSessionManagerImpl - just kvstore persistence implemented

* Issue requests in RegistrationSessionManagerImpl

* let tests access the in memory kv store

* Add TSRequestOWSURLSessionMock. Rename OWSURLSessionMock

* Add DateProvider

* Take a dateProvider in RegistrationSessionManagerImpl

* Add tests for RegistrationSessionManager

* pre-emptively update timeout for tests. will remove once promise Scheduler code is merged

* PR comments

* Use Schedulers
2023-02-08 15:37:12 -08:00
Sasha Weiss
e5f1af6c2e
Support lookup-by-username 2023-02-08 10:16:57 -08:00
Evan Hahn
b95a1c4363
Make FullTextSearchFinder stateless
This change should have no user impact. I think this is a useful
cleanup.
2023-02-06 13:33:43 -06:00
Harry
6576349613
Migrate KeyBackupService to the Swift Way™️
* Put KeyBackupService in its own folder

* Put SDSKeyValueStore in its own directory

* Put SDSDatabaseStorage in its own directory

* Stop doing useless dispatches in SDSTransactable

* Add V2 DB classes

* Wrap SDSKeyValueStore in a protocol and factory

* Make TSConstantsProtocol public to take it as a param in other places

* Take explicit transactions and do single lookups in TSAccountManager registration state methods

* Take explicit transaction on OWS2FAManager

* Make KeyBackupService an instance that takes dependencies on init

* Protocolize KeyBackupService

* Put Dependencies+SSK in its own directory

* Add DependenciesBridge

* add ViewControllerContext

* used shared context in OnboardingController

* Don't check KeyBackupService in RemoteConfigManager; the one and only callsite already checks it separately

* All the random cleanup that needed to happen to get the app to build again.

* Add mock dbv2 classes

* Migrate existing KeyBackupServiceTests

* Namespace KBS shims

* DBV2 -> DB, after changing the min swiftlint type length to 2 chars

* add toy example

* Unwrap writes as reads

* pr comments

* pr comments 2: return of the nits

* final Pr comment
2023-02-02 09:42:05 -08:00
Evan Hahn
1ba45411ae
Enable a RingRTC field trial for all users, with kill switch
The successor to 389515b0fa.

This enables the "WebRTC-Network-UseNWPathMonitor" RingRTC field trial
for all users.

The hard part: adding a remote config kill switch. I added a bunch of
comments (and tests) to try to make the intention clear.
2023-02-01 16:20:16 -06:00
Max Radermacher
d7c52b6ad0
Fix bugs marking SignalRecipients as registered
Previously, low-trust SignalRecipients wouldn’t be marked as registered
unless they were newly-created. Now, they are marked as registered in
places where they should be (eg, successfully sending a message or
fetching a pre key means that the device exists).

As part of this change, SignalRecipients are unregistered by default,
though most call sites still mark them as registered immediately, so the
behavior in practice will be identical. There are a few places (such as
ensureAccountId) which will no longer mark new values as registered.

Finally, creating a new SignalRecipient would also update Storage
Service, even if that recipient was created in response to a storage
service update. Now, recipients updated as part of storage service
operations won’t immediately trigger another storage service update.
2023-01-03 13:23:33 -08:00
Max Radermacher
47bea9635a Fix deprecation warning while enumerating messages 2023-01-02 10:47:15 -08:00
Evan Hahn
370ff654e7
Change license to AGPL
Change license to AGPL

This commit:

- Updates the `LICENSE` file

- Start every file with something like:

      // Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
      // SPDX-License-Identifier: AGPL-3.0-only

---

First, I removed existing license headers with this Ruby 3.1.2 script:

    require 'set'

    EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']

    same = 0
    different = 0

    all_files = `git ls-files`.lines.map { |line| line.strip }
    all_files.each do |relative_path|
      if relative_path == 'Pods'
        next
      end

      unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
        next
      end

      path = File.expand_path(relative_path)

      contents = File.read(path)
      new_contents = contents.sub(/\/\/\n\/\/  Copyright .*\n\/\/\n\n/, '')

      if contents == new_contents
        same += 1
      else
        different += 1
      end

      File.write(path, new_contents)
    end

    puts "updated #{different} file(s), left #{same} untouched"

I'm sure this script could be improved, but it worked well enough.

Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.

Then I fixed some stragglers and updated the precommit script.

See [a similar change in the Desktop app][0].

[0]: 8bfaf598af
2022-10-13 08:25:37 -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
a066511a62 Remove useless test setup/teardown
We had a lot of functions like this, which are useless:

    override func setUp() {
        super.setUp()
    }

This removes them.
2022-10-04 14:06:34 -07:00
Evan Hahn
4da042c1d5
Clean up database corruption storage code
_This change should have no user impact._

The database corruption flag lives on `UserDefaults`. Currently, this
flag is controlled through `SSKPreferences`, but I kinda think that's
the wrong place—database corruption isn't really a user preference.

This moves it into its own file, tests it, and [drops booleans in favor
of an enum][0]. I think this is useful on its own, but also prepares us
for an upcoming change.

[0]: https://www.luu.io/posts/dont-use-booleans
2022-09-23 18:19:02 +00:00
Evan Hahn
11c2cf0813
Add basic test for database migration
_This change should have no user impact._

This adds a basic test for database migration, and makes the necessary
changes to make that possible.
2022-09-22 17:24:40 +00:00
george-signal
bb33925499
Persist quoted replies
When you compose reply to a message but do not
send it, we would persist the text you entered but
would lose the quoted message to which you were
replying.

This commit adds support for persisting that
information.

ThreadReplyInfo is a new class that uses the
key-value store to associate a single optional
reference to a message with each thread.

The following behaviors are nw:
* When you enter the CVC the input toolbar is
  updated to have the quoted message.
* When you exit the CVC the quoted message is
  saved.
* When a thread is deleted, the quoted message is
  deleted.
2022-08-11 13:44:50 -07:00
Sasha Weiss (Signal)
0a089cb63c
Make "Keep Muted Chats Archived" option available publicly 2022-05-26 10:44:43 -04:00
Jordan Rose
4c8d7662a6 Add OWSIdentityManager.shouldSharePhoneNumber(with:transaction:)
When someone sends a message to your PNI, your responses (from your
ACI) must include a PNI signature, and the sealed sender certificate
you use during this period should include your phone number. This
confirms to the other user that your ACI is associated with your PNI.

This commit adds the state tracking that and ensures that both
TSOutgoingMessage and OWSUDManager check that state when building 1:1
messages and choosing certificates, respectively. Later commits will
set and clear this flag as needed.
2022-05-19 14:20:53 -07:00
Jordan Rose
926178abe1 Port OWSIdentityManagerTests to Swift
...for testing Swift-side things soon.
2022-05-18 11:28:39 -07:00
Jordan Rose
9132234a54 Fix for non-messages being filtered out of interaction results
Messages always have an isGroupStoryReply of true or false (1 or 0),
but non-messages don't have this field, and GRDB treats that as NULL
rather than falling back to the table default.
2022-04-15 15:42:33 -07:00
Jordan Rose
039dcc1d48 -[SSKPreKeyStore storePreKeyRecords:] should take a transaction
...so it can use an existing one when there is one, which in practice
there always is because we never refresh one-time pre-keys without
rotating our signed pre-key too.
2022-04-04 15:19:10 -07:00
George Nachman
22c1cb8a22 Fetch phone numbers in a batch.
This is the first meaty part of optimizing
fetching display names.

Some contacts fall back to phone numbers as their
display names. This PR fetches them in a single
SQL query via
`OWSContactsManager.phoneNumbers(for:, transaction)`.

To achieve this, this PR introduces
`GRDBSignalAccountFinder.signalAccounts(for:,transaction:)`
to fetch many accounts at once.

In order to fetch many accounts at once, we need
to be able to fetch many values from a
ModelReadCache at once. So this PR introduces
`ModelReadCache.readValues(for:,transaction:)` and
`ModelReadCache.getValues(for:,transaction:,returnNilOnCacheMiss:)`.

Existing methods that operate on a single value
were refactored to use the batch methods.

This PR adds tests for this functionality, which
necessitated changing the visibility of various
private symbols and also improving the fake
profile manager to make it more configurable.

There's also a tiny optimization for Refinery to
avoid calling a closure that has no work to do.
This helps elide do-nothing SQL queries that would
otherwise have been introduced.
2022-03-17 12:46:33 -07:00
Jordan Rose
7448b377fb Parameterize the 1:1 stores by identity (ACI or PNI)
This allows two stores to coexist in the database. Note that
everything *using* the stores will still always use the ACI stores at
this point.
2022-03-16 14:31:06 -07:00
Jordan Rose
2e39dab9b2 Support two SignalProtocolStores in SSKEnvironment
'sessionStore', 'preKeyStore', and 'signedPreKeyStore' are no longer
directly accessible; you have to go through
'signalProtocolStore(for:)' instead. This commit mechanically changes
all use sites to use `signalProtocolStore(for: .aci)`, with the
understanding that they will need cleanup in the future.

This is not enough to actually support multiple stores; they still
store in the database under the same keys. That's coming in the next
commit.
2022-03-16 14:31:06 -07:00
Jordan Rose
49d4684013 Teach OWSIdentityManager about PNI identity keys
And make all callers explicitly say which one they want (which for now
is always the ACI identity key).
2022-03-16 13:29:20 -07:00
Jordan Rose
8e52adbf74 -[OWSIdentityManager generateNewIdentityKey] should return the new key
A micro-optimization to avoid an extra database query.
2022-03-16 13:29:20 -07:00
Michelle Linington
e322921b10 Fix broken tests
If a test inserts a recipient, we need to have a registered local
address to perform some of our FTS index checks
2022-03-03 14:23:51 -08:00
Matthew Chen
5d780d1589 Apply script to normalize includes and imports. 2021-10-21 09:21:10 -03:00
Matthew Chen
9271f83624 Remove databaseChangesWillUpdate. 2021-09-08 21:41:13 -03:00
Matthew Chen
f2b76e60f9 Refine names. 2021-07-02 22:08:53 -03:00
Matthew Chen
f06b72bc2a Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
75de56236b Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
718120f725 Fix test imports. 2021-06-07 11:41:43 -04:00
Matthew Chen
37052a302a Fix build warnings around imports. 2021-06-07 11:11:30 -04:00
Matthew Chen
86b8eb08b8 Remove YapDatabase.
Apply asset from design.

Fix rebase breakage.
2021-03-25 11:41:16 -03:00
Matthew Chen
d0cbf8cfd0 Rework dependency access. 2021-03-25 09:24:27 -03:00
Jordan Rose
6ddd3ce184 SSK: Remove SPKProtocolContext
Brought over for convenience in the previous commit, but no longer
needed now that everything's in one framework.
2021-03-22 16:18:29 -07:00
Jordan Rose
68a27a76e2 Move AxolotlKit model classes into SSK and remove the dependency
We still need the AxolotlKit model classes to migrate old sessions,
but we don't need any of the actual protocol support. This also
means we can drop HKDFKit.

Additionally, we do still use some utilities from AxolotlKit:

- AxolotlExceptions.h: NSException names, should eventually be
  replaced by NSErrors everywhere

- NSData+keyVersionByte.h: prepend/remove public key type byte,
  should eventually be replaced by strong types (ECPublicKey)

- SPKProtocolContext.h: defines the SPKProtocol{Read,Write}Context
  marker protocols, should be replaced by direct use of
  SDSAny{Read,Write}Transaction
2021-03-22 16:17:47 -07:00
Jordan Rose
c7b6ba7010 Make OWSAccountIdFinder's methods into class methods
OWSAccountIdFinder is no longer used for dependency injection in
SignalMetadataKit, so there's no need to allocate empty NSObjects just
to call the methods.

No functionality change.
2021-01-28 12:03:50 -08:00
Matthew Chen
4ae673a043 Fix broken test. 2021-01-25 19:40:13 -03:00
Matthew Chen
c017e76aab Rename singleton accessors. 2020-09-17 21:11:09 -03:00
Matthew Chen
ad6bda8a44 Rename singleton accessors. 2020-09-17 21:11:07 -03:00
Matthew Chen
4c432b1ac3 Fix broken tests. 2020-09-17 17:31:23 -03:00
Nora Trapp
18e19088a5 Fix broken tests 2020-08-28 13:10:47 -07:00
Fumiaki Yoshimatsu
5a899b02b1 Fixes tests by giving a semi-bogus phone number to work around an assertion. 2020-08-28 09:43:54 -07:00
Fumiaki Yoshimatsu
93e5503b87 Fixed two tests related to UIDatabaseSnapshotDelegate. 2020-08-28 09:42:45 -07:00
Matthew Chen
f243889d00 Use protocol contexts in prekey stores. 2020-08-25 21:31:56 -03:00
Nora Trapp
9696671f8a Add trustLevel to SignalServiceAddress 2020-08-05 14:36:43 -07:00
Matthew Chen
154805cf68 Fix broken tests. 2020-06-23 10:04:39 -03:00