public static void publishPublicKey ( PepManager pepManager , PubkeyElement pubkeyElement , OpenPgpV4Fingerprint fingerprint ) throws InterruptedException , PubSubException . NotALeafNodeException , XMPPException . XMPPErrorException , SmackException . NotConnectedException , SmackException . NoResponseException { String keyNodeName = PEP_NODE_PUBLIC_KEY ( fingerprint ) ; PubSubManager pm = pepManager . getPepPubSubManager ( ) ; // Check if key available at data node // If not, publish key to data node LeafNode keyNode = pm . getOrCreateLeafNode ( keyNodeName ) ; changeAccessModelIfNecessary ( keyNode , AccessModel . open ) ; List < Item > items = keyNode . getItems ( 1 ) ; if ( items . isEmpty ( ) ) { LOGGER . log ( Level . FINE , "Node " + keyNodeName + " is empty. Publish." ) ; keyNode . publish ( new PayloadItem <> ( pubkeyElement ) ) ; } else { LOGGER . log ( Level . FINE , "Node " + keyNodeName + " already contains key. Skip." ) ; } // Fetch IDs from metadata node LeafNode metadataNode = pm . getOrCreateLeafNode ( PEP_NODE_PUBLIC_KEYS ) ; changeAccessModelIfNecessary ( metadataNode , AccessModel . open ) ; List < PayloadItem < PublicKeysListElement > > metadataItems = metadataNode . getItems ( 1 ) ; PublicKeysListElement . Builder builder = PublicKeysListElement . builder ( ) ; if ( ! metadataItems . isEmpty ( ) && metadataItems . get ( 0 ) . getPayload ( ) != null ) { // Add old entries back to list. PublicKeysListElement publishedList = metadataItems . get ( 0 ) . getPayload ( ) ; for ( PublicKeysListElement . PubkeyMetadataElement meta : publishedList . getMetadata ( ) . values ( ) ) { builder . addMetadata ( meta ) ; } } builder . addMetadata ( new PublicKeysListElement . PubkeyMetadataElement ( fingerprint , new Date ( ) ) ) ; // Publish IDs to metadata node metadataNode . publish ( new PayloadItem <> ( builder . build ( ) ) ) ; }
Publish the users OpenPGP public key to the public key node if necessary . Also announce the key to other users by updating the metadata node .