Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto user and device identity #1531

Merged
merged 1 commit into from
Aug 18, 2022
Merged

Crypto user and device identity #1531

merged 1 commit into from
Aug 18, 2022

Conversation

Anderas
Copy link
Contributor

@Anderas Anderas commented Jul 18, 2022

Add mechanisms to acquire MXDeviceInfo, MXCrossSigningInfo and other related objects using MatrixSDKCrypto and bootstrap cross-signing keys.

This is another pre-requisite for having all of the required pieces to implement device verification.

The (interrelated) changes in this PR:

  • Implement device and cross signing info sources that will return MatrixSDK objects from MatrixSDKCrypto definitions
  • create two wrappers that allow the creation of MXDeviceInfo and MXCrossSIgningInfo from swift code even if some of the API is not exposed to swift, but is in _Private.h header files
  • Add MXCrossSigningV2 (a subclass of MXCrossSigning) which overrides all functionality, similar to MXCryptoV2
  • Hook up cross signing with existing infrastructure to upload cross signing keys when new user logs in
  • Add MXNamedLog to avoid verbose and repeating logs, this log will always print logs in the "[Name] function: message" format
  • Run iOS tests instead of macos tests, to run unit tests containing MatrixSDKCrypto objects (currently only compiled for iOS), and without loosing anything mac-os specific Leaving tests on macos target, will try to recompile MatrixSDKCrypto for all platforms asap

@Anderas Anderas requested review from a team and SBiOSoftWhare and removed request for a team July 18, 2022 16:26
@Anderas Anderas force-pushed the andy/3_user_identity branch 4 times, most recently from 03fe387 to e6b761c Compare July 19, 2022 11:10
@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2022

Codecov Report

Merging #1531 (c66166f) into develop (1b167fb) will increase coverage by 0.00%.
The diff coverage is 22.85%.

@@           Coverage Diff            @@
##           develop    #1531   +/-   ##
========================================
  Coverage    45.27%   45.27%           
========================================
  Files          522      520    -2     
  Lines        84856    84763   -93     
  Branches     37532    37507   -25     
========================================
- Hits         38416    38374   -42     
+ Misses       45342    45290   -52     
- Partials      1098     1099    +1     
Impacted Files Coverage Δ
MatrixSDK/Contrib/Swift/JSONModels/MXEvent.swift 17.17% <0.00%> (-0.36%) ⬇️
...xSDK/Crypto/CrossSigning/Data/MXCrossSigningInfo.m 91.13% <ø> (ø)
MatrixSDK/Crypto/Devices/Data/MXDeviceInfo.m 89.44% <ø> (ø)
MatrixSDK/Crypto/Devices/MXDeviceList.h 100.00% <ø> (ø)
MatrixSDK/Crypto/Devices/MXDeviceList.m 84.05% <ø> (ø)
MatrixSDK/Crypto/Trust/MXDeviceTrustLevel.m 94.11% <ø> (ø)
MatrixSDK/Crypto/Trust/MXUserTrustLevel.m 81.25% <ø> (ø)
MatrixSDK/Crypto/Trust/MXUsersTrustLevelSummary.m 0.00% <ø> (ø)
MatrixSDK/Utils/MXLog.swift 53.43% <0.00%> (-12.61%) ⬇️
MatrixSDK/Crypto/MXCryptoV2.swift 100.00% <100.00%> (ø)
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@SBiOSoftWhare SBiOSoftWhare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I just added some small suggestions

{
_userId = userIdentity.userId;
NSMutableDictionary *keys = [NSMutableDictionary dictionary];
if (userIdentity.masterKeys) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small remark: We are usually making carriage return here in ObjC in this SDK:

if (userIdentity.masterKeys) 
{
    keys[MXCrossSigningKeyType.master] = userIdentity.masterKeys;
}

@@ -194,3 +194,40 @@ private var logger: SwiftyBeaver.Type = {
return "\(message) - \(details)"
}
}

/// Convenience wrapper around `MXLog` which formats all logs as "[Name] function: <message>"
struct MXNamedLog {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! If we want global usage of same log naming we can also make a MXLogModule like:

public enum LogModule: String {
  case webService
  case parsing
  case database
  case geolocation
}

extension LogModule {
  
  // MARK: Public

    func debug(_ message: String, function: String = #function) {
         MXLog.debug(formattedMessage(message, function: function))
     }
  
  // MARK: Private
    private func formattedMessage(_ message: String, function: String) -> String {
         return "[\(self.rawValue))] \(function): \(message)"
     }
}

And then use it like: MXLogModule.geolocation.debug("Test")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that sounds good, thought perhaps yet another use case, as it assumes a smaller number of stable areas, as your examples above. In my case the context equals any given class, which would be too many areas to keep a track of in an enum. I think both these use cases are complimentary

Comment on lines 359 to 365
func bootstrapCrossSigning(authParams: [AnyHashable: Any]) async throws {
let result = try machine.bootstrapCrossSigning()
try await requests.uploadSigningKeys(request: result.uploadSigningKeysRequest, authParams: authParams)
try await requests.uploadSignatures(request: result.signatureRequest)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can parallelize if possible:

         async let uploadSigningKeys = requests.uploadSigningKeys(request: result.uploadSigningKeysRequest, authParams: authParams)
         async let uploadSignatures = requests.uploadSignatures(request: result.signatureRequest)
         
         await (uploadSigningKeys, uploadSignatures)

Base automatically changed from andy/2_crypto_protocols to develop August 18, 2022 08:07
@Anderas Anderas merged commit d31fa31 into develop Aug 18, 2022
@Anderas Anderas deleted the andy/3_user_identity branch August 18, 2022 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants