access group for keychain. load sites for given hostname in extension

This commit is contained in:
Kyle Spearrin 2016-06-25 01:58:42 -04:00
parent 9d8f54af9d
commit 1307b6a1b2
12 changed files with 104 additions and 22 deletions

View file

@ -4,7 +4,7 @@ using Bit.App.Abstractions;
using Foundation; using Foundation;
using Security; using Security;
namespace Bit.iOS.Services namespace Bit.iOS.Core.Services
{ {
public class KeyChainStorageService : ISecureStorageService public class KeyChainStorageService : ISecureStorageService
{ {
@ -67,7 +67,8 @@ namespace Bit.iOS.Services
var record = new SecRecord(SecKind.GenericPassword) var record = new SecRecord(SecKind.GenericPassword)
{ {
Service = NSBundle.MainBundle.BundleIdentifier, Service = NSBundle.MainBundle.BundleIdentifier,
Account = key Account = key,
AccessGroup = "TEAMID.bitwarden"
}; };
if(data != null) if(data != null)

View file

@ -7,7 +7,7 @@ using MonoTouch.Foundation;
#endif #endif
using Plugin.Settings.Abstractions; using Plugin.Settings.Abstractions;
namespace Bit.iOS.Services namespace Bit.iOS.Core.Services
{ {
/// <summary> /// <summary>
/// Main implementation for ISettings /// Main implementation for ISettings

View file

@ -33,6 +33,14 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Plugin.Settings, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Settings.Abstractions, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SQLite-net, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="SQLite-net, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\sqlite-net-pcl.1.1.1\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll</HintPath> <HintPath>..\..\packages\sqlite-net-pcl.1.1.1\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@ -48,10 +56,14 @@
<ItemGroup> <ItemGroup>
<Compile Include="Constants.cs" /> <Compile Include="Constants.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Services\Settings.cs" />
<Compile Include="Services\SqlService.cs" /> <Compile Include="Services\SqlService.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\App\App.csproj"> <ProjectReference Include="..\App\App.csproj">

View file

@ -2,4 +2,5 @@
<packages> <packages>
<package id="sqlite-net-pcl" version="1.1.1" targetFramework="xamarinios10" /> <package id="sqlite-net-pcl" version="1.1.1" targetFramework="xamarinios10" />
<package id="SQLitePCL.raw" version="0.8.6" targetFramework="xamarinios10" /> <package id="SQLitePCL.raw" version="0.8.6" targetFramework="xamarinios10" />
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="xamarinios10" />
</packages> </packages>

View file

@ -2,20 +2,22 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Bit.App.Abstractions;
using Bit.iOS.Core; using Bit.iOS.Core;
using Bit.iOS.Extension.Models; using Bit.iOS.Extension.Models;
using Foundation; using Foundation;
using MobileCoreServices; using MobileCoreServices;
using Newtonsoft.Json; using Newtonsoft.Json;
using UIKit; using UIKit;
using Microsoft.Practices.Unity;
using XLabs.Ioc;
namespace Bit.iOS.Extension namespace Bit.iOS.Extension
{ {
public partial class ActionViewController : UIViewController public partial class ActionViewController : UIViewController
{ {
public ActionViewController(IntPtr handle) : base(handle) public ActionViewController(IntPtr handle) : base(handle)
{ { }
}
public Context Context { get; set; } public Context Context { get; set; }
@ -27,17 +29,20 @@ namespace Bit.iOS.Extension
base.ViewWillAppear(animated); base.ViewWillAppear(animated);
} }
public override void ViewDidLoad() public async override void ViewDidLoad()
{ {
base.ViewDidLoad(); base.ViewDidLoad();
List<Tuple<string, string>> sites = new List<Tuple<string, string>>(); Debug.WriteLine("BW LOG, Container");
for(int i = 1; i <= 100; i++) var siteService = Resolver.Resolve<ISiteService>();
{ Debug.WriteLine("BW LOG, siteService: " + siteService);
sites.Add(new Tuple<string, string>("Site " + i, "Username " + i)); var sites = await siteService.GetAllAsync();
} Debug.WriteLine("BW LOG, sites: " + sites.Count());
var siteModels = sites.Select(s => new SiteViewModel(s));
tableView.Source = new TableSource(sites, this); Debug.WriteLine("BW LOG, siteModels: " + siteModels.Count());
var filteredSiteModels = siteModels.Where(s => s.HostName == Context.Url?.Host);
Debug.WriteLine("BW LOG, filteredSiteModels: " + filteredSiteModels.Count());
tableView.Source = new TableSource(filteredSiteModels, this);
AutomaticallyAdjustsScrollViewInsets = false; AutomaticallyAdjustsScrollViewInsets = false;
} }
@ -59,11 +64,11 @@ namespace Bit.iOS.Extension
{ {
private const string CellIdentifier = "TableCell"; private const string CellIdentifier = "TableCell";
private IEnumerable<Tuple<string, string>> _tableItems; private IEnumerable<SiteViewModel> _tableItems;
private Context _context; private Context _context;
private ActionViewController _controller; private ActionViewController _controller;
public TableSource(IEnumerable<Tuple<string, string>> items, ActionViewController controller) public TableSource(IEnumerable<SiteViewModel> items, ActionViewController controller)
{ {
_tableItems = items; _tableItems = items;
_context = controller.Context; _context = controller.Context;
@ -86,8 +91,8 @@ namespace Bit.iOS.Extension
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier); cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier);
} }
cell.TextLabel.Text = item.Item1; cell.TextLabel.Text = item.Name;
cell.DetailTextLabel.Text = item.Item2; cell.DetailTextLabel.Text = item.Username;
return cell; return cell;
} }

View file

@ -6,5 +6,9 @@
<array> <array>
<string>group.com.8bit.bitwarden</string> <string>group.com.8bit.bitwarden</string>
</array> </array>
<key>keychain-access-groups</key>
<array>
<string>TEAMID.bitwarden</string>
</array>
</dict> </dict>
</plist> </plist>

View file

@ -14,6 +14,7 @@ using Bit.iOS.Core;
using Newtonsoft.Json; using Newtonsoft.Json;
using Bit.iOS.Extension.Models; using Bit.iOS.Extension.Models;
using MobileCoreServices; using MobileCoreServices;
using Plugin.Settings.Abstractions;
namespace Bit.iOS.Extension namespace Bit.iOS.Extension
{ {
@ -87,7 +88,7 @@ namespace Bit.iOS.Extension
// Services // Services
.RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager()) .RegisterType<IDatabaseService, DatabaseService>(new ContainerControlledLifetimeManager())
.RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager()) .RegisterType<ISqlService, SqlService>(new ContainerControlledLifetimeManager())
//.RegisterType<ISecureStorageService, KeyChainStorageService>(new ContainerControlledLifetimeManager()) .RegisterType<ISecureStorageService, KeyChainStorageService>(new ContainerControlledLifetimeManager())
.RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager()) .RegisterType<ICryptoService, CryptoService>(new ContainerControlledLifetimeManager())
.RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager()) .RegisterType<IAuthService, AuthService>(new ContainerControlledLifetimeManager())
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager()) .RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
@ -101,11 +102,13 @@ namespace Bit.iOS.Extension
.RegisterType<ISiteApiRepository, SiteApiRepository>(new ContainerControlledLifetimeManager()) .RegisterType<ISiteApiRepository, SiteApiRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager()); .RegisterType<IAuthApiRepository, AuthApiRepository>(new ContainerControlledLifetimeManager());
// Other // Other
//.RegisterInstance(CrossSettings.Current, new ContainerControlledLifetimeManager())
//.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager()) //.RegisterInstance(CrossConnectivity.Current, new ContainerControlledLifetimeManager())
//.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager()) //.RegisterInstance(UserDialogs.Instance, new ContainerControlledLifetimeManager())
//.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager()); //.RegisterInstance(CrossFingerprint.Current, new ContainerControlledLifetimeManager());
ISettings settings = new Settings("group.com.8bit.bitwarden");
container.RegisterInstance(settings, new ContainerControlledLifetimeManager());
Resolver.SetResolver(new UnityResolver(container)); Resolver.SetResolver(new UnityResolver(container));
} }

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using Bit.App.Models;
namespace Bit.iOS.Extension.Models
{
public class SiteViewModel
{
public SiteViewModel(Site site)
{
Id = site.Id;
Name = site.Name?.Decrypt();
Username = site.Username?.Decrypt();
Password = site.Password?.Decrypt();
Uri = site.Uri?.Decrypt();
}
public string Id { get; set; }
public string Name { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Uri { get; set; }
public string HostName
{
get
{
if(string.IsNullOrWhiteSpace(Uri))
{
return null;
}
try
{
return new Uri(Uri)?.Host;
}
catch
{
return null;
};
}
}
}
}

View file

@ -111,6 +111,7 @@
</Compile> </Compile>
<None Include="Info.plist" /> <None Include="Info.plist" />
<None Include="Entitlements.plist" /> <None Include="Entitlements.plist" />
<Compile Include="Models\SiteViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<InterfaceDefinition Include="MainInterface.storyboard" /> <InterfaceDefinition Include="MainInterface.storyboard" />
<None Include="packages.config"> <None Include="packages.config">
@ -118,6 +119,14 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Plugin.Settings, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Settings.Abstractions, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\Xamarin.iOS10\Plugin.Settings.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />

View file

@ -5,6 +5,7 @@
<package id="sqlite-net-pcl" version="1.1.1" targetFramework="xamarinios10" /> <package id="sqlite-net-pcl" version="1.1.1" targetFramework="xamarinios10" />
<package id="SQLitePCL.raw" version="0.8.6" targetFramework="xamarinios10" /> <package id="SQLitePCL.raw" version="0.8.6" targetFramework="xamarinios10" />
<package id="Unity" version="3.5.1405-prerelease" targetFramework="xamarinios10" /> <package id="Unity" version="3.5.1405-prerelease" targetFramework="xamarinios10" />
<package id="Xam.Plugins.Settings" version="2.1.0" targetFramework="xamarinios10" />
<package id="XLabs.IoC" version="2.0.5782" targetFramework="xamarinios10" /> <package id="XLabs.IoC" version="2.0.5782" targetFramework="xamarinios10" />
<package id="XLabs.IoC.Unity" version="2.0.5782" targetFramework="xamarinios10" /> <package id="XLabs.IoC.Unity" version="2.0.5782" targetFramework="xamarinios10" />
</packages> </packages>

View file

@ -6,5 +6,9 @@
<array> <array>
<string>group.com.8bit.bitwarden</string> <string>group.com.8bit.bitwarden</string>
</array> </array>
<key>keychain-access-groups</key>
<array>
<string>TEAMID.bitwarden</string>
</array>
</dict> </dict>
</plist> </plist>

View file

@ -110,10 +110,8 @@
<Compile Include="Controls\ExtendedEntryRenderer.cs" /> <Compile Include="Controls\ExtendedEntryRenderer.cs" />
<Compile Include="Controls\ExtendedTabbedPageRenderer.cs" /> <Compile Include="Controls\ExtendedTabbedPageRenderer.cs" />
<Compile Include="Services\ClipboardService.cs" /> <Compile Include="Services\ClipboardService.cs" />
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" /> <Compile Include="AppDelegate.cs" />
<Compile Include="Services\Settings.cs" />
<None Include="Entitlements.plist" /> <None Include="Entitlements.plist" />
<None Include="Info.plist" /> <None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />