async public Task HkdfoExpand_OutputTooBig_Throws(PclCryptoFunctionService sut)
        {
            var exception = await Assert.ThrowsAsync <ArgumentException>(
                () => sut.HkdfExpandAsync(Convert.FromBase64String(prk32Byte), "info", 8161, HkdfAlgorithm.Sha256));

            Assert.Contains("too large", exception.Message);
        }
        async public Task HkdfExpand_PrkTooSmall_Throws(PclCryptoFunctionService sut)
        {
            var exception = await Assert.ThrowsAsync <ArgumentException>(
                () => sut.HkdfExpandAsync(Convert.FromBase64String(prk16Byte), "info", 32, HkdfAlgorithm.Sha256));

            Assert.Contains("too small", exception.Message);
        }
Пример #3
0
        public static void RegisterLocalServices()
        {
            if (ServiceContainer.Resolve <INativeLogService>("nativeLogService", true) == null)
            {
                ServiceContainer.Register <INativeLogService>("nativeLogService", new ConsoleLogService());
            }

            ILogger logger = null;

            if (ServiceContainer.Resolve <ILogger>("logger", true) == null)
            {
#if DEBUG
                logger = DebugLogger.Instance;
#else
                logger = Logger.Instance;
#endif
                ServiceContainer.Register("logger", logger);
            }

            var preferencesStorage = new PreferencesStorageService(AppGroupId);
            var appGroupContainer  = new NSFileManager().GetContainerUrl(AppGroupId);
            var liteDbStorage      = new LiteDbStorageService(
                Path.Combine(appGroupContainer.Path, "Library", "bitwarden.db"));
            var localizeService      = new LocalizeService();
            var broadcasterService   = new BroadcasterService(logger);
            var messagingService     = new MobileBroadcasterMessagingService(broadcasterService);
            var i18nService          = new MobileI18nService(localizeService.GetCurrentCultureInfo());
            var secureStorageService = new KeyChainStorageService(AppId, AccessGroup,
                                                                  () => ServiceContainer.Resolve <IAppIdService>("appIdService").GetAppIdAsync());
            var cryptoPrimitiveService = new CryptoPrimitiveService();
            var mobileStorageService   = new MobileStorageService(preferencesStorage, liteDbStorage);
            var stateService           = new StateService(mobileStorageService, secureStorageService, messagingService);
            var stateMigrationService  =
                new StateMigrationService(liteDbStorage, preferencesStorage, secureStorageService);
            var deviceActionService  = new DeviceActionService(stateService, messagingService);
            var clipboardService     = new ClipboardService(stateService);
            var platformUtilsService = new MobilePlatformUtilsService(deviceActionService, clipboardService,
                                                                      messagingService, broadcasterService);
            var biometricService        = new BiometricService(mobileStorageService);
            var cryptoFunctionService   = new PclCryptoFunctionService(cryptoPrimitiveService);
            var cryptoService           = new CryptoService(stateService, cryptoFunctionService);
            var passwordRepromptService = new MobilePasswordRepromptService(platformUtilsService, cryptoService);

            ServiceContainer.Register <IBroadcasterService>("broadcasterService", broadcasterService);
            ServiceContainer.Register <IMessagingService>("messagingService", messagingService);
            ServiceContainer.Register <ILocalizeService>("localizeService", localizeService);
            ServiceContainer.Register <II18nService>("i18nService", i18nService);
            ServiceContainer.Register <ICryptoPrimitiveService>("cryptoPrimitiveService", cryptoPrimitiveService);
            ServiceContainer.Register <IStorageService>("storageService", mobileStorageService);
            ServiceContainer.Register <IStorageService>("secureStorageService", secureStorageService);
            ServiceContainer.Register <IStateService>("stateService", stateService);
            ServiceContainer.Register <IStateMigrationService>("stateMigrationService", stateMigrationService);
            ServiceContainer.Register <IDeviceActionService>("deviceActionService", deviceActionService);
            ServiceContainer.Register <IClipboardService>("clipboardService", clipboardService);
            ServiceContainer.Register <IPlatformUtilsService>("platformUtilsService", platformUtilsService);
            ServiceContainer.Register <IBiometricService>("biometricService", biometricService);
            ServiceContainer.Register <ICryptoFunctionService>("cryptoFunctionService", cryptoFunctionService);
            ServiceContainer.Register <ICryptoService>("cryptoService", cryptoService);
            ServiceContainer.Register <IPasswordRepromptService>("passwordRepromptService", passwordRepromptService);
        }
        async public Task HkdfExpand_Success(string expectedKey, HkdfAlgorithm algorithm, string prkString, int outputByteSize, string info, PclCryptoFunctionService sut)
        {
            var prk = Convert.FromBase64String(prkString);

            var key = await sut.HkdfExpandAsync(prk, info, outputByteSize, algorithm);

            Assert.Equal(expectedKey, Convert.ToBase64String(key));

            var keyFromByteArray = await sut.HkdfExpandAsync(prk, Encoding.UTF8.GetBytes(info), outputByteSize, algorithm);

            Assert.Equal(key, keyFromByteArray);
        }
        async public Task Hkdf_Success(string expectedKey, HkdfAlgorithm algorithm, string ikmString, string salt, string info, PclCryptoFunctionService sut)
        {
            byte[] ikm = Convert.FromBase64String(ikmString);

            var key = await sut.HkdfAsync(ikm, salt, info, 32, algorithm);

            Assert.Equal(expectedKey, Convert.ToBase64String(key));

            var keyFromByteArray = await sut.HkdfAsync(ikm, Encoding.UTF8.GetBytes(salt), Encoding.UTF8.GetBytes(info), 32, algorithm);

            Assert.Equal(key, keyFromByteArray);
        }
Пример #6
0
        public static void Init(string customUserAgent = null)
        {
            if (Inited)
            {
                return;
            }
            Inited = true;

            var           platformUtilsService   = Resolve <IPlatformUtilsService>("platformUtilsService");
            var           storageService         = Resolve <IStorageService>("storageService");
            var           secureStorageService   = Resolve <IStorageService>("secureStorageService");
            var           cryptoPrimitiveService = Resolve <ICryptoPrimitiveService>("cryptoPrimitiveService");
            var           i18nService            = Resolve <II18nService>("i18nService");
            var           messagingService       = Resolve <IMessagingService>("messagingService");
            SearchService searchService          = null;

            var stateService          = new StateService();
            var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService);
            var cryptoService         = new CryptoService(storageService, secureStorageService, cryptoFunctionService);
            var tokenService          = new TokenService(storageService);
            var apiService            = new ApiService(tokenService, platformUtilsService, (bool expired) =>
            {
                messagingService.Send("logout", expired);
                return(Task.FromResult(0));
            }, customUserAgent);
            var appIdService    = new AppIdService(storageService);
            var userService     = new UserService(storageService, tokenService);
            var settingsService = new SettingsService(userService, storageService);
            var cipherService   = new CipherService(cryptoService, userService, settingsService, apiService,
                                                    storageService, i18nService, () => searchService);
            var folderService = new FolderService(cryptoService, userService, apiService, storageService,
                                                  i18nService, cipherService);
            var collectionService = new CollectionService(cryptoService, userService, storageService, i18nService);

            searchService = new SearchService(cipherService);
            var lockService = new LockService(cryptoService, userService, platformUtilsService, storageService,
                                              folderService, cipherService, collectionService, searchService, messagingService, null);
            var policyService = new PolicyService(storageService, userService);
            var syncService   = new SyncService(userService, apiService, settingsService, folderService,
                                                cipherService, cryptoService, collectionService, storageService, messagingService, policyService,
                                                (bool expired) =>
            {
                messagingService.Send("logout", expired);
                return(Task.FromResult(0));
            });
            var passwordGenerationService = new PasswordGenerationService(cryptoService, storageService,
                                                                          cryptoFunctionService);
            var totpService = new TotpService(storageService, cryptoFunctionService);
            var authService = new AuthService(cryptoService, apiService, userService, tokenService, appIdService,
                                              i18nService, platformUtilsService, messagingService, lockService);
            var exportService      = new ExportService(folderService, cipherService);
            var auditService       = new AuditService(cryptoFunctionService, apiService);
            var environmentService = new EnvironmentService(apiService, storageService);
            var eventService       = new EventService(storageService, apiService, userService, cipherService);

            Register <IStateService>("stateService", stateService);
            Register <ICryptoFunctionService>("cryptoFunctionService", cryptoFunctionService);
            Register <ICryptoService>("cryptoService", cryptoService);
            Register <ITokenService>("tokenService", tokenService);
            Register <IApiService>("apiService", apiService);
            Register <IAppIdService>("appIdService", appIdService);
            Register <IUserService>("userService", userService);
            Register <ISettingsService>("settingsService", settingsService);
            Register <ICipherService>("cipherService", cipherService);
            Register <IFolderService>("folderService", folderService);
            Register <ICollectionService>("collectionService", collectionService);
            Register <ISearchService>("searchService", searchService);
            Register <IPolicyService>("policyService", policyService);
            Register <ISyncService>("syncService", syncService);
            Register <ILockService>("lockService", lockService);
            Register <IPasswordGenerationService>("passwordGenerationService", passwordGenerationService);
            Register <ITotpService>("totpService", totpService);
            Register <IAuthService>("authService", authService);
            Register <IExportService>("exportService", exportService);
            Register <IAuditService>("auditService", auditService);
            Register <IEnvironmentService>("environmentService", environmentService);
            Register <IEventService>("eventService", eventService);
        }
Пример #7
0
        private void RegisterLocalServices()
        {
            ServiceContainer.Register <ILogService>("logService", new AndroidLogService());

            // Note: This might cause a race condition. Investigate more.
            Task.Run(() =>
            {
                FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
                FFImageLoading.ImageService.Instance.Initialize(new FFImageLoading.Config.Configuration
                {
                    FadeAnimationEnabled         = false,
                    FadeAnimationForCachedImages = false,
                    HttpClient = new HttpClient(new AndroidClientHandler()
                    {
                        AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                    })
                });
                ZXing.Net.Mobile.Forms.Android.Platform.Init();
            });
            CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

            var preferencesStorage     = new PreferencesStorageService(null);
            var documentsPath          = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var liteDbStorage          = new LiteDbStorageService(Path.Combine(documentsPath, "bitwarden.db"));
            var localizeService        = new LocalizeService();
            var broadcasterService     = new BroadcasterService();
            var messagingService       = new MobileBroadcasterMessagingService(broadcasterService);
            var i18nService            = new MobileI18nService(localizeService.GetCurrentCultureInfo());
            var secureStorageService   = new SecureStorageService();
            var cryptoPrimitiveService = new CryptoPrimitiveService();
            var mobileStorageService   = new MobileStorageService(preferencesStorage, liteDbStorage);
            var deviceActionService    = new DeviceActionService(mobileStorageService, messagingService,
                                                                 broadcasterService, () => ServiceContainer.Resolve <IEventService>("eventService"));
            var platformUtilsService = new MobilePlatformUtilsService(deviceActionService, messagingService,
                                                                      broadcasterService);
            var biometricService        = new BiometricService();
            var cryptoFunctionService   = new PclCryptoFunctionService(cryptoPrimitiveService);
            var cryptoService           = new CryptoService(mobileStorageService, secureStorageService, cryptoFunctionService);
            var passwordRepromptService = new MobilePasswordRepromptService(platformUtilsService, cryptoService);

            ServiceContainer.Register <IBroadcasterService>("broadcasterService", broadcasterService);
            ServiceContainer.Register <IMessagingService>("messagingService", messagingService);
            ServiceContainer.Register <ILocalizeService>("localizeService", localizeService);
            ServiceContainer.Register <II18nService>("i18nService", i18nService);
            ServiceContainer.Register <ICryptoPrimitiveService>("cryptoPrimitiveService", cryptoPrimitiveService);
            ServiceContainer.Register <IStorageService>("storageService", mobileStorageService);
            ServiceContainer.Register <IStorageService>("secureStorageService", secureStorageService);
            ServiceContainer.Register <IClipboardService>("clipboardService", new ClipboardService(mobileStorageService));
            ServiceContainer.Register <IDeviceActionService>("deviceActionService", deviceActionService);
            ServiceContainer.Register <IPlatformUtilsService>("platformUtilsService", platformUtilsService);
            ServiceContainer.Register <IBiometricService>("biometricService", biometricService);
            ServiceContainer.Register <ICryptoFunctionService>("cryptoFunctionService", cryptoFunctionService);
            ServiceContainer.Register <ICryptoService>("cryptoService", cryptoService);
            ServiceContainer.Register <IPasswordRepromptService>("passwordRepromptService", passwordRepromptService);

            // Push
#if FDROID
            ServiceContainer.Register <IPushNotificationListenerService>(
                "pushNotificationListenerService", new NoopPushNotificationListenerService());
            ServiceContainer.Register <IPushNotificationService>(
                "pushNotificationService", new NoopPushNotificationService());
#else
            var notificationListenerService = new PushNotificationListenerService();
            ServiceContainer.Register <IPushNotificationListenerService>(
                "pushNotificationListenerService", notificationListenerService);
            var androidPushNotificationService = new AndroidPushNotificationService(
                mobileStorageService, notificationListenerService);
            ServiceContainer.Register <IPushNotificationService>(
                "pushNotificationService", androidPushNotificationService);
#endif
        }