Ejemplo n.º 1
0
        public EvernoteConnection(IAlephLogger log, IWebProxy proxy, EvernoteConfig config, HierachyEmulationConfig hConfig)
        {
            HConfig = hConfig;

            _config = config;
            _proxy  = proxy;
            _logger = log;
        }
Ejemplo n.º 2
0
        public static void Register(IAlephLogger log)
        {
            lock (_lock)
            {
                if (Inst != null)
                {
                    throw new NotSupportedException();
                }

                Inst = log;
            }
        }
Ejemplo n.º 3
0
        public static void DeleteFileAndFolderIfEmpty(string logsrc, IAlephLogger log, string baseFolder, string file)
        {
            var fi = new FileInfo(file);

            if (fi.Exists && fi.IsReadOnly)
            {
                fi.IsReadOnly = false;
            }

            File.Delete(file);

            DeleteFolderIfEmpty(logsrc, log, baseFolder, Path.GetDirectoryName(file));
        }
Ejemplo n.º 4
0
        public static void DeleteDirectoryWithRetry(IAlephLogger logger, string path)
        {
            for (int i = 0; i < 5; i++)
            {
                try
                {
                    Directory.Delete(path);
                    return;
                }
                catch (IOException e)
                {
                    logger.Debug("DeleteDirectoryWithRetry", "Retry Directory delete", "Retry directory delete, exception thrown:\r\n" + e);
                    Thread.Sleep(5);
                }
            }

            Directory.Delete(path);             // Do it again and throw Exception if it fails
        }
Ejemplo n.º 5
0
        public static void DeleteFolderIfEmpty(string logsrc, IAlephLogger log, string baseFolder, string folder)
        {
            var p1 = Path.GetFullPath(baseFolder).TrimEnd(Path.DirectorySeparatorChar).ToLower();
            var p2 = Path.GetFullPath(folder).TrimEnd(Path.DirectorySeparatorChar).ToLower();

            if (p1 == p2)
            {
                return;
            }
            if (p1.Count(c => c == Path.DirectorySeparatorChar) >= p2.Count(c => c == Path.DirectorySeparatorChar))
            {
                return;
            }

            if (Directory.EnumerateFileSystemEntries(folder).Any())
            {
                return;
            }

            log.Debug(logsrc, $"Cleanup empty folder '{p2}' (base = '{p1}')");
            Directory.Delete(folder);
        }
Ejemplo n.º 6
0
 public override void Init(IAlephLogger logger)
 {
     _logger = logger;
 }
Ejemplo n.º 7
0
 public abstract void Init(IAlephLogger logger);
Ejemplo n.º 8
0
 public override void Init(IAlephLogger logger)
 {
     _logger = logger;
     SimpleNoteAPI.Logger = logger;
 }
        private Tuple <IRemoteStorageSyncPersistance, List <INote> > DoSync(RemoteStorageAccount acc, IAlephLogger log)
        {
            var data = SelectedProvider.CreateEmptyRemoteSyncData();

            var conn = acc.Plugin.CreateRemoteStorageConnection(PluginManagerSingleton.Inst.GetProxyFactory().Build(), acc.Config, new HierachyEmulationConfig(false, "\\", '\\'));

            var resultNotes = new List <INote>();

            Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Connect to remote"; });
            conn.StartSync(data, new List <INote>(), new List <INote>());
            {
                Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "List notes from remote"; });
                var missing = conn.ListMissingNotes(new List <INote>());

                int idx = 0;
                foreach (var xnoteid in missing)
                {
                    var noteid = xnoteid;
                    idx++;

                    try
                    {
                        string msg = $"Download Note {idx}/{missing.Count}";
                        Application.Current.Dispatcher.Invoke(() => { SyncInfoText = msg; });

                        var note = conn.DownloadNote(noteid, out var isnewnote);
                        if (isnewnote)
                        {
                            note.SetLocalDirty();
                            note.ResetRemoteDirty();
                            resultNotes.Add(note);
                        }
                        else
                        {
                            log.Warn("Sync_FirstStart", string.Format("Download new note {{id:'{0}'}} returned false", noteid));
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        throw new Exception(string.Format("Could not download new note '{0}' on remote cause of {1}", noteid, e.Message));
                    }
                }
            }
            Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Finish synchronization"; });
            conn.FinishSync();

            return(Tuple.Create(data, resultNotes));
        }
Ejemplo n.º 10
0
        public static APIResultAuthorize Authenticate(ISimpleJsonRest web, string mail, string password, IAlephLogger logger)
        {
            var apiparams = web.Get <APIAuthParams>("auth/params", "email=" + mail);

            if (apiparams.version == "001")
            {
                return(Authenticate001(web, apiparams, mail, password, logger));
            }
            if (apiparams.version == "002")
            {
                return(Authenticate002(web, apiparams, mail, password, logger));
            }

            throw new Exception("Unsupported auth API version: " + apiparams.version);
        }
Ejemplo n.º 11
0
        private static APIResultAuthorize Authenticate001(ISimpleJsonRest web, APIAuthParams apiparams, string mail, string password, IAlephLogger logger)
        {
            try
            {
                logger.Debug(StandardNotePlugin.Name, $"AuthParams[version:1, pw_func:{apiparams.pw_func}, pw_alg:{apiparams.pw_alg}, pw_cost:{apiparams.pw_cost}, pw_key_size:{apiparams.pw_key_size}]");

                if (apiparams.pw_func != PasswordFunc.pbkdf2)
                {
                    throw new Exception("Unsupported pw_func: " + apiparams.pw_func);
                }

                byte[] bytes;

                if (apiparams.pw_alg == PasswordAlg.sha512)
                {
                    bytes = PBKDF2.GenerateDerivedKey(apiparams.pw_key_size / 8, Encoding.UTF8.GetBytes(password), Encoding.UTF8.GetBytes(apiparams.pw_salt), apiparams.pw_cost, PBKDF2.HMACType.SHA512);
                }
                else if (apiparams.pw_alg == PasswordAlg.sha512)
                {
                    bytes = PBKDF2.GenerateDerivedKey(apiparams.pw_key_size / 8, Encoding.UTF8.GetBytes(password), Encoding.UTF8.GetBytes(apiparams.pw_salt), apiparams.pw_cost, PBKDF2.HMACType.SHA512);
                }
                else
                {
                    throw new Exception("Unknown pw_alg: " + apiparams.pw_alg);
                }

                var pw = bytes.Take(bytes.Length / 2).ToArray();
                var mk = bytes.Skip(bytes.Length / 2).ToArray();

                var reqpw = EncodingConverter.ByteToHexBitFiddleUppercase(pw).ToLower();

                APIResultAuthorize tok;
                try
                {
                    tok = web.PostDownload <APIResultAuthorize>("auth/sign_in", "email=" + mail, "password="******"Server returned status {e1.StatusCode}.\nMessage: '{req.error.message}'", e1);
                        }
                    }

                    throw;
                }

                tok.masterkey = mk;
                tok.version   = "001";
                return(tok);
            }
            catch (StandardNoteAPIException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new StandardNoteAPIException("Authentification with StandardNoteAPI failed.", e);
            }
        }
Ejemplo n.º 12
0
        private static APIResultAuthorize Authenticate002(ISimpleJsonRest web, APIAuthParams apiparams, string mail, string password, IAlephLogger logger)
        {
            try
            {
                logger.Debug(StandardNotePlugin.Name, $"AutParams[version:2, pw_cost:{apiparams.pw_cost}]");

                if (apiparams.pw_func != PasswordFunc.pbkdf2)
                {
                    throw new Exception("Unknown pw_func: " + apiparams.pw_func);
                }

                byte[] bytes = PBKDF2.GenerateDerivedKey(768 / 8, Encoding.UTF8.GetBytes(password), Encoding.UTF8.GetBytes(apiparams.pw_salt), apiparams.pw_cost, PBKDF2.HMACType.SHA512);

                var pw = bytes.Skip(0 * (bytes.Length / 3)).Take(bytes.Length / 3).ToArray();
                var mk = bytes.Skip(1 * (bytes.Length / 3)).Take(bytes.Length / 3).ToArray();
                var ak = bytes.Skip(2 * (bytes.Length / 3)).Take(bytes.Length / 3).ToArray();

                var reqpw = EncodingConverter.ByteToHexBitFiddleUppercase(pw).ToLower();
                APIResultAuthorize tok;
                try
                {
                    tok = web.PostTwoWay <APIResultAuthorize>(new APIRequestUser {
                        email = mail, password = reqpw
                    }, "auth/sign_in");
                }
                catch (RestStatuscodeException e1)
                {
                    if (e1.StatusCode / 100 == 4 && !string.IsNullOrWhiteSpace(e1.HTTPContent))
                    {
                        var req = web.ParseJsonOrNull <APIBadRequest>(e1.HTTPContent);
                        if (req != null)
                        {
                            throw new StandardNoteAPIException($"Server returned status {e1.StatusCode}.\nMessage: '{req.error.message}'", e1);
                        }
                    }

                    throw;
                }

                tok.masterkey     = mk;
                tok.masterauthkey = ak;
                tok.version       = "002";
                return(tok);
            }
            catch (RestException)
            {
                throw;
            }
            catch (StandardNoteAPIException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new StandardNoteAPIException("Authentification with StandardNoteAPI failed.", e);
            }
        }
Ejemplo n.º 13
0
 public NextcloudConnection(IAlephLogger log, IWebProxy proxy, NextcloudConfig config)
 {
     _config = config;
     _proxy  = proxy;
     _logger = log;
 }
Ejemplo n.º 14
0
        public static APIResultAuthorize Authenticate(ISimpleJsonRest web, string mail, string password, IAlephLogger logger)
        {
            var apiparams = web.Get <APIAuthParams>("auth/params", "email=" + mail);

            if (apiparams.version == "001")
            {
                return(Authenticate001(web, apiparams, mail, password, logger));
            }
            if (apiparams.version == "002")
            {
                return(Authenticate002(web, apiparams, mail, password, logger));
            }
            if (apiparams.version == "003")
            {
                return(Authenticate003(web, apiparams, mail, password, logger));
            }
            if (apiparams.version == "004")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 004 in auth-params");
            }
            if (apiparams.version == "005")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 005 in auth-params");
            }
            if (apiparams.version == "006")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 006 in auth-params");
            }
            if (apiparams.version == "007")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 007 in auth-params");
            }
            if (apiparams.version == "008")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 008 in auth-params");
            }
            if (apiparams.version == "009")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 009 in auth-params");
            }
            if (apiparams.version == "010")
            {
                throw new StandardNoteAPIException("Unsupported encryption scheme 010 in auth-params");
            }

            throw new Exception("Unsupported auth API version: " + apiparams.version);
        }
Ejemplo n.º 15
0
 public override void Init(IAlephLogger l)
 {
     logger = l;
 }
Ejemplo n.º 16
0
        public static void DeleteFileAndFolderIfEmpty(string logsrc, IAlephLogger log, string baseFolder, string file)
        {
            File.Delete(file);

            DeleteFolderIfEmpty(logsrc, log, baseFolder, Path.GetDirectoryName(file));
        }
Ejemplo n.º 17
0
 public override void Init(IAlephLogger logger)
 {
     //
 }
Ejemplo n.º 18
0
 public FilesystemConnection(IAlephLogger log, FilesystemConfig config)
 {
     _config = config;
     _logger = log;
 }