Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTApiDAO.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2023 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package com.basistech.df.cybertriage.autopsy.ctapi;
20
21import com.basistech.df.cybertriage.autopsy.ctapi.json.AuthTokenRequest;
22import com.basistech.df.cybertriage.autopsy.ctapi.json.AuthTokenResponse;
23import com.basistech.df.cybertriage.autopsy.ctapi.json.AuthenticatedRequestData;
24import com.basistech.df.cybertriage.autopsy.ctapi.json.CTCloudBean;
25import com.basistech.df.cybertriage.autopsy.ctapi.json.CTCloudBeanResponse;
26import com.basistech.df.cybertriage.autopsy.ctapi.json.DecryptedLicenseResponse;
27import com.basistech.df.cybertriage.autopsy.ctapi.json.FileReputationRequest;
28import com.basistech.df.cybertriage.autopsy.ctapi.json.FileUploadRequest;
29import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseRequest;
30import com.basistech.df.cybertriage.autopsy.ctapi.json.LicenseResponse;
31import com.basistech.df.cybertriage.autopsy.ctapi.json.MetadataUploadRequest;
32import com.basistech.df.cybertriage.autopsy.ctapi.util.CTHostIDGenerationUtil;
33import java.io.InputStream;
34import java.util.Collections;
35import java.util.HashMap;
36import java.util.List;
37import java.util.Map;
38import org.apache.commons.collections.CollectionUtils;
39import org.sleuthkit.autopsy.core.UserPreferences;
40import org.sleuthkit.autopsy.coreutils.Version;
41
46public class CTApiDAO {
47
48 private static final String LICENSE_REQUEST_PATH = "/_ah/api/license/v1/activate";
49 private static final String AUTH_TOKEN_REQUEST_PATH = "/_ah/api/auth/v2/generate_token";
50 private static final String CTCLOUD_SERVER_HASH_PATH = "/_ah/api/reputation/v1/query/file/hash/md5?query_types=CORRELATION,MALWARE";
51 private static final String CTCLOUD_UPLOAD_FILE_METADATA_PATH = "/_ah/api/reputation/v1/upload/meta";
52
53 private static final String AUTOPSY_PRODUCT = "AUTOPSY";
54
55 private static final CTApiDAO instance = new CTApiDAO();
56
57 private CTApiDAO() {
58 }
59
60 public static CTApiDAO getInstance() {
61 return instance;
62 }
63
64 private static String getAppVersion() {
65 return Version.getVersion();
66 }
67
68 private final CTCloudHttpClient httpClient = CTCloudHttpClient.getInstance();
69
80
82 return getAuthToken(decrypted, null);
83 }
84
85 public AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted, Long fileUploadSize) throws CTCloudException {
86 AuthTokenRequest authTokenRequest = new AuthTokenRequest()
88 .setRequestFileUpload(fileUploadSize != null && fileUploadSize > 0)
89 .setFileUploadSize(fileUploadSize != null && fileUploadSize > 0 ? fileUploadSize : null)
90 .setBoostLicenseId(decrypted.getBoostLicenseId())
91 .setHostId(decrypted.getLicenseHostId());
92
93 return httpClient.doPost(AUTH_TOKEN_REQUEST_PATH, authTokenRequest, AuthTokenResponse.class);
94 }
95
96 public void uploadFile(FileUploadRequest fileUploadRequest) throws CTCloudException {
97 httpClient.doFileUploadPut(fileUploadRequest);
98 }
99
100 public void uploadMeta(AuthenticatedRequestData authenticatedRequestData, MetadataUploadRequest metaRequest) throws CTCloudException {
101 httpClient.doPost(CTCLOUD_UPLOAD_FILE_METADATA_PATH, getAuthParams(authenticatedRequestData), metaRequest, null);
102 }
103
104 private static Map<String, String> getAuthParams(AuthenticatedRequestData authenticatedRequestData) {
105 return new HashMap<String, String>() {
106 {
107 put("api_key", authenticatedRequestData.getApiKey());
108 put("token", authenticatedRequestData.getToken());
109 put("host_id", authenticatedRequestData.getHostId());
110 }
111 };
112 }
113
114 public List<CTCloudBean> getReputationResults(AuthenticatedRequestData authenticatedRequestData, List<String> md5Hashes) throws CTCloudException {
115 if (CollectionUtils.isEmpty(md5Hashes)) {
116 return Collections.emptyList();
117 }
118
120 .setHashes(md5Hashes);
121
122 CTCloudBeanResponse resp = httpClient.doPost(
124 getAuthParams(authenticatedRequestData),
125 fileRepReq,
127 );
128
129 return resp == null || resp.getItems() == null
130 ? Collections.emptyList()
131 : resp.getItems();
132 }
133}
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted)
Definition CTApiDAO.java:81
List< CTCloudBean > getReputationResults(AuthenticatedRequestData authenticatedRequestData, List< String > md5Hashes)
void uploadMeta(AuthenticatedRequestData authenticatedRequestData, MetadataUploadRequest metaRequest)
LicenseResponse getLicenseInfo(String licenseString)
Definition CTApiDAO.java:70
void uploadFile(FileUploadRequest fileUploadRequest)
Definition CTApiDAO.java:96
static Map< String, String > getAuthParams(AuthenticatedRequestData authenticatedRequestData)
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted, Long fileUploadSize)
Definition CTApiDAO.java:85
AuthTokenRequest setRequestFileUpload(boolean requestFileUpload)
LicenseRequest setBoostLicenseCode(String boostLicenseCode)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.