From 467a389eda9ac7f9f91a83d250839fe25cca1e69 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:14:26 +0100 Subject: [PATCH 01/13] Add callback to free array memory --- idiss-csharp/IdissLib/Idiss.cs | 268 +++++++++++------- idiss/Cargo.toml | 1 + idiss/src/cs_exports.rs | 10 + .../concordium_base/src/ffi_helpers/common.rs | 9 + 4 files changed, 187 insertions(+), 101 deletions(-) diff --git a/idiss-csharp/IdissLib/Idiss.cs b/idiss-csharp/IdissLib/Idiss.cs index 2d5e0c132..86611c1cf 100644 --- a/idiss-csharp/IdissLib/Idiss.cs +++ b/idiss-csharp/IdissLib/Idiss.cs @@ -9,38 +9,42 @@ namespace IdissLib public static class Idiss { /// Import of the five C functions that are exported by the Rust library "idiss". - [DllImport("idiss.dll")] + [DllImport("libidiss")] private static extern IntPtr validate_request_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ctx, int ctx_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ars_infos, int ars_infos_len, - [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_success); + [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, + out int out_length, out int out_capacity, out int out_success); - [DllImport("idiss.dll")] + [DllImport("libidiss")] private static extern IntPtr create_identity_object_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, [MarshalAs(UnmanagedType.LPArray)] byte[] alist, int alist_len, UInt64 expiry, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_private_key, int ip_private_key_ptr_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_cdi_private_key, int ip_cdi_private_key_ptr_len, - out int out_length, out int out_success); + out int out_length, out int out_capacity, out int out_success); - [DllImport("idiss.dll")] + [DllImport("libidiss")] private static extern IntPtr validate_request_v1_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ctx, int ctx_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ars_infos, int ars_infos_len, - [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length); + [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity); - [DllImport("idiss.dll")] + [DllImport("libidiss")] private static extern IntPtr create_identity_object_v1_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, [MarshalAs(UnmanagedType.LPArray)] byte[] alist, int alist_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_private_key, int ip_private_key_ptr_len, - out int out_length, out int out_success); + out int out_length, out int out_capacity, out int out_success); - [DllImport("idiss.dll")] + [DllImport("libidiss")] private static extern IntPtr validate_recovery_request_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ctx, int ctx_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, - [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length); + [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity); + + [DllImport("libidiss")] + private static extern IntPtr free_array_len_cap(IntPtr array_ptr, int out_length, int out_capacity); /// The delta determining the time interval in which identity recovery requests should be accepted. /// Recovery request timestamps are accepted in the interval [currentTime - TimestampDelta, currentTime + TimestampDelta]. @@ -56,27 +60,40 @@ private static extern IntPtr validate_recovery_request_cs([MarshalAs(UnmanagedTy /// - throws an exception, if the request is invalid or the input is malformed. public static AccountAddress ValidateRequest(Versioned global, Versioned ipInfo, Versioned> arsInfos, IdObjectRequest request) { - byte[] globalBytes = JsonSerializer.SerializeToUtf8Bytes(global); - byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); - byte[] arsInfosBytes = JsonSerializer.SerializeToUtf8Bytes(arsInfos); - byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); - int outLength = 0; - int outSuccess = 0; - var resultPtr = validate_request_cs(globalBytes, globalBytes.Length, ipInfoBytes, ipInfoBytes.Length, arsInfosBytes, arsInfosBytes.Length, requestBytes, requestBytes.Length, out outLength, out outSuccess); - byte[] outBytes = new byte[outLength]; - Marshal.Copy(resultPtr, outBytes, 0, outLength); - if (outSuccess == 1) + var resultPtr = IntPtr.Zero; + var outLength = 0; + var outCapacity = 0; + try { - return new AccountAddress(Encoding.UTF8.GetString(outBytes)); - } - else if (outSuccess == -1) - { - var errorString = Encoding.UTF8.GetString(outBytes); - throw new RequestValidationException(errorString); + byte[] globalBytes = JsonSerializer.SerializeToUtf8Bytes(global); + byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); + byte[] arsInfosBytes = JsonSerializer.SerializeToUtf8Bytes(arsInfos); + byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); + int outSuccess = 0; + resultPtr = validate_request_cs(globalBytes, globalBytes.Length, ipInfoBytes, ipInfoBytes.Length, + arsInfosBytes, arsInfosBytes.Length, requestBytes, requestBytes.Length, out outLength, + out outCapacity, + out outSuccess); + byte[] outBytes = new byte[outLength]; + Marshal.Copy(resultPtr, outBytes, 0, outLength); + + if (outSuccess == 1) + { + return new AccountAddress(Encoding.UTF8.GetString(outBytes)); + } + else if (outSuccess == -1) + { + var errorString = Encoding.UTF8.GetString(outBytes); + throw new RequestValidationException(errorString); + } + else + { + throw new RequestValidationException("Unknown error"); + } } - else + finally { - throw new RequestValidationException("Unknown error"); + FreeNonZeroPtr(resultPtr, outLength, outCapacity); } } @@ -90,18 +107,27 @@ public static AccountAddress ValidateRequest(Versioned global, Ve /// - throws an exception, if the request is invalid or the input is malformed. public static void ValidateRequestV1(Versioned global, Versioned ipInfo, Versioned> arsInfos, IdObjectRequestV1 request) { - byte[] globalBytes = JsonSerializer.SerializeToUtf8Bytes(global); - byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); - byte[] arsInfosBytes = JsonSerializer.SerializeToUtf8Bytes(arsInfos); - byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); - int outLength = 0; - var resultPtr = validate_request_v1_cs(globalBytes, globalBytes.Length, ipInfoBytes, ipInfoBytes.Length, arsInfosBytes, arsInfosBytes.Length, requestBytes, requestBytes.Length, out outLength); - if (resultPtr != IntPtr.Zero) + var resultPtr = IntPtr.Zero; + var outLength = 0; + var outCapacity = 0; + try { - byte[] outBytes = new byte[outLength]; - Marshal.Copy(resultPtr, outBytes, 0, outLength); - var errorString = Encoding.UTF8.GetString(outBytes); - throw new RequestValidationException(errorString); + byte[] globalBytes = JsonSerializer.SerializeToUtf8Bytes(global); + byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); + byte[] arsInfosBytes = JsonSerializer.SerializeToUtf8Bytes(arsInfos); + byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); + resultPtr = validate_request_v1_cs(globalBytes, globalBytes.Length, ipInfoBytes, ipInfoBytes.Length, arsInfosBytes, arsInfosBytes.Length, requestBytes, requestBytes.Length, out outLength, out outCapacity); + if (resultPtr != IntPtr.Zero) + { + byte[] outBytes = new byte[outLength]; + Marshal.Copy(resultPtr, outBytes, 0, outLength); + var errorString = Encoding.UTF8.GetString(outBytes); + throw new RequestValidationException(errorString); + } + } + finally + { + FreeNonZeroPtr(resultPtr, outLength, outCapacity); } } @@ -120,33 +146,42 @@ public static void ValidateRequestV1(Versioned global, Versioned< /// - throws an exception, if any of the inputs are malformed. public static IdentityCreation CreateIdentityObject(Versioned ipInfo, AttributeList alist, IdObjectRequest request, UInt64 expiry, IpPrivateKeys ipKeys) { - var options = new JsonSerializerOptions(); - options.Converters.Add(new DictionaryConverter()); - options.Converters.Add(new YearMonthConverter()); - options.Converters.Add(new AccountAddressConverter()); - byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); - byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); - byte[] alistBytes = JsonSerializer.SerializeToUtf8Bytes(alist, options); - byte[] ipPrivateKeyBytes = Encoding.UTF8.GetBytes(ipKeys.ipPrivateKey); - byte[] ipCdiPrivateKeyBytes = Encoding.UTF8.GetBytes(ipKeys.ipCdiPrivateKey); - int idOutLength = 0; - int outSuccess = 0; - var idPtr = create_identity_object_cs(ipInfoBytes, ipInfoBytes.Length, requestBytes, requestBytes.Length, alistBytes, alistBytes.Length, - expiry, ipPrivateKeyBytes, ipPrivateKeyBytes.Length, ipCdiPrivateKeyBytes, ipCdiPrivateKeyBytes.Length, out idOutLength, out outSuccess); - byte[] idOutBytes = new byte[idOutLength]; - Marshal.Copy(idPtr, idOutBytes, 0, idOutLength); - if (outSuccess == 1) - { - return JsonSerializer.Deserialize(idOutBytes, options); - } - else if (outSuccess == -1) + var resultPtr = IntPtr.Zero; + var outLength = 0; + var outCapacity = 0; + try { - var errorString = Encoding.UTF8.GetString(idOutBytes); - throw new IdentityCreationException(errorString); + var options = new JsonSerializerOptions(); + options.Converters.Add(new DictionaryConverter()); + options.Converters.Add(new YearMonthConverter()); + options.Converters.Add(new AccountAddressConverter()); + byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); + byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); + byte[] alistBytes = JsonSerializer.SerializeToUtf8Bytes(alist, options); + byte[] ipPrivateKeyBytes = Encoding.UTF8.GetBytes(ipKeys.ipPrivateKey); + byte[] ipCdiPrivateKeyBytes = Encoding.UTF8.GetBytes(ipKeys.ipCdiPrivateKey); + int outSuccess = 0; + resultPtr = create_identity_object_cs(ipInfoBytes, ipInfoBytes.Length, requestBytes, requestBytes.Length, alistBytes, alistBytes.Length, + expiry, ipPrivateKeyBytes, ipPrivateKeyBytes.Length, ipCdiPrivateKeyBytes, ipCdiPrivateKeyBytes.Length, out outLength, out outCapacity, out outSuccess); + byte[] idOutBytes = new byte[outLength]; + Marshal.Copy(resultPtr, idOutBytes, 0, outLength); + if (outSuccess == 1) + { + return JsonSerializer.Deserialize(idOutBytes, options); + } + else if (outSuccess == -1) + { + var errorString = Encoding.UTF8.GetString(idOutBytes); + throw new IdentityCreationException(errorString); + } + else + { + throw new IdentityCreationException("Unkown error."); + } } - else + finally { - throw new IdentityCreationException("Unkown error."); + FreeNonZeroPtr(resultPtr, outLength, outCapacity); } } @@ -163,32 +198,42 @@ public static IdentityCreation CreateIdentityObject(Versioned ipInfo, At /// - throws an exception, if any of the inputs are malformed. public static IdentityCreationV1 CreateIdentityObjectV1(Versioned ipInfo, AttributeList alist, IdObjectRequestV1 request, IpPrivateKeys ipKeys) { - var options = new JsonSerializerOptions(); - options.Converters.Add(new DictionaryConverter()); - options.Converters.Add(new YearMonthConverter()); - options.Converters.Add(new AccountAddressConverter()); - byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); - byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); - byte[] alistBytes = JsonSerializer.SerializeToUtf8Bytes(alist, options); - byte[] ipPrivateKeyBytes = Encoding.UTF8.GetBytes(ipKeys.ipPrivateKey); - int idOutLength = 0; - int outSuccess = 0; - var idPtr = create_identity_object_v1_cs(ipInfoBytes, ipInfoBytes.Length, requestBytes, requestBytes.Length, alistBytes, alistBytes.Length, - ipPrivateKeyBytes, ipPrivateKeyBytes.Length, out idOutLength, out outSuccess); - byte[] idOutBytes = new byte[idOutLength]; - Marshal.Copy(idPtr, idOutBytes, 0, idOutLength); - if (outSuccess == 1) + var resultPtr = IntPtr.Zero; + var outLength = 0; + var outCapacity = 0; + try { - return JsonSerializer.Deserialize(idOutBytes, options); + var options = new JsonSerializerOptions(); + options.Converters.Add(new DictionaryConverter()); + options.Converters.Add(new YearMonthConverter()); + options.Converters.Add(new AccountAddressConverter()); + byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); + byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); + byte[] alistBytes = JsonSerializer.SerializeToUtf8Bytes(alist, options); + byte[] ipPrivateKeyBytes = Encoding.UTF8.GetBytes(ipKeys.ipPrivateKey); + int outSuccess = 0; + resultPtr = create_identity_object_v1_cs(ipInfoBytes, ipInfoBytes.Length, requestBytes, + requestBytes.Length, alistBytes, alistBytes.Length, + ipPrivateKeyBytes, ipPrivateKeyBytes.Length, out outLength, out outCapacity, out outSuccess); + byte[] idOutBytes = new byte[outLength]; + Marshal.Copy(resultPtr, idOutBytes, 0, outLength); + if (outSuccess == 1) + { + return JsonSerializer.Deserialize(idOutBytes, options); + } + else if (outSuccess == -1) + { + var errorString = Encoding.UTF8.GetString(idOutBytes); + throw new IdentityCreationException(errorString); + } + else + { + throw new IdentityCreationException("Unkown error."); + } } - else if (outSuccess == -1) + finally { - var errorString = Encoding.UTF8.GetString(idOutBytes); - throw new IdentityCreationException(errorString); - } - else - { - throw new IdentityCreationException("Unkown error."); + FreeNonZeroPtr(resultPtr, outLength, outCapacity); } } @@ -202,25 +247,46 @@ public static IdentityCreationV1 CreateIdentityObjectV1(Versioned ipInfo /// - throws an exception, if the request is invalid or the input is malformed. public static void ValidateRecoveryRequest(Versioned global, Versioned ipInfo, IdRecoveryWrapper request, DateTimeOffset now) { - long nowTimestampLong = now.ToUnixTimeSeconds(); - ulong nowTimestamp = Convert.ToUInt64(nowTimestampLong); - ulong proofTimestamp = request.idRecoveryRequest.value.timestamp; - if (proofTimestamp < nowTimestamp - TimestampDelta || proofTimestamp > nowTimestamp + TimestampDelta) + var resultPtr = IntPtr.Zero; + var outLength = 0; + var outCapacity = 0; + try { - throw new RequestValidationException("Invalid timestamp."); + long nowTimestampLong = now.ToUnixTimeSeconds(); + ulong nowTimestamp = Convert.ToUInt64(nowTimestampLong); + ulong proofTimestamp = request.idRecoveryRequest.value.timestamp; + if (proofTimestamp < nowTimestamp - TimestampDelta || proofTimestamp > nowTimestamp + TimestampDelta) + { + throw new RequestValidationException("Invalid timestamp."); + } + + byte[] globalBytes = JsonSerializer.SerializeToUtf8Bytes(global); + byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); + byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); + resultPtr = validate_recovery_request_cs(globalBytes, globalBytes.Length, ipInfoBytes, + ipInfoBytes.Length, requestBytes, requestBytes.Length, out outLength, out outCapacity); + if (resultPtr != IntPtr.Zero) + { + byte[] outBytes = new byte[outLength]; + Marshal.Copy(resultPtr, outBytes, 0, outLength); + var errorString = Encoding.UTF8.GetString(outBytes); + throw new RequestValidationException(errorString); + } } - byte[] globalBytes = JsonSerializer.SerializeToUtf8Bytes(global); - byte[] requestBytes = JsonSerializer.SerializeToUtf8Bytes(request); - byte[] ipInfoBytes = JsonSerializer.SerializeToUtf8Bytes(ipInfo); - int outLength = 0; - var resultPtr = validate_recovery_request_cs(globalBytes, globalBytes.Length, ipInfoBytes, ipInfoBytes.Length, requestBytes, requestBytes.Length, out outLength); - if (resultPtr != IntPtr.Zero) + finally { - byte[] outBytes = new byte[outLength]; - Marshal.Copy(resultPtr, outBytes, 0, outLength); - var errorString = Encoding.UTF8.GetString(outBytes); - throw new RequestValidationException(errorString); + FreeNonZeroPtr(resultPtr, outLength, outCapacity); } } + + private static void FreeNonZeroPtr(IntPtr outputPtr, int outLength, int outCapacity) + { + if (outputPtr == IntPtr.Zero) + { + return; + } + + free_array_len_cap(outputPtr, outLength, outCapacity); + } } } diff --git a/idiss/Cargo.toml b/idiss/Cargo.toml index 4adcd908d..420bd6a34 100644 --- a/idiss/Cargo.toml +++ b/idiss/Cargo.toml @@ -43,6 +43,7 @@ optional = true [dependencies.concordium_base] path = "../rust-src/concordium_base" version = "3" +features = ["ffi"] [build-dependencies] napi-build = "*" diff --git a/idiss/src/cs_exports.rs b/idiss/src/cs_exports.rs index 09ee20d91..8a9ffb7a0 100644 --- a/idiss/src/cs_exports.rs +++ b/idiss/src/cs_exports.rs @@ -58,6 +58,7 @@ pub unsafe extern "C" fn validate_request_cs( request_ptr: *const u8, request_len: i32, out_length: *mut i32, + out_capacity: *mut i32, out_success: *mut i32, ) -> *mut u8 { let global_context_bytes = slice_from_ptr(ctx_ptr, ctx_len as usize); @@ -74,6 +75,7 @@ pub unsafe extern "C" fn validate_request_cs( Ok(addr) => { let mut bytes = format!("{}", addr).into_bytes(); *out_length = bytes.len() as i32; + *out_capacity = bytes.capacity() as i32; *out_success = 1; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); @@ -128,6 +130,7 @@ pub unsafe extern "C" fn validate_request_v1_cs( request_ptr: *const u8, request_len: i32, out_length: *mut i32, + out_capacity: *mut i32, ) -> *mut u8 { let global_context_bytes = slice_from_ptr(ctx_ptr, ctx_len as usize); let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); @@ -144,6 +147,7 @@ pub unsafe extern "C" fn validate_request_v1_cs( Err(e) => { let mut bytes = format!("{}", e).into_bytes(); *out_length = bytes.len() as i32; + *out_capacity = bytes.capacity() as i32; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); ptr @@ -207,6 +211,7 @@ pub unsafe extern "C" fn create_identity_object_cs( ip_cdi_private_key_ptr: *const u8, ip_cdi_private_key_len: i32, out_length: *mut i32, + out_capacity: *mut i32, out_success: *mut i32, ) -> *mut u8 { let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); @@ -232,6 +237,7 @@ pub unsafe extern "C" fn create_identity_object_cs( Err(e) => (format!("{}", e).into_bytes(), -1), }; *out_length = bytes.len() as i32; + *out_capacity = bytes.len() as i32; *out_success = success; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); @@ -285,6 +291,7 @@ pub unsafe extern "C" fn create_identity_object_v1_cs( ip_private_key_ptr: *const u8, ip_private_key_len: i32, out_length: *mut i32, + out_capacity: *mut i32, out_success: *mut i32, ) -> *mut u8 { let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); @@ -306,6 +313,7 @@ pub unsafe extern "C" fn create_identity_object_v1_cs( Err(e) => (format!("{}", e).into_bytes(), -1), }; *out_length = bytes.len() as i32; + *out_capacity = bytes.capacity() as i32; *out_success = success; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); @@ -345,6 +353,7 @@ pub unsafe extern "C" fn validate_recovery_request_cs( request_ptr: *const u8, request_len: i32, out_length: *mut i32, + out_capacity: *mut i32, ) -> *mut u8 { let global_context_bytes = slice_from_ptr(ctx_ptr, ctx_len as usize); let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); @@ -355,6 +364,7 @@ pub unsafe extern "C" fn validate_recovery_request_cs( Err(e) => { let mut bytes = format!("{}", e).into_bytes(); *out_length = bytes.len() as i32; + *out_capacity = bytes.len() as i32; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); ptr diff --git a/rust-src/concordium_base/src/ffi_helpers/common.rs b/rust-src/concordium_base/src/ffi_helpers/common.rs index 0434a4bf7..019886672 100644 --- a/rust-src/concordium_base/src/ffi_helpers/common.rs +++ b/rust-src/concordium_base/src/ffi_helpers/common.rs @@ -1,8 +1,17 @@ #[no_mangle] /// Free an array that was converted to a pointer from a vector. /// This assumes the vector's capacity and length were the same. +#[deprecated(note="use [`free_array_len_cap`] instead since it correctly frees the whole capacity size of the vector.")] extern "C" fn free_array_len(ptr: *mut u8, len: u64) { unsafe { Vec::from_raw_parts(ptr, len as usize, len as usize); } } + +#[no_mangle] +/// Free an array that was converted to a pointer from a vector. +extern "C" fn free_array_len_cap(ptr: *mut u8, len: u64, cap: u64) { + unsafe { + Vec::from_raw_parts(ptr, len as usize, cap as usize); + } +} From a88b55b7901b5aeaaa855d2a4f2257629f5a6b80 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:14:54 +0100 Subject: [PATCH 02/13] change to existing dll --- idiss-csharp/IdissLib/Idiss.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/idiss-csharp/IdissLib/Idiss.cs b/idiss-csharp/IdissLib/Idiss.cs index 86611c1cf..e6da3bb72 100644 --- a/idiss-csharp/IdissLib/Idiss.cs +++ b/idiss-csharp/IdissLib/Idiss.cs @@ -9,14 +9,14 @@ namespace IdissLib public static class Idiss { /// Import of the five C functions that are exported by the Rust library "idiss". - [DllImport("libidiss")] + [DllImport("idiss.dll")] private static extern IntPtr validate_request_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ctx, int ctx_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ars_infos, int ars_infos_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity, out int out_success); - [DllImport("libidiss")] + [DllImport("idiss.dll")] private static extern IntPtr create_identity_object_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, [MarshalAs(UnmanagedType.LPArray)] byte[] alist, int alist_len, @@ -25,25 +25,25 @@ private static extern IntPtr create_identity_object_cs([MarshalAs(UnmanagedType. [MarshalAs(UnmanagedType.LPArray)] byte[] ip_cdi_private_key, int ip_cdi_private_key_ptr_len, out int out_length, out int out_capacity, out int out_success); - [DllImport("libidiss")] + [DllImport("idiss.dll")] private static extern IntPtr validate_request_v1_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ctx, int ctx_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ars_infos, int ars_infos_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity); - [DllImport("libidiss")] + [DllImport("idiss.dll")] private static extern IntPtr create_identity_object_v1_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, [MarshalAs(UnmanagedType.LPArray)] byte[] alist, int alist_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_private_key, int ip_private_key_ptr_len, out int out_length, out int out_capacity, out int out_success); - [DllImport("libidiss")] + [DllImport("idiss.dll")] private static extern IntPtr validate_recovery_request_cs([MarshalAs(UnmanagedType.LPArray)] byte[] ctx, int ctx_len, [MarshalAs(UnmanagedType.LPArray)] byte[] ip_info, int ip_info_len, [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity); - [DllImport("libidiss")] + [DllImport("idiss.dll")] private static extern IntPtr free_array_len_cap(IntPtr array_ptr, int out_length, int out_capacity); /// The delta determining the time interval in which identity recovery requests should be accepted. From 1ffef4ffcea57e2eceed198492718a9873cc1f4f Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:24:42 +0100 Subject: [PATCH 03/13] Bump versions and updated changelogs --- idiss-csharp/CHANGELOG.md | 5 ++++- idiss-csharp/IdissLib/IdissLib.csproj | 2 +- idiss/CHANGELOG.md | 3 +++ idiss/Cargo.lock | 2 +- idiss/Cargo.toml | 2 +- rust-src/concordium_base/CHANGELOG.md | 2 ++ 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/idiss-csharp/CHANGELOG.md b/idiss-csharp/CHANGELOG.md index 98187b76b..8df8caa5b 100644 --- a/idiss-csharp/CHANGELOG.md +++ b/idiss-csharp/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.1.1 +- Bugfix memory leak caused by unreleased pointers. + # 1.1.0 - Add new functions `ValidateRequestV1` and `CreateIdentityObjectV1` to support the version 1 identity creation flow. - Add function `ValidateRecoveryRequest` for validating identity recovery requests. @@ -8,4 +11,4 @@ Fix JSON serialization of AR records. # 1.0.0 -Initial release \ No newline at end of file +Initial release diff --git a/idiss-csharp/IdissLib/IdissLib.csproj b/idiss-csharp/IdissLib/IdissLib.csproj index 39255fae6..11e246c55 100644 --- a/idiss-csharp/IdissLib/IdissLib.csproj +++ b/idiss-csharp/IdissLib/IdissLib.csproj @@ -2,7 +2,7 @@ net5.0 - 1.1.0 + 1.1.1 diff --git a/idiss/CHANGELOG.md b/idiss/CHANGELOG.md index 6085a75ab..82afbe798 100644 --- a/idiss/CHANGELOG.md +++ b/idiss/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.6.1 + - Add dependency to feature `ffi` from `concordium_base` such that `ffi_helpers` module can be used. + ## 0.6.0 - Add functions `validate_request_v1`, `create_identity_object_v1` to support the new version 1 identity creation flow. - Add function `validate_recovery_request` for validating identity recovery requests. diff --git a/idiss/Cargo.lock b/idiss/Cargo.lock index 9ee388404..708da86fa 100644 --- a/idiss/Cargo.lock +++ b/idiss/Cargo.lock @@ -756,7 +756,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idiss" -version = "0.6.0" +version = "0.6.1" dependencies = [ "anyhow", "byteorder", diff --git a/idiss/Cargo.toml b/idiss/Cargo.toml index 420bd6a34..1a7199b5a 100644 --- a/idiss/Cargo.toml +++ b/idiss/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "idiss" build = "build.rs" -version = "0.6.0" +version = "0.6.1" authors = ["Concordium AG "] edition = "2018" license-file = "../../LICENSE-APACHE" diff --git a/rust-src/concordium_base/CHANGELOG.md b/rust-src/concordium_base/CHANGELOG.md index 0eb693b00..d28c60410 100644 --- a/rust-src/concordium_base/CHANGELOG.md +++ b/rust-src/concordium_base/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased changes +- Add extern function `free_array_len_cap` such vector pointers can be released and deprecated `free_array_len` + since it didn't account for capacity size. - Add `From` trait to convert `AccountKeys` into `AccountPublicKeys`. - Add `singleton` and `new` function to `AccountAccessStructure`. - Export `PublicKey`, `SecretKey`, and `Signature` type from `ed25519_dalek` crate. From a7a6c9f1c89ea3bb31c7432ba63d365932790ed3 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:25:44 +0100 Subject: [PATCH 04/13] fix formatting --- rust-src/concordium_base/src/ffi_helpers/common.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust-src/concordium_base/src/ffi_helpers/common.rs b/rust-src/concordium_base/src/ffi_helpers/common.rs index 019886672..a2d6f8400 100644 --- a/rust-src/concordium_base/src/ffi_helpers/common.rs +++ b/rust-src/concordium_base/src/ffi_helpers/common.rs @@ -1,7 +1,10 @@ #[no_mangle] /// Free an array that was converted to a pointer from a vector. /// This assumes the vector's capacity and length were the same. -#[deprecated(note="use [`free_array_len_cap`] instead since it correctly frees the whole capacity size of the vector.")] +#[deprecated( + note = "use [`free_array_len_cap`] instead since it correctly frees the whole capacity size \ + of the vector." +)] extern "C" fn free_array_len(ptr: *mut u8, len: u64) { unsafe { Vec::from_raw_parts(ptr, len as usize, len as usize); From 0934ce1acae11fbb6adfb7d4aea282435925a359 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:29:15 +0100 Subject: [PATCH 05/13] added missing json file for test --- idiss-csharp/data/valid_request_v1.json | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 idiss-csharp/data/valid_request_v1.json diff --git a/idiss-csharp/data/valid_request_v1.json b/idiss-csharp/data/valid_request_v1.json new file mode 100644 index 000000000..6e1570ba7 --- /dev/null +++ b/idiss-csharp/data/valid_request_v1.json @@ -0,0 +1,38 @@ +{ + "idObjectRequest": { + "v": 0, + "value": { + "idCredPub": "b05e024461f74ef98d14d6ae17121df28bc397fbfd55fedf08889c48c59d92e61c6853c561f054a9a1b6ad648d1da154", + "ipArData": { + "1": { + "encPrfKeyShare": "b1bc2dbd660d86c23432f61edf4f2991ae08307d2596c3fbfe021e31d5a8a347cd8b6bf4bcebc6cfb5672ad1e5a26e37b530ce61ee539a330bcd736dcd3e7b38c0cf19c98bc8eb3345291d9ae54138895e5869910af4de56fc1392b91b6788f1b0098b3daa032768a7c3a6e3ff9ef6fa099d6fb3127a5e606182c438e374ab4c36731524d34325979dfd83fb8210ca21a3b22ccb7bf7471d79e3b8c59432617e859fc12ea73a9ba0cf29486dd9eeb64d43afcdbb62210f7fef97aeee3f880450a5871d28e51473ba7c4f3cef78374b27fe349291cd92aa4864e18062ecbd5d833ea94a1f379689c10e3f4a322365c3148324be85fcc7adac0e17cd7334c1d08859189bec35a9bf0cb2a97e0853a7bbf45d49105dbc3740579744844519306fabb306794ef7c3f464bd8dd24068416de2400deab08230025c20de291484e095272d8bd61bb7f22817b50990d7c1c904fa97cc7b42bfbd3fa01d750ff4c1c62ef6fd944ee88f9026b29419479ea066ee9cb0703986f96e39c9b0a29515de56997f92a49b3f08f1429fc1da1604760c5e4c365aba381ecc33188809e24aca94d9d4d7757f85d5d08266737eef66dedb1a1ea1ec29bf87bb01643e68b41e3f71b6c1c4f14c7b9f5b0df1067dace88b5cefa16600e12623ef4c36d4b914fcb687e2a794b2e9317df4d941be823171d0710d6b48f7073c8cf05a9a00261d3cc756dd05a7229510fd668ca636d73a7170bc399f90ca07fd620063aa19f825a221e0b34a80f3c48cb2d7cd29a10a03f80ee7e572d8a65958636820b489ef865f921a16c2ad8a933205f7c1d9f78aab534fb4082402ea6474a7cf0520982c525b56620e44089fb7cf5c08695d81c29f8b8d0dfe9daecacab7118dc1c7aeb48eb08c3c2fc86aeb1c459303e595aade2ed6d4c4f6e0596a3c1eddac73c92416c4838634474bb1f2f1aa8d0e9d8d3080aa9ec74e38f8d0e65d168053bf5b6fddb1f4cb82f00621c2cf8f8add5e9896897ee0d4d011a483de003a0a948464396b9a619930f1f5b91e6b373625bb3f2d9db0bb3adf1dc486571edcfab5da39c6aea2cc7361f13d", + "proofComEncEq": "0dd96dce68332c1a4157246e915bdee45b1e93495393cfa71c1cfaf10e7a05ad54e1b57b7d5902e8e967ffae1e16ed4c64740597401b2da81800863e27a80a4054a4bba15da5bbe3e4a83d4e4144134fa51e353ae54ba36ca80cd17dba1a6747" + }, + "2": { + "encPrfKeyShare": "b92ab7dc5a6a93df05366f557e4413c5a64b28e74b80f8daa13620771402bd7dbd439753b24848413cd8de38992ba7f0a56f2af90b9d45f9fddad6b32b3cb3977b5b5ce408e8489800ec0e20a3379faa41145315d6acf1b8c221d77fa2cf5883966b2100bed35f244487297b94fd3f6cc3f79834392d04b1160cac7b5a9adb4eda42f107db151ea51a212fbdaaed132a84d913436f978b345f996feb66ec60952b389244b022d54a5d3c8efa03fe566df2b48f98786ab28915cd591541ecda038b162e4f9a8a507afd99fa5c9edbb099c64dc0eb5a12c67e76a64e6a3eacfa9bcd072996380d286f37857c777f9522bc941d72cbc40c94864652b090136e8b163ebb27efc70636a8422179acb91008c8ff4684b8cd734bab799951aa70d17effaa266db5f4976f69df1096e227671f05eed7115cbec450341da9ca2dbdc6c38071eee429675970b2a5d049eb55906378a0ca1fc2e35d4b113182720f31212f214fc9a109a68a2dc2dea6b12d1aa6cd2645213ee88da93e0e7919fa774f7a9b618a29de6b7982986912cf8c7938b4b6d6da9643e58a819a7700e71c0132cdde8fd4a2956752e65222875393583d181a38adf639dec62a545fcd8d869b63732901ad1de36d83e6dccd4586f4abae9af077853b2cb8d2b2089d03080634c641db05ab03d09242d40c4c27e8fd16a7c8715078894616d596321db81b6fae5d6693836a0dd1a8c9784115cfa5fb7d94f180f4904e88359e5ce02a5e8864db18ca92ae6f391e9357be92b1d20aa70b82bd34cd1305245374264b3df355a455d9af413eaad2b3104e72d1128ac725c73c80383fee8ea0b9a6747bf40678d1ad63ce61785cc5d263d2f3d4ee296c0577870896f685e22a7e30c5be9e4b27d890bd5f62ab45a21874727e01b70e5d3e0d1567d182ce7e34d1e23060dbc5dd3416b74fdcc0982ca3fa154b751d829dff4bb3d1ac63a0ce328deba2f17799ecfeeb17c8d48a91a468e0c92a689500495499080328f1b08267ee544bd31b08570966da78ccc5aad0c6428ce9ae6549166f03bc7d13248ee26f9336e640fdb27687ecee3b5379", + "proofComEncEq": "5317b956953c475ccc067c7107882df504da32d0278e84cc92cf2e215d09a7ea1db77bbc943e2169f527581f63b697fbdf39324392e4461bde4debba2e8e9767720a6e8266cbbb29acd5644d8359fde7f66122eb24e89a1d979e113b85ffeda4" + }, + "3": { + "encPrfKeyShare": "a77410a5f854de44b37a9b804bef5948dbec9ee813cd94ced7cf381b46fad1d38d09898bfcbcd51d59054969be44f1faa5ddcc2f49b82b7b78ae7d3f579e1b92c0dcf5cf68600097f47503e322008b2e9b8c6f780bb0f4911e4b289895601dafa59c34cf0f1f3ef2c8a0bb3433270538fc26111414e845dcb7e3152bb3343d74fb9e228110a8c8f1c971bb99f183a1f4a7b2e284f775cb634bf1fe7d45505a29018952cef12d78304a2959f57b7a21536be1e3f3a09a60f3ab618da995b828a799b1fc33a27f1f819186666ad7395b8ba731b9488d7f1ceb250b3df1208c444357cc3c7895e790d1663d85714052e9cdae65d0075e7ee318741b6f3389a3f813b6d032d4b4b051b910e4bb04701e41edf7825f52f4e0f495cac9d5593ed10432900a6e05997084eaa4e2cf3b7cc8c731cdd5e8d54302869d56b94115be3364baf2460da2616a66e83ce2fc51e70a351883f8ff54f41849afb891da9729480f19172d452652b17577d9d810882a37d48a70ae75a411317288acdfa2cef65757c5ae55188c18b97ee36f1258bdb965711cb7844db47db3dfa74c6b86a4956f07e5df154aaef7282a6df65eb4bc77229c72a5d9c3963511595871f3b0b1c6f2bb9107a86e65a193dd48b05d01515d8966e606af3fc89efe4fda5b4f34ce6482ebc78b545cc9ff5fc2cd43ea8f8db65df572f5f612031b627e93a16f0cfdf46c0af5db295a67fd2e8a08dbf53ac4f08092969476a24aed094dae81842df5386fe526d48d3ba33916ffc0b2141dfce8a2e456706e76480033a93c9752a31f9b1e004180b2178edc4fbec36ecea31b1fd77342460db974a6c27993ac3baa93a724a7bc6de1249dbbb9d45272edee4c6272978d94364147e5898d3d3fcc96b3f2d14c1734f321a2fd9e8c4d9825a4847d73f821daf5bfc4be1218634170abe04b653687b0046096458168477c6e4c1408dcd53e8d8cb22079bd77424da642723be6e48653006f74d139c9c6ba01a7b38e7ed98290621321d7d531168090bda25e83e5f150e5a12bb086a27b516b0fd137babd78e1ec4a197aa37aed427d539e4cbad3f7", + "proofComEncEq": "07e84b1c9716abe49e403d10d99e7bb0ee4ad673684ec4bcbea0c1cb41dd5542677d369caebef26c10db3eea50adfcd3431d5dca24f33a9ddf5e5c1689181c0d1cc5248080b2f43f7cbd2047c49a5dcac18ed8bace59bf819da8e3727bbc271d" + } + }, + "choiceArData": { + "arIdentities": [ + 1, + 2, + 3 + ], + "threshold": 2 + }, + "idCredSecCommitment": "ad0d70c0945a9c2cd52700b0dabc42c691c7eec453c843b8477276d0d20c47a953f5c7d4f1265a44e3b983f1cd407514", + "prfKeyCommitmentWithIP": "8b3fc130fa2f73f34defea76ccec411d5a329241e2318639dda3f62c85d713e934faef3478e68771dee52cba1b07d2ba", + "prfKeySharingCoeffCommitments": [ + "b5db80922bd4ecc59648fee44a51cbb24ea62c11bef56b7d8a9c1268b213a632051666e5de82b9e23df5c256952718b6", + "b4ec3cd3724b76e5d6944ab4e1f8899deaaff60fd31eee9ad7a807c85fde12067128b5af9a1b66ae68ab2e4e68c3b91a" + ], + "proofsOfKnowledge": "c6392f58901993d354ce66f601bed0f9e3ae0b5b817a0730308f58db11d80ec656de34a924ae27c38b9e74b57f4470920e76b45eec02ad3e60717da2e465488229774e9689ff347200b55d622c2e278a382d94155196cad8a8a39fad0c49492d6ecdc49a992462f6a4cf846281df0869052fa65fcb970808251bee0fc9aaf108236a86f7ec7a63e6d74cfdcd32e6bd454904f3c332274df0895e14f300b0d7c001a98addede69b6f33923b29d0a88c233e302e087a45b78dd98c5fbad05377c0456016d6fedf547b5b52a98642d1de637ddbfa5d87dbd00e306165a0ec74cbfb0000000000000003adcdb5aca367b8f4a37410f7c83977df310085c101d60d81bbf8fd63b61e436336aab40a612eaa85a10c941ac483f7ee8a1ea0cee0e656886e9a83fd376c991a92e0a6acc3ec2a02b7fd6105551091cd2a5149ba71ecfd04ba33d8d9891420f0b5fc782f670deaa7dca4a23329c729e45065c26dfe34da94f1aa5287de93a24221df9fd01e4e0aa0f7f2ac229bdfd2d180f142ecafc3a58a551548197ee50531c8483030fa72392a805404de15f6bf3725e7e68b2974fb0ca319c1d28a983b544c22cf5107757830addd9b19aab59c9056ba1177f62dc565e3372f7e9e421a99612019303cbcb9a38c589e059f7c7d909403c5f11493160c61628296722ac52e43a35c5d9a307dcdf0c02504cf8c0c7c26b62faba82c1b4f944b724f107fd43e00000008945c68aab1b501851d7b9c8b3045b44faffa72491d9e04aa447cb1fb5ba3b7bf27e6631f5f365841026abd1d5a2c7bfbb9d8b7da724637da99d59eeb7b40664006f87602ddf1bb4ab56385f89090fc6d0ecbcde00e737fc00b997b6eca6a4e7d8a8c3155ff528563524b78dfbc9e2181c56c5acde58b257d4b83c58b9eb18508163f0d83d4c32134aa405d02ffe583ab97d6a7d80fe486451f94ef3c3516369e69d623fc591d43886b848ea713d2f6ead935813566695f57b342831eb480a21c97907a6a1e3230236e861f619283ccfdd41d081a882284a09b27b272df0617e81cc06763b6083b2005a7d4d4c1cf79a081995f44ad0b001648ef618ac5e3497998722f36280be327e7244e72d141663dcb40943e01370dc2916b2a58705d9dec941676237a7e00faefb39ef8bdfc5e490b4f53db098499bb67832dbb3ee98e1ab9df8a8020b975e7f4881fb90d9c4d1fa1874435b783e1cc94f553de3da03a5c95c8007bdfe3cbafbcf37ccba424a914ee9baaa88e8c214b2d42af4403f6cec6b307774f89c9aee2b43cfba11b530eebcb648a72d1120e34e5831540cb1fbb75e6746ad3acc3d7343194e2226c444557a730b9d1bd94af9004ba82d2db1814068e17e5187db7a72ca709c39ac047c12a206a7db26049a24dcde877b31f98b100934675f60392d7feee0b4a1f2db52b9371327e8fcbe7b07a5bc6d051751ef4f161ea193bdd64c298c2d8c3879ca98ed498616b94b5b7f5a9aa9b493aff94d3163c19cea68a1ffdfdae1c510cb29838839e6258f6f8c83de2ba8773dd6ffaced7831795776d1cac2659096adae3050876c87f557ccac2dede9d12414286c29c71ab5710b28c38406c3580f3b496e9b805b2197fbbd1772edfa70ad6952f8f3a66be80378ee7749ef929e61734f32837356fd2c558357f19395a0d3cc0b6ee0486abe88191ebc72aff641c50c771093eea95d59b37a18170b17f9183a53e5a0948ac83b47f0124c02e361a0eccedf2e94a93192a03ec7f90ae02ee41fd27d6ebfaf12c3e0aefb3721718730354f08f04c90801914e55a5dfe7a1a332bc05065e773f466c688c362ecc0e86eb1a2b641a49bfe43017a7a6a4328da8ff3760eaa69d269376fca26ee1368ea34bffce37ba8210b3b1e107d49a73f6243352d2912923ab776aefe28e010d64382dd31872abe5a03eca39809b2a912699a13702017f32eee689deaf4a1206c3083b832b9c5fd2b33ba82c086114e3994e8bc7cdfaec028abab73ebc4c7564ff2eb7cd385c756d7c69d83d1cda6d5e80efd3d8fbc68fa8b0639b5f15b2f0c9bcf617c15b37bfbf9a2eaf147d87d9fca9c338883aaeb729c70bf4f26fba8d98c78ec05a2097a5f3b266234770dbfb1bb695152663db4ddda84f6353fbbbe384ddd975427253d5b37cfc67676b337cd95110c23115f160310e079310a7f64d0c8c60720526e0c6bd19dc4605540ca3972c18c87ba338eb0266467c029cd3fde18b155a23e7ee5473c33d5b744bdd5bd17e3f47591efeb08449a118b6405dc0a3219b7f3dca0749a3b554ef94c36376ec62aa6ccd5c802413000000088cf4d39fc00f5421adb274c2633f2655f69b2356e51c8e1c529f306be0a8df477e013b8e399b0143a03c11842431ec81984fc91c1384058c8a6eb65240e70a810ddd8dd4a0d6a6baef72b2e2ca3f11ca5d379bfec709935d5c6dfb818fd14189af9602db647ed86528efb0fd4ac437f31b74c7b06d482cbde173c236bf1e9de61fd7fee7d182f3b588d07862f9297ba0ac3572bae12f6be179913816f776d1dfb0c9be2d097676492303c6878698672ed094d92d6f8856e1c3634c6f74c6ed33b9fee1a7a2ee67b0719414db75e8b4c1780d30bbae7f6c65d54cf80e20afbe97ffd0a8b683841f291d93f446006edc44a57a6a6008cc045c648b60656b2e2f0dddbc7e8fe63c592c27ab11e5c04eac9193f9a3b687436cfda8fd7060e67f28ab82ed6ed397fc36cf12c9f2c53981fe3167cb9986f8011148297f630148c8f3af59978ab0bf91f822f93bbba0dc0e235cb8fada97375889f262097e1e10e62dccae535e512b09ab3f0393a2564f48cb0e68afcacd3ce603b4fe2e3e6c1e64e0eca3a31c8b9d487997d9a7b55b35c68cb4dd0bd1f194a75020f885137e6ce53cc997eafc121578baa537461e9439c46cdda012ec2a2c741454b9c681b168d1274991ea450532f31bd3fd69b21a05e2bd50273bf3e1390b83151b166212bb994500a86bd66358c44077206ae255b686b43e50986c0115fa97055862e1ee8a2dedfa5cbd044f6b214e2c0a99399fcc1771b7b4b5682638661646c1d373ebf0b6bea43cdc0ba62d2fcc9cb91c44edd1f61cd64c3ccd1eaf33a6c94af7641ec7cee50d98a82c8aaaacd226642662bae50f86abd317cbed9f26b5bab692c5975fa552c23d3989d2554e8dc113c998740b3444a3adc1182af737a7596741b4f00aec870d59f853c3969ef29cd0220e3348ba68c0fff2a9ba4d3da1f56930de6179755806a4a363be4d2d9e547386281058f29a0c5f5401e2c4602711a7409951db4da554868ef0865506930314bbab30bfc90a55a128d45376e16da475e1a34dce54eebffa9d6abffc7b07368d00febf118ec031f1f3969f8571a0619d2d3bb3d8a682a23d60a86751f417f17810c1a3e1e2e85136f55da3855ac6c26e4a99383f2c481250be4937271b8e6be1832d7737b88a7f42dd74740228a1f9ed42f3e4b2546bf8ad2ffcbcb11b90267e7ba2a35da22d93dfe4fd806187dad0d3a6572fcf92294bf0fd8d7d379a2d9c139809dc4517255d94ee97c15e16276020856d78e34e7a7fc228f35c0c0b04a60b1006e80920581c4d2b58960eab6c7159aa1a1b8a5b351595f08ab82bdcca9ed4d262d156abe3a21c80b8b8892f91b8050890d90d06be39d49a403d2e85de3b47fb238a576b525eb10106616604c79122d34e4119ae1cd9b0cb1af7d0c6426eba4a819ace7a324b4f996959a2824ed2de67ee706787bd7f500e1ef3d3a1dee05aae9a542014b3a851a203811a2c2cfa08eedf0a7a3035586038a03e809a010b07f38e17ab83ff447b80dfd0c64e637de92d672527ed747f111c9a3740acf82a8dff7c8bf6eb4f9bc51bb47420fa9d0478f95b01bb87857700000008a31089d16ac39a166ba284c11e7eaaa6b9a4de1640c791e2744cdd29cacdcc7596985ae632cbfdb9891e14f2c987c461a56ebbce6f1c88af634fa41369a7b3e0a7bde27f53fb7d9400657bd8b326c7b2aba080ade45dab5a5dfe6cc609c91414b618b71b4157f3ec1e7641f6a2b4c44c97967b9ff09bc601e8e068552d99e8a76d4f2dedcd80a0c995f41a524d24fff3ae4b75ff620600e1a5e7fcb08f8be9da650cac1deccac96bc48d4cc9dcf4da9ace2004f805ef331d9f51a8df070477ecb6411650a719f647f99fffda974a913076e07c579e2138c67daf33b104399add335273b0b5fb6a9330bb8b2c5688aa4ea9d97db2d2d03787e6a4315977c80d5548df9d9e653d587bca24910f7dcef6b3d405ed903cb9e5c401dc799ede2441418f9e1a24b3af50a5bca5f36ee660d79adc13fb7794581e266f297575fcd598c83a9588d0c1e60816b13e31f76d9bbe6ab64af0f807045bcf4e9ae30a4067180f4685b93374afb2aca61a7da562b95bdb91dbca390544d7c3c5563f7dbb99911287a53ae2d5d7b296a7d07afc34144df00bc220ecee647670e83f34871e287601cc1601b25a2a0efe0fd3b75a4b203f8880804a1240f96b4ff53d1e34487d73fbd265c2c3c60ec5c61745df4eca52c0bb7b82365948b8d52f32ce176530a70704a37407fb2705ad70c134dc86a5bad595802029c4264919034461c4a81fe79fbecc551f1e4eb4a4c71be8409cdffb749ea8fd9293c4f0a5880259b66352c3801df8c0402efac4bd139d5d044bbe8b4b72e5036e46c19b001c85241a6d76de6ee190441ac8214bd2cdd6fc55cd37c06ff31d1f2825d63f7938c329f45eb6ffce21222ac77f09f44098c8818cc239dbbf30863682792f71cba1e997f05208510b0d1ce75a5d75b49be507ec73b005373abfbca206fea6bacd56a22bb97c15d9532b91a93524df49efbe32f011fb20f2a9e4a3f2259e718243bbc0bab91c98e1ac38440cd62b31a7cf1d608f0a7c432d9eae91255351e5a33a67f11e9143fa5fca881bb60a8c5e43f77c87034e020d8b99c33f1ac8ef41ee8177905d9cfe3512eb226b78a8b28f4790e4e1dc0f60f4766193da4917609ab10ed5b73ff30467f6b5dd5b4db6b76e7d1e0075283a322c660130f7dd796d4d4586272139ae1f1df4121f" + } + }, + "redirectURI": "Example.com" + } From 34aa264957db41b74747fa896d0c3670c4e718f5 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:37:46 +0100 Subject: [PATCH 06/13] Fix wrong call --- idiss/src/cs_exports.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/idiss/src/cs_exports.rs b/idiss/src/cs_exports.rs index 8a9ffb7a0..595772ae5 100644 --- a/idiss/src/cs_exports.rs +++ b/idiss/src/cs_exports.rs @@ -237,7 +237,7 @@ pub unsafe extern "C" fn create_identity_object_cs( Err(e) => (format!("{}", e).into_bytes(), -1), }; *out_length = bytes.len() as i32; - *out_capacity = bytes.len() as i32; + *out_capacity = bytes.capacity() as i32; *out_success = success; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); @@ -364,7 +364,7 @@ pub unsafe extern "C" fn validate_recovery_request_cs( Err(e) => { let mut bytes = format!("{}", e).into_bytes(); *out_length = bytes.len() as i32; - *out_capacity = bytes.len() as i32; + *out_capacity = bytes.capacity() as i32; let ptr = bytes.as_mut_ptr(); std::mem::forget(bytes); ptr From 9bd62bbc2208907ec03d6a785d43052ce5d466b2 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:29:11 +0100 Subject: [PATCH 07/13] Updated changelog --- idiss/CHANGELOG.md | 5 +++-- idiss/Cargo.lock | 2 +- idiss/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/idiss/CHANGELOG.md b/idiss/CHANGELOG.md index 82afbe798..8b37dc6d6 100644 --- a/idiss/CHANGELOG.md +++ b/idiss/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog -## 0.6.1 - - Add dependency to feature `ffi` from `concordium_base` such that `ffi_helpers` module can be used. +## 1.0.0 + - Updated interfaces used by feature `csharp` to include a reference pointer which sets the capacity of the array returned. + - Add dependency to feature `ffi` from `concordium_base` since `free_array_len_cap` is now exported from the `ffi_helpers` module. ## 0.6.0 - Add functions `validate_request_v1`, `create_identity_object_v1` to support the new version 1 identity creation flow. diff --git a/idiss/Cargo.lock b/idiss/Cargo.lock index 4f7a74e19..a3a30ad95 100644 --- a/idiss/Cargo.lock +++ b/idiss/Cargo.lock @@ -756,7 +756,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idiss" -version = "0.6.1" +version = "1.0.0" dependencies = [ "anyhow", "byteorder", diff --git a/idiss/Cargo.toml b/idiss/Cargo.toml index 1a7199b5a..955b7d421 100644 --- a/idiss/Cargo.toml +++ b/idiss/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "idiss" build = "build.rs" -version = "0.6.1" +version = "1.0.0" authors = ["Concordium AG "] edition = "2018" license-file = "../../LICENSE-APACHE" From 680ca9e2350b5853045d0356f55e55f45d2e907c Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:43:24 +0100 Subject: [PATCH 08/13] changed pointers and updated changelog --- idiss/src/cs_exports.rs | 47 +++++++++---------- rust-src/concordium_base/CHANGELOG.md | 3 -- .../concordium_base/src/ffi_helpers/common.rs | 4 -- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/idiss/src/cs_exports.rs b/idiss/src/cs_exports.rs index 595772ae5..09bef8fcb 100644 --- a/idiss/src/cs_exports.rs +++ b/idiss/src/cs_exports.rs @@ -1,3 +1,5 @@ +use std::mem::ManuallyDrop; + use crate::*; /// Like [`std::slice::from_raw_parts`] but with special handling of empty @@ -60,7 +62,7 @@ pub unsafe extern "C" fn validate_request_cs( out_length: *mut i32, out_capacity: *mut i32, out_success: *mut i32, -) -> *mut u8 { +) -> *const u8 { let global_context_bytes = slice_from_ptr(ctx_ptr, ctx_len as usize); let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); let ars_infos_bytes = slice_from_ptr(ars_infos_ptr, ars_len as usize); @@ -82,12 +84,11 @@ pub unsafe extern "C" fn validate_request_cs( ptr } Err(e) => { - let mut bytes = format!("{}", e).into_bytes(); + let bytes = format!("{}", e).into_bytes(); *out_length = bytes.len() as i32; *out_success = -1; - let ptr = bytes.as_mut_ptr(); - std::mem::forget(bytes); - ptr + let wrapper = ManuallyDrop::new(bytes); + wrapper.as_ptr() } } } @@ -131,7 +132,7 @@ pub unsafe extern "C" fn validate_request_v1_cs( request_len: i32, out_length: *mut i32, out_capacity: *mut i32, -) -> *mut u8 { +) -> *const u8 { let global_context_bytes = slice_from_ptr(ctx_ptr, ctx_len as usize); let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); let ars_infos_bytes = slice_from_ptr(ars_infos_ptr, ars_len as usize); @@ -145,12 +146,11 @@ pub unsafe extern "C" fn validate_request_v1_cs( match result { Ok(()) => std::ptr::null_mut(), Err(e) => { - let mut bytes = format!("{}", e).into_bytes(); + let bytes = format!("{}", e).into_bytes(); *out_length = bytes.len() as i32; *out_capacity = bytes.capacity() as i32; - let ptr = bytes.as_mut_ptr(); - std::mem::forget(bytes); - ptr + let wrapper = ManuallyDrop::new(bytes); + wrapper.as_ptr() } } } @@ -213,7 +213,7 @@ pub unsafe extern "C" fn create_identity_object_cs( out_length: *mut i32, out_capacity: *mut i32, out_success: *mut i32, -) -> *mut u8 { +) -> *const u8 { let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); let alist_bytes = slice_from_ptr(alist_ptr, alist_len as usize); let ip_private_key_bytes = slice_from_ptr(ip_private_key_ptr, ip_private_key_len as usize); @@ -229,7 +229,7 @@ pub unsafe extern "C" fn create_identity_object_cs( ip_private_key_bytes, ip_cdi_private_key_bytes, ); - let (mut bytes, success) = match response { + let (bytes, success) = match response { Ok(id_creation) => match serde_json::to_vec(&id_creation) { Ok(bytes) => (bytes, 1), Err(e) => (format!("{}", e).into_bytes(), -1), @@ -239,9 +239,8 @@ pub unsafe extern "C" fn create_identity_object_cs( *out_length = bytes.len() as i32; *out_capacity = bytes.capacity() as i32; *out_success = success; - let ptr = bytes.as_mut_ptr(); - std::mem::forget(bytes); - ptr + let wrapper = ManuallyDrop::new(bytes); + wrapper.as_ptr() } /// This function takes pointers to bytearrays and use the library function @@ -293,7 +292,7 @@ pub unsafe extern "C" fn create_identity_object_v1_cs( out_length: *mut i32, out_capacity: *mut i32, out_success: *mut i32, -) -> *mut u8 { +) -> *const u8 { let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); let alist_bytes = slice_from_ptr(alist_ptr, alist_len as usize); let ip_private_key_bytes = slice_from_ptr(ip_private_key_ptr, ip_private_key_len as usize); @@ -305,7 +304,7 @@ pub unsafe extern "C" fn create_identity_object_v1_cs( request_bytes, ip_private_key_bytes, ); - let (mut bytes, success) = match response { + let (bytes, success) = match response { Ok(id_creation) => match serde_json::to_vec(&id_creation) { Ok(bytes) => (bytes, 1), Err(e) => (format!("{}", e).into_bytes(), -1), @@ -315,9 +314,8 @@ pub unsafe extern "C" fn create_identity_object_v1_cs( *out_length = bytes.len() as i32; *out_capacity = bytes.capacity() as i32; *out_success = success; - let ptr = bytes.as_mut_ptr(); - std::mem::forget(bytes); - ptr + let wrapper = ManuallyDrop::new(bytes); + wrapper.as_ptr() } /// This function takes pointers to bytearrays and use the library function @@ -354,7 +352,7 @@ pub unsafe extern "C" fn validate_recovery_request_cs( request_len: i32, out_length: *mut i32, out_capacity: *mut i32, -) -> *mut u8 { +) -> *const u8 { let global_context_bytes = slice_from_ptr(ctx_ptr, ctx_len as usize); let ip_info_bytes = slice_from_ptr(ip_info_ptr, ip_info_len as usize); let request_bytes = slice_from_ptr(request_ptr, request_len as usize); @@ -362,12 +360,11 @@ pub unsafe extern "C" fn validate_recovery_request_cs( match result { Ok(()) => std::ptr::null_mut(), Err(e) => { - let mut bytes = format!("{}", e).into_bytes(); + let bytes = format!("{}", e).into_bytes(); *out_length = bytes.len() as i32; *out_capacity = bytes.capacity() as i32; - let ptr = bytes.as_mut_ptr(); - std::mem::forget(bytes); - ptr + let wrapper = ManuallyDrop::new(bytes); + wrapper.as_ptr() } } } diff --git a/rust-src/concordium_base/CHANGELOG.md b/rust-src/concordium_base/CHANGELOG.md index 0e0e8d8ab..7532198ac 100644 --- a/rust-src/concordium_base/CHANGELOG.md +++ b/rust-src/concordium_base/CHANGELOG.md @@ -1,8 +1,5 @@ ## Unreleased changes -- Add extern function `free_array_len_cap` such vector pointers can be released and deprecated `free_array_len` - since it didn't account for capacity size. - ## 3.2.0 (2023-11-22) - Add `From` trait to convert `AccountKeys` into `AccountPublicKeys`. diff --git a/rust-src/concordium_base/src/ffi_helpers/common.rs b/rust-src/concordium_base/src/ffi_helpers/common.rs index a2d6f8400..98b199638 100644 --- a/rust-src/concordium_base/src/ffi_helpers/common.rs +++ b/rust-src/concordium_base/src/ffi_helpers/common.rs @@ -1,10 +1,6 @@ #[no_mangle] /// Free an array that was converted to a pointer from a vector. /// This assumes the vector's capacity and length were the same. -#[deprecated( - note = "use [`free_array_len_cap`] instead since it correctly frees the whole capacity size \ - of the vector." -)] extern "C" fn free_array_len(ptr: *mut u8, len: u64) { unsafe { Vec::from_raw_parts(ptr, len as usize, len as usize); From ea7f966860412a8ce3ab0a02d11f890ca661eb1d Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:56:29 +0100 Subject: [PATCH 09/13] Update Idiss.cs --- idiss-csharp/IdissLib/Idiss.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/idiss-csharp/IdissLib/Idiss.cs b/idiss-csharp/IdissLib/Idiss.cs index e6da3bb72..314ff8435 100644 --- a/idiss-csharp/IdissLib/Idiss.cs +++ b/idiss-csharp/IdissLib/Idiss.cs @@ -44,7 +44,7 @@ private static extern IntPtr validate_recovery_request_cs([MarshalAs(UnmanagedTy [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity); [DllImport("idiss.dll")] - private static extern IntPtr free_array_len_cap(IntPtr array_ptr, int out_length, int out_capacity); + private static extern IntPtr free_array_len_cap(IntPtr array_ptr, uint out_length, uint out_capacity); /// The delta determining the time interval in which identity recovery requests should be accepted. /// Recovery request timestamps are accepted in the interval [currentTime - TimestampDelta, currentTime + TimestampDelta]. @@ -286,7 +286,7 @@ private static void FreeNonZeroPtr(IntPtr outputPtr, int outLength, int outCapac return; } - free_array_len_cap(outputPtr, outLength, outCapacity); + free_array_len_cap(outputPtr, checked((uint)outLength), checked((uint)outCapacity)); } } } From fcc3be2712c17620305c43e724d924b1b8dd3a76 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:43:55 +0100 Subject: [PATCH 10/13] Fix uint -> ulong --- idiss-csharp/IdissLib/Idiss.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/idiss-csharp/IdissLib/Idiss.cs b/idiss-csharp/IdissLib/Idiss.cs index 314ff8435..d5ea77eb8 100644 --- a/idiss-csharp/IdissLib/Idiss.cs +++ b/idiss-csharp/IdissLib/Idiss.cs @@ -44,7 +44,7 @@ private static extern IntPtr validate_recovery_request_cs([MarshalAs(UnmanagedTy [MarshalAs(UnmanagedType.LPArray)] byte[] request, int request_len, out int out_length, out int out_capacity); [DllImport("idiss.dll")] - private static extern IntPtr free_array_len_cap(IntPtr array_ptr, uint out_length, uint out_capacity); + private static extern IntPtr free_array_len_cap(IntPtr array_ptr, ulong out_length, ulong out_capacity); /// The delta determining the time interval in which identity recovery requests should be accepted. /// Recovery request timestamps are accepted in the interval [currentTime - TimestampDelta, currentTime + TimestampDelta]. @@ -286,7 +286,7 @@ private static void FreeNonZeroPtr(IntPtr outputPtr, int outLength, int outCapac return; } - free_array_len_cap(outputPtr, checked((uint)outLength), checked((uint)outCapacity)); + free_array_len_cap(outputPtr, checked((ulong)outLength), checked((ulong)outCapacity)); } } } From b338501b997fd65a503f771d30255deacdcab3e4 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:46:22 +0100 Subject: [PATCH 11/13] Fix comment --- rust-src/concordium_base/src/ffi_helpers/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-src/concordium_base/src/ffi_helpers/common.rs b/rust-src/concordium_base/src/ffi_helpers/common.rs index 98b199638..97be089da 100644 --- a/rust-src/concordium_base/src/ffi_helpers/common.rs +++ b/rust-src/concordium_base/src/ffi_helpers/common.rs @@ -8,7 +8,7 @@ extern "C" fn free_array_len(ptr: *mut u8, len: u64) { } #[no_mangle] -/// Free an array that was converted to a pointer from a vector. +/// Free a vector from its raw pointer, length and capacity. extern "C" fn free_array_len_cap(ptr: *mut u8, len: u64, cap: u64) { unsafe { Vec::from_raw_parts(ptr, len as usize, cap as usize); From 75f58046e3d955ff270653c118959d48d9c365c0 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:55:44 +0100 Subject: [PATCH 12/13] Change to minor bump --- idiss/CHANGELOG.md | 2 +- idiss/Cargo.lock | 2 +- idiss/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/idiss/CHANGELOG.md b/idiss/CHANGELOG.md index 8b37dc6d6..82c7ba1c5 100644 --- a/idiss/CHANGELOG.md +++ b/idiss/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 1.0.0 +## 0.7.0 - Updated interfaces used by feature `csharp` to include a reference pointer which sets the capacity of the array returned. - Add dependency to feature `ffi` from `concordium_base` since `free_array_len_cap` is now exported from the `ffi_helpers` module. diff --git a/idiss/Cargo.lock b/idiss/Cargo.lock index a3a30ad95..756ac175e 100644 --- a/idiss/Cargo.lock +++ b/idiss/Cargo.lock @@ -756,7 +756,7 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idiss" -version = "1.0.0" +version = "0.7.0" dependencies = [ "anyhow", "byteorder", diff --git a/idiss/Cargo.toml b/idiss/Cargo.toml index 955b7d421..185e8fabb 100644 --- a/idiss/Cargo.toml +++ b/idiss/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "idiss" build = "build.rs" -version = "1.0.0" +version = "0.7.0" authors = ["Concordium AG "] edition = "2018" license-file = "../../LICENSE-APACHE" From a37d5e4d522a179404489012003736aed17190b2 Mon Sep 17 00:00:00 2001 From: schwartz-concordium <132270889+schwartz-concordium@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:57:16 +0100 Subject: [PATCH 13/13] better naming --- rust-src/concordium_base/src/ffi_helpers/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-src/concordium_base/src/ffi_helpers/common.rs b/rust-src/concordium_base/src/ffi_helpers/common.rs index 97be089da..4224b0c56 100644 --- a/rust-src/concordium_base/src/ffi_helpers/common.rs +++ b/rust-src/concordium_base/src/ffi_helpers/common.rs @@ -8,7 +8,7 @@ extern "C" fn free_array_len(ptr: *mut u8, len: u64) { } #[no_mangle] -/// Free a vector from its raw pointer, length and capacity. +/// Free a vector using its raw pointer, length and capacity. extern "C" fn free_array_len_cap(ptr: *mut u8, len: u64, cap: u64) { unsafe { Vec::from_raw_parts(ptr, len as usize, cap as usize);