Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -35,7 +34,8 @@
import org.apache.commons.fileupload.util.Streams;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.DeferredFileOutputStream;
import org.apache.commons.io.output.CipheredDeferredFileOutputStream;


/**
* <p> The default implementation of the
Expand Down Expand Up @@ -138,7 +138,7 @@ public class DiskFileItem
/**
* Output stream for this item.
*/
private transient DeferredFileOutputStream dfos;
private transient CipheredDeferredFileOutputStream dfos;

/**
* The temporary file to use.
Expand Down Expand Up @@ -201,7 +201,7 @@ public DiskFileItem(final String fieldName,
public InputStream getInputStream()
throws IOException {
if (!isInMemory()) {
return new FileInputStream(dfos.getFile());
return dfos.createCipheredInputStream();
}

if (cachedContent == null) {
Expand Down Expand Up @@ -284,7 +284,7 @@ public long getSize() {
if (dfos.isInMemory()) {
return dfos.getData().length;
}
return dfos.getFile().length();
return dfos.getByteCount();
}

/**
Expand All @@ -308,7 +308,7 @@ public byte[] get() {
InputStream fis = null;

try {
fis = new FileInputStream(dfos.getFile());
fis = dfos.createCipheredInputStream();
IOUtils.readFully(fis, fileData);
} catch (final IOException e) {
fileData = null;
Expand Down Expand Up @@ -500,7 +500,7 @@ public void setFormField(final boolean state) {
public OutputStream getOutputStream() throws IOException {
if (dfos == null) {
final File outputFile = getTempFile();
dfos = new DeferredFileOutputStream(sizeThreshold, outputFile);
dfos = new CipheredDeferredFileOutputStream(sizeThreshold, outputFile);
}
return dfos;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.fileupload.util.crypto;

import javax.crypto.Cipher;

/**
* Ciphers for temporary file encryption.
*/
public interface CipherServiceProvider {

CipherProvider getCipherProvider();

interface CipherProvider {

/**
* Cipher for encryption of temporary file.
*/
Cipher getEncryptionCipher();

/**
* Cipher for decryption of temporary file.
*/
Cipher getDecryptionCipher();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.fileupload.util.crypto;

import java.util.Iterator;
import java.util.ServiceLoader;

import org.apache.commons.fileupload.util.crypto.CipherServiceProvider.CipherProvider;

public final class CipherSpiLoader {

/**
* This provider provide consequent enrcyption or decyption cipher. There is no effect, if it is null.
*/
private static CipherServiceProvider cipherServiceProvider;

static {
Iterator<CipherServiceProvider> iterator = ServiceLoader.load(CipherServiceProvider.class)
.iterator();
if (iterator.hasNext()) {
cipherServiceProvider = iterator.next();
}
}

private CipherSpiLoader() {
}

public static CipherProvider getCipherProvider() {
return cipherServiceProvider == null ? null : cipherServiceProvider.getCipherProvider();
}

public static void changeCipherProvider(CipherServiceProvider myCipherServiceProvider) {
cipherServiceProvider = myCipherServiceProvider;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* This package contains an interface which provide ciphers for encription
* and decription. The Util class load one implementation and wrap input or
* outputStreams with cipher.
*/
package org.apache.commons.fileupload.util.crypto;
Loading