Autopsy  4.20.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 
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import org.apache.commons.collections.CollectionUtils;
38 
43 public class CTApiDAO {
44 
45  private static final String LICENSE_REQUEST_PATH = "/_ah/api/license/v1/activate";
46  private static final String AUTH_TOKEN_REQUEST_PATH = "/_ah/api/auth/v2/generate_token";
47  private static final String CTCLOUD_SERVER_HASH_PATH = "/_ah/api/reputation/v1/query/file/hash/md5?query_types=CORRELATION,MALWARE";
48  private static final String AUTOPSY_PRODUCT = "AUTOPSY";
49 
50  private static final CTApiDAO instance = new CTApiDAO();
51 
52  private CTApiDAO() {
53  }
54 
55  public static CTApiDAO getInstance() {
56  return instance;
57  }
58 
59  private static String getAppVersion() {
60  return Version.getVersion();
61  }
62 
64 
65  public LicenseResponse getLicenseInfo(String licenseString) throws CTCloudException {
66  LicenseRequest licenseRequest = new LicenseRequest()
67  .setBoostLicenseCode(licenseString)
69  .setProduct(AUTOPSY_PRODUCT)
71 
72  return httpClient.doPost(LICENSE_REQUEST_PATH, licenseRequest, LicenseResponse.class);
73 
74  }
75 
77  AuthTokenRequest authTokenRequest = new AuthTokenRequest()
79  .setRequestFileUpload(false)
80  .setBoostLicenseId(decrypted.getBoostLicenseId())
81  .setHostId(decrypted.getLicenseHostId());
82 
83  return httpClient.doPost(AUTH_TOKEN_REQUEST_PATH, authTokenRequest, AuthTokenResponse.class);
84  }
85 
86  private static Map<String, String> getAuthParams(AuthenticatedRequestData authenticatedRequestData) {
87  return new HashMap<String, String>() {
88  {
89  put("api_key", authenticatedRequestData.getApiKey());
90  put("token", authenticatedRequestData.getToken());
91  put("host_id", authenticatedRequestData.getHostId());
92  }
93  };
94  }
95 
96  public List<CTCloudBean> getReputationResults(AuthenticatedRequestData authenticatedRequestData, List<String> md5Hashes) throws CTCloudException {
97  if (CollectionUtils.isEmpty(md5Hashes)) {
98  return Collections.emptyList();
99  }
100 
102  .setHashes(md5Hashes);
103 
104  CTCloudBeanResponse resp = httpClient.doPost(
105  CTCLOUD_SERVER_HASH_PATH,
106  getAuthParams(authenticatedRequestData),
107  fileRepReq,
108  CTCloudBeanResponse.class
109  );
110 
111  return resp == null || resp.getItems() == null
112  ? Collections.emptyList()
113  : resp.getItems();
114  }
115 }
static Map< String, String > getAuthParams(AuthenticatedRequestData authenticatedRequestData)
Definition: CTApiDAO.java:86
List< CTCloudBean > getReputationResults(AuthenticatedRequestData authenticatedRequestData, List< String > md5Hashes)
Definition: CTApiDAO.java:96
LicenseRequest setBoostLicenseCode(String boostLicenseCode)
AuthTokenRequest setRequestFileUpload(boolean requestFileUpload)
AuthTokenResponse getAuthToken(DecryptedLicenseResponse decrypted)
Definition: CTApiDAO.java:76
LicenseResponse getLicenseInfo(String licenseString)
Definition: CTApiDAO.java:65

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