Fixed a few c conversions which could crash if they failed

pull/988/head
Morgan Pretty 9 months ago
parent 703fbf4848
commit b5a61704e3

@ -83,7 +83,8 @@ public extension Crypto.Generator {
.unsafeCopyUInt8Array()))
.defaulting(to: [])
var secretKey: [UInt8] = ed25519PrivateKey
var cEncryptedDataPtr: UnsafeMutablePointer<UInt8>? = session_encrypt_for_multiple_simple_ed25519(
var cDomain: [CChar] = try domain.cString(using: .utf8) ?? { throw LibSessionError.invalidCConversion }()
let cEncryptedDataPtr: UnsafeMutablePointer<UInt8>? = session_encrypt_for_multiple_simple_ed25519(
&outLen,
&cMessages,
&messageSizes,
@ -91,7 +92,7 @@ public extension Crypto.Generator {
&cRecipients,
recipients.count,
&secretKey,
domain.cString(using: .utf8),
&cDomain,
nil,
0
)
@ -232,13 +233,14 @@ public extension Crypto.Generator {
var cEncryptedData: [UInt8] = Array(ciphertext)
var cEd25519PrivateKey: [UInt8] = ed25519PrivateKey
var cSenderPubkey: [UInt8] = senderSessionId.publicKey
var cDecryptedDataPtr: UnsafeMutablePointer<UInt8>? = session_decrypt_for_multiple_simple_ed25519(
var cDomain: [CChar] = try domain.cString(using: .utf8) ?? { throw LibSessionError.invalidCConversion }()
let cDecryptedDataPtr: UnsafeMutablePointer<UInt8>? = session_decrypt_for_multiple_simple_ed25519(
&outLen,
&cEncryptedData,
cEncryptedData.count,
&cEd25519PrivateKey,
&cSenderPubkey,
domain.cString(using: .utf8)
&cDomain
)
let decryptedData: Data? = cDecryptedDataPtr.map { Data(bytes: $0, count: outLen) }

@ -139,10 +139,16 @@ public extension Crypto.Verification {
id: "sessionId",
args: [standardSessionId, blindedSessionId, serverPublicKey]
) {
guard
var cStandardSessionId: [CChar] = standardSessionId.cString(using: .utf8),
var cBlindedSessionId: [CChar] = blindedSessionId.cString(using: .utf8),
var cServerPublicKey: [CChar] = serverPublicKey.cString(using: .utf8)
else { return false }
return session_id_matches_blinded_id(
standardSessionId.cString(using: .utf8),
blindedSessionId.cString(using: .utf8),
serverPublicKey.cString(using: .utf8)
&cStandardSessionId,
&cBlindedSessionId,
&cServerPublicKey
)
}
}

@ -28,9 +28,10 @@ internal extension Crypto.Generator {
guard
cNonce.count == 24,
var cName: [CChar] = name.lowercased().cString(using: .utf8),
session_decrypt_ons_response(
name.lowercased().cString(using: .utf8),
name.count,
&cName,
cName.count,
&cCiphertext,
cCiphertext.count,
&cNonce,

Loading…
Cancel
Save