Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make SVG work in autofill credential view (#771)
Leendert de Borsta86896ee9959
diff --git a/mobile-app/ios/Autofill/CredentialProviderView.swift b/mobile-app/ios/Autofill/CredentialProviderView.swiftindex d14c56a1e..f2ac16b4e 100644--- a/mobile-app/ios/Autofill/CredentialProviderView.swift+++ b/mobile-app/ios/Autofill/CredentialProviderView.swift@@ -1,30 +1,53 @@import SwiftUIimport AuthenticationServices-+import Macawlet placeholderImageBase64 = "UklGRjoEAABXRUJQVlA4IC4EAAAwFwCdASqAAIAAPpFCm0olo6Ihp5IraLASCWUA0eb/0s56RrLtCnYfLPiBshdXWMx8j1Ez65f169iA4xUDBTEV6ylMQeCIj2b7RngGi7gKZ9WjKdSoy9R8JcgOmjCMlDmLG20KhNo/i/Dc/Ah5GAvGfm8kfniV3AkR6fxN6eKwjDc6xrDgSfS48G5uGV6WzQt24YAVlLSK9BMwndzfHnePK1KFchFrL7O3ulB8cGNCeomu4o+l0SrS/JKblJ4WTzj0DAD++lCUEouSfgRKdiV2TiYCD+H+l3tANKSPQFPQuzi7rbvxqGeRmXB9kDwURaoSTTpYjA9REMUi9uA6aV7PWtBNXgUzMLowYMZeos6Xvyhb34GmufswMHA5ZyYpxzjTphOak4ZjNOiz8aScO5ygiTx99SqwX/uL+HSeVOSraHw8IymrMwm+jLxqN8BS8dGcItLlm/ioulqH2j4V8glDgSut+ExkxiD7m8TGPrrjCQNJbRDzpOFsyCyfBZupvp8QjGKW2KGziSZeIWes4aTB9tRmeEBhnUrmTDZQuXcc67Fg82KHrSfaeeOEq6jjuUjQ8wUnzM4Zz3dhrwSyslVz/WvnKqYkr4V/TTXPFF5EjF4rM1bHZ8bK63EfTnK41+n3n4gEFoYP4mXkNH0hntnYcdTqiE7Gn+q0BpRRxnkpBSZlA6Wa70jpW0FGqkw5e591A5/H+OV+60WAo+4Mi+NlsKrvLZ9EiVaPnoEFZlJQx1fA777AJ2MjXJ4KSsrWDWJi1lE8yPs8V6XvcC0chDTYt8456sKXAagCZyY+fzQriFMaddXyKQdG8qBqcdYjAsiIcjzaRFBBoOK9sU+sFY7N6B6+xtrlu3c37rQKkI3O2EoiJOris54EjJ5OFuumA0M6riNUuBf/MEPFBVx1JRcUEs+upEBsCnwYski7FT3TTqHrx7v5AjgFN97xhPTkmVpu6sxRnWBi1fxIRp8eWZeFM6mUcGgVk1WeVb1yhdV9hoMo2TsNEPE0tHo/wvuSJSzbZo7wibeXM9v/rRfKcx7X93rfiXVnyQ9f/5CaAQ4lxedPp/6uzLtOS4FyL0bCNeZ6L5w+AiuyWCTDFIYaUzhwfG+/YTQpWyeZCdQIKzhV+3GeXI2cxoP0ER/DlOKymf1gm+zRU3sqf1lBVQ0y+mK/Awl9bS3uaaQmI0FUyUwHUKP7PKuXnO+LcwDv4OfPT6hph8smc1EtMe5ib/apar/qZ9dyaEaElALJ1KKxnHziuvVl8atk1fINSQh7OtXDyqbPw9o/nGIpTnv5iFmwmWJLis2oyEgPkJqyx0vYI8rjkVEzKc8eQavAJBYSpjMwM193Swt+yJyjvaGYWPnqExxKiNarpB2WSO7soCAZXhS1uEYHryrK47BH6W1dRiruqT0xpLih3MXiwU3VDwAAAA=="+// Add Color extension for hex support+extension SwiftUI.Color {+ init(hex: String) {+ let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)+ var int: UInt64 = 0+ Scanner(string: hex).scanHexInt64(&int)+ let a, r, g, b: UInt64+ switch hex.count {+ case 3: (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)+ case 6: (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)+ case 8: (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)+ default: (a, r, g, b) = (255, 0, 0, 0)+ }+ self.init(+ .sRGB,+ red: Double(r) / 255,+ green: Double(g) / 255,+ blue: Double(b) / 255,+ opacity: Double(a) / 255+ )+ }+}+struct ColorConstants {struct Light {- static let text = Color(hex: "#11181C")- static let textMuted = Color(hex: "#4b5563")- static let background = Color(hex: "#ffffff")- static let accentBackground = Color(hex: "#fff")- static let accentBorder = Color(hex: "#d1d5db")- static let primary = Color(hex: "#f49541")- static let secondary = Color(hex: "#6b7280")- static let icon = Color(hex: "#687076")+ static let text = SwiftUI.Color(hex: "#11181C")+ static let textMuted = SwiftUI.Color(hex: "#4b5563")+ static let background = SwiftUI.Color(hex: "#ffffff")+ static let accentBackground = SwiftUI.Color(hex: "#fff")+ static let accentBorder = SwiftUI.Color(hex: "#d1d5db")+ static let primary = SwiftUI.Color(hex: "#f49541")+ static let secondary = SwiftUI.Color(hex: "#6b7280")+ static let icon = SwiftUI.Color(hex: "#687076")}struct Dark {- static let text = Color(hex: "#ECEDEE")- static let textMuted = Color(hex: "#9BA1A6")- static let background = Color(hex: "#111827")- static let accentBackground = Color(hex: "#1f2937")- static let accentBorder = Color(hex: "#4b5563")- static let primary = Color(hex: "#f49541")- static let secondary = Color(hex: "#6b7280")- static let icon = Color(hex: "#9BA1A6")+ static let text = SwiftUI.Color(hex: "#ECEDEE")+ static let textMuted = SwiftUI.Color(hex: "#9BA1A6")+ static let background = SwiftUI.Color(hex: "#111827")+ static let accentBackground = SwiftUI.Color(hex: "#1f2937")+ static let accentBorder = SwiftUI.Color(hex: "#4b5563")+ static let primary = SwiftUI.Color(hex: "#f49541")+ static let secondary = SwiftUI.Color(hex: "#6b7280")+ static let icon = SwiftUI.Color(hex: "#9BA1A6")}}@@ -128,27 +151,88 @@ struct ServiceLogoView: View {return nil}+ private func detectMimeType(_ data: Data) -> String {+ // Check for SVG+ if let str = String(data: data.prefix(5), encoding: .utf8)?.lowercased(),+ str.contains("<?xml") || str.contains("<svg") {+ return "image/svg+xml"+ }++ // Check file signature for PNG+ let bytes = [UInt8](data.prefix(4))+ if bytes.count >= 4 &&+ bytes[0] == 0x89 && bytes[1] == 0x50 &&+ bytes[2] == 0x4E && bytes[3] == 0x47 {+ return "image/png"+ }++ return "image/x-icon"+ }++ private func renderSVGNode(_ data: Data) -> Node? {+ if let svgString = String(data: data, encoding: .utf8) {+ return try? SVGParser.parse(text: svgString)+ }+ return nil+ }++ struct SVGImageView: UIViewRepresentable {+ let node: Node++ func makeUIView(context: Context) -> MacawView {+ let macawView = MacawView(node: node, frame: CGRect(x: 0, y: 0, width: 32, height: 32))+ macawView.backgroundColor = .clear+ macawView.contentMode = .scaleAspectFit+ macawView.node.place = Transform.identity+ return macawView+ }++ func updateUIView(_ uiView: MacawView, context: Context) {+ uiView.node = node+ uiView.backgroundColor = .clear+ uiView.contentMode = .scaleAspectFit+ uiView.node.place = Transform.identity+ }+ }+var body: some View {Group {- if let logoData = logoData, let image = UIImage(data: logoData) {- Image(uiImage: image)- .resizable()- .aspectRatio(contentMode: .fit)- .frame(width: 40, height: 40)+ if let logoData = logoData {+ let mimeType = detectMimeType(logoData)+ if mimeType == "image/svg+xml",+ let svgNode = renderSVGNode(logoData) {+ SVGImageView(node: svgNode)+ .frame(width: 32, height: 32)+ .clipShape(RoundedRectangle(cornerRadius: 4))+ } else if let image = UIImage(data: logoData) {+ Image(uiImage: image)+ .resizable()+ .aspectRatio(contentMode: .fit)+ .frame(width: 32, height: 32)+ .clipShape(RoundedRectangle(cornerRadius: 4))+ } else if let placeholder = placeholderImage {+ Image(uiImage: placeholder)+ .resizable()+ .aspectRatio(contentMode: .fit)+ .frame(width: 32, height: 32)+ .clipShape(RoundedRectangle(cornerRadius:4))+ }} else if let placeholder = placeholderImage {Image(uiImage: placeholder).resizable().aspectRatio(contentMode: .fit)- .frame(width: 40, height: 40)+ .frame(width: 32, height: 32)+ .clipShape(RoundedRectangle(cornerRadius: 4))} else {// Ultimate fallback if placeholder fails to loadCircle().fill(colorScheme == .dark ? ColorConstants.Dark.accentBackground : ColorConstants.Light.background)- .frame(width: 40, height: 40)+ .frame(width: 32, height: 32).overlay(Circle().stroke(colorScheme == .dark ? ColorConstants.Dark.accentBorder : ColorConstants.Light.accentBorder, lineWidth: 1))+ .clipShape(RoundedRectangle(cornerRadius: 4))}}}@@ -164,7 +248,7 @@ struct CredentialCard: View {HStack(spacing: 16) {// Service logoServiceLogoView(logoData: credential.service.logo)- .frame(width: 40, height: 40)+ .frame(width: 32, height: 32)VStack(alignment: .leading, spacing: 4) {Text(credential.service.name ?? "Unknown Service")@@ -181,13 +265,13 @@ struct CredentialCard: View {Image(systemName: "chevron.right").foregroundColor(colorScheme == .dark ? ColorConstants.Dark.icon : ColorConstants.Light.icon)}- .padding(16)+ .padding(12).background(colorScheme == .dark ? ColorConstants.Dark.accentBackground : ColorConstants.Light.background).overlay(- RoundedRectangle(cornerRadius: 12)+ RoundedRectangle(cornerRadius: 8).stroke(colorScheme == .dark ? ColorConstants.Dark.accentBorder : ColorConstants.Light.accentBorder, lineWidth: 1))- .cornerRadius(12)+ .cornerRadius(8)}}}@@ -410,29 +494,135 @@ class CredentialProviderViewModel: ObservableObject {}}-// Add Color extension for hex support-extension Color {- init(hex: String) {- let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)- var int: UInt64 = 0- Scanner(string: hex).scanHexInt64(&int)- let a, r, g, b: UInt64- switch hex.count {- case 3: // RGB (12-bit)- (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)- case 6: // RGB (24-bit)- (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)- case 8: // ARGB (32-bit)- (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)- default:- (a, r, g, b) = (1, 1, 1, 0)- }- self.init(- .sRGB,- red: Double(r) / 255,- green: Double(g) / 255,- blue: Double(b) / 255,- opacity: Double(a) / 255+// MARK: - Preview Helpers+extension Service {+ static var preview: Service {+ Service(+ id: UUID(),+ name: "Example Service",+ url: "https://example.com",+ logo: Data(base64Encoded: placeholderImageBase64),+ createdAt: Date(),+ updatedAt: Date(),+ isDeleted: false+ )+ }+}++extension Password {+ static var preview: Password {+ Password(+ id: UUID(),+ credentialId: UUID(),+ value: "password123",+ createdAt: Date(),+ updatedAt: Date(),+ isDeleted: false+ )+ }+}++extension Alias {+ static var preview: Alias {+ Alias(+ id: UUID(),+ gender: "Not specified",+ firstName: "John",+ lastName: "Doe",+ nickName: "JD",+ birthDate: Date(),+ email: "[email protected]",+ createdAt: Date(),+ updatedAt: Date(),+ isDeleted: false+ )+ }+}++extension Credential {+ static var preview: Credential {+ Credential(+ id: UUID(),+ alias: .preview,+ service: .preview,+ username: "johndoe",+ notes: "Sample credential",+ password: .preview,+ createdAt: Date(),+ updatedAt: Date(),+ isDeleted: false)}}++class PreviewCredentialProviderViewModel: CredentialProviderViewModel {+ override init(extensionContext: ASCredentialProviderExtensionContext? = nil) {+ super.init(extensionContext: nil)+ self.credentials = [+ .preview,+ Credential(+ id: UUID(),+ alias: .preview,+ service: Service(+ id: UUID(),+ name: "Another Service",+ url: "https://another.com",+ logo: nil,+ createdAt: Date(),+ updatedAt: Date(),+ isDeleted: false+ ),+ username: "anotheruser",+ notes: "Another sample credential",+ password: .preview,+ createdAt: Date(),+ updatedAt: Date(),+ isDeleted: false+ )+ ]+ self.filteredCredentials = self.credentials+ self.isLoading = false+ }+}++struct CredentialProviderView_Previews: PreviewProvider {+ static var previews: some View {+ Group {+ // Light mode preview+ CredentialProviderView(viewModel: PreviewCredentialProviderViewModel())+ .preferredColorScheme(.light)+ .previewDisplayName("Light Mode")++ // Dark mode preview+ CredentialProviderView(viewModel: PreviewCredentialProviderViewModel())+ .preferredColorScheme(.dark)+ .previewDisplayName("Dark Mode")++ // Loading state preview+ CredentialProviderView(viewModel: {+ let vm = PreviewCredentialProviderViewModel()+ vm.isLoading = true+ return vm+ }())+ .previewDisplayName("Loading State")++ // Empty state preview+ CredentialProviderView(viewModel: {+ let vm = PreviewCredentialProviderViewModel()+ vm.credentials = []+ vm.filteredCredentials = []+ return vm+ }())+ .previewDisplayName("Empty State")++ // Search state preview+ CredentialProviderView(viewModel: {+ let vm = PreviewCredentialProviderViewModel()+ vm.searchText = "john"+ vm.filterCredentials()+ return vm+ }())+ .previewDisplayName("Search State")+ }+ }+}diff --git a/mobile-app/ios/Podfile b/mobile-app/ios/Podfileindex 245b777b4..457794050 100644--- a/mobile-app/ios/Podfile+++ b/mobile-app/ios/Podfile@@ -71,6 +71,7 @@ endtarget 'Autofill' dopod 'KeychainAccess', '~> 4.2.2'pod 'SQLite.swift', '~> 0.14.0'+ pod 'Macaw', '~> 0.9.7'endtarget 'VaultStoreTests' dodiff --git a/mobile-app/ios/Podfile.lock b/mobile-app/ios/Podfile.lockindex e5e97e2d1..5f2f3c5ae 100644--- a/mobile-app/ios/Podfile.lock+++ b/mobile-app/ios/Podfile.lock@@ -281,6 +281,8 @@ PODS:- hermes-engine/Pre-built (= 0.76.9)- hermes-engine/Pre-built (0.76.9)- KeychainAccess (4.2.2)+ - Macaw (0.9.10):+ - SWXMLHash- OpenSSL-Universal (3.3.3001)- RCT-Folly (2024.10.14.00):- boost@@ -2170,6 +2172,7 @@ PODS:- SQLite.swift (0.14.1):- SQLite.swift/standard (= 0.14.1)- SQLite.swift/standard (0.14.1)+ - SWXMLHash (7.0.2)- Yoga (0.0.0)DEPENDENCIES:@@ -2207,6 +2210,7 @@ DEPENDENCIES:- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)- KeychainAccess (~> 4.2.2)+ - Macaw (~> 0.9.7)- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)- RCT-Folly/Fabric (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)- RCTDeprecation (from `../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)@@ -2283,9 +2287,11 @@ SPEC REPOS:trunk:- CatCrypto- KeychainAccess+ - Macaw- OpenSSL-Universal- SocketRocket- SQLite.swift+ - SWXMLHashEXTERNAL SOURCES:boost:@@ -2528,6 +2534,7 @@ SPEC CHECKSUMS:glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6ahermes-engine: 9e868dc7be781364296d6ee2f56d0c1a9ef0bb11KeychainAccess: c0c4f7f38f6fc7bbe58f5702e25f7bd2f65abf51+ Macaw: 7af8ea57aa2cab35b4a52a45e6f85eea753ea9aeOpenSSL-Universal: 6082b0bf950e5636fe0d78def171184e2b3899c2RCT-Folly: ea9d9256ba7f9322ef911169a9f696e5857b9e17RCTDeprecation: ebe712bb05077934b16c6bf25228bdec34b64f83@@ -2598,8 +2605,9 @@ SPEC CHECKSUMS:RNSVG: 3a1cce2e940268a7d3554e3cf2bbd2195871f4feSocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748SQLite.swift: 2992550ebf3c5b268bf4352603e3df87d2a4ed72+ SWXMLHash: dd733a457e9c4fe93b1538654057aefae4acb382Yoga: feb4910aba9742cfedc059e2b2902e22ffe9954a-PODFILE CHECKSUM: e59cf67cb78ba2a84cafbd801ecd808fa31a9a45+PODFILE CHECKSUM: 667ccd24947933a6749a53afdd8b0323040c64b6COCOAPODS: 1.16.2diff --git a/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj b/mobile-app/ios/aliasvault.xcodeproj/project.pbxprojindex 1fa2ea581..ef8a6b62b 100644--- a/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj+++ b/mobile-app/ios/aliasvault.xcodeproj/project.pbxproj@@ -3,7 +3,7 @@archiveVersion = 1;classes = {};- objectVersion = 70;+ objectVersion = 60;objects = {/* Begin PBXBuildFile section */@@ -94,7 +94,7 @@/* End PBXFileReference section *//* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */- CE9A5BBB2DBBB60D00CB0A4C /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {+ CE9A5BBB2DBBB60D00CB0A4C /* Exceptions for "Models" folder in "VaultStoreTests" target */ = {isa = PBXFileSystemSynchronizedBuildFileExceptionSet;membershipExceptions = (AuthMethods.swift,@@ -102,7 +102,7 @@);target = CE9A5BAF2DBBB47200CB0A4C /* VaultStoreTests */;};- CEE9098F2DA548C7008D568F /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {+ CEE9098F2DA548C7008D568F /* Exceptions for "Autofill" folder in "Autofill" target */ = {isa = PBXFileSystemSynchronizedBuildFileExceptionSet;membershipExceptions = (Info.plist,@@ -112,9 +112,41 @@/* End PBXFileSystemSynchronizedBuildFileExceptionSet section *//* Begin PBXFileSystemSynchronizedRootGroup section */- CE9A5B592DBAE06400CB0A4C /* Models */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (CE9A5BBB2DBBB60D00CB0A4C /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Models; sourceTree = "<group>"; };- CE9A5BB12DBBB47200CB0A4C /* VaultStoreTests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultStoreTests; sourceTree = "<group>"; };- CEE909812DA548C7008D568F /* Autofill */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (CEE9098F2DA548C7008D568F /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Autofill; sourceTree = "<group>"; };+ CE9A5B592DBAE06400CB0A4C /* Models */ = {+ isa = PBXFileSystemSynchronizedRootGroup;+ exceptions = (+ CE9A5BBB2DBBB60D00CB0A4C /* Exceptions for "Models" folder in "VaultStoreTests" target */,+ );+ explicitFileTypes = {+ };+ explicitFolders = (+ );+ path = Models;+ sourceTree = "<group>";+ };+ CE9A5BB12DBBB47200CB0A4C /* VaultStoreTests */ = {+ isa = PBXFileSystemSynchronizedRootGroup;+ exceptions = (+ );+ explicitFileTypes = {+ };+ explicitFolders = (+ );+ path = VaultStoreTests;+ sourceTree = "<group>";+ };+ CEE909812DA548C7008D568F /* Autofill */ = {+ isa = PBXFileSystemSynchronizedRootGroup;+ exceptions = (+ CEE9098F2DA548C7008D568F /* Exceptions for "Autofill" folder in "Autofill" target */,+ );+ explicitFileTypes = {+ };+ explicitFolders = (+ );+ path = Autofill;+ sourceTree = "<group>";+ };/* End PBXFileSystemSynchronizedRootGroup section *//* Begin PBXFrameworksBuildPhase section */@@ -756,7 +788,10 @@LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";MTL_ENABLE_DEBUG_INFO = YES;ONLY_ACTIVE_ARCH = YES;- OTHER_LDFLAGS = "$(inherited) ";+ OTHER_LDFLAGS = (+ "$(inherited)",+ " ",+ );REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";SDKROOT = iphoneos;SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";@@ -811,7 +846,10 @@);LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";MTL_ENABLE_DEBUG_INFO = NO;- OTHER_LDFLAGS = "$(inherited) ";+ OTHER_LDFLAGS = (+ "$(inherited)",+ " ",+ );REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";SDKROOT = iphoneos;USE_HERMES = true;