Autopsy  4.21.0
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  */
19 package com.basistech.df.cybertriage.autopsy.ctapi;
20 
33 import java.io.InputStream;
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import org.apache.commons.collections.CollectionUtils;
41 
46 public 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 
70  public LicenseResponse getLicenseInfo(String licenseString) throws CTCloudException {
71  LicenseRequest licenseRequest = new LicenseRequest()
72  .setBoostLicenseCode(licenseString)
74  .setProduct(AUTOPSY_PRODUCT)
76 
77  return httpClient.doPost(LICENSE_REQUEST_PATH, licenseRequest, LicenseResponse.class);
78 
79  }
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(
123  CTCLOUD_SERVER_HASH_PATH,
124  getAuthParams(authenticatedRequestData),
125  fileRepReq,
126  CTCloudBeanResponse.class
127  );
128 
129  return resp == null || resp.getItems() == null
130  ? Collections.emptyList()
131  : resp.getItems();
132  }
133 }
static Map< String, String > getAuthParams(AuthenticatedRequestData authenticatedRequestData)
Definition: CTApiDAO.java:104
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted, Long fileUploadSize)
Definition: CTApiDAO.java:85
void uploadMeta(AuthenticatedRequestData authenticatedRequestData, MetadataUploadRequest metaRequest)
Definition: CTApiDAO.java:100
List< CTCloudBean > getReputationResults(AuthenticatedRequestData authenticatedRequestData, List< String > md5Hashes)
Definition: CTApiDAO.java:114
LicenseRequest setBoostLicenseCode(String boostLicenseCode)
AuthTokenRequest setRequestFileUpload(boolean requestFileUpload)
void uploadFile(FileUploadRequest fileUploadRequest)
Definition: CTApiDAO.java:96
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted)
Definition: CTApiDAO.java:81
LicenseResponse getLicenseInfo(String licenseString)
Definition: CTApiDAO.java:70

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.