mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
file upload api changes
This commit is contained in:
parent
3e7e331aa1
commit
b3bafd8a22
@ -78,13 +78,14 @@ public class CTApiDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted) throws CTCloudException {
|
public AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted) throws CTCloudException {
|
||||||
return getAuthToken(decrypted, false);
|
return getAuthToken(decrypted, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted, boolean fileUpload) throws CTCloudException {
|
public AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted, Long fileUploadSize) throws CTCloudException {
|
||||||
AuthTokenRequest authTokenRequest = new AuthTokenRequest()
|
AuthTokenRequest authTokenRequest = new AuthTokenRequest()
|
||||||
.setAutopsyVersion(getAppVersion())
|
.setAutopsyVersion(getAppVersion())
|
||||||
.setRequestFileUpload(fileUpload)
|
.setRequestFileUpload(fileUploadSize != null && fileUploadSize > 0)
|
||||||
|
.setFileUploadSize(fileUploadSize != null && fileUploadSize > 0 ? fileUploadSize : null)
|
||||||
.setBoostLicenseId(decrypted.getBoostLicenseId())
|
.setBoostLicenseId(decrypted.getBoostLicenseId())
|
||||||
.setHostId(decrypted.getLicenseHostId());
|
.setHostId(decrypted.getLicenseHostId());
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ public class CTApiDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void uploadFile(String url, String fileName, InputStream fileIs) throws CTCloudException {
|
public void uploadFile(String url, String fileName, InputStream fileIs) throws CTCloudException {
|
||||||
httpClient.doFileUploadPost(url, fileName, fileIs);
|
httpClient.doFileUploadPut(url, fileName, fileIs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadMeta(AuthenticatedRequestData authenticatedRequestData, MetadataUploadRequest metaRequest) throws CTCloudException {
|
public void uploadMeta(AuthenticatedRequestData authenticatedRequestData, MetadataUploadRequest metaRequest) throws CTCloudException {
|
||||||
|
@ -55,11 +55,13 @@ import org.apache.http.HttpStatus;
|
|||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
import org.apache.http.client.methods.HttpRequestBase;
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.apache.http.entity.InputStreamEntity;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
@ -184,7 +186,7 @@ class CTCloudHttpClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doFileUploadPost(String fullUrlPath, String fileName, InputStream fileIs) throws CTCloudException {
|
public void doFileUploadPut(String fullUrlPath, String fileName, InputStream fileIs) throws CTCloudException {
|
||||||
URI postUri;
|
URI postUri;
|
||||||
try {
|
try {
|
||||||
postUri = new URI(fullUrlPath);
|
postUri = new URI(fullUrlPath);
|
||||||
@ -195,23 +197,26 @@ class CTCloudHttpClient {
|
|||||||
|
|
||||||
try (CloseableHttpClient httpclient = createConnection(proxySelector, sslContext)) {
|
try (CloseableHttpClient httpclient = createConnection(proxySelector, sslContext)) {
|
||||||
LOGGER.log(Level.INFO, "initiating http post request to ctcloud server " + fullUrlPath);
|
LOGGER.log(Level.INFO, "initiating http post request to ctcloud server " + fullUrlPath);
|
||||||
HttpPost post = new HttpPost(postUri);
|
HttpPut put = new HttpPut(postUri);
|
||||||
configureRequestTimeout(post);
|
configureRequestTimeout(put);
|
||||||
|
|
||||||
post.addHeader("Connection", "keep-alive");
|
put.addHeader("Connection", "keep-alive");
|
||||||
|
put.addHeader("Content-Type", "application/octet-stream");
|
||||||
|
|
||||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
// MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||||
builder.addBinaryBody(
|
// builder.addBinaryBody(
|
||||||
"file",
|
// "file",
|
||||||
fileIs,
|
// fileBytes,
|
||||||
ContentType.APPLICATION_OCTET_STREAM,
|
// ContentType.APPLICATION_OCTET_STREAM,
|
||||||
fileName
|
// file.getFileName()
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
|
// HttpEntity multipart = builder.build();
|
||||||
|
// post.setEntity(multipart);
|
||||||
|
|
||||||
HttpEntity multipart = builder.build();
|
put.setEntity(new InputStreamEntity(fileIs));
|
||||||
post.setEntity(multipart);
|
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpclient.execute(post)) {
|
try (CloseableHttpResponse response = httpclient.execute(put)) {
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) {
|
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) {
|
||||||
LOGGER.log(Level.INFO, "Response Received. - Status OK");
|
LOGGER.log(Level.INFO, "Response Received. - Status OK");
|
||||||
|
@ -34,6 +34,9 @@ public class AuthTokenRequest {
|
|||||||
@JsonProperty("requestFileUpload")
|
@JsonProperty("requestFileUpload")
|
||||||
private boolean requestFileUpload;
|
private boolean requestFileUpload;
|
||||||
|
|
||||||
|
@JsonProperty("fileUploadSize")
|
||||||
|
private Long fileUploadSize;
|
||||||
|
|
||||||
@JsonProperty("host_id")
|
@JsonProperty("host_id")
|
||||||
private String hostId;
|
private String hostId;
|
||||||
|
|
||||||
@ -64,6 +67,16 @@ public class AuthTokenRequest {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getFileUploadSize() {
|
||||||
|
return fileUploadSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthTokenRequest setFileUploadSize(Long fileUploadSize) {
|
||||||
|
this.fileUploadSize = fileUploadSize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getHostId() {
|
public String getHostId() {
|
||||||
return hostId;
|
return hostId;
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,10 @@ class MalwareScanIngestModule implements FileIngestModule {
|
|||||||
//minimum file uploads left before issuing warning
|
//minimum file uploads left before issuing warning
|
||||||
private static final long LOW_UPLOADS_REMAINING = 25;
|
private static final long LOW_UPLOADS_REMAINING = 25;
|
||||||
|
|
||||||
|
// min and max upload size in bytes
|
||||||
private static final long MIN_UPLOAD_SIZE = 1;
|
private static final long MIN_UPLOAD_SIZE = 1;
|
||||||
private static final long MAX_UPLOAD_SIZE = 1_000_000_000;
|
private static final long MAX_UPLOAD_SIZE = 100_000_000; // 100MB
|
||||||
|
|
||||||
private static final int NUM_FILE_UPLOAD_RETRIES = 7;
|
private static final int NUM_FILE_UPLOAD_RETRIES = 7;
|
||||||
private static final long FILE_UPLOAD_RETRY_SLEEP_MILLIS = 60 * 1000;
|
private static final long FILE_UPLOAD_RETRY_SLEEP_MILLIS = 60 * 1000;
|
||||||
|
|
||||||
@ -634,7 +636,7 @@ class MalwareScanIngestModule implements FileIngestModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get auth token / file upload url
|
// get auth token / file upload url
|
||||||
AuthTokenResponse authTokenResponse = ctApiDAO.getAuthToken(ingestJobState.getLicenseInfo().getDecryptedLicense(), true);
|
AuthTokenResponse authTokenResponse = ctApiDAO.getAuthToken(ingestJobState.getLicenseInfo().getDecryptedLicense(), af.getSize());
|
||||||
if (StringUtils.isBlank(authTokenResponse.getFileUploadUrl())) {
|
if (StringUtils.isBlank(authTokenResponse.getFileUploadUrl())) {
|
||||||
throw new CTCloudException(CTCloudException.ErrorCode.NETWORK_ERROR);
|
throw new CTCloudException(CTCloudException.ErrorCode.NETWORK_ERROR);
|
||||||
} else if (remaining(authTokenResponse.getFileUploadLimit(), authTokenResponse.getFileUploadCount()) <= 0) {
|
} else if (remaining(authTokenResponse.getFileUploadLimit(), authTokenResponse.getFileUploadCount()) <= 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user