1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 01:59:38 +02:00

Add first JET test

This commit is contained in:
vanitasvitae 2017-07-30 23:32:00 +02:00
parent b0b46ad167
commit 177ed6ea0d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 160 additions and 17 deletions

View file

@ -37,21 +37,22 @@ public abstract class AesGcmNoPadding {
protected final Cipher cipher;
protected final byte[] key, iv, keyAndIv;
public AesGcmNoPadding(int length) throws NoSuchAlgorithmException, NoSuchProviderException,
public AesGcmNoPadding(int bits) throws NoSuchAlgorithmException, NoSuchProviderException,
NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException {
this.length = length;
this.length = bits;
int bytes = bits / 8;
KeyGenerator keyGenerator = KeyGenerator.getInstance(keyType);
keyGenerator.init(length);
keyGenerator.init(bits);
key = keyGenerator.generateKey().getEncoded();
SecureRandom secureRandom = new SecureRandom();
iv = new byte[length];
iv = new byte[bytes];
secureRandom.nextBytes(iv);
keyAndIv = new byte[2 * length];
System.arraycopy(key, 0, keyAndIv, 0, length);
System.arraycopy(iv, 0, keyAndIv, length, length);
keyAndIv = new byte[2 * bytes];
System.arraycopy(key, 0, keyAndIv, 0, bytes);
System.arraycopy(iv, 0, keyAndIv, bytes, bytes);
SecretKey secretKey = new SecretKeySpec(key, keyType);
IvParameterSpec ivSpec = new IvParameterSpec(iv);
@ -65,9 +66,11 @@ public abstract class AesGcmNoPadding {
this.key = key;
this.iv = iv;
keyAndIv = new byte[2 * length];
System.arraycopy(key, 0, keyAndIv, 0, length);
System.arraycopy(iv, 0, keyAndIv, length, length);
int bytes = length / 8;
keyAndIv = new byte[2 * bytes];
System.arraycopy(key, 0, keyAndIv, 0, bytes);
System.arraycopy(iv, 0, keyAndIv, bytes, bytes);
cipher = Cipher.getInstance(cipherMode, "BC");
SecretKeySpec keySpec = new SecretKeySpec(key, keyType);

View file

@ -23,6 +23,7 @@ import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jet.internal.JetSecurity;
import org.jivesoftware.smackx.jft.JingleFileTransferManager;
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
@ -54,6 +55,8 @@ public final class JetManager extends Manager implements JingleDescriptionManage
private JetManager(XMPPConnection connection) {
super(connection);
this.jingleManager = JingleManager.getInstanceFor(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
jingleManager.addJingleDescriptionManager(this);
}
public static JetManager getInstanceFor(XMPPConnection connection) {