Search in sources :

Example 6 with CipherSpec

use of org.syncany.crypto.CipherSpec in project syncany by syncany.

the class CipherSessionTest method testCipherSessionReadKeyCacheSizeOfThree.

@Test
public void testCipherSessionReadKeyCacheSizeOfThree() throws Exception {
    SaltedSecretKey masterKey = createDummyMasterKey();
    CipherSession cipherSession = new CipherSession(masterKey, 2, 999);
    CipherSpec cipherSpecAes128 = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
    byte[] readKeySalt1 = CipherUtil.createRandomArray(cipherSpecAes128.getKeySize());
    byte[] readKeySalt2 = CipherUtil.createRandomArray(cipherSpecAes128.getKeySize());
    byte[] readKeySalt3 = CipherUtil.createRandomArray(cipherSpecAes128.getKeySize());
    SaltedSecretKey readSecretKey1Aes128 = cipherSession.getReadSecretKey(cipherSpecAes128, readKeySalt1);
    SaltedSecretKey readSecretKey2Aes128 = cipherSession.getReadSecretKey(cipherSpecAes128, readKeySalt2);
    SaltedSecretKey readSecretKey3Aes128 = cipherSession.getReadSecretKey(cipherSpecAes128, readKeySalt3);
    assertNotSame(readSecretKey1Aes128, readSecretKey2Aes128);
    assertNotSame(readSecretKey1Aes128, readSecretKey3Aes128);
    assertNotSame(readSecretKey2Aes128, readSecretKey3Aes128);
// TODO [medium] This does NOT TEST the actual read cache. How to test this. The cache is completely hidden/private?!
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) CipherSession(org.syncany.crypto.CipherSession) CipherSpec(org.syncany.crypto.CipherSpec) Test(org.junit.Test)

Example 7 with CipherSpec

use of org.syncany.crypto.CipherSpec in project syncany by syncany.

the class CipherSpecsTest method testCipherSpecHashCodeEquals.

@Test
public void testCipherSpecHashCodeEquals() {
    CipherSpec cipherSpec1 = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM);
    CipherSpec cipherSpec2 = CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM);
    assertNotSame(cipherSpec1.hashCode(), cipherSpec2.hashCode());
    assertNotSame(cipherSpec1, cipherSpec2);
    assertEquals(0x01, cipherSpec1.getId());
}
Also used : CipherSpec(org.syncany.crypto.CipherSpec) Test(org.junit.Test)

Example 8 with CipherSpec

use of org.syncany.crypto.CipherSpec in project syncany by syncany.

the class CipherSpecsTest method testCipherSpec2.

@Test
public void testCipherSpec2() {
    CipherSpec twofish128CipherSpec = CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM);
    assertEquals(twofish128CipherSpec.getId(), 2);
    assertEquals(twofish128CipherSpec.getAlgorithm(), "Twofish/GCM/NoPadding");
    assertEquals(twofish128CipherSpec.getKeySize(), 128);
    assertEquals(twofish128CipherSpec.getIvSize(), 128);
    assertEquals(twofish128CipherSpec.needsUnlimitedStrength(), false);
    assertNotNull(twofish128CipherSpec.toString());
}
Also used : CipherSpec(org.syncany.crypto.CipherSpec) Test(org.junit.Test)

Example 9 with CipherSpec

use of org.syncany.crypto.CipherSpec in project syncany by syncany.

the class InitCommand method parseOptions.

@Override
public InitOperationOptions parseOptions(String[] operationArguments) throws Exception {
    InitOperationOptions operationOptions = new InitOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionNoCreateTarget = parser.acceptsAll(asList("T", "no-create-target"));
    OptionSpec<Void> optionAdvanced = parser.acceptsAll(asList("a", "advanced"));
    OptionSpec<Void> optionNoCompression = parser.acceptsAll(asList("G", "no-compression"));
    OptionSpec<Void> optionNoEncryption = parser.acceptsAll(asList("E", "no-encryption"));
    OptionSpec<String> optionPlugin = parser.acceptsAll(asList("P", "plugin")).withRequiredArg();
    OptionSpec<String> optionPluginOpts = parser.acceptsAll(asList("o", "plugin-option")).withRequiredArg();
    OptionSpec<Void> optionAddDaemon = parser.acceptsAll(asList("n", "add-daemon"));
    OptionSpec<Void> optionShortUrl = parser.acceptsAll(asList("s", "short"));
    OptionSpec<Void> optionHeadlessMode = parser.acceptsAll(asList("l", "headless"));
    OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
    OptionSet options = parser.parse(operationArguments);
    // Set interactivity mode
    isInteractive = !options.has(optionPlugin);
    // Set headless mode
    isHeadless = options.has(optionHeadlessMode);
    // Ask or set transfer settings
    TransferSettings transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
    // Some misc settings
    boolean createTargetPath = !options.has(optionNoCreateTarget);
    boolean advancedModeEnabled = options.has(optionAdvanced);
    boolean encryptionEnabled = !options.has(optionNoEncryption);
    boolean compressionEnabled = !options.has(optionNoCompression);
    // Cipher specs: --no-encryption, --advanced
    List<CipherSpec> cipherSpecs = getCipherSpecs(encryptionEnabled, advancedModeEnabled);
    // Compression: --no-compression
    // DefaultRepoTOFactory also creates default chunkers
    RepoTOFactory repoTOFactory = new DefaultRepoTOFactory(compressionEnabled, cipherSpecs);
    // Genlink options: --short
    GenlinkOperationOptions genlinkOptions = new GenlinkOperationOptions();
    genlinkOptions.setShortUrl(options.has(optionShortUrl));
    // Set repo password
    String password = validateAndGetPassword(options, optionNoEncryption, optionPassword);
    operationOptions.setPassword(password);
    // Create configTO and repoTO
    ConfigTO configTO = createConfigTO(transferSettings);
    RepoTO repoTO = repoTOFactory.createRepoTO();
    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);
    operationOptions.setCreateTarget(createTargetPath);
    operationOptions.setEncryptionEnabled(encryptionEnabled);
    operationOptions.setCipherSpecs(cipherSpecs);
    operationOptions.setDaemon(options.has(optionAddDaemon));
    operationOptions.setGenlinkOptions(genlinkOptions);
    return operationOptions;
}
Also used : InitOperationOptions(org.syncany.operations.init.InitOperationOptions) DefaultRepoTOFactory(org.syncany.config.to.DefaultRepoTOFactory) TransferSettings(org.syncany.plugins.transfer.TransferSettings) GenlinkOperationOptions(org.syncany.operations.init.GenlinkOperationOptions) OptionParser(joptsimple.OptionParser) DefaultRepoTOFactory(org.syncany.config.to.DefaultRepoTOFactory) RepoTOFactory(org.syncany.config.to.RepoTOFactory) CipherSpec(org.syncany.crypto.CipherSpec) ConfigTO(org.syncany.config.to.ConfigTO) OptionSet(joptsimple.OptionSet) RepoTO(org.syncany.config.to.RepoTO)

Example 10 with CipherSpec

use of org.syncany.crypto.CipherSpec in project syncany by syncany.

the class InitCommand method askCipherSpecs.

private List<CipherSpec> askCipherSpecs() throws Exception {
    List<CipherSpec> cipherSpecs = new ArrayList<CipherSpec>();
    Map<Integer, CipherSpec> availableCipherSpecs = CipherSpecs.getAvailableCipherSpecs();
    out.println();
    out.println("Please choose your encryption settings. If you're paranoid,");
    out.println("you can choose multiple cipher suites by separating with a comma.");
    out.println();
    out.println("Options:");
    for (CipherSpec cipherSuite : availableCipherSpecs.values()) {
        out.println(" [" + cipherSuite.getId() + "] " + cipherSuite);
    }
    out.println();
    boolean continueLoop = true;
    boolean unlimitedStrengthNeeded = false;
    while (continueLoop) {
        String commaSeparatedCipherIdStr = console.readLine("Cipher(s): ");
        String[] cipherSpecIdStrs = commaSeparatedCipherIdStr.split(",");
        // Choose cipher
        try {
            // Add cipher suites
            for (String cipherSpecIdStr : cipherSpecIdStrs) {
                Integer cipherSpecId = Integer.parseInt(cipherSpecIdStr);
                CipherSpec cipherSpec = availableCipherSpecs.get(cipherSpecId);
                if (cipherSpec == null) {
                    throw new Exception();
                }
                if (cipherSpec.needsUnlimitedStrength()) {
                    unlimitedStrengthNeeded = true;
                }
                cipherSpecs.add(cipherSpec);
            }
            // Unlimited strength
            if (unlimitedStrengthNeeded) {
                out.println();
                out.println("At least one of the chosen ciphers or key sizes might");
                out.println("not be allowed in your country.");
                out.println();
                String yesno = console.readLine("Are you sure you want to use it (y/n)? ");
                if (yesno.toLowerCase().startsWith("y")) {
                    try {
                        CipherUtil.enableUnlimitedStrength();
                    } catch (Exception e) {
                        throw new Exception("Unable to enable unlimited crypto. Check out: http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html");
                    }
                } else {
                    continue;
                }
            }
            continueLoop = false;
            break;
        } catch (Exception e) {
            out.println("ERROR: Please choose at least one valid option.");
            out.println();
            continue;
        }
    }
    return cipherSpecs;
}
Also used : ArrayList(java.util.ArrayList) CipherSpec(org.syncany.crypto.CipherSpec)

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