1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Hinton
4bdbc30873 Dylib 2023-04-27 14:38:32 +02:00
Hinton
39bfda0a24 Add linking instruction everywhere 2023-04-24 15:44:41 +02:00
Hinton
3172b0d571 Use aarch64-apple-ios instead 2023-04-24 15:17:52 +02:00
Hinton
464d1f8a9a test 2023-04-24 14:57:12 +02:00
11 changed files with 185 additions and 0 deletions

BIN
lib/ios/libbitwarden_c.a Normal file

Binary file not shown.

View File

@@ -11,6 +11,21 @@ namespace Bit.iOS.Autofill
get; set;
}
public override void FinishedLaunching(UIApplication application)
{
var ln = @"libbitwarden_c.framework/libbitwarden_c";
var documentsPath = NSBundle.MainBundle.BundlePath;
var filePath = System.IO.Path.Combine(documentsPath, "Frameworks", ln);
var ptr = ObjCRuntime.Dlfcn.dlopen(filePath, 0);
var sdkClient = new BitwardenClient();
var test = sdkClient.Fingerprint();
base.FinishedLaunching(application);
}
public override void OnResignActivation(UIApplication application)
{
}

View File

@@ -0,0 +1,31 @@
using System;
namespace Bit.iOS
{
public class BitwardenClient : IDisposable
{
private readonly BitwardenClientSafeHandle handle;
public BitwardenClient()
{
handle = BitwardenClientWrapper.init("");
}
public string Fingerprint()
{
return BitwardenClientWrapper.run_command("{}", handle.Ptr);
}
protected virtual void Dispose(bool disposing)
{
if (handle != null && !handle.IsInvalid)
handle.Dispose();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using Microsoft.Win32.SafeHandles;
namespace Bit.iOS
{
internal class BitwardenClientSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public BitwardenClientSafeHandle() : base(true) { }
public IntPtr Ptr => this.handle;
protected override bool ReleaseHandle()
{
BitwardenClientWrapper.free_mem(handle);
return true;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Runtime.InteropServices;
namespace Bit.iOS
{
internal static class BitwardenClientWrapper
{
#if Android
const string DllName = "libBitwardenC.so";
#else
const string DllName = "__Internal";
#endif
[DllImport(DllName, EntryPoint = "init")]
internal static extern BitwardenClientSafeHandle init(string settings);
[DllImport(DllName, EntryPoint = "free_mem")]
internal static extern void free_mem(IntPtr clientPtr);
[DllImport(DllName, EntryPoint = "run_command")]
internal static extern string run_command(string loginRequest, IntPtr clientPtr);
}
}

View File

@@ -194,6 +194,9 @@
<InterfaceDefinition Include="MainInterface.storyboard" />
<BundleResource Include="Resources\MaterialIcons_Regular.ttf" />
<BundleResource Include="Resources\bwi-font.ttf" />
<Compile Include="BitwardenClient.cs" />
<Compile Include="BitwardenClientSafeHandle.cs" />
<Compile Include="BitwardenClientWrapper.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
@@ -278,5 +281,11 @@
<ItemGroup>
<BundleResource Include="Resources\yubikey%403x.png" />
</ItemGroup>
<ItemGroup>
<NativeReference Include="..\..\..\sdk\libbitwarden_c.framework">
<Kind>Framework</Kind>
<SmartLink>False</SmartLink>
</NativeReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.AppExtension.CSharp.targets" />
</Project>

View File

@@ -182,7 +182,15 @@ namespace Bit.iOS
LoggerHelper.LogEvenIfCantBeResolved(ex);
}
});
var ln = @"libbitwarden_c.framework/libbitwarden_c";
var documentsPath = NSBundle.MainBundle.BundlePath;
var filePath = System.IO.Path.Combine(documentsPath, "Frameworks", ln);
var ptr = ObjCRuntime.Dlfcn.dlopen(filePath, 0);
var sdkClient = new BitwardenClient();
var test = sdkClient.Fingerprint();
return base.FinishedLaunching(app, options);
}

View File

@@ -0,0 +1,31 @@
using System;
namespace Bit.iOS
{
public class BitwardenClient : IDisposable
{
private readonly BitwardenClientSafeHandle handle;
public BitwardenClient()
{
handle = BitwardenClientWrapper.init("");
}
public string Fingerprint()
{
return BitwardenClientWrapper.run_command("{}", handle.Ptr);
}
protected virtual void Dispose(bool disposing)
{
if (handle != null && !handle.IsInvalid)
handle.Dispose();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using Microsoft.Win32.SafeHandles;
namespace Bit.iOS
{
internal class BitwardenClientSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public BitwardenClientSafeHandle() : base(true) { }
public IntPtr Ptr => this.handle;
protected override bool ReleaseHandle()
{
BitwardenClientWrapper.free_mem(handle);
return true;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Runtime.InteropServices;
namespace Bit.iOS
{
internal static class BitwardenClientWrapper
{
#if Android
const string DllName = "libBitwardenC.so";
#else
const string DllName = "__Internal";
#endif
[DllImport(DllName, EntryPoint = "init")]
internal static extern BitwardenClientSafeHandle init(string settings);
[DllImport(DllName, EntryPoint = "free_mem")]
internal static extern void free_mem(IntPtr clientPtr);
[DllImport(DllName, EntryPoint = "run_command")]
internal static extern string run_command(string loginRequest, IntPtr clientPtr);
}
}

View File

@@ -183,6 +183,9 @@
<ImageAsset Include="Resources\Assets.xcassets\empty_items_state.imageset\Empty-items-state-dark.pdf" />
<ImageAsset Include="Resources\Assets.xcassets\empty_items_state.imageset\Empty-items-state.pdf" />
<ImageAsset Include="Resources\Assets.xcassets\empty_items_state.imageset\Contents.json" />
<Compile Include="BitwardenClient.cs" />
<Compile Include="BitwardenClientSafeHandle.cs" />
<Compile Include="BitwardenClientWrapper.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="LaunchScreen.storyboard" />
@@ -424,6 +427,12 @@
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<_ResolvedWatchAppReferences Include="$(WatchAppBundleFullPath)" />
</ItemGroup>
<ItemGroup>
<NativeReference Include="..\..\..\sdk\libbitwarden_c.framework">
<Kind>Framework</Kind>
<SmartLink>False</SmartLink>
</NativeReference>
</ItemGroup>
<PropertyGroup Condition=" '$(_ResolvedWatchAppReferences)' != '' ">
<CodesignExtraArgs>--deep</CodesignExtraArgs>
</PropertyGroup>