<div dir="ltr"><br><div class="gmail_extra"><div>Hi Summers<br class=""><br></div><div>Referring to  <a href="http://aerogear-dev.1069024.n5.nabble.com/aerogear-dev-Fallback-Strat-for-DataManager-td5188.html">http://aerogear-dev.1069024.n5.nabble.com/aerogear-dev-Fallback-Strat-for-DataManager-td5188.html</a></div>
<div>where we might have async API for store in JS, I think we might benefit of async for native apps too, specially in the case of encrypted stores.</div><div><br></div><div>Something like <a href="https://github.com/rnapier/RNCryptor#asynchronous-use">https://github.com/rnapier/RNCryptor#asynchronous-use</a></div>
<div><br></div><div>Of course, it can be done in later releases. Encrypting large field, you don&#39;t want to have your UI sluggish.</div><div><br></div><div>wdyt?</div><div><br></div><div>++</div><div>Corinne</div><br><div class="gmail_quote">
On 5 November 2013 17:44, Summers Pittman <span dir="ltr">&lt;<a href="mailto:supittma@redhat.com" target="_blank">supittma@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On 11/05/2013 02:41 AM, Corinne Krych wrote:<br>
&gt; Hello all,<br>
&gt;<br>
&gt; I&#39;ve got 2 points:<br>
&gt;<br>
&gt; - modularity: AeroGear libs are small and modular: we have a separate aerogear-otp-ios, aerogear-push-ios-registration so that if the user wants to use aerogear without push, he can use aerogear-ios, if he needs the push-registration, he uses both. For encryption store, where do we want to put EncryptedStore? aerogear-android depends on aerogear-crypto.<br>

</div>On Android it is going into the main library.  We can research slicing<br>
the client library up for 2.0, but I would like to, for now, make<br>
getting up and running with anything AeroGear on Android as simple as<br>
including the dependency.<br>
<div class="im">&gt;<br>
&gt; - Encrypting data takes time. It would be nice to have EncryptedStore encrypts data on separate thread and provide callbacks on completion.<br>
&gt; thoughts?<br>
</div>Then we would have an encrypted Pipe.  One of the things about Stores is<br>
that they are synchronous, Pipes are asynchronous.<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5">&gt;<br>
&gt; ++<br>
&gt; Corinne<br>
&gt; On Nov 4, 2013, at 5:30 PM, Daniel Passos &lt;<a href="mailto:daniel@passos.me">daniel@passos.me</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; The idea is implementing only save(add/update) and delete, using the stores we already have today by just adding crypt / decrypt and scheduling Query (readWithFilter) for the next release<br>
&gt;&gt; DataManager<br>
&gt;&gt;<br>
&gt;&gt; public Store encryptedStore(String storeName, String passphrase) {<br>
&gt;&gt;          // TODO Create a default passphrase-based KeyStore<br>
&gt;&gt;          KeyStore keyStore = null;<br>
&gt;&gt;          return encryptedStore(storeName, keyStore);<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; public Store encryptedStore(String storeName, KeyStore keyStore) {<br>
&gt;&gt;          StoreConfig storeConfig = new StoreConfig();<br>
&gt;&gt;          storeConfig.setType(StoreTypes.ENCRYPTED_MEMORY);<br>
&gt;&gt;          return encryptedStore(storeName, storeConfig, keyStore);<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; public Store encryptedStore(String storeName, StoreConfig config, String passphrase) {<br>
&gt;&gt;          // TODO Create a default passphrase-based KeyStore<br>
&gt;&gt;          KeyStore keyStore = null;<br>
&gt;&gt;          return encryptedStore(storeName, config, keyStore);<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; public Store encryptedStore(String storeName, StoreConfig config, KeyStore keyStore) {<br>
&gt;&gt;          config.setKeyStore(keyStore);<br>
&gt;&gt;          Store store = storeFactory.createStore(config);<br>
&gt;&gt;          stores.put(storeName, store);<br>
&gt;&gt;          return store;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; EncryptedMemoryStore<br>
&gt;&gt;<br>
&gt;&gt; public class EncryptedMemoryStore&lt;T&gt; implements Store&lt;T&gt; {<br>
&gt;&gt;<br>
&gt;&gt;      private final MemoryStorage&lt;T&gt; memoryStorage;<br>
&gt;&gt;      private final CryptoUtils&lt;T&gt; cryptoUtils;<br>
&gt;&gt;<br>
&gt;&gt;      public EncryptedMemoryStore(IdGenerator idGenerator, KeyStore keyStore) {<br>
&gt;&gt;          memoryStorage = new MemoryStorage(idGenerator);<br>
&gt;&gt;          cryptoUtils = new CryptoUtils&lt;T&gt;(keyStore);<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public StoreType getType() {<br>
&gt;&gt;          return StoreTypes.ENCRYPTED_MEMORY;<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public Collection&lt;T&gt; readAll() throws InvalidKeyException {<br>
&gt;&gt;          Collection&lt;T&gt; encryptedCollection = memoryStorage.readAll();<br>
&gt;&gt;          return cryptoUtils.decrypt(encryptedCollection);<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public T read(Serializable id) throws InvalidKeyException {<br>
&gt;&gt;          T encryptedItem = memoryStorage.read(id);<br>
&gt;&gt;          return cryptoUtils.decrypt(encryptedItem);<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public List&lt;T&gt; readWithFilter(ReadFilter filter) throws InvalidKeyException {<br>
&gt;&gt;          List&lt;T&gt; encryptedList = memoryStorage.readWithFilter(filter);<br>
&gt;&gt;          return cryptoUtils.decrypt(encryptedList);<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public void save(T item) {<br>
&gt;&gt;          memoryStorage.save(cryptoUtils.encrypt(item));<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public void reset() {<br>
&gt;&gt;          memoryStorage.reset();<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public void remove(Serializable id) {<br>
&gt;&gt;          memoryStorage.remove(id);<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      @Override<br>
&gt;&gt;      public boolean isEmpty() {<br>
&gt;&gt;          return memoryStorage.isEmpty();<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; CryptoUtils<br>
&gt;&gt;<br>
&gt;&gt; Here is where the magic happens.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; public class CryptoUtils&lt;T&gt; {<br>
&gt;&gt;<br>
&gt;&gt;      private final KeyStore keyStore;<br>
&gt;&gt;<br>
&gt;&gt;      public CryptoUtils(KeyStore keyStore) {<br>
&gt;&gt;          this.keyStore = keyStore;<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      public Collection&lt;T&gt; decrypt(Collection&lt;T&gt; encryptedCollection) {<br>
&gt;&gt;          List&lt;T&gt; decryptedList = new ArrayList&lt;T&gt;();<br>
&gt;&gt;          for (T item : encryptedCollection) {<br>
&gt;&gt;              decryptedList.add(decrypt(item));<br>
&gt;&gt;          }<br>
&gt;&gt;          return decryptedList;<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      public List&lt;T&gt; decrypt(List&lt;T&gt; encryptedList) {<br>
&gt;&gt;          List&lt;T&gt; decryptedList = new ArrayList&lt;T&gt;();<br>
&gt;&gt;          for (T item : encryptedList) {<br>
&gt;&gt;              decryptedList.add(decrypt(item));<br>
&gt;&gt;          }<br>
&gt;&gt;          return decryptedList;<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      public T decrypt(T item) {<br>
&gt;&gt;          // TODO Read all fields and decrypt<br>
&gt;&gt;          return item;<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt;      public T encrypt(T item) {<br>
&gt;&gt;          // TODO Read all fields and encrypt<br>
&gt;&gt;          return item;<br>
&gt;&gt;      }<br>
&gt;&gt;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; aerogear-dev mailing list<br>
&gt;&gt; <a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; aerogear-dev mailing list<br>
&gt; <a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
<br>
_______________________________________________<br>
aerogear-dev mailing list<br>
<a href="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/aerogear-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/aerogear-dev</a><br>
</div></div></blockquote></div><br></div></div>