Autopsy  4.19.3
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  */
19 package org.sleuthkit.autopsy.datamodel;
20 
21 import com.google.common.collect.Range;
22 import com.google.common.collect.RangeMap;
23 import com.google.common.collect.TreeRangeMap;
24 import java.io.IOException;
25 import java.io.InputStreamReader;
26 import java.util.Optional;
27 import java.util.logging.Level;
28 import javax.annotation.concurrent.GuardedBy;
29 import org.apache.commons.csv.CSVFormat;
30 import org.apache.commons.csv.CSVParser;
31 import org.apache.commons.csv.CSVRecord;
32 import org.apache.commons.lang3.StringUtils;
36 
37 public 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) {
189  loadBINRanges();
190  return binRanges.get(bin);
191  }
192 }
synchronized static void loadBINRanges()
static synchronized BankIdentificationNumber getBINInfo(int bin)
static final RangeMap< Integer, BINRange > binRanges
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void warn(String title, String message)

Copyright © 2012-2022 Basis Technology. Generated on: Sun Oct 2 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.