Exemplo n.º 1
0
        // Use GenerateRandomDeviceId to generate a random device id only once per device,
        // store it and reuse later on subsequent logins.
        // Calling Vault.Open(username, password, Vault.GenerateRandomDeviceId(), ui) is
        // not a good idea. See bellow.
        public static Vault Open(string username, string password, string deviceId, Ui ui)
        {
            var clientInfo = new ClientInfo(username: username,
                                            password: password,
                                            deviceId: deviceId);
            using var transport = new RestTransport();

            return Open(clientInfo, ui, transport);
        }
Exemplo n.º 2
0
 // The main entry point. Use this function to open the vault in the CLI/API mode. In
 // this mode the login is fully non-interactive even with 2FA enabled. Bitwarden servers
 // don't use 2FA in this mode and permit to bypass it. There's no captcha in this mode
 // either. If the browser mode is triggering a captcha, this mode should be used instead.
 // This mode requires a different type of credentials that could be found in the vault
 // settings: the client ID and the client secret.
 // The device ID should be unique to each installation, but it should not be new on
 // every run. A new random device ID should be generated with GenerateRandomDeviceId
 // on the first run and reused later on.
 public static Vault Open(ClientInfoCliApi clientInfo, string baseUrl = null)
 {
     using var transport = new RestTransport();
     return(new Vault(Client.OpenVaultCliApi(clientId: clientInfo.ClientId,
                                             clientSecret: clientInfo.ClientSecret,
                                             password: clientInfo.Password,
                                             deviceId: clientInfo.DeviceId,
                                             baseUrl: baseUrl,
                                             transport: transport)));
 }
Exemplo n.º 3
0
 // This version allows custom base URL. baseUrl could be set to null or "" for a default value.
 public static Vault Open(string username,
                          string password,
                          string deviceId,
                          string baseUrl,
                          IUi ui,
                          ISecureStorage storage)
 {
     using var transport = new RestTransport();
     return(new Vault(Client.OpenVault(username, password, deviceId, baseUrl, ui, storage, transport)));
 }
Exemplo n.º 4
0
 // This version allows custom base URL. baseUrl could be set to null or "" for the default value.
 public static Vault Open(ClientInfoBrowser clientInfo, string baseUrl, IUi ui, ISecureStorage storage)
 {
     using var transport = new RestTransport();
     return(new Vault(Client.OpenVaultBrowser(username: clientInfo.Username,
                                              password: clientInfo.Password,
                                              deviceId: clientInfo.DeviceId,
                                              baseUrl: baseUrl,
                                              ui: ui,
                                              storage: storage,
                                              transport: transport)));
 }
 // This is for asserting inside a request like this:
 // InRequest(
 //     rest => rest.Get(url),                    // <- perform a rest call
 //     "<html><head>...",                        // <- respond with this content
 //     req => Assert.Equal(url, req.RequestUri)  // <- verify that the request is as expected
 // );
 internal static void InRequest(Action <RestClient> restCall,
                                string responseContent,
                                IRequestSigner signer,
                                IReadOnlyDictionary <string, string> defaultHeaders,
                                IReadOnlyDictionary <string, string> defaultCookies,
                                Action <HttpRequestMessage> assertRequest)
 {
     using var transport = new RestTransport(request =>
     {
         assertRequest(request);
         return(RespondWith(responseContent, NoHeaders)(request));
     });
     restCall(new RestClient(transport, "", signer, defaultHeaders, defaultCookies));
 }
Exemplo n.º 6
0
        // Valid domains are: my.1password.com, my.1password.eu, my.1password.ca
        public static Session LogIn(string username,
                                    string password,
                                    string accountKey,
                                    string uuid,
                                    string domain,
                                    IUi ui,
                                    ISecureStorage storage)
        {
            var transport = new RestTransport();

            try
            {
                return(LogIn(new ClientInfo(username, password, accountKey, uuid, domain), ui, storage, transport));
            }
            catch (Exception)
            {
                transport.Dispose();
                throw;
            }
        }
Exemplo n.º 7
0
        // The deviceId should be generated via Vault.GenerateRandomDeviceId on the first call and reused
        // later on for the same device. This allows to bypass the email verification on every connection and
        // prevents the pollution of the server side list of known devices.
        public static Vault Open(string username,
                                 string password,
                                 string deviceId,
                                 string deviceName,
                                 IUi ui,
                                 ISqliteProvider sqliteProvider)
        {
            // Download the database.
            using var transport = new RestTransport();
            var db = Client.OpenVaultDb(username: username,
                                        password: password,
                                        deviceId: deviceId,
                                        deviceName: deviceName,
                                        ui: ui,
                                        transport: transport);

            // Parse the database, extract and decrypt all the account information.
            var accounts = Parser.ParseAccounts(db, password, sqliteProvider);

            return(new Vault(accounts));
        }
Exemplo n.º 8
0
 public static Vault Open(string username, string password, ClientInfo clientInfo, IUi ui)
 {
     using var transport = new RestTransport();
     return(new Vault(Client.OpenVault(username, password, clientInfo, ui, transport)));
 }
Exemplo n.º 9
0
 public static Vault Open(string username, string accountPassword, string vaultPassword)
 {
     using var restTransport = new RestTransport();
     using var boshTransport = new WebSocketBoshTransport();
     return(Open(username, accountPassword, vaultPassword, restTransport, boshTransport));
 }
Exemplo n.º 10
0
 public static Vault Open(string username, string password, Ui ui, ISecureStorage storage)
 {
     using var transport = new RestTransport();
     return(Open(username, password, ui, storage, transport));
 }
Exemplo n.º 11
0
 public static Vault Open(string username, string password, string deviceId, Ui ui)
 {
     using var transport = new RestTransport();
     return(Open(username, password, deviceId, ui, transport));
 }
Exemplo n.º 12
0
 public static Vault Open(string oauthToken, string[] recoveryWords)
 {
     using var transport = new RestTransport();
     return(Open(oauthToken, recoveryWords, transport));
 }