Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CreditCards.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2011-2018 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 org.sleuthkit.autopsy.datamodel;
20
21import com.google.common.collect.Range;
22import com.google.common.collect.RangeMap;
23import com.google.common.collect.TreeRangeMap;
24import java.io.IOException;
25import java.io.InputStreamReader;
26import java.util.Optional;
27import java.util.logging.Level;
28import javax.annotation.concurrent.GuardedBy;
29import org.apache.commons.csv.CSVFormat;
30import org.apache.commons.csv.CSVParser;
31import org.apache.commons.csv.CSVRecord;
32import org.apache.commons.lang3.StringUtils;
33import org.sleuthkit.autopsy.coreutils.Logger;
34import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
35import org.sleuthkit.autopsy.datamodel.accounts.BINRange;
36
37public class CreditCards {
38
39 //Interface for objects that provide details about one or more BINs.
40 static public interface BankIdentificationNumber {
41
47 Optional<String> getBankCity();
48
54 Optional<String> getBankName();
55
61 Optional<String> getBankPhoneNumber();
62
68 Optional<String> getBankURL();
69
75 Optional<String> getBrand();
76
82 Optional<String> getCardType();
83
89 Optional<String> getCountry();
90
101 Optional<Integer> getNumberLength();
102
108 Optional<String> getScheme();
109 }
110
111 private static final Logger logger = Logger.getLogger(CreditCards.class.getName());
112
113
118 @GuardedBy("CreditCards.class")
119 private final static RangeMap<Integer, BINRange> binRanges = TreeRangeMap.create();
120
124 @GuardedBy("CreditCards.class")
125 private static boolean binsLoaded = false;
126
131 synchronized private static void loadBINRanges() {
132 if (binsLoaded == false) {
133 try {
134 InputStreamReader in = new InputStreamReader(CreditCards.class.getResourceAsStream("ranges.csv")); //NON-NLS
135
136 CSVParser rangesParser = CSVFormat.RFC4180.builder().setHeader().setSkipHeaderRecord(true).build().parse(in);
137
138 //parse each row and add to range map
139 for (CSVRecord record : rangesParser) {
140
146 String start = StringUtils.rightPad(record.get("iin_start"), 8, "0"); //pad start with 0's //NON-NLS
147
148 //if there is no end listed, use start, since ranges will be closed.
149 String end = StringUtils.defaultIfBlank(record.get("iin_end"), start); //NON-NLS
150 end = StringUtils.rightPad(end, 8, "99"); //pad end with 9's //NON-NLS
151
152 final String numberLength = record.get("number_length"); //NON-NLS
153
154 try {
155 BINRange binRange = new BINRange(Integer.parseInt(start),
156 Integer.parseInt(end),
157 StringUtils.isBlank(numberLength) ? null : Integer.valueOf(numberLength),
158 record.get("scheme"), //NON-NLS
159 record.get("brand"), //NON-NLS
160 record.get("type"), //NON-NLS
161 record.get("country"), //NON-NLS
162 record.get("bank_name"), //NON-NLS
163 record.get("bank_url"), //NON-NLS
164 record.get("bank_phone"), //NON-NLS
165 record.get("bank_city")); //NON-NLS
166
167 binRanges.put(Range.closed(binRange.getBINstart(), binRange.getBINend()), binRange);
168
169 } catch (NumberFormatException numberFormatException) {
170 logger.log(Level.WARNING, "Failed to parse BIN range: " + record.toString(), numberFormatException); //NON-NLS
171 }
172 binsLoaded = true;
173 }
174 } catch (IOException ex) {
175 logger.log(Level.WARNING, "Failed to load BIN ranges form ranges.csv", ex); //NON-NLS
176 MessageNotifyUtil.Notify.warn("Credit Card Number Discovery", "There was an error loading Bank Identification Number information. Accounts will not have their BINs identified.");
177 }
178 }
179 }
180
188 synchronized static public BankIdentificationNumber getBINInfo(int bin) {
190 return binRanges.get(bin);
191 }
192}
synchronized static Logger getLogger(String name)
Definition Logger.java:124
static final RangeMap< Integer, BINRange > binRanges
static synchronized BankIdentificationNumber getBINInfo(int bin)

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