use of org.syncany.crypto.CipherSpec in project syncany by syncany.
the class ApplicationLink method createEncryptedLink.
public String createEncryptedLink(SaltedSecretKey masterKey) throws Exception {
byte[] plaintextStorageXml = getPlaintextStorageXml();
// TODO [low] Shouldn't this be the same as the application?!
List<CipherSpec> cipherSpecs = CipherSpecs.getDefaultCipherSpecs();
byte[] masterKeySalt = masterKey.getSalt();
byte[] encryptedPluginBytes = CipherUtil.encrypt(new ByteArrayInputStream(plaintextStorageXml), cipherSpecs, masterKey);
String masterKeySaltEncodedStr = Base58.encode(masterKeySalt);
String encryptedEncodedPlugin = Base58.encode(encryptedPluginBytes);
String applicationLink = String.format(LINK_FORMAT_ENCRYPTED, masterKeySaltEncodedStr, encryptedEncodedPlugin);
if (shortUrl) {
return shortenLink(applicationLink);
} else {
return applicationLink;
}
}
use of org.syncany.crypto.CipherSpec in project syncany by syncany.
the class CipherTransformer method initCipherSpecs.
private void initCipherSpecs(String cipherSpecListStr) throws Exception {
String[] cipherSpecIdStrs = cipherSpecListStr.split(",");
for (String cipherSpecIdStr : cipherSpecIdStrs) {
int cipherSpecId = Integer.parseInt(cipherSpecIdStr);
CipherSpec cipherSpec = CipherSpecs.getCipherSpec(cipherSpecId);
if (cipherSpec == null) {
throw new Exception("Cannot find cipher suite with ID '" + cipherSpecId + "'");
}
cipherSpecs.add(cipherSpec);
}
}
use of org.syncany.crypto.CipherSpec in project syncany by syncany.
the class FrameworkCombinationTest method fillCombinations.
private void fillCombinations() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
// MultiChunks
List<MultiChunker> multiChunkers = new LinkedList<MultiChunker>();
int[] multiChunkSizes = new int[] { 250000, 500000 };
for (int i = 0; i < multiChunkSizes.length; i++) {
// multiChunkers.add(new CustomMultiChunker(multiChunkSizes[i]));
multiChunkers.add(new ZipMultiChunker(multiChunkSizes[i]));
}
// Chunks
List<Chunker> chunkers = new LinkedList<Chunker>();
int[] chunkSizes = new int[] { 8000, 16000 };
String[] digestAlgs = new String[] { /*"MD5" ,*/
"SHA1" };
String[] fingerprinters = new String[] { "Adler32" /*, "Plain", "Rabin"*/
};
for (int i = 0; i < chunkSizes.length; i++) {
for (int j = 0; j < digestAlgs.length; j++) {
for (int k = 0; k < fingerprinters.length; k++) {
chunkers.add(new TttdChunker(chunkSizes[i], TttdChunker.DEFAULT_WINDOW_SIZE, digestAlgs[j], fingerprinters[k]));
}
}
}
// Compression/Encryption
List<CipherSpec> cipherSpecs = new ArrayList<CipherSpec>();
cipherSpecs.add(CipherSpecs.getCipherSpec(1));
cipherSpecs.add(CipherSpecs.getCipherSpec(2));
List<Transformer> transformerChains = new LinkedList<Transformer>();
transformerChains.add(new NoTransformer());
transformerChains.add(new GzipTransformer());
transformerChains.add(new CipherTransformer(cipherSpecs, masterKey));
transformerChains.add(new GzipTransformer(new CipherTransformer(cipherSpecs, masterKey)));
for (MultiChunker multiChunker : multiChunkers) {
for (Transformer transformer : transformerChains) {
for (Chunker chunker : chunkers) {
String configName = multiChunker + "/" + chunker + "/" + transformer;
combinations.add(new FrameworkCombination(configName, chunker, multiChunker, transformer));
}
}
}
}
use of org.syncany.crypto.CipherSpec in project syncany by syncany.
the class CipherUtilTest method testCreateDerivedKeys.
@Test
public void testCreateDerivedKeys() throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException {
SaltedSecretKey masterKey = createDummyMasterKey();
CipherSpec cipherSpec = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
byte[] derivedKeySalt1 = new byte[] { 1, 2, 3 };
byte[] derivedKeySalt2 = new byte[] { 1, 2, 3, 4 };
SaltedSecretKey derivedKey1 = CipherUtil.createDerivedKey(masterKey, derivedKeySalt1, cipherSpec);
SaltedSecretKey derivedKey2 = CipherUtil.createDerivedKey(masterKey, derivedKeySalt2, cipherSpec);
logger.log(Level.INFO, "- Derived key 1: " + StringUtil.toHex(derivedKey1.getEncoded()));
logger.log(Level.INFO, " with salt: " + StringUtil.toHex(derivedKey1.getSalt()));
logger.log(Level.INFO, "- Derived key 2: " + StringUtil.toHex(derivedKey2.getEncoded()));
logger.log(Level.INFO, " with salt: " + StringUtil.toHex(derivedKey2.getSalt()));
assertEquals(128 / 8, derivedKey1.getEncoded().length);
assertEquals(128 / 8, derivedKey2.getEncoded().length);
assertFalse(Arrays.equals(derivedKey1.getSalt(), derivedKey2.getSalt()));
assertFalse(Arrays.equals(derivedKey1.getEncoded(), derivedKey2.getEncoded()));
}
use of org.syncany.crypto.CipherSpec in project syncany by syncany.
the class CipherSessionTest method testCipherSessionWriteKeyReuseCountOfTwo.
@Test
public void testCipherSessionWriteKeyReuseCountOfTwo() throws Exception {
SaltedSecretKey masterKey = createDummyMasterKey();
CipherSession cipherSession = new CipherSession(masterKey, 999, 2);
CipherSpec cipherSpecAes128 = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
CipherSpec cipherSpecTwofish128 = CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM);
SaltedSecretKey writeSecretKey1Aes128 = cipherSession.getWriteSecretKey(cipherSpecAes128);
SaltedSecretKey writeSecretKey2Aes128 = cipherSession.getWriteSecretKey(cipherSpecAes128);
SaltedSecretKey writeSecretKey3Aes128 = cipherSession.getWriteSecretKey(cipherSpecAes128);
SaltedSecretKey writeSecretKey1Twofish128 = cipherSession.getWriteSecretKey(cipherSpecTwofish128);
SaltedSecretKey writeSecretKey2Twofish128 = cipherSession.getWriteSecretKey(cipherSpecTwofish128);
SaltedSecretKey writeSecretKey3Twofish128 = cipherSession.getWriteSecretKey(cipherSpecTwofish128);
assertEquals(writeSecretKey1Aes128, writeSecretKey2Aes128);
assertNotSame(writeSecretKey1Aes128, writeSecretKey3Aes128);
assertEquals(writeSecretKey1Twofish128, writeSecretKey2Twofish128);
assertNotSame(writeSecretKey1Twofish128, writeSecretKey3Twofish128);
assertNotSame(writeSecretKey1Aes128, writeSecretKey1Twofish128);
}
Aggregations