Search in sources :

Example 1 with CipherSpec

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;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CipherSpec(org.syncany.crypto.CipherSpec)

Example 2 with CipherSpec

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);
    }
}
Also used : CipherSpec(org.syncany.crypto.CipherSpec) IOException(java.io.IOException)

Example 3 with 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));
            }
        }
    }
}
Also used : GzipTransformer(org.syncany.chunk.GzipTransformer) CipherTransformer(org.syncany.chunk.CipherTransformer) GzipTransformer(org.syncany.chunk.GzipTransformer) NoTransformer(org.syncany.chunk.NoTransformer) Transformer(org.syncany.chunk.Transformer) ZipMultiChunker(org.syncany.chunk.ZipMultiChunker) TttdChunker(org.syncany.chunk.TttdChunker) Chunker(org.syncany.chunk.Chunker) MultiChunker(org.syncany.chunk.MultiChunker) CipherTransformer(org.syncany.chunk.CipherTransformer) ArrayList(java.util.ArrayList) ZipMultiChunker(org.syncany.chunk.ZipMultiChunker) MultiChunker(org.syncany.chunk.MultiChunker) TttdChunker(org.syncany.chunk.TttdChunker) LinkedList(java.util.LinkedList) NoTransformer(org.syncany.chunk.NoTransformer) ZipMultiChunker(org.syncany.chunk.ZipMultiChunker) CipherSpec(org.syncany.crypto.CipherSpec)

Example 4 with CipherSpec

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()));
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) CipherSpec(org.syncany.crypto.CipherSpec) Test(org.junit.Test)

Example 5 with CipherSpec

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);
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) CipherSession(org.syncany.crypto.CipherSession) CipherSpec(org.syncany.crypto.CipherSpec) Test(org.junit.Test)

Aggregations

CipherSpec (org.syncany.crypto.CipherSpec)11 Test (org.junit.Test)5 SaltedSecretKey (org.syncany.crypto.SaltedSecretKey)3 ArrayList (java.util.ArrayList)2 CipherSession (org.syncany.crypto.CipherSession)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 Chunker (org.syncany.chunk.Chunker)1 CipherTransformer (org.syncany.chunk.CipherTransformer)1 GzipTransformer (org.syncany.chunk.GzipTransformer)1 MultiChunker (org.syncany.chunk.MultiChunker)1 NoTransformer (org.syncany.chunk.NoTransformer)1 Transformer (org.syncany.chunk.Transformer)1 TttdChunker (org.syncany.chunk.TttdChunker)1 ZipMultiChunker (org.syncany.chunk.ZipMultiChunker)1 ConfigTO (org.syncany.config.to.ConfigTO)1