Update for 'throws' removal in SignalClient
This commit is contained in:
parent
902ed32a34
commit
bb1f262434
@ -43,7 +43,7 @@ public protocol SMKCertificateValidator: SMKCertificateValidatorObjC {
|
||||
public func throwswrapped_validate(senderCertificate: SenderCertificate, validationTime: UInt64) throws {
|
||||
// try {
|
||||
// ServerCertificate serverCertificate = certificate.getSigner();
|
||||
let serverCertificate = try! senderCertificate.serverCertificate()
|
||||
let serverCertificate = senderCertificate.serverCertificate
|
||||
|
||||
// validate(serverCertificate);
|
||||
try throwswrapped_validate(serverCertificate: serverCertificate)
|
||||
@ -51,8 +51,8 @@ public protocol SMKCertificateValidator: SMKCertificateValidatorObjC {
|
||||
// if (!Curve.verifySignature(serverCertificate.getKey(), certificate.getCertificate(), certificate.getSignature())) {
|
||||
// throw new InvalidCertificateException("Signature failed");
|
||||
// }
|
||||
guard try serverCertificate.publicKey().verifySignature(message: senderCertificate.certificateBytes(),
|
||||
signature: senderCertificate.signatureBytes()) else {
|
||||
guard try serverCertificate.publicKey.verifySignature(message: senderCertificate.certificateBytes,
|
||||
signature: senderCertificate.signatureBytes) else {
|
||||
Logger.error("Sender certificate signature verification failed.")
|
||||
let error = SMKCertificateError.invalidCertificate(description: "Sender certificate signature verification failed.")
|
||||
Logger.error("\(error)")
|
||||
@ -62,7 +62,7 @@ public protocol SMKCertificateValidator: SMKCertificateValidatorObjC {
|
||||
// if (validationTime > certificate.getExpiration()) {
|
||||
// throw new InvalidCertificateException("Certificate is expired");
|
||||
// }
|
||||
guard validationTime <= (try! senderCertificate.expiration()) else {
|
||||
guard validationTime <= senderCertificate.expiration else {
|
||||
let error = SMKCertificateError.invalidCertificate(description: "Certficate is expired.")
|
||||
Logger.error("\(error)")
|
||||
throw error
|
||||
@ -79,8 +79,8 @@ public protocol SMKCertificateValidator: SMKCertificateValidatorObjC {
|
||||
// if (!Curve.verifySignature(trustRoot, certificate.getCertificate(), certificate.getSignature())) {
|
||||
// throw new InvalidCertificateException("Signature failed");
|
||||
// }
|
||||
guard try trustRoot.key.verifySignature(message: serverCertificate.certificateBytes(),
|
||||
signature: serverCertificate.signatureBytes()) else {
|
||||
guard try trustRoot.key.verifySignature(message: serverCertificate.certificateBytes,
|
||||
signature: serverCertificate.signatureBytes) else {
|
||||
let error = SMKCertificateError.invalidCertificate(description: "Server certificate signature verification failed.")
|
||||
Logger.error("\(error)")
|
||||
throw error
|
||||
@ -89,7 +89,7 @@ public protocol SMKCertificateValidator: SMKCertificateValidatorObjC {
|
||||
// if (REVOKED.contains(certificate.getKeyId())) {
|
||||
// throw new InvalidCertificateException("Server certificate has been revoked");
|
||||
// }
|
||||
guard !SMKCertificateDefaultValidator.kRevokedCertificateIds.contains(try! serverCertificate.keyId()) else {
|
||||
guard !SMKCertificateDefaultValidator.kRevokedCertificateIds.contains(serverCertificate.keyId) else {
|
||||
let error = SMKCertificateError.invalidCertificate(description: "Revoked certificate.")
|
||||
Logger.error("\(error)")
|
||||
throw error
|
||||
|
||||
@ -202,7 +202,7 @@ fileprivate extension SMKMessageType {
|
||||
senderCertificate: SenderCertificate,
|
||||
protocolContext: SPKProtocolWriteContext?) throws -> Data {
|
||||
guard deviceId > 0 else {
|
||||
throw SMKError.assertionError(description: "\(SMKSecretSessionCipher.logTag) invalid deviceId")
|
||||
throw SMKError.assertionError(description: "\(String(describing: SMKSecretSessionCipher.logTag)) invalid deviceId")
|
||||
}
|
||||
|
||||
// CiphertextMessage message = new SessionCipher(signalProtocolStore, destinationAddress).encrypt(paddedPlaintext);
|
||||
@ -235,7 +235,7 @@ fileprivate extension SMKMessageType {
|
||||
identityStore: self.identityStore,
|
||||
context: &protocolContextAsPtr)
|
||||
|
||||
let senderAddress = try messageContent.senderCertificate().sender()
|
||||
let senderAddress = messageContent.senderCertificate.sender
|
||||
let localAddress = try SMKAddress(uuid: localUuid, e164: localE164)
|
||||
|
||||
guard !SMKAddress(senderAddress).matches(localAddress) ||
|
||||
@ -248,7 +248,7 @@ fileprivate extension SMKMessageType {
|
||||
// validator.validate(content.getSenderCertificate(), timestamp);
|
||||
let certificateValidator = certificateValidator as! SMKCertificateValidator
|
||||
try certificateValidator.throwswrapped_validate(
|
||||
senderCertificate: try messageContent.senderCertificate(),
|
||||
senderCertificate: messageContent.senderCertificate,
|
||||
validationTime: timestamp)
|
||||
|
||||
let paddedMessagePlaintext = try throwswrapped_decrypt(messageContent: messageContent,
|
||||
@ -265,7 +265,7 @@ fileprivate extension SMKMessageType {
|
||||
return SMKDecryptResult(senderAddress: SMKAddress(senderAddress),
|
||||
senderDeviceId: Int(senderAddress.deviceId),
|
||||
paddedPayload: Data(paddedMessagePlaintext),
|
||||
messageType: SMKMessageType(try messageContent.messageType()))
|
||||
messageType: SMKMessageType(messageContent.messageType))
|
||||
} catch {
|
||||
throw SecretSessionKnownSenderError(senderAddress: SMKAddress(senderAddress),
|
||||
senderDeviceId: senderAddress.deviceId,
|
||||
@ -285,7 +285,7 @@ fileprivate extension SMKMessageType {
|
||||
// message.getSenderCertificate().getSenderDeviceId());
|
||||
//
|
||||
// NOTE: We use the sender properties from the sender certificate, not from this class' properties.
|
||||
let sender = try! messageContent.senderCertificate().sender()
|
||||
let sender = messageContent.senderCertificate.sender
|
||||
guard sender.deviceId >= 0 && sender.deviceId <= INT32_MAX else {
|
||||
throw SMKError.assertionError(description: "\(logTag) Invalid senderDeviceId.")
|
||||
}
|
||||
@ -298,9 +298,9 @@ fileprivate extension SMKMessageType {
|
||||
// }
|
||||
var protocolContextAsPtr = protocolContext
|
||||
let plaintextData: [UInt8]
|
||||
switch try messageContent.messageType() {
|
||||
switch messageContent.messageType {
|
||||
case .whisper:
|
||||
let cipherMessage = try SignalMessage(bytes: messageContent.contents())
|
||||
let cipherMessage = try SignalMessage(bytes: messageContent.contents)
|
||||
plaintextData = try signalDecrypt(
|
||||
message: cipherMessage,
|
||||
from: ProtocolAddress(from: sender),
|
||||
@ -308,7 +308,7 @@ fileprivate extension SMKMessageType {
|
||||
identityStore: identityStore,
|
||||
context: &protocolContextAsPtr)
|
||||
case .preKey:
|
||||
let cipherMessage = try PreKeySignalMessage(bytes: messageContent.contents())
|
||||
let cipherMessage = try PreKeySignalMessage(bytes: messageContent.contents)
|
||||
plaintextData = try signalDecryptPreKey(
|
||||
message: cipherMessage,
|
||||
from: ProtocolAddress(from: sender),
|
||||
|
||||
@ -103,13 +103,13 @@ class SMKTest: XCTestCase {
|
||||
} else {
|
||||
senderAddress = .e164("+1235551234")
|
||||
senderDevice = 123
|
||||
identityKey = try! IdentityKeyPair.generate().identityKey
|
||||
identityKey = IdentityKeyPair.generate().identityKey
|
||||
}
|
||||
|
||||
let certificateData: Data = {
|
||||
let builder = SMKProtoSenderCertificateCertificate.builder(senderDevice: senderDevice,
|
||||
expires: expires,
|
||||
identityKey: Data(try! identityKey.serialize()),
|
||||
identityKey: Data(identityKey.serialize()),
|
||||
signer: signer)
|
||||
if let e164 = senderAddress.e164 {
|
||||
builder.setSenderE164(e164)
|
||||
|
||||
@ -23,7 +23,7 @@ class SMKSecretSessionCipherTest: XCTestCase {
|
||||
initializeSessions(aliceMockClient: aliceMockClient, bobMockClient: bobMockClient)
|
||||
|
||||
// ECKeyPair trustRoot = Curve.generateKeyPair();
|
||||
let trustRoot = try! IdentityKeyPair.generate()
|
||||
let trustRoot = IdentityKeyPair.generate()
|
||||
|
||||
// SenderCertificate senderCertificate = createCertificateFor(trustRoot, "+14151111111", 1, aliceStore.getIdentityKeyPair().getPublicKey().getPublicKey(), 31337);
|
||||
let senderCertificate = createCertificateFor(trustRoot: trustRoot,
|
||||
@ -79,8 +79,8 @@ class SMKSecretSessionCipherTest: XCTestCase {
|
||||
|
||||
// ECKeyPair trustRoot = Curve.generateKeyPair();
|
||||
// ECKeyPair falseTrustRoot = Curve.generateKeyPair();
|
||||
let trustRoot = try! IdentityKeyPair.generate()
|
||||
let falseTrustRoot = try! IdentityKeyPair.generate()
|
||||
let trustRoot = IdentityKeyPair.generate()
|
||||
let falseTrustRoot = IdentityKeyPair.generate()
|
||||
// SenderCertificate senderCertificate = createCertificateFor(falseTrustRoot, "+14151111111", 1, aliceStore.getIdentityKeyPair().getPublicKey().getPublicKey(), 31337);
|
||||
let senderCertificate = createCertificateFor(trustRoot: falseTrustRoot,
|
||||
senderAddress: aliceMockClient.address,
|
||||
@ -140,7 +140,7 @@ class SMKSecretSessionCipherTest: XCTestCase {
|
||||
initializeSessions(aliceMockClient: aliceMockClient, bobMockClient: bobMockClient)
|
||||
|
||||
// ECKeyPair trustRoot = Curve.generateKeyPair();
|
||||
let trustRoot = try! IdentityKeyPair.generate()
|
||||
let trustRoot = IdentityKeyPair.generate()
|
||||
|
||||
// SenderCertificate senderCertificate = createCertificateFor(trustRoot, "+14151111111", 1, aliceStore.getIdentityKeyPair().getPublicKey().getPublicKey(), 31337);
|
||||
let senderCertificate = createCertificateFor(trustRoot: trustRoot,
|
||||
@ -202,9 +202,9 @@ class SMKSecretSessionCipherTest: XCTestCase {
|
||||
bobMockClient: bobMockClient)
|
||||
|
||||
// ECKeyPair trustRoot = Curve.generateKeyPair();
|
||||
let trustRoot = try! IdentityKeyPair.generate()
|
||||
let trustRoot = IdentityKeyPair.generate()
|
||||
// ECKeyPair randomKeyPair = Curve.generateKeyPair();
|
||||
let randomKeyPair = try! IdentityKeyPair.generate()
|
||||
let randomKeyPair = IdentityKeyPair.generate()
|
||||
// SenderCertificate senderCertificate = createCertificateFor(trustRoot, "+14151111111", 1, randomKeyPair.getPublicKey(), 31337);
|
||||
let senderCertificate = createCertificateFor(trustRoot: trustRoot,
|
||||
senderAddress: aliceMockClient.address,
|
||||
@ -261,7 +261,7 @@ class SMKSecretSessionCipherTest: XCTestCase {
|
||||
senderDeviceId: UInt32,
|
||||
identityKey: PublicKey,
|
||||
expirationTimestamp: UInt64) -> SenderCertificate {
|
||||
let serverKey = try! IdentityKeyPair.generate()
|
||||
let serverKey = IdentityKeyPair.generate()
|
||||
let serverCertificate = try! ServerCertificate(keyId: 1,
|
||||
publicKey: serverKey.publicKey,
|
||||
trustRoot: trustRoot.privateKey)
|
||||
|
||||
@ -43,7 +43,7 @@ class MockClient: NSObject {
|
||||
self.address = address
|
||||
self.deviceId = deviceId
|
||||
self.registrationId = registrationId
|
||||
self.identityKeyPair = try! IdentityKeyPair.generate()
|
||||
self.identityKeyPair = IdentityKeyPair.generate()
|
||||
|
||||
let protocolStore = InMemorySignalProtocolStore(identity: identityKeyPair,
|
||||
deviceId: UInt32(bitPattern: deviceId))
|
||||
@ -63,17 +63,17 @@ class MockClient: NSObject {
|
||||
|
||||
func generateMockPreKey() -> PreKeyRecord {
|
||||
let preKeyId = UInt32(Int32.random(in: 0...Int32.max))
|
||||
let preKey = try! PreKeyRecord(id: preKeyId, privateKey: try PrivateKey.generate())
|
||||
let preKey = try! PreKeyRecord(id: preKeyId, privateKey: PrivateKey.generate())
|
||||
try! self.preKeyStore.storePreKey(preKey, id: preKeyId, context: nil)
|
||||
return preKey
|
||||
}
|
||||
|
||||
func generateMockSignedPreKey() -> SignedPreKeyRecord {
|
||||
let signedPreKeyId = UInt32(Int32.random(in: 0...Int32.max))
|
||||
let keyPair = try! IdentityKeyPair.generate()
|
||||
let keyPair = IdentityKeyPair.generate()
|
||||
let generatedAt = Date()
|
||||
let identityKeyPair = try! self.identityStore.identityKeyPair(context: nil)
|
||||
let signature = try! identityKeyPair.privateKey.generateSignature(message: try! keyPair.publicKey.serialize())
|
||||
let signature = identityKeyPair.privateKey.generateSignature(message: keyPair.publicKey.serialize())
|
||||
let signedPreKey = try! SignedPreKeyRecord(id: signedPreKeyId,
|
||||
timestamp: UInt64(generatedAt.timeIntervalSince1970),
|
||||
privateKey: keyPair.privateKey,
|
||||
@ -98,11 +98,11 @@ class MockClient: NSObject {
|
||||
// PreKeyBundle bobBundle = new PreKeyBundle(1, 1, 1, bobPreKey.getPublicKey(), 2, bobSignedPreKey.getKeyPair().getPublicKey(), bobSignedPreKey.getSignature(), bobIdentityKey.getPublicKey());
|
||||
let bobBundle = try! SignalClient.PreKeyBundle(registrationId: UInt32(bitPattern: bobMockClient.registrationId),
|
||||
deviceId: UInt32(bitPattern: bobMockClient.deviceId),
|
||||
prekeyId: try! bobPreKey.id(),
|
||||
prekey: try! bobPreKey.publicKey(),
|
||||
signedPrekeyId: try! bobSignedPreKey.id(),
|
||||
signedPrekey: try! bobSignedPreKey.publicKey(),
|
||||
signedPrekeySignature: try! bobSignedPreKey.signature(),
|
||||
prekeyId: bobPreKey.id,
|
||||
prekey: bobPreKey.publicKey,
|
||||
signedPrekeyId: bobSignedPreKey.id,
|
||||
signedPrekey: bobSignedPreKey.publicKey,
|
||||
signedPrekeySignature: bobSignedPreKey.signature,
|
||||
identity: bobIdentityKey.identityKey)
|
||||
|
||||
// SessionBuilder aliceSessionBuilder = new SessionBuilder(aliceStore, new SignalProtocolAddress("+14152222222", 1));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user