1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-07 11:31:10 +01:00

WiP finished, no more compiler errors - untested

This commit is contained in:
Paul Schaub 2018-06-14 14:40:35 +02:00
parent 49a51bfa2d
commit 422baa6d2e
21 changed files with 647 additions and 396 deletions

View file

@ -232,14 +232,14 @@ public final class OpenPgpManager extends Manager {
SecretKeyBackupSelectionCallback selectKeyCallback)
throws InterruptedException, PubSubException.NotALeafNodeException,
XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException,
SmackException.NotLoggedInException {
SmackException.NotLoggedInException, SmackOpenPgpException, IOException {
throwIfNoProviderSet();
throwIfNotAuthenticated();
BareJid ownJid = connection().getUser().asBareJid();
String backupCode = generateBackupPassword();
Set<OpenPgpV4Fingerprint> availableKeyPairs = provider.getStore().getAvailableKeyPairFingerprints();
Set<OpenPgpV4Fingerprint> availableKeyPairs = provider.getStore().getAvailableKeyPairFingerprints(ownJid);
Set<OpenPgpV4Fingerprint> selectedKeyPairs = selectKeyCallback.selectKeysToBackup(availableKeyPairs);
SecretkeyElement secretKey = createSecretkeyElement(ownJid, selectedKeyPairs, backupCode);
@ -419,7 +419,7 @@ public final class OpenPgpManager extends Manager {
OpenPgpV4Fingerprint fingerprint,
Date date)
throws MissingOpenPgpPublicKeyException {
byte[] keyBytes = provider.getStore().getPublicKeyBytes(owner, fingerprint);
byte[] keyBytes = provider.getStore().getPublicKeyRingBytes(owner, fingerprint);
return createPubkeyElement(keyBytes, date);
}
@ -429,11 +429,11 @@ public final class OpenPgpManager extends Manager {
private SecretkeyElement createSecretkeyElement(BareJid owner,
Set<OpenPgpV4Fingerprint> fingerprints,
String backupCode) {
String backupCode) throws SmackOpenPgpException, IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (OpenPgpV4Fingerprint fingerprint : fingerprints) {
try {
byte[] bytes = provider.getStore().getSecretKeyBytes(owner, fingerprint);
byte[] bytes = provider.getStore().getSecretKeyRingBytes(owner, fingerprint);
buffer.write(bytes);
} catch (MissingOpenPgpKeyPairException | IOException e) {
LOGGER.log(Level.WARNING, "Cannot backup secret key " + Long.toHexString(fingerprint.getKeyId()) + ".", e);
@ -443,7 +443,8 @@ public final class OpenPgpManager extends Manager {
return createSecretkeyElement(buffer.toByteArray(), backupCode);
}
private SecretkeyElement createSecretkeyElement(byte[] keys, String backupCode) {
private SecretkeyElement createSecretkeyElement(byte[] keys, String backupCode)
throws SmackOpenPgpException, IOException {
byte[] encrypted = provider.symmetricallyEncryptWithPassword(keys, backupCode);
return new SecretkeyElement(Base64.encode(encrypted));
}

View file

@ -49,11 +49,12 @@ public interface OpenPgpStore {
/**
* Return a {@link Set} containing the {@link OpenPgpV4Fingerprint}s of the master keys of all available
* OpenPGP key pairs.
* OpenPGP key pairs of {@code owner}.
*
* @param owner owner.
* @return set of fingerprints of available OpenPGP key pairs master keys.
*/
Set<OpenPgpV4Fingerprint> getAvailableKeyPairFingerprints();
Set<OpenPgpV4Fingerprint> getAvailableKeyPairFingerprints(BareJid owner) throws SmackOpenPgpException;
/**
* Return a {@link Map} containing the {@link OpenPgpV4Fingerprint}s of all OpenPGP public keys of a
@ -86,7 +87,7 @@ public interface OpenPgpStore {
Map<OpenPgpV4Fingerprint, Date> getAnnouncedKeysFingerprints(BareJid contact);
/**
* Store a {@Map} of a contacts fingerprints and publication dates in persistent storage.
* Store a {@link Map} of a contacts fingerprints and publication dates in persistent storage.
*
* @param contact {@link BareJid} of the owner of the announced public keys.
* @param fingerprints {@link Map} which contains a list of the keys of {@code owner}.
@ -94,22 +95,22 @@ public interface OpenPgpStore {
void setAnnouncedKeysFingerprints(BareJid contact, Map<OpenPgpV4Fingerprint, Date> fingerprints);
/**
* Return the {@link Date} of the last revision which was fetched from PubSub.
* Return the a {@link Map} of {@link OpenPgpV4Fingerprint}s and the {@link Date}s of when they were last
* fetched from PubSub.
*
* @param owner owner of the key
* @param fingerprint fingerprint of the key.
* @return {@link Date} or {@code null} if no record found.
* @param owner owner of the keys
* @return {@link Map} of keys last revision dates.
*/
Date getPubkeysLastRevision(BareJid owner, OpenPgpV4Fingerprint fingerprint);
Map<OpenPgpV4Fingerprint, Date> getPubkeysLastRevisions(BareJid owner);
/**
* Set the {@link Date} of the last revision which was fetched from PubSub.
* Set the last revision dates of all keys of a contact.
*
* @param owner owner of the key
* @param fingerprint fingerprint of the key
* @param revision {@link Date} of the revision
* @param owner owner of the keys
* @param revisionDates {@link Map} of {@link OpenPgpV4Fingerprint}s and the {@link Date}s of when they
* were last fetched from PubSub.
*/
void setPubkeysLastRevision(BareJid owner, OpenPgpV4Fingerprint fingerprint, Date revision);
void setPubkeysLastRevision(BareJid owner, Map<OpenPgpV4Fingerprint, Date> revisionDates);
/**
* Return a {@link MultiMap} which contains contacts and their trusted keys {@link OpenPgpV4Fingerprint}s.
@ -125,7 +126,7 @@ public interface OpenPgpStore {
* @param fingerprint fingerprint of the key
* @return byte representation of the public key.
*/
byte[] getPublicKeyBytes(BareJid owner, OpenPgpV4Fingerprint fingerprint)
byte[] getPublicKeyRingBytes(BareJid owner, OpenPgpV4Fingerprint fingerprint)
throws MissingOpenPgpPublicKeyException;
/**
@ -135,7 +136,7 @@ public interface OpenPgpStore {
* @param fingerprint fingerprint of the key
* @return byte representation of the secret key.
*/
byte[] getSecretKeyBytes(BareJid owner, OpenPgpV4Fingerprint fingerprint)
byte[] getSecretKeyRingBytes(BareJid owner, OpenPgpV4Fingerprint fingerprint)
throws MissingOpenPgpKeyPairException;
}

View file

@ -1,3 +1,19 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ox.callback;
public interface SmackMissingOpenPgpPublicKeyCallback {

View file

@ -0,0 +1,20 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Chat related classes for XEP-0373: OpenPGP for XMPP.
*/
package org.jivesoftware.smackx.ox.chat;

View file

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.ox.exception;
import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint;
import org.jxmpp.jid.BareJid;
/**
@ -26,15 +28,23 @@ public class MissingOpenPgpKeyPairException extends Exception {
private static final long serialVersionUID = 1L;
private final BareJid owner;
private final OpenPgpV4Fingerprint fingerprint;
/**
* Create a new {@link MissingOpenPgpKeyPairException}.
*
* @param owner owner of the missing key pair.
* @param e
* @param fingerprint fingerprint of the missing key.
*/
public MissingOpenPgpKeyPairException(BareJid owner, Throwable e) {
super("Missing OpenPGP key pair for user " + owner);
public MissingOpenPgpKeyPairException(BareJid owner, OpenPgpV4Fingerprint fingerprint) {
super("Missing OpenPGP key pair " + fingerprint.toString() + " for user " + owner);
this.owner = owner;
this.fingerprint = fingerprint;
}
public MissingOpenPgpKeyPairException(BareJid owner, OpenPgpV4Fingerprint fingerprint, Throwable e) {
super("Missing OpenPGP key pair " + fingerprint.toString() + " for user " + owner, e);
this.fingerprint = fingerprint;
this.owner = owner;
}
@ -46,4 +56,10 @@ public class MissingOpenPgpKeyPairException extends Exception {
public BareJid getOwner() {
return owner;
}
public OpenPgpV4Fingerprint getFingerprint() {
return fingerprint;
}
}

View file

@ -27,8 +27,8 @@ public class MissingOpenPgpPublicKeyException extends Exception {
private static final long serialVersionUID = 1L;
private BareJid user;
private OpenPgpV4Fingerprint fingerprint;
private final BareJid owner;
private final OpenPgpV4Fingerprint fingerprint;
/**
* Create a new {@link MissingOpenPgpPublicKeyException}.
@ -37,22 +37,25 @@ public class MissingOpenPgpPublicKeyException extends Exception {
* @param fingerprint {@link OpenPgpV4Fingerprint} of the missing key.
*/
public MissingOpenPgpPublicKeyException(BareJid owner, OpenPgpV4Fingerprint fingerprint) {
super("Missing public key " + fingerprint.toString() + " for user " + owner + ".");
this.user = owner;
super("Missing public key " + fingerprint.toString() + " for owner " + owner + ".");
this.owner = owner;
this.fingerprint = fingerprint;
}
public MissingOpenPgpPublicKeyException(Throwable e) {
public MissingOpenPgpPublicKeyException(BareJid owner, OpenPgpV4Fingerprint fingerprint, Throwable e) {
super("Missing public key " + fingerprint.toString() + " for owner " + owner + ".", e);
this.owner = owner;
this.fingerprint = fingerprint;
}
/**
* Return the {@link BareJid} of the owner of the missing key.
*
* @return owner of missing key.
*/
public BareJid getUser() {
return user;
public BareJid getOwner() {
return owner;
}
/**

View file

@ -1,3 +1,19 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ox.exception;
import org.jxmpp.jid.BareJid;

View file

@ -1,3 +1,19 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ox.exception;
public class NoBackupFoundException {

View file

@ -1,3 +1,19 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ox.util;
import java.util.Arrays;

View file

@ -1,3 +1,19 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.ox.util;
import java.util.Arrays;

View file

@ -0,0 +1,20 @@
/**
*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Utility classes for XEP-0373: OpenPGP for XMPP.
*/
package org.jivesoftware.smackx.ox.util;