001/** 002 * 003 * Copyright 2018 Paul Schaub. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.ox.crypto; 018 019import java.io.IOException; 020import java.util.Collection; 021 022import org.jivesoftware.smackx.ox.OpenPgpContact; 023import org.jivesoftware.smackx.ox.OpenPgpMessage; 024import org.jivesoftware.smackx.ox.OpenPgpSelf; 025import org.jivesoftware.smackx.ox.element.CryptElement; 026import org.jivesoftware.smackx.ox.element.OpenPgpContentElement; 027import org.jivesoftware.smackx.ox.element.OpenPgpElement; 028import org.jivesoftware.smackx.ox.element.SignElement; 029import org.jivesoftware.smackx.ox.element.SigncryptElement; 030import org.jivesoftware.smackx.ox.store.definition.OpenPgpStore; 031 032import org.bouncycastle.openpgp.PGPException; 033import org.pgpainless.decryption_verification.OpenPgpMetadata; 034 035public interface OpenPgpProvider { 036 037 /** 038 * Return the {@link OpenPgpStore} instance of this provider. 039 * This MUST NOT return null. 040 * 041 * @return store 042 */ 043 OpenPgpStore getStore(); 044 045 /** 046 * Sign a {@link SigncryptElement} using our signing key and encrypt it for all {@code recipients} and ourselves. 047 * 048 * @param element {@link SigncryptElement} which contains a payload which will be transmitted. 049 * @param self our own OpenPGP identity. 050 * @param recipients recipients identities. 051 * 052 * @return signed and encrypted {@link SigncryptElement} as a {@link OpenPgpElement}, along with 053 * {@link OpenPgpMetadata} about the encryption/signatures. 054 * 055 * @throws IOException IO is dangerous 056 * @throws PGPException PGP is brittle 057 */ 058 OpenPgpElementAndMetadata signAndEncrypt(SigncryptElement element, OpenPgpSelf self, Collection<OpenPgpContact> recipients) 059 throws IOException, PGPException; 060 061 /** 062 * Sign a {@link SignElement} using our signing key. 063 * @param element {@link SignElement} which contains a payload. 064 * @param self our OpenPGP identity. 065 * 066 * @return signed {@link SignElement} as {@link OpenPgpElement}, along with {@link OpenPgpMetadata} about the 067 * signatures. 068 * 069 * @throws IOException IO is dangerous 070 * @throws PGPException PGP is brittle 071 */ 072 OpenPgpElementAndMetadata sign(SignElement element, OpenPgpSelf self) 073 throws IOException, PGPException; 074 075 /** 076 * Encrypt a {@link CryptElement} for all {@code recipients} and ourselves. 077 * @param element {@link CryptElement} which contains a payload which will be transmitted. 078 * @param self our own OpenPGP identity. 079 * @param recipients recipient identities. 080 * 081 * @return encrypted {@link CryptElement} as an {@link OpenPgpElement}, along with {@link OpenPgpMetadata} about 082 * the encryption. 083 * 084 * @throws IOException IO is dangerous 085 * @throws PGPException PGP is brittle 086 */ 087 OpenPgpElementAndMetadata encrypt(CryptElement element, OpenPgpSelf self, Collection<OpenPgpContact> recipients) 088 throws IOException, PGPException; 089 090 /** 091 * Decrypt and/or verify signatures on an incoming {@link OpenPgpElement}. 092 * If the message is encrypted, this method decrypts it. If it is (also) signed, the signature will be checked. 093 * The resulting {@link OpenPgpMessage} contains the original {@link OpenPgpContentElement}, as well as information 094 * about the encryption/signing. 095 * 096 * @param element signed and or encrypted {@link OpenPgpElement}. 097 * @param self our OpenPGP identity. 098 * @param sender OpenPGP identity of the sender. 099 * 100 * @return decrypted message as {@link OpenPgpMessage}. 101 * 102 * @throws IOException IO is dangerous 103 * @throws PGPException PGP is brittle 104 */ 105 OpenPgpMessage decryptAndOrVerify(OpenPgpElement element, OpenPgpSelf self, OpenPgpContact sender) 106 throws IOException, PGPException; 107}