public TransferSettings createTransferSettings() throws Exception { if (encrypted || plaintextSettingsBytes == null) { throw new IllegalArgumentException("Link is encrypted. Cannot call this method."); } return createTransferSettings(plaintextSettingsBytes); }
public ApplicationLink(String applicationLink) throws IllegalArgumentException, StorageException { if (LINK_SHORT_URL_PATTERN.matcher(applicationLink).matches()) { applicationLink = expandLink(applicationLink); } if (LINK_HTTP_PATTERN.matcher(applicationLink).matches()) { applicationLink = resolveLink(applicationLink, 0); } parseLink(applicationLink); }
public String createPlaintextLink() throws Exception { byte[] plaintextStorageXml = getPlaintextStorageXml(); String plaintextEncodedStorage = Base58.encode(plaintextStorageXml); return String.format(LINK_FORMAT_NOT_ENCRYPTED, plaintextEncodedStorage); }
private ConfigTO createConfigTOFromLink(ConfigTO configTO, String link, String masterPassword) throws StorageException, CipherException { logger.log(Level.INFO, "Creating config TO from link: " + link + " ..."); ApplicationLink applicationLink = new ApplicationLink(link); if (applicationLink.isEncrypted()) { SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt()); TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey); SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt()); TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey); logger.log(Level.INFO, " - Link is NOT encrypted. No password needed."); TransferSettings transferSettings = applicationLink.createTransferSettings(); configTO.setTransferSettings(transferSettings);
@Override public GenlinkOperationResult execute() throws Exception { logger.log(Level.INFO, ""); logger.log(Level.INFO, "Running 'GenLink'"); logger.log(Level.INFO, "--------------------------------------------"); if (configTO == null) { configTO = ConfigHelper.loadConfigTO(config.getLocalDir()); } ApplicationLink applicationLink = new ApplicationLink(configTO.getTransferSettings(), options.isShortUrl()); if (configTO.getMasterKey() != null) { String encryptedLinkStr = applicationLink.createEncryptedLink(configTO.getMasterKey()); return new GenlinkOperationResult(encryptedLinkStr, true); } else { String plaintextLinkStr = applicationLink.createPlaintextLink(); return new GenlinkOperationResult(plaintextLinkStr, false); } } }
HttpResponse httpResponse = createHttpClient().execute(headMethod); return resolveLink(locationHeaderUrl, ++redirectCount);
public String createEncryptedLink(SaltedSecretKey masterKey) throws Exception { byte[] plaintextStorageXml = getPlaintextStorageXml(); List<CipherSpec> cipherSpecs = CipherSpecs.getDefaultCipherSpecs(); // TODO [low] Shouldn't this be the same as the application?! 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; } }
private String shortenLink(String applicationLink) { if (!LINK_PATTERN.matcher(applicationLink).matches()) { throw new IllegalArgumentException("Invalid link provided, must start with syncany:// and match link pattern."); } try { logger.log(Level.INFO, "Shortining link " + applicationLink + " via " + LINK_SHORT_API_URL_ADD + " ..."); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("l", applicationLink)); HttpPost postMethod = new HttpPost(LINK_SHORT_API_URL_ADD); postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse httpResponse = createHttpClient().execute(postMethod); ApplicationLinkShortenerResponse shortenerResponse = new Persister().read(ApplicationLinkShortenerResponse.class, httpResponse .getEntity().getContent()); return String.format(LINK_SHORT_URL_FORMAT, shortenerResponse.getShortLinkId()); } catch (Exception e) { logger.log(Level.WARNING, "Cannot shorten URL. Using long URL.", e); return applicationLink; } }
public TransferSettings createTransferSettings(SaltedSecretKey masterKey) throws Exception { if (!encrypted || encryptedSettingsBytes == null) { throw new IllegalArgumentException("Link is not encrypted. Cannot call this method."); } byte[] plaintextPluginSettingsBytes = CipherUtil.decrypt(new ByteArrayInputStream(encryptedSettingsBytes), masterKey); return createTransferSettings(plaintextPluginSettingsBytes); }