Smack 4.4.0 - aTalk Regenerate OMEMO identities implementation and problem faced

Current aTalk “Regenerate OMEMO identities” implementations are shown below. The debug log captured the whole process flow when one perform this operation; replacing…
old: peacock@atalk.sytes.net:648420352
new: peacock@atalk.sytes.net:1966536913

 * Regenerate new omemo identity for the device
 * 1. Purge server bundle data and items for the old omemoDevice
 * 2. Purge account Omemo info in the local database
 * 3. Call via AndroidOmemoService() to:...

The process flow consists of 3 parts as shown above

  1. Purge server bundle data and items for the old omemoDevice
    aTalk attempts to clean up the server bundle info for the old omemoDevice i.e. peacock@atalk.sytes.net:648420352

  2. Purge account Omemo info in the local database
    All the relevant table parameters for the old device are removed i.e. omemo_device, prekeys, signed_prekeys and associated identities.

  3. Call via AndroidOmemoService() to:…
    Via smack-omemo, to create a new deviceid and publish to the server

From the debug log, all the above 3 steps are completed successfully without problem.
However the problem is when smack-omemo requests for the devicelist from the server, the old
peacock@atalk.sytes.net:648420352 is returned. This old and new is merged in smack-omemo and published to the servers.

This causes problem when omemo messages is sent/received. See debug log on
“=========== sending omemo message between peacock to swordfish ==========”

Any idea why the server still return an deleted omemoDevice?
Any advice on how to resolve the problem is appreciated.

2021-01-23 08:07:43.363 12826-13551/org.atalk.android D/SMACK: SENT (0): 
    <iq id='ZTN97-46' type='get'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.devicelist'/>
      </pubsub>
    </iq>
    <a xmlns='urn:xmpp:sm:3' h='77'/>

2021-01-23 08:07:43.380 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='ZTN97-46'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B57EEA619D0'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='648420352'/>
            </list>
          </item>
        </items>
      </pubsub>
    </iq>
================== aTalk Regenerate Implementation ===============
    /**
     * Regenerate new omemo identity for the device
     * 1. Purge server bundle data and items for the old omemoDevice
     * 2. Purge account Omemo info in the local database
     * 3. Call via AndroidOmemoService() to:
     *   a. create new Omemo deviceId
     *   b. generate fresh user identityKeyPairs, bundle
     *   c. publish it to the server.
     */
    public void regenerate(AccountID accountId)
    {
        ProtocolProviderService pps = accountId.getProtocolProvider();
        if (pps != null) {
            XMPPConnection connection = pps.getConnection();
            if ((connection != null) && connection.isAuthenticated()) {

                // Purge all omemo devices info in database and server for the specified account
                purgeUserOmemoData(accountId);
                new AndroidOmemoService(pps).initOmemoDevice();
            }
        }
    }

    /**
     * Clean up omemo database and omemo bundle data on the server for user account when deleted.
     *
     * @param accountId the omemo local database/server of the accountID to be purged.
     */
    public void purgeUserOmemoData(AccountID accountId)
    {
        // Purge server omemo bundle nodes for the deleted account (only if online and registered)
        ProtocolProviderService pps = accountId.getProtocolProvider();
        if (pps != null) {
            XMPPConnection connection = pps.getConnection();
            if ((connection != null) && connection.isAuthenticated()) {
                BareJid userJid = accountId.getBareJid();
                PubSubManager pubsubManager = PubSubManager.getInstanceFor(connection, userJid);
                OmemoCachedDeviceList deviceList = mDB.loadCachedDeviceList(userJid);
                for (int deviceId : deviceList.getAllDevices()) {
                    try {
                        OmemoDevice omemoDevice = new OmemoDevice(userJid, deviceId);
                        Timber.d("Purge server bundle for omemo device: %s", omemoDevice);
                        String nodeId = omemoDevice.getBundleNodeName();
                        LeafNode leafNode = pubsubManager.getLeafNode(nodeId);
                        leafNode.deleteAllItems();
                        pubsubManager.deleteNode(nodeId);
                    } catch (SmackException | InterruptedException | XMPPException.XMPPErrorException e) {
                        aTalkApp.showToastMessage(R.string.omemo_purge_inactive_device_error, userJid);
                    }
                }
            }
        }
        // Purge local omemo database for the specified account
        mDB.purgeOmemoDb(accountId);
        trustCache.evictAll();
    }
================ aTalk Regeneration process flow ===============
2021-01-23 08:06:47.891 12826-14889/org.atalk.android D/(OmemoRegenerateDialog.java:91)#run: Regenerate Omemo for: peacock@atalk.sytes.net
2021-01-23 08:06:47.899 12826-14889/org.atalk.android D/(SQLiteOmemoStore.java:809)#purgeUserOmemoData: Purge server bundle for omemo device: peacock@atalk.sytes.net:648420352
2021-01-23 08:06:47.907 12826-13551/org.atalk.android D/SMACK: SENT (0): 
    <iq id='ZTN97-40' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
        <purge node='eu.siacs.conversations.axolotl.bundles:648420352'/>
      </pubsub>
    </iq>
2021-01-23 08:06:47.938 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='ZTN97-40'/>
2021-01-23 08:06:47.954 12826-13551/org.atalk.android D/SMACK: SENT (0): 
    <iq id='ZTN97-42' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
        <delete node='eu.siacs.conversations.axolotl.bundles:648420352'/>
      </pubsub>
    </iq>
2021-01-23 08:06:47.981 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='ZTN97-42'/>

2021-01-23 08:06:47.987 12826-14889/org.atalk.android D/(DatabaseBackend.java:1337)#purgeOmemoDb: >>> Wiping OMEMO database for account : peacock@atalk.sytes.net

2021-01-23 08:06:48.063 12826-14889/org.atalk.android I/(DatabaseBackend.java:499)#storeOmemoRegId: ### Omemo device added for: peacock@atalk.sytes.net; 1966536913
2021-01-23 08:06:48.067 12826-14889/org.atalk.android I/(AndroidOmemoService.java:50)#<init>: ### Registered omemo messageListener for: peacock@atalk.sytes.net
2021-01-23 08:06:48.702 12826-14892/org.atalk.android I/(SQLiteOmemoStore.java:383)#storeOmemoIdentityKeyPair: Store omemo identityKeyPair for :peacock@atalk.sytes.net:1966536913

2021-01-23 08:07:43.201 12826-13551/org.atalk.android D/SMACK: SENT (0): 
    <iq id='ZTN97-44' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.bundles:1966536913'>
          <item>
            <bundle xmlns='eu.siacs.conversations.axolotl'>
              <signedPreKeyPublic signedPreKeyId='1'>
                BSLyWws2FkR10UoDLmnWFf5C63YTC3eFuBaRgqeIffkA
              </signedPreKeyPublic>
              <signedPreKeySignature>
                zGyTbE02UHrOW2M1ga4szdsETi7nIPp6K7G9FC5acWUQGt+JLQyG23UC4EYB5qf5j75WX931YkpaVIfj1bhIBA==
              </signedPreKeySignature>

                <preKeyPublic preKeyId='100'>
                  BeVUafA/gU7Jo7IyyVxvO+ntMrZ3y8NTxdyuzsEsn0p0
                </preKeyPublic>
              </prekeys>
            </bundle>
          </item>
        </publish>
      </pubsub>
    </iq>

2021-01-23 08:07:43.297 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.bundles:1966536913'>
          <item id='64B5800B6767E'>
            <bundle xmlns='eu.siacs.conversations.axolotl'>
              <signedPreKeyPublic signedPreKeyId='1'>
                BSLyWws2FkR10UoDLmnWFf5C63YTC3eFuBaRgqeIffkA
              </signedPreKeyPublic>
              <signedPreKeySignature>
                zGyTbE02UHrOW2M1ga4szdsETi7nIPp6K7G9FC5acWUQGt+JLQyG23UC4EYB5qf5j75WX931YkpaVIfj1bhIBA==
              </signedPreKeySignature>
              <identityKey>
                BfnGBADzVw8VPpDqd4KS9aVHJbWafvIPW4/Gw5Ds7eBf
              </identityKey>
              <prekeys>
                <preKeyPublic preKeyId='1'>
                  BYjl5vnY8yVID+soGOatBCavTP/wP1mhBgE1Ihs82PFR
                </preKeyPublic>

                <preKeyPublic preKeyId='100'>
                  BeVUafA/gU7Jo7IyyVxvO+ntMrZ3y8NTxdyuzsEsn0p0
                </preKeyPublic>
              </prekeys>
            </bundle>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>

2021-01-23 08:07:43.346 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='ZTN97-44'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.bundles:1966536913'>
          <item id='64B5800B6767E'/>
        </publish>
      </pubsub>
    </iq>

2021-01-23 08:07:43.363 12826-13551/org.atalk.android D/SMACK: SENT (0): 
    <iq id='ZTN97-46' type='get'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.devicelist'/>
      </pubsub>
    </iq>
    <a xmlns='urn:xmpp:sm:3' h='77'/>

2021-01-23 08:07:43.380 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='ZTN97-46'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B57EEA619D0'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='648420352'/>
            </list>
          </item>
        </items>
      </pubsub>
    </iq>

2021-01-23 08:07:43.396 12826-14892/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352]
2021-01-23 08:07:43.399 12826-14892/org.atalk.android D/(DatabaseBackend.java:1025)#storeCachedDeviceList: Identities table - create new activeDevice: peacock@atalk.sytes.net:648420352 
2021-01-23 08:07:43.405 12826-14892/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[1966536913]
2021-01-23 08:07:43.424 12826-14892/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.430 12826-14892/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]

2021-01-23 08:07:43.440 12826-13551/org.atalk.android D/SMACK: SENT (0): 
    <iq id='ZTN97-48' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='648420352'/>
              <device id='1966536913'/>
            </list>
          </item>
        </publish>
      </pubsub>
    </iq>
2021-01-23 08:07:43.493 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5800B99E57'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='648420352'/>
              <device id='1966536913'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>

2021-01-23 08:07:43.521 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='ZTN97-48'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5800B99E57'/>
        </publish>
      </pubsub>
    </iq>

2021-01-23 08:07:43.532 12826-14892/org.atalk.android D/(AndroidOmemoService.java:113)#initializationFinished: Initialize OmemoManager successful for peacock@atalk.sytes.net/atalk
2021-01-23 08:07:43.534 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.534 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5800B99E57'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='648420352'/>
              <device id='1966536913'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
2021-01-23 08:07:43.543 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.569 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.575 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.585 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.591 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.606 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.612 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.622 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.627 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.641 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.646 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.654 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.659 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 08:07:43.672 12826-14891/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[648420352, 1966536913]
2021-01-23 08:07:43.677 12826-14891/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]

=========== sending omemo message between peacock to swordfish ==========
2021-01-23 08:36:25.385 12826-13552/org.atalk.android D/SMACK: RECV (0): 
    <message xml:lang='en' to='peacock@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net/atalk' type='chat' id='1611362180107266596046'>
      <encrypted xmlns='eu.siacs.conversations.axolotl'>
        <header sid='82553717'>
          <key rid='648420352'>
            MwohBTnU7NJlSeYAIR/RmXM0vEz9j8KMFXRyyPqRBZneujlkEAAYACIwx+ZWvwnuGXxpxtQVyK6o6/V4vSVIRkSFueq6qoov8rIcxXQ1yPzfDXb00Fjh83extdSlZv9MsFE=
          </key>
          <key prekey='true' rid='1966536913'>
            MwgVEiEFnevX95gb5u//pq/RmM1vJxYXeP5ddytLBZ3koaCMmWMaIQXkM+ePcDIY5Ru0ze3cYmIE+9Zdb3/q2z7nT9JA/xZ/OCJiMwohBTggkIbKEbuJQBiEjWPGYFhADbF8AebgXGj+cDThJUdLEAAYACIwMGlyCzlKYmyAbRVxdMcAqAQIanK6L0JWi4w9kff9IfqpV8w9nTBSll5K4Dh1IH5qsSqqe/RWVbgoADAB
          </key>
          <iv>
            D/yV4N6QyqW24qg1
          </iv>
        </header>
        <payload>
          gdC4
        </payload>
      </encrypted>
      <store xmlns='urn:xmpp:hints'/>
      <encryption xmlns='urn:xmpp:eme:0' namespace='eu.siacs.conversations.axolotl' name='OMEMO'/>
      <origin-id xmlns='urn:xmpp:sid:0' id='FW51-WGWE-I7R8-Y'/>
      <active xmlns='http://jabber.org/protocol/chatstates'/>
      <request xmlns='urn:xmpp:receipts'/>
      <body>
        I sent you an OMEMO encrypted message but your client doesn&apos;t seem to support that. Find more information on https://conversations.im/omemo
      </body>
    </message>

2021-01-23 08:36:39.102 12826-16485/org.atalk.android E/AndroidRuntime: FATAL EXCEPTION: Thread-120
    Process: org.atalk.android, PID: 12826
    java.lang.IllegalArgumentException: Null values!
        at org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters.<init>(AliceSignalProtocolParameters.java:38)
        at org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters.<init>(AliceSignalProtocolParameters.java:14)
        at org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters$Builder.create(AliceSignalProtocolParameters.java:110)
        at org.whispersystems.libsignal.SessionBuilder.process(SessionBuilder.java:201)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoService.processBundle(SignalOmemoService.java:104)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoService.processBundle(SignalOmemoService.java:48)
        at org.jivesoftware.smackx.omemo.OmemoService.buildFreshSessionWithDevice(OmemoService.java:803)
        at org.jivesoftware.smackx.omemo.OmemoService.repairBrokenSessionWithPreKeyMessage(OmemoService.java:1335)
        at org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived(OmemoService.java:1213)
        at org.jivesoftware.smackx.omemo.OmemoManager$3.run(OmemoManager.java:959)
        at java.lang.Thread.run(Thread.java:764)
2021-01-23 08:36:39.105 12826-16485/org.atalk.android E/(UtilActivator.java:90)#uncaughtException: An uncaught exception occurred in thread = Thread[Thread-120,5,main] and message was: Null values!
    java.lang.IllegalArgumentException: Null values!
        at org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters.<init>(AliceSignalProtocolParameters.java:38)
        at org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters.<init>(AliceSignalProtocolParameters.java:14)
        at org.whispersystems.libsignal.ratchet.AliceSignalProtocolParameters$Builder.create(AliceSignalProtocolParameters.java:110)
        at org.whispersystems.libsignal.SessionBuilder.process(SessionBuilder.java:201)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoService.processBundle(SignalOmemoService.java:104)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoService.processBundle(SignalOmemoService.java:48)
        at org.jivesoftware.smackx.omemo.OmemoService.buildFreshSessionWithDevice(OmemoService.java:803)
        at org.jivesoftware.smackx.omemo.OmemoService.repairBrokenSessionWithPreKeyMessage(OmemoService.java:1335)
        at org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived(OmemoService.java:1213)
        at org.jivesoftware.smackx.omemo.OmemoManager$3.run(OmemoManager.java:959)
        at java.lang.Thread.run(Thread.java:764)

Finally understand where is the problem. I need to purge both the bundle and deviceList on the server. So I updated the purgeUserOmemoData() to the following to include the deviceList deletion.

After the change, from the debug log, everything looks good for the part of the OMEMO regeneration. The server deviceList now only contains the newly created omemDeive and the identityKeyPair is saved to the identities table i.e.

2021-01-23 10:44:17.407 32142-32475/org.atalk.android I/(SQLiteOmemoStore.java:384)#storeOmemoIdentityKeyPair: Store omemo identityKeyPair for :peacock@atalk.sytes.net:2024425783

smack-omemo then proceed to update the active state for the device via storeCachedDeviceList(), and publish the deviceList to the server.
From the log, it is seen that multiple storeCachedDeviceList() are being carried out.

2021-01-23 10:45:15.461 32142-32475/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.470 32142-32475/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]

When peacock attempt to send an omemo message, something goes very wrong:
“=========== compose and send omemo message ============”

After omemo received the bundle for ‘eu.siacs.conversations.axolotl.bundles:2024425783’, it is treated as contact’s prekeys instead of own omemoDevice prekeys??? and smack-omemo executes storeOmemoIdentityKey(). In aTalk implementation, this replaces the own IdentityKeyPair with IdentityKey, leading to a data corruption.

2021-01-23 10:53:36.930 32142-32142/org.atalk.android D/(DatabaseBackend.java:961)#loadIdentityKeys: Missing key (possibly pre-verified) in database for account: peacock@atalk.sytes.net
2021-01-23 10:53:36.933 32142-32142/org.atalk.android I/(SQLiteOmemoStore.java:448)#storeOmemoIdentityKey: Update identityKey for: peacock@atalk.sytes.net:2024425783; org.whispersystems.libsignal.IdentityKey@264bfb2a;

The corrupted preKeyPair now causes Corrupted Omemo IdentityKeyPair Exception as capatued in the log.

2021-01-23 10:54:34.868 32142-1285/org.atalk.android E/(SQLiteOmemoStore.java:364)#loadOmemoIdentityKeyPair: Corrupted Omemo IdentityKeyPair: Invalid IdentityKeyPairs for omemoDevice: peacock@atalk.sytes.net:2024425783.
    Exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero)..

Please comment.

  1. Why omemo treats own omemoDevice as contact’s device, leading to IdentityKeyPairs being overwrittend with IdentityKey?

  2. Does own omemo device contains both an IdentityKeyPairs and an IdentityKey; and they must not be saved in the same table as aTalk does today?

  3. Does the identity active state only apply to keyPair, and it does not apply to IdentityKeyPairs.

    /**
     * Clean up omemo local database, and omemo bundle and deviceList on the server when:
     * 1. When a user account is deleted.
     * 2. During Regenerate OMEMO identities
     *
     * @param accountId the omemo local database/server of the accountID to be purged.
     */
    public void purgeUserOmemoData(AccountID accountId)
    {
        // Purge server omemo bundle nodes for the deleted account (only if online and authenticated)
        ProtocolProviderService pps = accountId.getProtocolProvider();
        if (pps != null) {
            XMPPConnection connection = pps.getConnection();
            if ((connection != null) && connection.isAuthenticated()) {
                BareJid userJid = accountId.getBareJid();
                OmemoDevice omemoDevice = OmemoManager.getInstanceFor(connection).getOwnDevice();
                PubSubManager pubsubManager = PubSubManager.getInstanceFor(connection, userJid);
                Timber.d("Purge server bundle and deviceList for omemo device: %s", omemoDevice);
                try {
                    // Purge omemo preKeys table on server
                    String nodeId = omemoDevice.getBundleNodeName();
                    LeafNode leafNode = pubsubManager.getLeafNode(nodeId);
                    leafNode.deleteAllItems();
                    pubsubManager.deleteNode(nodeId);

                    // Purge omemo deviceList on server
                    nodeId = OmemoConstants.PEP_NODE_DEVICE_LIST;
                    leafNode = pubsubManager.getLeafNode(nodeId);
                    leafNode.deleteAllItems();
                    pubsubManager.deleteNode(nodeId);

                } catch (SmackException | InterruptedException | XMPPException.XMPPErrorException e) {
                    aTalkApp.showToastMessage(R.string.omemo_purge_inactive_device_error, userJid);
                }
            }
        }
        // Purge local omemo database for the specified account
        mDB.purgeOmemoDb(accountId);
        trustCache.evictAll();
    }
============ aTalk regeneration ============
2021-01-23 10:44:16.211 32142-32473/org.atalk.android D/(OmemoRegenerateDialog.java:91)#run: Regenerate Omemo for: peacock@atalk.sytes.net
2021-01-23 10:44:16.220 32142-32473/org.atalk.android D/(SQLiteOmemoStore.java:808)#purgeUserOmemoData: Purge server bundle and deviceList for omemo device: peacock@atalk.sytes.net:1966536913
2021-01-23 10:44:16.228 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-18' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
        <purge node='eu.siacs.conversations.axolotl.bundles:1966536913'/>
      </pubsub>
    </iq>
2021-01-23 10:44:16.261 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-18'/>

2021-01-23 10:44:16.275 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-20' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
        <delete node='eu.siacs.conversations.axolotl.bundles:1966536913'/>
      </pubsub>
    </iq>
2021-01-23 10:44:16.296 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-20'/>

2021-01-23 10:44:16.311 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-22' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
        <purge node='eu.siacs.conversations.axolotl.devicelist'/>
      </pubsub>
    </iq>
2021-01-23 10:44:16.329 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-22'/>

2021-01-23 10:44:16.344 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-24' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
        <delete node='eu.siacs.conversations.axolotl.devicelist'/>
      </pubsub>
    </iq>
2021-01-23 10:44:16.365 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-24'/>

2021-01-23 10:44:16.375 32142-32473/org.atalk.android D/(DatabaseBackend.java:1337)#purgeOmemoDb: >>> Wiping OMEMO database for account : peacock@atalk.sytes.net
2021-01-23 10:44:17.407 32142-32475/org.atalk.android I/(SQLiteOmemoStore.java:384)#storeOmemoIdentityKeyPair: Store omemo identityKeyPair for :peacock@atalk.sytes.net:2024425783

2021-01-23 10:45:15.259 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-26' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.bundles:2024425783'>
          <item>
            <bundle xmlns='eu.siacs.conversations.axolotl'>
              <signedPreKeyPublic signedPreKeyId='1'>
                BcyoYtavGIRYbN7COIXE8PG7L429YZ1HVRHV1kt2qmAW
              </signedPreKeyPublic>

                <preKeyPublic preKeyId='100'>
                  BdLOyINcUeRHmrJNe2N7fse+cwT4uV+j5FtpZiOsGLdQ
                </preKeyPublic>
              </prekeys>
            </bundle>
          </item>
        </publish>
      </pubsub>
    </iq>
2021-01-23 10:45:15.364 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.bundles:2024425783'>
          <item id='64B5A4F78C3C8'>
            <bundle xmlns='eu.siacs.conversations.axolotl'>
              <signedPreKeyPublic signedPreKeyId='1'>
                BcyoYtavGIRYbN7COIXE8PG7L429YZ1HVRHV1kt2qmAW
              </signedPreKeyPublic>
              <signedPreKeySignature>
                z5sV3N2JbWJBTjP/5qYTIkDgempIDQmyftjJlJYkOAjVD9JFZjPswjIBlOzZeuprENFie836pab8hxU+epUQjQ==
              </signedPreKeySignature>
              <identityKey>
                BUedsDSXhsVVQW4PXOd9hgP0yIVRoQi910euNVFYd+RE
              </identityKey>
              <prekeys>
                <preKeyPublic preKeyId='1'>
                  BfWm57rJ/rTxlyQltWK/khcUAmyqVN6/+7skp5gknT8G
                </preKeyPublic>

                </preKeyPublic>
                <preKeyPublic preKeyId='100'>
                  BdLOyINcUeRHmrJNe2N7fse+cwT4uV+j5FtpZiOsGLdQ
                </preKeyPublic>
              </prekeys>
            </bundle>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>

2021-01-23 10:45:15.415 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-26'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.bundles:2024425783'>
          <item id='64B5A4F78C3C8'/>
        </publish>
      </pubsub>
    </iq>

2021-01-23 10:45:15.433 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='48HWG-8' type='get'>
      <query xmlns='http://jabber.org/protocol/disco#info' node='eu.siacs.conversations.axolotl.devicelist'>
      </query>
    </iq>
2021-01-23 10:45:15.446 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='48HWG-8'>
      <query node='eu.siacs.conversations.axolotl.devicelist' xmlns='http://jabber.org/protocol/disco#info'>
        <identity type='registered' category='account'/>
      </query>
    </iq>

2021-01-23 10:45:15.458 32142-32475/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.461 32142-32475/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.470 32142-32475/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.475 32142-32475/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.484 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-28' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='2024425783'/>
            </list>
          </item>
        </publish>
      </pubsub>
    </iq>
2021-01-23 10:45:15.541 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7BB549'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='2024425783'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>

2021-01-23 10:45:15.556 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-28'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7BB549'/>
        </publish>
      </pubsub>
    </iq>

2021-01-23 10:45:15.564 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.570 32142-32475/org.atalk.android D/(AndroidOmemoService.java:113)#initializationFinished: Initialize OmemoManager successful for peacock@atalk.sytes.net/atalk
2021-01-23 10:45:15.571 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7BB549'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='2024425783'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
2021-01-23 10:45:15.572 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.595 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.600 32142-32413/org.atalk.android D/(DatabaseBackend.java:1025)#storeCachedDeviceList: Identities table - create new activeDevice: peacock@atalk.sytes.net:1966536913 
2021-01-23 10:45:15.614 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.629 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-30' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='1966536913'/>
              <device id='2024425783'/>
            </list>
          </item>
        </publish>
      </pubsub>
    </iq>
2021-01-23 10:45:15.629 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.633 32142-32413/org.atalk.android D/(DatabaseBackend.java:1025)#storeCachedDeviceList: Identities table - create new activeDevice: peacock@atalk.sytes.net:2024425783 
2021-01-23 10:45:15.642 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[1966536913]
2021-01-23 10:45:15.660 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.665 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[1966536913]
2021-01-23 10:45:15.676 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.681 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[1966536913]
2021-01-23 10:45:15.689 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7E0862'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='1966536913'/>
              <device id='2024425783'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
2021-01-23 10:45:15.695 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.699 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <r xmlns='urn:xmpp:sm:3'/>
2021-01-23 10:45:15.701 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.702 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <a xmlns='urn:xmpp:sm:3' h='52'/>
2021-01-23 10:45:15.702 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-30'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7E0862'/>
        </publish>
      </pubsub>
    </iq>
2021-01-23 10:45:15.711 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.714 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7E0862'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='1966536913'/>
              <device id='2024425783'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
2021-01-23 10:45:15.715 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-32' type='set'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='1966536913'/>
              <device id='2024425783'/>
            </list>
          </item>
        </publish>
      </pubsub>
    </iq>
2021-01-23 10:45:15.716 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[1966536913]
2021-01-23 10:45:15.724 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <r xmlns='urn:xmpp:sm:3'/>
2021-01-23 10:45:15.727 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <a xmlns='urn:xmpp:sm:3' h='54'/>
2021-01-23 10:45:15.729 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[2024425783]
2021-01-23 10:45:15.733 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[1966536913]
2021-01-23 10:45:15.742 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.748 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.760 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.766 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.772 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.778 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7F37C0'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='1966536913'/>
              <device id='2024425783'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
2021-01-23 10:45:15.779 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.788 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-32'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <publish node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7F37C0'/>
        </publish>
      </pubsub>
    </iq>
2021-01-23 10:45:15.791 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.797 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <r xmlns='urn:xmpp:sm:3'/>
2021-01-23 10:45:15.798 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.800 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <a xmlns='urn:xmpp:sm:3' h='56'/>
2021-01-23 10:45:15.800 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
      <event xmlns='http://jabber.org/protocol/pubsub#event'>
        <items node='eu.siacs.conversations.axolotl.devicelist'>
          <item id='64B5A4F7F37C0'>
            <list xmlns='eu.siacs.conversations.axolotl'>
              <device id='1966536913'/>
              <device id='2024425783'/>
            </list>
          </item>
        </items>
      </event>
      <addresses xmlns='http://jabber.org/protocol/address'>
        <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
      </addresses>
    </message>
2021-01-23 10:45:15.806 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.810 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <r xmlns='urn:xmpp:sm:3'/>
2021-01-23 10:45:15.813 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.813 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <a xmlns='urn:xmpp:sm:3' h='57'/>
2021-01-23 10:45:15.825 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.831 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.837 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.843 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.855 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.861 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.868 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.873 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.886 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.892 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.898 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.904 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.915 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.921 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.927 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.933 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.944 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.950 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.959 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.966 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]
2021-01-23 10:45:15.981 32142-32413/org.atalk.android D/(DatabaseBackend.java:1012)#storeCachedDeviceList: Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1966536913, 2024425783]
2021-01-23 10:45:15.987 32142-32413/org.atalk.android I/(DatabaseBackend.java:1041)#storeCachedDeviceList: Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[]

=========== compose and send omemo message ============
2021-01-23 10:53:17.055 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <message to='swordfish@atalk.sytes.net' type='normal'>
      <composing xmlns='http://jabber.org/protocol/chatstates'/>
      <origin-id xmlns='urn:xmpp:sid:0' id='V48T-SFLI-N66F-P'/>
    </message>
2021-01-23 10:53:20.432 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq id='KP5XU-37' type='get'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.bundles:2024425783'/>
      </pubsub>
    </iq>
2021-01-23 10:53:20.477 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='KP5XU-37'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.bundles:2024425783'>
          <item id='64B5A4F78C3C8'>
            <bundle xmlns='eu.siacs.conversations.axolotl'>
              <signedPreKeyPublic signedPreKeyId='1'>
                BcyoYtavGIRYbN7COIXE8PG7L429YZ1HVRHV1kt2qmAW
              </signedPreKeyPublic>

                <preKeyPublic preKeyId='100'>
                  BdLOyINcUeRHmrJNe2N7fse+cwT4uV+j5FtpZiOsGLdQ
                </preKeyPublic>
              </prekeys>
            </bundle>
          </item>
        </items>
      </pubsub>
    </iq>
2021-01-23 10:53:29.603 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <message to='swordfish@atalk.sytes.net' type='normal'>
      <paused xmlns='http://jabber.org/protocol/chatstates'/>
      <origin-id xmlns='urn:xmpp:sid:0' id='B3BS-CGBF-N9A9-4'/>
    </message>    

2021-01-23 10:53:36.930 32142-32142/org.atalk.android D/(DatabaseBackend.java:961)#loadIdentityKeys: Missing key (possibly pre-verified) in database for account: peacock@atalk.sytes.net
2021-01-23 10:53:36.933 32142-32142/org.atalk.android I/(SQLiteOmemoStore.java:448)#storeOmemoIdentityKey: Update identityKey for: peacock@atalk.sytes.net:2024425783; org.whispersystems.libsignal.IdentityKey@264bfb2a; 

2021-01-23 10:53:36.981 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq to='swordfish@atalk.sytes.net' id='48HWG-11' type='get'>
      <query xmlns='http://jabber.org/protocol/disco#info' node='eu.siacs.conversations.axolotl.bundles:82553717'>
      </query>
    </iq>
2021-01-23 10:53:37.027 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='48HWG-11'>
      <query node='eu.siacs.conversations.axolotl.bundles:82553717' xmlns='http://jabber.org/protocol/disco#info'>
        <identity type='pep' category='pubsub'/>
        <identity type='leaf' category='pubsub'/>
        <identity type='registered' category='account'/>
        <feature var='http://jabber.org/protocol/pubsub'/>
        <feature var='http://jabber.org/protocol/rsm'/>
        <feature var='http://jabber.org/protocol/pubsub#create-nodes'/>
        <feature var='http://jabber.org/protocol/pubsub#auto-create'/>
        <feature var='http://jabber.org/protocol/pubsub#auto-subscribe'/>
        <feature var='http://jabber.org/protocol/pubsub#delete-nodes'/>
        <feature var='http://jabber.org/protocol/pubsub#delete-items'/>
        <feature var='http://jabber.org/protocol/pubsub#filtered-notifications'/>
        <feature var='http://jabber.org/protocol/pubsub#modify-affiliations'/>
        <feature var='http://jabber.org/protocol/pubsub#outcast-affiliation'/>
        <feature var='http://jabber.org/protocol/pubsub#persistent-items'/>
        <feature var='http://jabber.org/protocol/pubsub#publish'/>
        <feature var='http://jabber.org/protocol/pubsub#publish-options'/>
        <feature var='http://jabber.org/protocol/pubsub#purge-nodes'/>
        <feature var='http://jabber.org/protocol/pubsub#retract-items'/>
        <feature var='http://jabber.org/protocol/pubsub#retrieve-affiliations'/>
        <feature var='http://jabber.org/protocol/pubsub#retrieve-items'/>
        <feature var='http://jabber.org/protocol/pubsub#retrieve-subscriptions'/>
        <feature var='http://jabber.org/protocol/pubsub#subscribe'/>
      </query>
    </iq>
2021-01-23 10:53:37.061 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <iq to='swordfish@atalk.sytes.net' id='KP5XU-39' type='get'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.bundles:82553717'/>
      </pubsub>
    </iq>
    <a xmlns='urn:xmpp:sm:3' h='63'/>
2021-01-23 10:53:37.107 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net' type='result' id='KP5XU-39'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='eu.siacs.conversations.axolotl.bundles:82553717'>
          <item id='64B57F06DC038'>
            <bundle xmlns='eu.siacs.conversations.axolotl'>
              <signedPreKeyPublic signedPreKeyId='1'>
                BRAez5ETTAwxRLTXG9Mj9tGTmyemSs8W5NdvcvdwOkU1
              </signedPreKeyPublic>
              
                <preKeyPublic preKeyId='101'>
                  BZWWL2V+3+hDIgd+kyHrtHfp0xpx2Qui6KsCIeRiUnMb
                </preKeyPublic>
              </prekeys>
            </bundle>
          </item>
        </items>
      </pubsub>
    </iq>              


2021-01-23 10:53:57.963 32142-32369/org.atalk.android D/SMACK: SENT (0): 
    <message to='swordfish@atalk.sytes.net' id='161137040040863076376' type='chat'>
      <encrypted xmlns='eu.siacs.conversations.axolotl'>
        <header sid='1966536913'>
          <key prekey='true' rid='2024425783'>
            MwhPEiEF/Zp00RoojjRAnYEBqz8Zd0N3KMQ0TE2++IhJhi4Xxw4aIQVHnbA0l4bFVUFuD1znfYYD9MiFUaEIvddHrjVRWHfkRCJiMwohBRKB4kOkJ0BveftRXLStzN2HzicXOqAJ/iPsV9qv4+FNEAAYACIwJwSqTHtMeSFk7ChnLSEK4N0I8/i6RRSItZv1SA+xv1JcXpgxBXVvuZzzZ23TKy3Qo+GvxyhW3Q0oADAB
          </key>
          <key prekey='true' rid='82553717'>
            Mwg9EiEF8voYGl0LKYSOmJ7ES0XQNyWlkIXUdGpEglhfSYUImEsaIQVHnbA0l4bFVUFuD1znfYYD9MiFUaEIvddHrjVRWHfkRCJiMwohBeZ4lPeimhiSA5CewvoPUHry8+OPa0PD0ZSGI8oF93NfEAAYACIwDtbqfM9/IvlhkCJdmQj5SIjijwJfAyQJaH0CflyjfHEVwya+9hG5hIz7/3v+8rIm48wKL7d7dkUoADAB
          </key>
          <iv>
            UiuZyCJsodcAar3F
          </iv>
        </header>
        <payload>
          UPQagEBMRQ==
        </payload>
      </encrypted>
      <body>
        I sent you an OMEMO encrypted message but your client doesn't seem to support that. Find more information on https://conversations.im/omemo
      </body>
      <store xmlns='urn:xmpp:hints'/>
      <encryption xmlns='urn:xmpp:eme:0' namespace='eu.siacs.conversations.axolotl' name='OMEMO'/>
      <origin-id xmlns='urn:xmpp:sid:0' id='MZ53-WNJF-ZW1R-C'/>
      <request xmlns='urn:xmpp:receipts'/>
      <active xmlns='http://jabber.org/protocol/chatstates'/>
    </message>

2021-01-23 10:54:30.811 32142-32370/org.atalk.android D/SMACK: RECV (0): 
    <message xml:lang='en' to='peacock@atalk.sytes.net/atalk' from='swordfish@atalk.sytes.net/atalk' type='chat' id='1611370464669145440248'>
      <encrypted xmlns='eu.siacs.conversations.axolotl'>
        <header sid='82553717'>
          <key prekey='true' rid='2024425783'>
            MwgbEiEFJwD6XFiHkKpkhwCJmiGEI2mt/1Ycja6JvKGl84ycti4aIQXkM+ePcDIY5Ru0ze3cYmIE+9Zdb3/q2z7nT9JA/xZ/OCJiMwohBbXNZPEaET3/a33jC8Et5UFio0nU8AbKdfJTpCL6nDk5EAAYACIwlu7XSvCjpOx2OQ3nzEdsoO61ITc8nT8qI66G6Q5MLrBr4qwmi8WpnZjBn87UL/DcGP97pksTz1soADAB
          </key>
          <key rid='1966536913'>
            MwohBVCQsNLq6heJlj7EznmikJdh6Av/4pVfL/xcfF5LWE94EAEYACIwYoKT/LedybZPo9m4I2KXlym43nbsXBjFbBFdiQIhGhb3723bZ5iwFoo+T95YrMC6nP90nXMVw7o=
          </key>
          <iv>
            TT30JR35c43z9Dti
          </iv>
        </header>
        <payload>
          RwA=
        </payload>
      </encrypted>
      <store xmlns='urn:xmpp:hints'/>
      <encryption xmlns='urn:xmpp:eme:0' namespace='eu.siacs.conversations.axolotl' name='OMEMO'/>
      <origin-id xmlns='urn:xmpp:sid:0' id='WI5Y-KYIB-XERC-T'/>
      <active xmlns='http://jabber.org/protocol/chatstates'/>
      <request xmlns='urn:xmpp:receipts'/>
      <body>
        I sent you an OMEMO encrypted message but your client doesn&apos;t seem to support that. Find more information on https://conversations.im/omemo
      </body>
    </message>
                  
              
2021-01-23 10:54:34.868 32142-1285/org.atalk.android E/(SQLiteOmemoStore.java:364)#loadOmemoIdentityKeyPair: Corrupted Omemo IdentityKeyPair: Invalid IdentityKeyPairs for omemoDevice: peacock@atalk.sytes.net:2024425783.
    Exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero)..
2021-01-23 10:54:34.875 32142-1283/org.atalk.android W/aTalk: [78052] org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived() No raw session found for contact swordfish@atalk.sytes.net:82553717. 
    org.jivesoftware.smackx.omemo.exceptions.NoRawSessionException: org.whispersystems.libsignal.InvalidMessageException: No valid sessions.
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoRatchet.doubleRatchetDecrypt(SignalOmemoRatchet.java:128)
        at org.jivesoftware.smackx.omemo.OmemoRatchet.retrieveMessageKeyAndAuthTag(OmemoRatchet.java:107)
        at org.jivesoftware.smackx.omemo.OmemoService.decryptMessage(OmemoService.java:457)
        at org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived(OmemoService.java:1192)
        at org.jivesoftware.smackx.omemo.OmemoManager$3.run(OmemoManager.java:959)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: org.whispersystems.libsignal.InvalidMessageException: No valid sessions.
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:290)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:243)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:211)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoRatchet.doubleRatchetDecrypt(SignalOmemoRatchet.java:122)
        at org.jivesoftware.smackx.omemo.OmemoRatchet.retrieveMessageKeyAndAuthTag(OmemoRatchet.java:107) 
        at org.jivesoftware.smackx.omemo.OmemoService.decryptMessage(OmemoService.java:457) 
        at org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived(OmemoService.java:1192) 
        at org.jivesoftware.smackx.omemo.OmemoManager$3.run(OmemoManager.java:959) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: org.whispersystems.libsignal.InvalidMessageException: Bad Mac!
        at org.whispersystems.libsignal.protocol.SignalMessage.verifyMac(SignalMessage.java:119)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:313)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:268)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:243) 
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:211) 
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoRatchet.doubleRatchetDecrypt(SignalOmemoRatchet.java:122) 
        at org.jivesoftware.smackx.omemo.OmemoRatchet.retrieveMessageKeyAndAuthTag(OmemoRatchet.java:107) 
        at org.jivesoftware.smackx.omemo.OmemoService.decryptMessage(OmemoService.java:457) 
        at org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived(OmemoService.java:1192) 
        at org.jivesoftware.smackx.omemo.OmemoManager$3.run(OmemoManager.java:959) 
        at java.lang.Thread.run(Thread.java:764) 
2021-01-23 10:54:34.887 32142-1285/org.atalk.android E/aTalk: [78054] org.jivesoftware.smackx.omemo.signal.SignalOmemoStoreConnector.getIdentityKeyPair() IdentityKeyPair seems to be invalid.
    org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException: Invalid IdentityKeyPairs for omemoDevice: peacock@atalk.sytes.net:2024425783.
    Exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero)..
        at org.atalk.crypto.omemo.SQLiteOmemoStore.loadOmemoIdentityKeyPair(SQLiteOmemoStore.java:365)
        at org.atalk.crypto.omemo.SQLiteOmemoStore.loadOmemoIdentityKeyPair(SQLiteOmemoStore.java:73)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoStoreConnector.getIdentityKeyPair(SignalOmemoStoreConnector.java:82)
        at org.whispersystems.libsignal.SessionBuilder.processV3(SessionBuilder.java:129)
        at org.whispersystems.libsignal.SessionBuilder.process(SessionBuilder.java:107)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:180)
        at org.whispersystems.libsignal.SessionCipher.decrypt(SessionCipher.java:150)
        at org.jivesoftware.smackx.omemo.signal.SignalOmemoRatchet.doubleRatchetDecrypt(SignalOmemoRatchet.java:101)
        at org.jivesoftware.smackx.omemo.OmemoRatchet.retrieveMessageKeyAndAuthTag(OmemoRatchet.java:107)
        at org.jivesoftware.smackx.omemo.OmemoService.decryptMessage(OmemoService.java:457)
        at org.jivesoftware.smackx.omemo.OmemoService.onOmemoMessageStanzaReceived(OmemoService.java:1192)
        at org.jivesoftware.smackx.omemo.OmemoManager$3.run(OmemoManager.java:959)
        at java.lang.Thread.run(Thread.java:764)

Obviously you should not let the server bundle updates overwrite your own bundle.
This would let the server overwrite your secret identity key part.

Note that in the store implementations there is a difference between storeOmemoIdentityKeyPair(OmemoDevice userDevice, T_IdKeyPair identityKeyPair) and storeOmemoIdentityKey(OmemoDevice userDevice, OmemoDevice contactsDevice, T_IdKey contactsKey)!
The former is intended to store your own identity key PAIR while the latter is intended to store a contacts identity key PUBLIC part.
Those should go into different tables and not be mixed.

I recommend reading the javadoc documentation of the OmemoStore with the knowledge that userDevice is always your own device and contactsDevice is always the device of a contact.

I hope that you soon have your problem figured out :slight_smile:

Yes, I do understand the differences between IdentityKeyPairs and IdentityKey. My understanding is that only own omemo device uses IdentityKeyPairs which contains both a public key and private key; whereas the contact only has IdentityKey.

You need to goes through the latest aTalk debug log in details and my previous comments to understand the actual problem. Actually peacock@atalk.sytes.net:2024425783 is newly generated user own omemodevices; and smack-omemo indeed stores the IdentityKeyPair correctly when it is first initialized via storeOmemoIdentityKeyPair().

However when peacock starts to send the first omemo message, smack-omemo overwritten this with a IdentityKey via storeOmemoIdentityKey(). It seems that smack-omemo mistaken its own omemo device as contact device.

There is why I am confused, and need your clarification on the following 3 areas.

  1. Why omemo treats own omemoDevice as contact’s device, leading to IdentityKeyPairs being overwrittend with IdentityKey?

  2. Does own omemo device contains both an IdentityKeyPairs and an IdentityKey; and they must not be saved in the same table as aTalk does today? Actually it is same as conversation implementation.

  3. Does the identity active state only apply to keyPair, and it does not apply to IdentityKeyPairs.

aTalk identities table implementation follows conversation, where both the own omemo device IdentityKeyPairs is stored in the same table with the contacts’ identities; with the understanding that own omemo device should not contains both IdentityKeyPair and IdentityKey.

Obviously you should not let the server bundle updates overwrite your own bundle.
This would let the server overwrite your secret identity key part.

Do not quite understanding the above comment. From debug log, my understanding it is smack-omemo that performs storeOmemoIdentityKey which causes problem.

Following are use to init the bundle for the newly regenerated device id in the regen function call.

new AndroidOmemoService(pps).initOmemoDevice() → mOmemoManager.initializeAsync(this);

Yeah, but you have to make sure that storeOmemoIdentityKey() cannot change the value that is being returned by loadOmemoIdentityKeyPair(). Storing a key MUST NOT change the key pair.

My understanding from your last comment is that an user OWN omemo device can have both
the IdentityKeyPairs AND the IdentityKey values. i.e. It is possible for it to behave as own omemo device and also as an contact device.

The smack-omemo function call for

storeOmemoIdentityKey(OmemoDevice userDevice, OmemoDevice contactDevice, IdentityKey contactKey)

should only save the IdentityKey to the user OWN omemo device to IdnetityKey location and

storeOmemoIdentityKeyPair(OmemoDevice userDevice, IdentityKeyPair identityKeyPair)

should only save the IdentityKeyPairs to the user OWN omemo device to IdnetityKeyPair location

What about

storeCachedDeviceList(OmemoDevice userDevice, BareJid contact, OmemoCachedDeviceList contactDeviceList)

Can I assume that this does not apply to own omemo device IdentityKeyPairs

Appreciate if you can reconfirm the above, as this means I have to make a change to the database and function implementations.

What about
storeCachedDeviceList(OmemoDevice userDevice, BareJid contact, OmemoCachedDeviceList contactDeviceList)
Can I assume that this does not apply to own omemo device IdentityKeyPairs

The cached device list is a copy of the devices list as published by the server and has nothing to do with the users identity key. I do not fully understand the question?

The workflow of regenerating an identity should be as follows:

  • The user has an old device ID of XXXXXXXXX.
  • Now the user deletes all keys and information related to XXXXXXXXX (identity key pair, prekeys, cached device list…)
  • The user generates a new identity key pair and bundle
  • Published bundle and device ID to the server
  • Removes old device ID + adds new device ID to the device list and republishes the list to the server
  • done.

aTalk omemo DB tables structure follows closely with conversations. Unlike file base storage, in DB implementation, it usually groups all the relevant properties of a key parameter into a single table e.g. “identities” where
a. Key parameter is a row record of omemoDevice (baseJid:deviceId) and
b. properties are stored in columns values e,g. fingerPrint, trust, key etc

Active state is currently treated as a property of omemoDevice in the “identities” table, same as the IdentityKeyPairs / IdentityKey. These “active” flags are being updated via

storeCachedDeviceList(OmemoDevice userDevice, BareJid contact, OmemoCachedDeviceList contactDeviceList).

If the active state applies to both the IdentityKeyPairs / IdentityKey, and are used by smack-omemo, then active column of own/contact omemoDevice rows must both be update; else only row with IdentityKey is considered i.e. “own device” flag (see below) must use as a row selection criteria.

Similarly in my previous question:
If the Own device can have both the IdentityKeyPairs and IdentityKey value, then I need to add in a new column value e.g. “own device” or alike flag set to ‘1’ to denotes the Key/identityKey column contains a IdentityKeyPairs.

When smack-omemo issue the command

storeOmemoIdentityKey(OmemoDevice userDevice, OmemoDevice contactDevice, IdentityKey contactKey)

it will only updates to a row with “own device” set to ‘0’ as the row selection criteria.

However when if the Own device can only have the IdentityKeyPairs value, there is no requirement to change the ‘identities’ table to add in the new “own device” column
When smack-omemo issue the command

storeOmemoIdentityKey(OmemoDevice userDevice, OmemoDevice contactDevice, IdentityKey contactKey)

aTalk can just skips the update if userDevice.equals(contactDevice), there is no change to the “identities” table. This check can also be performed in smack-omemo if need to, pending on final implementation.

aTalk database

Conversations database

=========== Omemo Regeneration ==========
aTalk has implements all the required steps as mentioned;

in addition, before step “Now the user deletes…”, it purges the bundle/items and update device list with the old omemoDevice Id removed on the server. Otherwise the published nodes/items and devicelist on the server database keep growing and the old deleted devices data are left untouched.

After many trial and error to implement OMEMO Regeration. Finally settle on the following
The workflow of regenerating an identity in aTalk are as follows:

  1. User device has an old device peacock@atalk.sytes.net:492495813

  2. Deletes all keys and information related to 492495813 (identity key pair, prekeys, cached device list…) via
    ’ >>> Wiping OMEMO database for account : peacock@atalk.sytes.net

3a. Generates a new identity key pair and bundle
3b. Published bundle and device ID to the server
3c Removes old device ID + adds new device ID to the device list and republishes the list to the server
done. All these are carried out via call to OmemoManager.initializeAsync(this)

  1. Purge server old Bundle and update devicelist to remove 492495813
    The whole process flow is captured in the aTalk log below:

However I found that smack-omemo always finds a way to add back the old 492495813 to the devicelist. The leads to an deviceId without a prekeys bundle on server. It will be shown as corrupted device on next omemo message sending. A dialog is launched to that effect, to allow user to select all the corrupted devices and purged them. Then everything is back to order. Will keep the implementation as it it now.

Has carried out regeneration multiple times, but the last reported problem of IdentityKeyPairs gets overwritten by IdentityKey does not happen in all these trials. I also cannot see a reason why an user own device will have both the IdentityKeyPairs as well as IdentityKey; so decided not to change the identities table. But as a precaution, aTalk will skip the update if userDevice.equals(contactDevice) when

storeOmemoIdentityKey(OmemoDevice userDevice, OmemoDevice contactDevice, IdentityKey contactKey)

is called. Will keep monitoring.

=========== aTalk Omemo Regeneration ================
01-25 14:00:46.110 D/(OmemoRegenerateDialog.java:91)#run(21411): Regenerate Omemo for: peacock@atalk.sytes.net
01-25 14:00:46.112 D/(DatabaseBackend.java:1337)#purgeOmemoDb(21411): >>> Wiping OMEMO database for account : peacock@atalk.sytes.net

01-25 14:00:46.203 I/(DatabaseBackend.java:499)#storeOmemoRegId(21411): ### Omemo device added for: peacock@atalk.sytes.net; 477474523
01-25 14:00:46.205 I/(AndroidOmemoService.java:50)#<init>(21411): ### Registered omemo messageListener for: peacock@atalk.sytes.net

01-25 14:00:46.207 D/(SQLiteOmemoStore.java:813)#purgeBundleDeviceList(21411): Purge server bundle and deviceList for omemo device: peacock@atalk.sytes.net:492495813
01-25 14:00:46.211 D/SMACK   (21411): SENT (0): 
01-25 14:00:46.211 D/SMACK   (21411): <iq id='JIU64-18' type='get'>
01-25 14:00:46.211 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
01-25 14:00:46.211 D/SMACK   (21411):     <items node='eu.siacs.conversations.axolotl.devicelist'/>
01-25 14:00:46.211 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.211 D/SMACK   (21411): </iq>
01-25 14:00:46.230 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.230 D/SMACK   (21411): <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='JIU64-18'>
01-25 14:00:46.230 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
01-25 14:00:46.230 D/SMACK   (21411):     <items node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.230 D/SMACK   (21411):       <item id='64B86DCDF0078'>
01-25 14:00:46.230 D/SMACK   (21411):         <list xmlns='eu.siacs.conversations.axolotl'>
01-25 14:00:46.230 D/SMACK   (21411):           <device id='1341355667'/>
01-25 14:00:46.230 D/SMACK   (21411):           <device id='2024425783'/>
01-25 14:00:46.230 D/SMACK   (21411):           <device id='492495813'/>
01-25 14:00:46.230 D/SMACK   (21411):         </list>
01-25 14:00:46.230 D/SMACK   (21411):       </item>
01-25 14:00:46.230 D/SMACK   (21411):     </items>
01-25 14:00:46.230 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.230 D/SMACK   (21411): </iq>
01-25 14:00:46.235 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.235 D/SMACK   (21411): <r xmlns='urn:xmpp:sm:3'/>
01-25 14:00:46.240 D/SMACK   (21411): SENT (0): 
01-25 14:00:46.240 D/SMACK   (21411): <iq id='JIU64-20' type='set'>
01-25 14:00:46.240 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
01-25 14:00:46.240 D/SMACK   (21411):     <publish node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.240 D/SMACK   (21411):       <item>
01-25 14:00:46.240 D/SMACK   (21411):         <list xmlns='eu.siacs.conversations.axolotl'>
01-25 14:00:46.240 D/SMACK   (21411):           <device id='1341355667'/>
01-25 14:00:46.240 D/SMACK   (21411):           <device id='2024425783'/>
01-25 14:00:46.240 D/SMACK   (21411):         </list>
01-25 14:00:46.240 D/SMACK   (21411):       </item>
01-25 14:00:46.240 D/SMACK   (21411):     </publish>
01-25 14:00:46.240 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.240 D/SMACK   (21411): </iq>

01-25 14:00:46.266 I/(SQLiteOmemoStore.java:390)#storeOmemoIdentityKeyPair(21411): Store omemo identityKeyPair for :peacock@atalk.sytes.net:477474523
01-25 14:00:46.290 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.290 D/SMACK   (21411): <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
01-25 14:00:46.290 D/SMACK   (21411):   <event xmlns='http://jabber.org/protocol/pubsub#event'>
01-25 14:00:46.290 D/SMACK   (21411):     <items node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.290 D/SMACK   (21411):       <item id='64B875CE1EB60'>
01-25 14:00:46.290 D/SMACK   (21411):         <list xmlns='eu.siacs.conversations.axolotl'>
01-25 14:00:46.290 D/SMACK   (21411):           <device id='1341355667'/>
01-25 14:00:46.290 D/SMACK   (21411):           <device id='2024425783'/>
01-25 14:00:46.290 D/SMACK   (21411):         </list>
01-25 14:00:46.290 D/SMACK   (21411):       </item>
01-25 14:00:46.290 D/SMACK   (21411):     </items>
01-25 14:00:46.290 D/SMACK   (21411):   </event>
01-25 14:00:46.290 D/SMACK   (21411):   <addresses xmlns='http://jabber.org/protocol/address'>
01-25 14:00:46.290 D/SMACK   (21411):     <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
01-25 14:00:46.290 D/SMACK   (21411):   </addresses>
01-25 14:00:46.290 D/SMACK   (21411): </message>
01-25 14:00:46.300 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.300 D/SMACK   (21411): <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='JIU64-20'>
01-25 14:00:46.300 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
01-25 14:00:46.300 D/SMACK   (21411):     <publish node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.300 D/SMACK   (21411):       <item id='64B875CE1EB60'/>
01-25 14:00:46.300 D/SMACK   (21411):     </publish>
01-25 14:00:46.300 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.300 D/SMACK   (21411): </iq>
01-25 14:00:46.307 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.307 D/SMACK   (21411): <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
01-25 14:00:46.307 D/SMACK   (21411):   <event xmlns='http://jabber.org/protocol/pubsub#event'>
01-25 14:00:46.307 D/SMACK   (21411):     <items node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.307 D/SMACK   (21411):       <item id='64B875CE1EB60'>
01-25 14:00:46.307 D/SMACK   (21411):         <list xmlns='eu.siacs.conversations.axolotl'>
01-25 14:00:46.307 D/SMACK   (21411):           <device id='1341355667'/>
01-25 14:00:46.307 D/SMACK   (21411):           <device id='2024425783'/>
01-25 14:00:46.307 D/SMACK   (21411):         </list>
01-25 14:00:46.307 D/SMACK   (21411):       </item>
01-25 14:00:46.307 D/SMACK   (21411):     </items>
01-25 14:00:46.307 D/SMACK   (21411):   </event>
01-25 14:00:46.307 D/SMACK   (21411):   <addresses xmlns='http://jabber.org/protocol/address'>
01-25 14:00:46.307 D/SMACK   (21411):     <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
01-25 14:00:46.307 D/SMACK   (21411):   </addresses>
01-25 14:00:46.307 D/SMACK   (21411): </message>
01-25 14:00:46.312 D/SMACK   (21411): SENT (0): 
01-25 14:00:46.312 D/SMACK   (21411): <iq id='JIU64-22' type='set'>
01-25 14:00:46.312 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
01-25 14:00:46.312 D/SMACK   (21411):     <purge node='eu.siacs.conversations.axolotl.bundles:492495813'/>
01-25 14:00:46.312 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.312 D/SMACK   (21411): </iq>
01-25 14:00:46.316 D/(DatabaseBackend.java:1012)#storeCachedDeviceList(21411): Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1341355667, 2024425783]
01-25 14:00:46.321 D/(DatabaseBackend.java:1025)#storeCachedDeviceList(21411): Identities table - create new activeDevice: peacock@atalk.sytes.net:1341355667 
01-25 14:00:46.332 D/(DatabaseBackend.java:1025)#storeCachedDeviceList(21411): Identities table - create new activeDevice: peacock@atalk.sytes.net:2024425783 
01-25 14:00:46.333 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.333 D/SMACK   (21411): <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='JIU64-22'/>
01-25 14:00:46.337 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.337 D/SMACK   (21411): <r xmlns='urn:xmpp:sm:3'/>
01-25 14:00:46.343 D/SMACK   (21411): SENT (0): 
01-25 14:00:46.343 D/SMACK   (21411): <iq id='JIU64-24' type='set'>
01-25 14:00:46.343 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
01-25 14:00:46.343 D/SMACK   (21411):     <delete node='eu.siacs.conversations.axolotl.bundles:492495813'/>
01-25 14:00:46.343 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.343 D/SMACK   (21411): </iq>
01-25 14:00:46.343 I/(DatabaseBackend.java:1041)#storeCachedDeviceList(21411): Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[477474523]
01-25 14:00:46.361 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.361 D/SMACK   (21411): <iq xml:lang='en-GB' to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='result' id='JIU64-24'/>
01-25 14:00:46.368 D/SMACK   (21411): SENT (0): 
01-25 14:00:46.373 D/(DatabaseBackend.java:1012)#storeCachedDeviceList(21411): Identities table - updating for activeDevice: peacock@atalk.sytes.net:[1341355667, 2024425783, 492495813]
01-25 14:00:46.392 I/(DatabaseBackend.java:1041)#storeCachedDeviceList(21411): Identities table updated for inactiveDevice: peacock@atalk.sytes.net:[477474523]
01-25 14:00:46.409 D/SMACK   (21411): SENT (0): 
01-25 14:00:46.409 D/SMACK   (21411): <iq id='JIU64-26' type='set'>
01-25 14:00:46.409 D/SMACK   (21411):   <pubsub xmlns='http://jabber.org/protocol/pubsub'>
01-25 14:00:46.409 D/SMACK   (21411):     <publish node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.409 D/SMACK   (21411):       <item>
01-25 14:00:46.409 D/SMACK   (21411):         <list xmlns='eu.siacs.conversations.axolotl'>
01-25 14:00:46.409 D/SMACK   (21411):           <device id='1341355667'/>
01-25 14:00:46.409 D/SMACK   (21411):           <device id='2024425783'/>
01-25 14:00:46.409 D/SMACK   (21411):           <device id='492495813'/>
01-25 14:00:46.409 D/SMACK   (21411):         </list>
01-25 14:00:46.409 D/SMACK   (21411):       </item>
01-25 14:00:46.409 D/SMACK   (21411):     </publish>
01-25 14:00:46.409 D/SMACK   (21411):   </pubsub>
01-25 14:00:46.409 D/SMACK   (21411): </iq>
01-25 14:00:46.471 D/SMACK   (21411): RECV (0): 
01-25 14:00:46.471 D/SMACK   (21411): <message to='peacock@atalk.sytes.net/atalk' from='peacock@atalk.sytes.net' type='headline'>
01-25 14:00:46.471 D/SMACK   (21411):   <event xmlns='http://jabber.org/protocol/pubsub#event'>
01-25 14:00:46.471 D/SMACK   (21411):     <items node='eu.siacs.conversations.axolotl.devicelist'>
01-25 14:00:46.471 D/SMACK   (21411):       <item id='64B875CE486C7'>
01-25 14:00:46.471 D/SMACK   (21411):         <list xmlns='eu.siacs.conversations.axolotl'>
01-25 14:00:46.471 D/SMACK   (21411):           <device id='1341355667'/>
01-25 14:00:46.471 D/SMACK   (21411):           <device id='2024425783'/>
01-25 14:00:46.471 D/SMACK   (21411):           <device id='492495813'/>
01-25 14:00:46.471 D/SMACK   (21411):         </list>
01-25 14:00:46.471 D/SMACK   (21411):       </item>
01-25 14:00:46.471 D/SMACK   (21411):     </items>
01-25 14:00:46.471 D/SMACK   (21411):   </event>
01-25 14:00:46.471 D/SMACK   (21411):   <addresses xmlns='http://jabber.org/protocol/address'>
01-25 14:00:46.471 D/SMACK   (21411):     <address jid='peacock@atalk.sytes.net/atalk' type='replyto'/>
01-25 14:00:46.471 D/SMACK   (21411):   </addresses>
01-25 14:00:46.471 D/SMACK   (21411): </message>
1 Like

This indicates that a deviceListUpdate listener is still active.
To prevent this, you could call oldOmemoManager.stopStanzaAndPEPListeners() before deleting the device ID from the device list.

Thanks for the input. It does fix the reported problem. With this I am able to revert to the initial implementation order as below. I have included this fix in aTalk v2.5.0 release.
Thanks again for your guidance.

1. Purge server old Bundle and update devicelist to remove 492495813
The whole process flow is captured in the aTalk log below:
2. User device has an old device peacock@atalk.sytes.net:492495813
3. Deletes all keys and information related to 492495813 (identity key pair, prekeys, cached device list…) via
’ >>> Wiping OMEMO database for account : [peacock@atalk.sytes.net](mailto:peacock@atalk.sytes.net)’

4a. Generates a new identity key pair and bundle
4b. Published bundle and device ID to the server
4c Removes old device ID + adds new device ID to the device list and republishes the list to the server
done. All these are carried out via call to OmemoManager.initializeAsync(this)
1 Like

Glad you got it to work :slight_smile:.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.