Autopsy  4.19.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  */
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  CSVParser rangesParser = CSVFormat.RFC4180.withFirstRecordAsHeader().parse(in);
136 
137  //parse each row and add to range map
138  for (CSVRecord record : rangesParser) {
139 
145  String start = StringUtils.rightPad(record.get("iin_start"), 8, "0"); //pad start with 0's //NON-NLS
146 
147  //if there is no end listed, use start, since ranges will be closed.
148  String end = StringUtils.defaultIfBlank(record.get("iin_end"), start); //NON-NLS
149  end = StringUtils.rightPad(end, 8, "99"); //pad end with 9's //NON-NLS
150 
151  final String numberLength = record.get("number_length"); //NON-NLS
152 
153  try {
154  BINRange binRange = new BINRange(Integer.parseInt(start),
155  Integer.parseInt(end),
156  StringUtils.isBlank(numberLength) ? null : Integer.valueOf(numberLength),
157  record.get("scheme"), //NON-NLS
158  record.get("brand"), //NON-NLS
159  record.get("type"), //NON-NLS
160  record.get("country"), //NON-NLS
161  record.get("bank_name"), //NON-NLS
162  record.get("bank_url"), //NON-NLS
163  record.get("bank_phone"), //NON-NLS
164  record.get("bank_city")); //NON-NLS
165 
166  binRanges.put(Range.closed(binRange.getBINstart(), binRange.getBINend()), binRange);
167 
168  } catch (NumberFormatException numberFormatException) {
169  logger.log(Level.WARNING, "Failed to parse BIN range: " + record.toString(), numberFormatException); //NON-NLS
170  }
171  binsLoaded = true;
172  }
173  } catch (IOException ex) {
174  logger.log(Level.WARNING, "Failed to load BIN ranges form ranges.csv", ex); //NON-NLS
175  MessageNotifyUtil.Notify.warn("Credit Card Number Discovery", "There was an error loading Bank Identification Number information. Accounts will not have their BINs identified.");
176  }
177  }
178  }
179 
187  synchronized static public BankIdentificationNumber getBINInfo(int bin) {
188  loadBINRanges();
189  return binRanges.get(bin);
190  }
191 }
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-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.