From 7e1248f9e8cf26121f6d03f41ec52a2dc195bb62 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 12 Feb 2017 19:26:28 +0100 Subject: [PATCH] DRAFT/WIP Started XEP-0373: OpenPGP for XMPP implementation --- settings.gradle | 4 +- smack-openpgp-bouncycastle/build.gradle | 12 +++ .../BouncycastleOpenPgpProvider.java | 32 +++++++ .../smackx/ox/bouncycastle/package-info.java | 20 +++++ smack-openpgp/build.gradle | 10 +++ .../smackx/ox/OpenPgpManager.java | 26 ++++++ .../smackx/ox/OpenPgpMessage.java | 82 ++++++++++++++++++ .../smackx/ox/OpenPgpProvider.java | 25 ++++++ .../smackx/ox/element/CryptElement.java | 44 ++++++++++ .../EncryptedOpenPgpContentElement.java | 41 +++++++++ .../ox/element/OpenPgpContentElement.java | 78 +++++++++++++++++ .../smackx/ox/element/OpenPgpElement.java | 85 +++++++++++++++++++ .../smackx/ox/element/SignElement.java | 44 ++++++++++ .../smackx/ox/element/SigncryptElement.java | 44 ++++++++++ .../smackx/ox/element/package-info.java | 20 +++++ .../jivesoftware/smackx/ox/package-info.java | 20 +++++ .../ox/provider/CryptElementProvider.java | 31 +++++++ .../OpenPgpContentElementProvider.java | 69 +++++++++++++++ .../ox/provider/OpenPgpElementProvider.java | 31 +++++++ .../ox/provider/SignElementProvider.java | 40 +++++++++ .../ox/provider/SigncryptElementProvider.java | 30 +++++++ .../smackx/ox/provider/package-info.java | 20 +++++ 22 files changed, 807 insertions(+), 1 deletion(-) create mode 100644 smack-openpgp-bouncycastle/build.gradle create mode 100644 smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/BouncycastleOpenPgpProvider.java create mode 100644 smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/package-info.java create mode 100644 smack-openpgp/build.gradle create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/CryptElement.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/EncryptedOpenPgpContentElement.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpContentElement.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SignElement.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SigncryptElement.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/package-info.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/package-info.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/CryptElementProvider.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpContentElementProvider.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpElementProvider.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SignElementProvider.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SigncryptElementProvider.java create mode 100644 smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/package-info.java diff --git a/settings.gradle b/settings.gradle index a0024efb2..b97085392 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,4 +26,6 @@ include 'smack-core', 'smack-omemo', 'smack-omemo-signal', 'smack-omemo-signal-integration-test', - 'smack-repl' + 'smack-repl', + 'smack-openpgp', + 'smack-openpgp-bouncycastle' diff --git a/smack-openpgp-bouncycastle/build.gradle b/smack-openpgp-bouncycastle/build.gradle new file mode 100644 index 000000000..a30b82889 --- /dev/null +++ b/smack-openpgp-bouncycastle/build.gradle @@ -0,0 +1,12 @@ +description = """\ +Smack API for OpenPGP using Bouncycastle.""" + +// Note that the test dependencies (junit, …) are inferred from the +// sourceSet.test of the core subproject +dependencies { + compile project(':smack-core') + compile project(':smack-openpgp') + compile 'org.bouncycastle:bcpg-jdk15on:1.56' + testCompile project(path: ":smack-core", configuration: "testRuntime") + testCompile project(path: ":smack-core", configuration: "archives") +} diff --git a/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/BouncycastleOpenPgpProvider.java b/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/BouncycastleOpenPgpProvider.java new file mode 100644 index 000000000..5c3fc2445 --- /dev/null +++ b/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/BouncycastleOpenPgpProvider.java @@ -0,0 +1,32 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.bouncycastle; + +import java.io.InputStream; + +import org.jivesoftware.smackx.ox.OpenPgpMessage; +import org.jivesoftware.smackx.ox.OpenPgpProvider; + +public class BouncycastleOpenPgpProvider implements OpenPgpProvider { + + @Override + public OpenPgpMessage toOpenPgpMessage(InputStream is) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/package-info.java b/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/package-info.java new file mode 100644 index 000000000..a251c0154 --- /dev/null +++ b/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/package-info.java @@ -0,0 +1,20 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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. + */ +/** + * Providers for XEP-0373: OpenPGP for XMPP using Bouncycastle. + */ +package org.jivesoftware.smackx.ox.bouncycastle; diff --git a/smack-openpgp/build.gradle b/smack-openpgp/build.gradle new file mode 100644 index 000000000..7085e5dcd --- /dev/null +++ b/smack-openpgp/build.gradle @@ -0,0 +1,10 @@ +description = """\ +Smack API for XEP-0373: OpenPGP for XMPP.""" + +// Note that the test dependencies (junit, …) are inferred from the +// sourceSet.test of the core subproject +dependencies { + compile project(':smack-core') + testCompile project(path: ":smack-core", configuration: "testRuntime") + testCompile project(path: ":smack-core", configuration: "archives") +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java new file mode 100644 index 000000000..cb7a5f682 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java @@ -0,0 +1,26 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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; + +import java.io.InputStream; + +public class OpenPgpManager { + + public static OpenPgpMessage toOpenPgpMessage(InputStream is) { + return null; + } +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java new file mode 100644 index 000000000..4824b62a3 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java @@ -0,0 +1,82 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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; + +import java.io.IOException; + +import org.jivesoftware.smackx.ox.element.CryptElement; +import org.jivesoftware.smackx.ox.element.OpenPgpContentElement; +import org.jivesoftware.smackx.ox.element.SignElement; +import org.jivesoftware.smackx.ox.element.SigncryptElement; +import org.jivesoftware.smackx.ox.provider.OpenPgpContentElementProvider; +import org.xmlpull.v1.XmlPullParserException; + +public class OpenPgpMessage { + + enum State { + signcrypt, + sign, + crypt, + ; + } + + private final String element; + private final State state; + + private OpenPgpContentElement openPgpContentElement; + + public OpenPgpMessage(State state, String content) { + this.element = content; + this.state = state; + } + + public OpenPgpContentElement getOpenPgpContentElement() throws XmlPullParserException, IOException { + ensureOpenPgpContentElementSet(); + + return openPgpContentElement; + } + + private void ensureOpenPgpContentElementSet() throws XmlPullParserException, IOException { + if (openPgpContentElement != null) + return; + + openPgpContentElement = OpenPgpContentElementProvider.parseOpenPgpContentElement(element); + switch (state) { + case signcrypt: + if (!(openPgpContentElement instanceof SigncryptElement)) { + throw new IllegalStateException( + "The used OpenPGP content element does not match the mode used in the raw OpenPGP message. Content element: " + + openPgpContentElement.getElementName() + ". Mode: " + state); + } + break; + case sign: + if (!(openPgpContentElement instanceof SignElement)) { + throw new IllegalStateException( + "The used OpenPGP content element does not match the mode used in the raw OpenPGP message. Content element: " + + openPgpContentElement.getElementName() + ". Mode: " + state); + } + break; + case crypt: + if (!(openPgpContentElement instanceof CryptElement)) { + throw new IllegalStateException( + "The used OpenPGP content element does not match the mode used in the raw OpenPGP message. Content element: " + + openPgpContentElement.getElementName() + ". Mode: " + state); + } + break; + } + } +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java new file mode 100644 index 000000000..4fb9b044b --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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; + +import java.io.InputStream; + +public interface OpenPgpProvider { + + public OpenPgpMessage toOpenPgpMessage(InputStream is); + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/CryptElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/CryptElement.java new file mode 100644 index 000000000..8342dfa85 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/CryptElement.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.element; + +import java.util.Date; +import java.util.List; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jxmpp.jid.Jid; + +public class CryptElement extends EncryptedOpenPgpContentElement { + + public static final String ELEMENT = "crypt"; + + public CryptElement(List to, String rpad, Date timestamp, List payload) { + super(to, rpad, timestamp, payload); + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public CharSequence toXML() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/EncryptedOpenPgpContentElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/EncryptedOpenPgpContentElement.java new file mode 100644 index 000000000..7f29f5a60 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/EncryptedOpenPgpContentElement.java @@ -0,0 +1,41 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.element; + +import java.util.Date; +import java.util.List; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; + +public abstract class EncryptedOpenPgpContentElement extends OpenPgpContentElement { + + private final String rpad; + + protected EncryptedOpenPgpContentElement(List to, String rpad, Date timestamp, List payload) { + super(to, timestamp, payload); + this.rpad = rpad; + } + + @Override + protected void addCommonXml(XmlStringBuilder xml) { + super.addCommonXml(xml); + + xml.openElement("rpad").escape(rpad).closeElement("rpad"); + } +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpContentElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpContentElement.java new file mode 100644 index 000000000..b0ec65464 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpContentElement.java @@ -0,0 +1,78 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.element; + +import java.util.Date; +import java.util.List; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; +import org.jxmpp.util.XmppDateTime; + +public abstract class OpenPgpContentElement implements ExtensionElement { + + private final List to; + private final Date timestamp; + private final List payload; + + private String timestampString; + + protected OpenPgpContentElement(List to, Date timestamp, List payload) { + this.to = to; + this.timestamp = timestamp; + this.payload = payload; + } + + public final List getTo() { + return to; + } + + public final Date getTimestamp() { + return timestamp; + } + + public final List getPayload() { + return payload; + } + + @Override + public String getNamespace() { + return OpenPgpElement.NAMESPACE; + } + + protected void ensureTimestampStringSet() { + if (timestampString != null) return; + + timestampString = XmppDateTime.formatXEP0082Date(timestamp); + } + + protected void addCommonXml(XmlStringBuilder xml) { + for (Jid toJid : to) { + xml.halfOpenElement("to").attribute("jid", toJid).closeEmptyElement(); + } + + ensureTimestampStringSet(); + xml.halfOpenElement("time").attribute("stamp", timestampString).closeEmptyElement(); + + xml.openElement("payload"); + for (ExtensionElement element : payload) { + xml.append(element.toXML()); + } + xml.closeElement("payload"); + } +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java new file mode 100644 index 000000000..9f057aa65 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/OpenPgpElement.java @@ -0,0 +1,85 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.element; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jivesoftware.smack.util.stringencoder.Base64; +import org.jivesoftware.smackx.ox.OpenPgpManager; +import org.jivesoftware.smackx.ox.OpenPgpMessage; +import org.xmlpull.v1.XmlPullParserException; + +public class OpenPgpElement implements ExtensionElement { + + public static final String ELEMENT = "openpgp"; + public static final String NAMESPACE = "urn:xmpp:openpg:0"; + + private final String base64EncodedOpenPgpMessage; + + private OpenPgpMessage openPgpMessage; + + private byte[] openPgpMessageBytes; + + private OpenPgpContentElement openPgpContentElement; + + public OpenPgpElement(String base64EncodedOpenPgpMessage) { + this.base64EncodedOpenPgpMessage = base64EncodedOpenPgpMessage; + } + + public OpenPgpMessage getOpenPgpMessage() { + if (openPgpMessage == null) { + ensureOpenPgpMessageBytesSet(); + InputStream is = new ByteArrayInputStream(openPgpMessageBytes); + openPgpMessage = OpenPgpManager.toOpenPgpMessage(is); + } + + return openPgpMessage; + } + + public OpenPgpContentElement getContentElement() throws XmlPullParserException, IOException { + if (openPgpContentElement == null) { + openPgpContentElement = getOpenPgpMessage().getOpenPgpContentElement(); + } + + return openPgpContentElement; + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public CharSequence toXML() { + // TODO Auto-generated method stub + return null; + } + + private final void ensureOpenPgpMessageBytesSet() { + if (openPgpMessageBytes != null) return; + + openPgpMessageBytes = Base64.decode(base64EncodedOpenPgpMessage); + } +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SignElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SignElement.java new file mode 100644 index 000000000..553bdf3be --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SignElement.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.element; + +import java.util.Date; +import java.util.List; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jxmpp.jid.Jid; + +public class SignElement extends OpenPgpContentElement { + + public SignElement(List to, Date timestamp, List payload) { + super(to, timestamp, payload); + } + + public static final String ELEMENT = "sign"; + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public CharSequence toXML() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SigncryptElement.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SigncryptElement.java new file mode 100644 index 000000000..e8f9c9616 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/SigncryptElement.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.element; + +import java.util.Date; +import java.util.List; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jxmpp.jid.Jid; + +public class SigncryptElement extends EncryptedOpenPgpContentElement { + + public static final String ELEMENT = "signcrypt"; + + public SigncryptElement(List to, String rpad, Date timestamp, List payload) { + super(to, rpad, timestamp, payload); + } + + @Override + public String getElementName() { + return ELEMENT; + } + + @Override + public CharSequence toXML() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/package-info.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/package-info.java new file mode 100644 index 000000000..fad677c14 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/element/package-info.java @@ -0,0 +1,20 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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. + */ +/** + * XML elements for XEP-0373: OpenPGP for XMPP. + */ +package org.jivesoftware.smackx.ox.element; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/package-info.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/package-info.java new file mode 100644 index 000000000..591a9f057 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/package-info.java @@ -0,0 +1,20 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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. + */ +/** + * Smack API for XEP-0373: OpenPGP for XMPP. + */ +package org.jivesoftware.smackx.ox; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/CryptElementProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/CryptElementProvider.java new file mode 100644 index 000000000..28010eb00 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/CryptElementProvider.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.provider; + +import org.jivesoftware.smackx.ox.element.CryptElement; +import org.xmlpull.v1.XmlPullParser; + +public class CryptElementProvider extends OpenPgpContentElementProvider { + + @Override + public CryptElement parse(XmlPullParser parser, int initialDepth) throws Exception { + OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth); + + return new CryptElement(data.to, data.rpad, data.timestamp, data.payload); + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpContentElementProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpContentElementProvider.java new file mode 100644 index 000000000..c3ae74991 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpContentElementProvider.java @@ -0,0 +1,69 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.provider; + +import java.io.IOException; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.ox.element.OpenPgpContentElement; +import org.jxmpp.jid.Jid; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +public abstract class OpenPgpContentElementProvider extends ExtensionElementProvider { + + public static OpenPgpContentElement parseOpenPgpContentElement(String element) + throws XmlPullParserException, IOException { + XmlPullParser parser = PacketParserUtils.getParserFor(element); + return parseOpenPgpContentElement(parser); + } + + public static OpenPgpContentElement parseOpenPgpContentElement(XmlPullParser parser) { + return null; + } + + @Override + public abstract O parse(XmlPullParser parser, int initialDepth) throws Exception; + + protected static OpenPgpContentElementData parseOpenPgpContentElementData(XmlPullParser parser, int initialDepth) { + List to = new LinkedList<>(); + Date timestamp = null; + String rpad = null; + List payload = new LinkedList<>(); + + return new OpenPgpContentElementData(to, timestamp, rpad, payload); + } + + protected final static class OpenPgpContentElementData { + protected final List to; + protected final Date timestamp; + protected final String rpad; + protected final List payload; + + private OpenPgpContentElementData(List to, Date timestamp, String rpad, List payload) { + this.to = to; + this.timestamp = timestamp; + this.rpad = rpad; + this.payload = payload; + } + } +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpElementProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpElementProvider.java new file mode 100644 index 000000000..984ee630b --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/OpenPgpElementProvider.java @@ -0,0 +1,31 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.provider; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.ox.element.OpenPgpElement; +import org.xmlpull.v1.XmlPullParser; + +public class OpenPgpElementProvider extends ExtensionElementProvider { + + @Override + public OpenPgpElement parse(XmlPullParser parser, int initialDepth) throws Exception { + String base64EncodedOpenPgpMessage = parser.nextText(); + return new OpenPgpElement(base64EncodedOpenPgpMessage); + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SignElementProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SignElementProvider.java new file mode 100644 index 000000000..5a21c73cc --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SignElementProvider.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.provider; + +import java.util.logging.Logger; + +import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.ox.element.SignElement; +import org.xmlpull.v1.XmlPullParser; + +public class SignElementProvider extends OpenPgpContentElementProvider { + + private static final Logger LOGGER = Logger.getLogger(SigncryptElementProvider.class.getName()); + + @Override + public SignElement parse(XmlPullParser parser, int initialDepth) throws Exception { + OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth); + + if (StringUtils.isNotEmpty(data.rpad)) { + LOGGER.warning("Ignoring rpad in XEP-0373 element"); + } + + return new SignElement(data.to, data.timestamp, data.payload); + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SigncryptElementProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SigncryptElementProvider.java new file mode 100644 index 000000000..68a0aaf03 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/SigncryptElementProvider.java @@ -0,0 +1,30 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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.provider; + +import org.jivesoftware.smackx.ox.element.SigncryptElement; +import org.xmlpull.v1.XmlPullParser; + +public class SigncryptElementProvider extends OpenPgpContentElementProvider { + + @Override + public SigncryptElement parse(XmlPullParser parser, int initialDepth) throws Exception { + OpenPgpContentElementData data = parseOpenPgpContentElementData(parser, initialDepth); + return new SigncryptElement(data.to, data.rpad, data.timestamp, data.payload); + } + +} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/package-info.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/package-info.java new file mode 100644 index 000000000..27049c801 --- /dev/null +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/provider/package-info.java @@ -0,0 +1,20 @@ +/** + * + * Copyright 2017 Florian Schmaus. + * + * 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. + */ +/** + * Providers for XEP-0373: OpenPGP for XMPP. + */ +package org.jivesoftware.smackx.ox.provider;