mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 12:02:18 +02:00
swift: Eliminate ZKGUuid type in favor of Foundation.UUID
This commit is contained in:
parent
2198447164
commit
bd248f715f
@ -14,9 +14,9 @@ public class ClientZkAuthOperations {
|
|||||||
self.serverPublicParams = serverPublicParams
|
self.serverPublicParams = serverPublicParams
|
||||||
}
|
}
|
||||||
|
|
||||||
public func receiveAuthCredential(uuid: ZKGUuid, redemptionTime: UInt32, authCredentialResponse: AuthCredentialResponse) throws -> AuthCredential {
|
public func receiveAuthCredential(uuid: UUID, redemptionTime: UInt32, authCredentialResponse: AuthCredentialResponse) throws -> AuthCredential {
|
||||||
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
|
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
|
try authCredentialResponse.withUnsafePointerToSerialized { authCredentialResponse in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_server_public_params_receive_auth_credential($0, serverPublicParams, uuid, redemptionTime, authCredentialResponse)
|
signal_server_public_params_receive_auth_credential($0, serverPublicParams, uuid, redemptionTime, authCredentialResponse)
|
||||||
|
@ -14,9 +14,9 @@ public class ClientZkGroupCipher {
|
|||||||
self.groupSecretParams = groupSecretParams
|
self.groupSecretParams = groupSecretParams
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encryptUuid(uuid: ZKGUuid) throws -> UuidCiphertext {
|
public func encryptUuid(uuid: UUID) throws -> UuidCiphertext {
|
||||||
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_group_secret_params_encrypt_uuid($0, groupSecretParams, uuid)
|
signal_group_secret_params_encrypt_uuid($0, groupSecretParams, uuid)
|
||||||
}
|
}
|
||||||
@ -24,20 +24,20 @@ public class ClientZkGroupCipher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func decryptUuid(uuidCiphertext: UuidCiphertext) throws -> ZKGUuid {
|
public func decryptUuid(uuidCiphertext: UuidCiphertext) throws -> UUID {
|
||||||
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
||||||
try uuidCiphertext.withUnsafePointerToSerialized { uuidCiphertext in
|
try uuidCiphertext.withUnsafePointerToSerialized { uuidCiphertext in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningUuid {
|
||||||
signal_group_secret_params_decrypt_uuid($0, groupSecretParams, uuidCiphertext)
|
signal_group_secret_params_decrypt_uuid($0, groupSecretParams, uuidCiphertext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encryptProfileKey(profileKey: ProfileKey, uuid: ZKGUuid) throws -> ProfileKeyCiphertext {
|
public func encryptProfileKey(profileKey: ProfileKey, uuid: UUID) throws -> ProfileKeyCiphertext {
|
||||||
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
||||||
try profileKey.withUnsafePointerToSerialized { profileKey in
|
try profileKey.withUnsafePointerToSerialized { profileKey in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_group_secret_params_encrypt_profile_key($0, groupSecretParams, profileKey, uuid)
|
signal_group_secret_params_encrypt_profile_key($0, groupSecretParams, profileKey, uuid)
|
||||||
}
|
}
|
||||||
@ -46,10 +46,10 @@ public class ClientZkGroupCipher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func decryptProfileKey(profileKeyCiphertext: ProfileKeyCiphertext, uuid: ZKGUuid) throws -> ProfileKey {
|
public func decryptProfileKey(profileKeyCiphertext: ProfileKeyCiphertext, uuid: UUID) throws -> ProfileKey {
|
||||||
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
return try groupSecretParams.withUnsafePointerToSerialized { groupSecretParams in
|
||||||
try profileKeyCiphertext.withUnsafePointerToSerialized { profileKeyCiphertext in
|
try profileKeyCiphertext.withUnsafePointerToSerialized { profileKeyCiphertext in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_group_secret_params_decrypt_profile_key($0, groupSecretParams, profileKeyCiphertext, uuid)
|
signal_group_secret_params_decrypt_profile_key($0, groupSecretParams, profileKeyCiphertext, uuid)
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@ public class ClientZkProfileOperations {
|
|||||||
self.serverPublicParams = serverPublicParams
|
self.serverPublicParams = serverPublicParams
|
||||||
}
|
}
|
||||||
|
|
||||||
public func createProfileKeyCredentialRequestContext(uuid: ZKGUuid, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
|
public func createProfileKeyCredentialRequestContext(uuid: UUID, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
|
||||||
return try createProfileKeyCredentialRequestContext(randomness: Randomness.generate(), uuid: uuid, profileKey: profileKey)
|
return try createProfileKeyCredentialRequestContext(randomness: Randomness.generate(), uuid: uuid, profileKey: profileKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func createProfileKeyCredentialRequestContext(randomness: Randomness, uuid: ZKGUuid, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
|
public func createProfileKeyCredentialRequestContext(randomness: Randomness, uuid: UUID, profileKey: ProfileKey) throws -> ProfileKeyCredentialRequestContext {
|
||||||
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
|
return try serverPublicParams.withUnsafePointerToSerialized { serverPublicParams in
|
||||||
try randomness.withUnsafePointerToBytes { randomness in
|
try randomness.withUnsafePointerToBytes { randomness in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try profileKey.withUnsafePointerToSerialized { profileKey in
|
try profileKey.withUnsafePointerToSerialized { profileKey in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_server_public_params_create_profile_key_credential_request_context_deterministic($0, serverPublicParams, randomness, uuid, profileKey)
|
signal_server_public_params_create_profile_key_credential_request_context_deterministic($0, serverPublicParams, randomness, uuid, profileKey)
|
||||||
|
@ -14,9 +14,9 @@ public class ProfileKey: ByteArray {
|
|||||||
try super.init(newContents: contents, expectedLength: ProfileKey.SIZE)
|
try super.init(newContents: contents, expectedLength: ProfileKey.SIZE)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getCommitment(uuid: ZKGUuid) throws -> ProfileKeyCommitment {
|
public func getCommitment(uuid: UUID) throws -> ProfileKeyCommitment {
|
||||||
return try withUnsafePointerToSerialized { contents in
|
return try withUnsafePointerToSerialized { contents in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_profile_key_get_commitment($0, contents, uuid)
|
signal_profile_key_get_commitment($0, contents, uuid)
|
||||||
}
|
}
|
||||||
@ -24,9 +24,9 @@ public class ProfileKey: ByteArray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getProfileKeyVersion(uuid: ZKGUuid) throws -> ProfileKeyVersion {
|
public func getProfileKeyVersion(uuid: UUID) throws -> ProfileKeyVersion {
|
||||||
return try withUnsafePointerToSerialized { contents in
|
return try withUnsafePointerToSerialized { contents in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_profile_key_get_profile_key_version($0, contents, uuid)
|
signal_profile_key_get_profile_key_version($0, contents, uuid)
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@ public class ServerZkAuthOperations {
|
|||||||
self.serverSecretParams = serverSecretParams
|
self.serverSecretParams = serverSecretParams
|
||||||
}
|
}
|
||||||
|
|
||||||
public func issueAuthCredential(uuid: ZKGUuid, redemptionTime: UInt32) throws -> AuthCredentialResponse {
|
public func issueAuthCredential(uuid: UUID, redemptionTime: UInt32) throws -> AuthCredentialResponse {
|
||||||
return try issueAuthCredential(randomness: Randomness.generate(), uuid: uuid, redemptionTime: redemptionTime)
|
return try issueAuthCredential(randomness: Randomness.generate(), uuid: uuid, redemptionTime: redemptionTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func issueAuthCredential(randomness: Randomness, uuid: ZKGUuid, redemptionTime: UInt32) throws -> AuthCredentialResponse {
|
public func issueAuthCredential(randomness: Randomness, uuid: UUID, redemptionTime: UInt32) throws -> AuthCredentialResponse {
|
||||||
return try serverSecretParams.withUnsafePointerToSerialized { serverSecretParams in
|
return try serverSecretParams.withUnsafePointerToSerialized { serverSecretParams in
|
||||||
try randomness.withUnsafePointerToBytes { randomness in
|
try randomness.withUnsafePointerToBytes { randomness in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_server_secret_params_issue_auth_credential_deterministic($0, serverSecretParams, randomness, uuid, redemptionTime)
|
signal_server_secret_params_issue_auth_credential_deterministic($0, serverSecretParams, randomness, uuid, redemptionTime)
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,15 @@ public class ServerZkProfileOperations {
|
|||||||
self.serverSecretParams = serverSecretParams
|
self.serverSecretParams = serverSecretParams
|
||||||
}
|
}
|
||||||
|
|
||||||
public func issueProfileKeyCredential(profileKeyCredentialRequest: ProfileKeyCredentialRequest, uuid: ZKGUuid, profileKeyCommitment: ProfileKeyCommitment) throws -> ProfileKeyCredentialResponse {
|
public func issueProfileKeyCredential(profileKeyCredentialRequest: ProfileKeyCredentialRequest, uuid: UUID, profileKeyCommitment: ProfileKeyCommitment) throws -> ProfileKeyCredentialResponse {
|
||||||
return try issueProfileKeyCredential(randomness: Randomness.generate(), profileKeyCredentialRequest: profileKeyCredentialRequest, uuid: uuid, profileKeyCommitment: profileKeyCommitment)
|
return try issueProfileKeyCredential(randomness: Randomness.generate(), profileKeyCredentialRequest: profileKeyCredentialRequest, uuid: uuid, profileKeyCommitment: profileKeyCommitment)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func issueProfileKeyCredential(randomness: Randomness, profileKeyCredentialRequest: ProfileKeyCredentialRequest, uuid: ZKGUuid, profileKeyCommitment: ProfileKeyCommitment) throws -> ProfileKeyCredentialResponse {
|
public func issueProfileKeyCredential(randomness: Randomness, profileKeyCredentialRequest: ProfileKeyCredentialRequest, uuid: UUID, profileKeyCommitment: ProfileKeyCommitment) throws -> ProfileKeyCredentialResponse {
|
||||||
return try serverSecretParams.withUnsafePointerToSerialized { serverSecretParams in
|
return try serverSecretParams.withUnsafePointerToSerialized { serverSecretParams in
|
||||||
try randomness.withUnsafePointerToBytes { randomness in
|
try randomness.withUnsafePointerToBytes { randomness in
|
||||||
try profileKeyCredentialRequest.withUnsafePointerToSerialized { request in
|
try profileKeyCredentialRequest.withUnsafePointerToSerialized { request in
|
||||||
try uuid.withUnsafePointerToSerialized { uuid in
|
try withUnsafePointer(to: uuid.uuid) { uuid in
|
||||||
try profileKeyCommitment.withUnsafePointerToSerialized { commitment in
|
try profileKeyCommitment.withUnsafePointerToSerialized { commitment in
|
||||||
try invokeFnReturningSerialized {
|
try invokeFnReturningSerialized {
|
||||||
signal_server_secret_params_issue_profile_key_credential_deterministic($0, serverSecretParams, randomness, request, uuid, commitment)
|
signal_server_secret_params_issue_profile_key_credential_deterministic($0, serverSecretParams, randomness, request, uuid, commitment)
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright 2020-2021 Signal Messenger, LLC.
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
//
|
|
||||||
|
|
||||||
public class ZKGUuid: ByteArray {
|
|
||||||
|
|
||||||
static let SIZE: Int = 16
|
|
||||||
|
|
||||||
public required init(contents: [UInt8]) throws {
|
|
||||||
try super.init(newContents: contents, expectedLength: ZKGUuid.SIZE)
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ import SignalClient
|
|||||||
|
|
||||||
class ZKGroupTests: TestCaseBase {
|
class ZKGroupTests: TestCaseBase {
|
||||||
|
|
||||||
let TEST_ARRAY_16: [UInt8] = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
|
let TEST_ARRAY_16: UUID = UUID(uuid: (0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f))
|
||||||
|
|
||||||
let TEST_ARRAY_32: Randomness = Randomness((0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
let TEST_ARRAY_32: Randomness = Randomness((0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||||
@ -131,8 +131,7 @@ class ZKGroupTests: TestCaseBase {
|
|||||||
0xd7, 0xa4, 0xab, 0x36, 0x7b, 0x06]
|
0xd7, 0xa4, 0xab, 0x36, 0x7b, 0x06]
|
||||||
|
|
||||||
func testAuthIntegration() throws {
|
func testAuthIntegration() throws {
|
||||||
|
let uuid: UUID = TEST_ARRAY_16
|
||||||
let uuid: ZKGUuid = try ZKGUuid(contents: TEST_ARRAY_16)
|
|
||||||
let redemptionTime: UInt32 = 123456
|
let redemptionTime: UInt32 = 123456
|
||||||
|
|
||||||
// Generate keys (client's are per-group, server's are not)
|
// Generate keys (client's are per-group, server's are not)
|
||||||
@ -164,7 +163,7 @@ class ZKGroupTests: TestCaseBase {
|
|||||||
// Create and decrypt user entry
|
// Create and decrypt user entry
|
||||||
let uuidCiphertext = try clientZkGroupCipher.encryptUuid(uuid: uuid)
|
let uuidCiphertext = try clientZkGroupCipher.encryptUuid(uuid: uuid)
|
||||||
let plaintext = try clientZkGroupCipher.decryptUuid(uuidCiphertext: uuidCiphertext)
|
let plaintext = try clientZkGroupCipher.decryptUuid(uuidCiphertext: uuidCiphertext)
|
||||||
XCTAssertEqual(uuid.serialize(), plaintext.serialize())
|
XCTAssertEqual(uuid, plaintext)
|
||||||
|
|
||||||
// Create presentation
|
// Create presentation
|
||||||
let presentation = try clientZkAuthCipher.createAuthCredentialPresentation(randomness: TEST_ARRAY_32_5, groupSecretParams: groupSecretParams, authCredential: authCredential)
|
let presentation = try clientZkAuthCipher.createAuthCredentialPresentation(randomness: TEST_ARRAY_32_5, groupSecretParams: groupSecretParams, authCredential: authCredential)
|
||||||
@ -180,8 +179,7 @@ class ZKGroupTests: TestCaseBase {
|
|||||||
|
|
||||||
func testProfileKeyIntegration() throws {
|
func testProfileKeyIntegration() throws {
|
||||||
|
|
||||||
let uuid: ZKGUuid = try ZKGUuid(contents: TEST_ARRAY_16)
|
let uuid: UUID = TEST_ARRAY_16
|
||||||
|
|
||||||
// Generate keys (client's are per-group, server's are not)
|
// Generate keys (client's are per-group, server's are not)
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
@ -218,7 +216,7 @@ class ZKGroupTests: TestCaseBase {
|
|||||||
let uuidCiphertext = try clientZkGroupCipher.encryptUuid(uuid: uuid)
|
let uuidCiphertext = try clientZkGroupCipher.encryptUuid(uuid: uuid)
|
||||||
let plaintext = try clientZkGroupCipher.decryptUuid(uuidCiphertext: uuidCiphertext)
|
let plaintext = try clientZkGroupCipher.decryptUuid(uuidCiphertext: uuidCiphertext)
|
||||||
|
|
||||||
XCTAssertEqual(plaintext.serialize(), uuid.serialize())
|
XCTAssertEqual(plaintext, uuid)
|
||||||
|
|
||||||
let profileKeyCiphertext = try clientZkGroupCipher.encryptProfileKey(profileKey: profileKey, uuid: uuid)
|
let profileKeyCiphertext = try clientZkGroupCipher.encryptProfileKey(profileKey: profileKey, uuid: uuid)
|
||||||
let decryptedProfileKey = try clientZkGroupCipher.decryptProfileKey(profileKeyCiphertext: profileKeyCiphertext, uuid: uuid)
|
let decryptedProfileKey = try clientZkGroupCipher.decryptProfileKey(profileKeyCiphertext: profileKeyCiphertext, uuid: uuid)
|
||||||
|
Loading…
Reference in New Issue
Block a user