/** * @param file Default encryption setting for file * @return Return custom key for AWS-KMS if set for bucket in preferences. Otherwise default SSE algorithm. */ @Override public Algorithm getDefault(final Path file) { final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName()); if(StringUtils.isNotBlank(preferences.getProperty(key))) { return Algorithm.fromString(preferences.getProperty(key)); } // Return default setting in preferences final String setting = preferences.getProperty("s3.encryption.algorithm"); if(StringUtils.equals(SSE_AES256.algorithm, setting)) { return SSE_AES256; } return Algorithm.NONE; }
encryptionPopup.addItemWithTitle(LocaleFactory.localizedString(algorithm.getDescription(), "S3")); encryptionPopup.lastItem().setRepresentedObject(algorithm.toString()); encryptionPopup.selectItemAtIndex(encryptionPopup.indexOfItemWithRepresentedObject(algorithm.toString())); encryptionPopup.itemAtIndex(encryptionPopup.indexOfItemWithRepresentedObject(algorithm.toString())) .setState(selectedEncryptionKeys.size() == 1 ? NSCell.NSOnState : NSCell.NSMixedState);
/** * @param file File to copy with new setting or bucket to change default preference * @param setting A supported algorithm for server side encryption */ @Override public void setEncryption(final Path file, final Algorithm setting) throws BackgroundException { if(containerService.isContainer(file)) { final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName()); preferences.setProperty(key, setting.toString()); } if(file.isFile() || file.isPlaceholder()) { try { final S3ThresholdCopyFeature copy = new S3ThresholdCopyFeature(session); // Copy item in place to write new attributes final TransferStatus status = new TransferStatus(); status.setEncryption(setting); status.setLength(file.attributes().getSize()); copy.copy(file, file, status, new DisabledConnectionCallback()); } catch(NotfoundException e) { if(file.isPlaceholder()) { // No placeholder file may exist but we just have a common prefix return; } throw e; } } }
public void setDefaultEncryptionPopup(NSPopUpButton b) { this.defaultEncryptionPopup = b; this.defaultEncryptionPopup.setAutoenablesItems(false); this.defaultEncryptionPopup.removeAllItems(); this.defaultEncryptionPopup.addItemWithTitle(LocaleFactory.localizedString("None")); this.defaultEncryptionPopup.lastItem().setRepresentedObject(S3EncryptionFeature.Algorithm.NONE.toString()); this.defaultEncryptionPopup.addItemWithTitle(LocaleFactory.localizedString(S3EncryptionFeature.SSE_AES256.getDescription(), "S3")); this.defaultEncryptionPopup.lastItem().setRepresentedObject(S3EncryptionFeature.SSE_AES256.toString()); this.defaultEncryptionPopup.addItemWithTitle(LocaleFactory.localizedString(KMSEncryptionFeature.SSE_KMS_DEFAULT.getDescription(), "S3")); this.defaultEncryptionPopup.lastItem().setRepresentedObject(KMSEncryptionFeature.SSE_KMS_DEFAULT.toString()); this.defaultEncryptionPopup.setTarget(this.id()); this.defaultEncryptionPopup.setAction(Foundation.selector("defaultEncryptionPopupClicked:")); if(StringUtils.isEmpty(preferences.getProperty("s3.encryption.algorithm"))) { this.defaultEncryptionPopup.selectItemWithTitle(LocaleFactory.localizedString("None")); } else { this.defaultEncryptionPopup.selectItemAtIndex(this.defaultEncryptionPopup.indexOfItemWithRepresentedObject(preferences.getProperty("s3.encryption.algorithm"))); } }
@Action public void encryptionPopupClicked(final NSPopUpButton sender) { final String algorithm = sender.selectedItem().representedObject(); if(null != algorithm && this.toggleS3Settings(false)) { final Encryption.Algorithm encryption = Encryption.Algorithm.fromString(algorithm); controller.background(new WorkerBackgroundAction<Boolean>(controller, session, new WriteEncryptionWorker(files, encryption, new PromptRecursiveCallback<Encryption.Algorithm>(this), controller) { @Override public void cleanup(final Boolean v) { toggleS3Settings(true); initS3(); } } ) ); } }
public void setFileKey(final TransferStatus status) throws BackgroundException { final FileKey fileKey = TripleCryptConverter.toSwaggerFileKey(Crypto.generateFileKey()); final ObjectWriter writer = session.getClient().getJSON().getContext(null).writerFor(FileKey.class); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { writer.writeValue(out, fileKey); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } status.setFilekey(ByteBuffer.wrap(out.toByteArray())); status.setEncryption(new Encryption.Algorithm("AES256", null)); }
@Override public Algorithm getDefault(final Path file) { final String setting = preferences.getProperty("s3.encryption.algorithm"); if(StringUtils.equals(KMSEncryptionFeature.SSE_KMS_DEFAULT.algorithm, setting)) { final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName()); if(StringUtils.isNotBlank(preferences.getProperty(key))) { return Algorithm.fromString(preferences.getProperty(key)); } return KMSEncryptionFeature.SSE_KMS_DEFAULT; } return super.getDefault(file); }
@Override public Algorithm getEncryption(final Path file) throws BackgroundException { if(containerService.isContainer(file)) { final String key = String.format("s3.encryption.key.%s", containerService.getContainer(file).getName()); if(StringUtils.isNotBlank(preferences.getProperty(key))) { return Algorithm.fromString(preferences.getProperty(key)); } } return super.getEncryption(file); }