Sleuth Kit Java Bindings (JNI) 4.14.0
Java bindings for using The Sleuth Kit
Loading...
Searching...
No Matches
HostAddressManager.java
Go to the documentation of this file.
1/*
2 * Sleuth Kit Data Model
3 *
4 * Copyright 2021 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.datamodel;
20
21import com.google.common.cache.Cache;
22import com.google.common.cache.CacheBuilder;
23import java.sql.PreparedStatement;
24import java.sql.ResultSet;
25import java.sql.SQLException;
26import java.sql.Statement;
27import java.util.ArrayList;
28import java.util.List;
29import java.util.Objects;
30import java.util.Optional;
31import java.util.logging.Level;
32import java.util.logging.Logger;
33import java.util.regex.Pattern;
34import org.sleuthkit.datamodel.SleuthkitCase.CaseDbConnection;
35import org.sleuthkit.datamodel.HostAddress.HostAddressType;
36
40public class HostAddressManager {
41
42 private static final Logger LOGGER = Logger.getLogger(HostAddressManager.class.getName());
43
44 private final SleuthkitCase db;
45 private final static byte DEFAULT_MAPPING_CACHE_VALUE = 1;
46
52 private final Cache<Long, Byte> recentHostNameAndIpMappingCache = CacheBuilder.newBuilder().maximumSize(200000).build();
53
60 private final Cache<String, HostAddress> recentHostAddressCache = CacheBuilder.newBuilder().maximumSize(200000).build();
61
68 private final Cache<String, Boolean> hostAddressUsageCache = CacheBuilder.newBuilder().maximumSize(200000).build();
69
76 HostAddressManager(SleuthkitCase skCase) {
77 this.db = skCase;
78 }
79
90 public Optional<HostAddress> getHostAddress(HostAddress.HostAddressType type, String address) throws TskCoreException {
91
92 db.acquireSingleUserCaseReadLock();
93 try (CaseDbConnection connection = this.db.getConnection()) {
94 return HostAddressManager.this.getHostAddress(type, address, connection);
95 } finally {
96 db.releaseSingleUserCaseReadLock();
97 }
98 }
99
111 private Optional<HostAddress> getHostAddress(HostAddress.HostAddressType type, String address, CaseDbConnection connection) throws TskCoreException {
112
113 HostAddress hostAddress = recentHostAddressCache.getIfPresent(createRecentHostAddressKey(type, address));
114 if (Objects.nonNull(hostAddress)) {
115 return Optional.of(hostAddress);
116 }
117 HostAddress.HostAddressType addressType = type;
118 if (type.equals(HostAddress.HostAddressType.DNS_AUTO)) {
119 addressType = getDNSType(address);
120 }
121 String normalizedAddress = getNormalizedAddress(address);
122 String queryString = "SELECT * FROM tsk_host_addresses"
123 + " WHERE address = ? AND address_type = ?";
124 try {
125 PreparedStatement query = connection.getPreparedStatement(queryString, Statement.NO_GENERATED_KEYS);
126 query.clearParameters();
127 query.setString(1, normalizedAddress.toLowerCase());
128 query.setInt(2, addressType.getId());
129 try (ResultSet rs = query.executeQuery()) {
130 if (!rs.next()) {
131 return Optional.empty(); // no match found
132 } else {
133 HostAddress newHostAddress = new HostAddress(db, rs.getLong("id"), HostAddressType.fromID(rs.getInt("address_type")), rs.getString("address"));
134 recentHostAddressCache.put(createRecentHostAddressKey(newHostAddress.getAddressType(), normalizedAddress), newHostAddress);
135 return Optional.of(newHostAddress);
136 }
137 }
138 } catch (SQLException ex) {
139 throw new TskCoreException(String.format("Error getting host address with type = %s and address = %s", type.getName(), address), ex);
140 }
141 }
142
151 private String createRecentHostAddressKey(HostAddressType type, String address) {
152 return createRecentHostAddressKey(type.getId(), address);
153 }
154
163 private String createRecentHostAddressKey(int typeId, String address) {
164 return typeId + "#" + address.toLowerCase();
165 }
166
179 db.acquireSingleUserCaseWriteLock();
180 CaseDbConnection connection = this.db.getConnection();
181 try {
182 return HostAddressManager.this.newHostAddress(type, address, connection);
183 } catch (TskCoreException ex) {
184 // The insert may have failed because the HostAddress already exists, so
185 // try loading it from the database.
186 Optional<HostAddress> hostAddress = HostAddressManager.this.getHostAddress(type, address, connection);
187 if (hostAddress.isPresent()) {
188 return hostAddress.get();
189 }
190 throw ex;
191 } finally {
192 connection.close();
193 db.releaseSingleUserCaseWriteLock();
194 }
195 }
196
208 private HostAddress newHostAddress(HostAddress.HostAddressType type, String address, CaseDbConnection connection) throws TskCoreException {
209 HostAddress.HostAddressType addressType = type;
210 if (type.equals(HostAddress.HostAddressType.DNS_AUTO)) {
211 addressType = getDNSType(address);
212 }
213
214 String normalizedAddress = getNormalizedAddress(address);
215 // This prevents orphaned objects and ensures we return the existing valid object.
216 Optional<HostAddress> existingAddr = getHostAddress(addressType, normalizedAddress, connection);
217 if (existingAddr.isPresent()) {
218 return existingAddr.get();
219 }
220 try {
221
222 // TODO: need to get the correct parent obj id.
223 long parentObjId = 0;
224 int objTypeId = TskData.ObjectType.HOST_ADDRESS.getObjectType();
225
226 long objId = db.addObject(parentObjId, objTypeId, connection);
227
228 String hostAddressInsertSQL = "INSERT INTO tsk_host_addresses(id, address_type, address) VALUES (?, ?, ?) "; //NON-NLS
229
230 PreparedStatement preparedStatement = connection.getPreparedStatement(hostAddressInsertSQL, Statement.RETURN_GENERATED_KEYS);
231
232 preparedStatement.clearParameters();
233 preparedStatement.setLong(1, objId);
234 preparedStatement.setInt(2, addressType.getId());
235 preparedStatement.setString(3, normalizedAddress.toLowerCase());
236
237 connection.executeUpdate(preparedStatement);
238 HostAddress hostAddress = new HostAddress(db, objId, addressType, normalizedAddress);
239 recentHostAddressCache.put(createRecentHostAddressKey(addressType, normalizedAddress), hostAddress);
240 return hostAddress;
241 } catch (SQLException ex) {
242 throw new TskCoreException(String.format("Error adding host address of type = %s, with address = %s", type.getName(), address), ex);
243 }
244 }
245
256 public void assignHostToAddress(Host host, HostAddress hostAddress, Long time, Content source) throws TskCoreException {
257
258 String insertSQL = db.getInsertOrIgnoreSQL(" INTO tsk_host_address_map(host_id, addr_obj_id, source_obj_id, time) "
259 + " VALUES(?, ?, ?, ?) ");
260
261 db.acquireSingleUserCaseWriteLock();
262 try (CaseDbConnection connection = this.db.getConnection()) {
263
264 PreparedStatement preparedStatement = connection.getPreparedStatement(insertSQL, Statement.NO_GENERATED_KEYS);
265
266 preparedStatement.clearParameters();
267 preparedStatement.setLong(1, host.getHostId());
268 preparedStatement.setLong(2, hostAddress.getId());
269 preparedStatement.setLong(3, source.getId());
270 if (time != null) {
271 preparedStatement.setLong(4, time);
272 } else {
273 preparedStatement.setNull(4, java.sql.Types.BIGINT);
274 }
275
276 connection.executeUpdate(preparedStatement);
277 } catch (SQLException ex) {
278 LOGGER.log(Level.SEVERE, null, ex);
279 throw new TskCoreException(String.format("Error adding host address mapping for host name = %s, with address = %s", host.getName(), hostAddress.getAddress()), ex);
280 } finally {
281 db.releaseSingleUserCaseWriteLock();
282 }
283 }
284
292 public List<HostAddress> getHostAddressesAssignedTo(Host host) throws TskCoreException {
293
294 String queryString = "SELECT addr_obj_id FROM tsk_host_address_map "
295 + " WHERE host_id = " + host.getHostId();
296
297 List<HostAddress> addresses = new ArrayList<>();
298
299 db.acquireSingleUserCaseReadLock();
300 try (CaseDbConnection connection = this.db.getConnection();
301 Statement s = connection.createStatement();
302 ResultSet rs = connection.executeQuery(s, queryString)) {
303
304 while (rs.next()) {
305 addresses.add(HostAddressManager.this.getHostAddress(rs.getLong("addr_obj_id"), connection));
306 }
307
308 return addresses;
309 } catch (SQLException ex) {
310 throw new TskCoreException(String.format("Error getting host addresses for host " + host.getName()), ex);
311 } finally {
312 db.releaseSingleUserCaseReadLock();
313 }
314 }
315
326 db.acquireSingleUserCaseReadLock();
327 try (CaseDbConnection connection = this.db.getConnection()) {
328 return HostAddressManager.this.getHostAddress(id, connection);
329 } finally {
330 db.releaseSingleUserCaseReadLock();
331 }
332 }
333
344 private HostAddress getHostAddress(long id, CaseDbConnection connection) throws TskCoreException {
345 String queryString = "SELECT * FROM tsk_host_addresses"
346 + " WHERE id = " + id;
347
348 try (Statement s = connection.createStatement();
349 ResultSet rs = connection.executeQuery(s, queryString)) {
350
351 if (!rs.next()) {
352 throw new TskCoreException(String.format("No address found with id = %d", id));
353 } else {
354 long objId = rs.getLong("id");
355 int type = rs.getInt("address_type");
356 String address = rs.getString("address");
357 HostAddress hostAddress = new HostAddress(db, objId, HostAddress.HostAddressType.fromID(type), address);
358 recentHostAddressCache.put(createRecentHostAddressKey(type, address), hostAddress);
359 return hostAddress;
360 }
361 } catch (SQLException ex) {
362 throw new TskCoreException(String.format("Error getting host address with id = %d", id), ex);
363 }
364 }
365
376 public void addHostNameAndIpMapping(HostAddress dnsNameAddress, HostAddress ipAddress, Long time, Content source) throws TskCoreException {
377
378 db.acquireSingleUserCaseWriteLock();
379 try (CaseDbConnection connection = this.db.getConnection()) {
380 addHostNameAndIpMapping(dnsNameAddress, ipAddress, time, source, connection);
381 } catch (SQLException ex) {
382 throw new TskCoreException(String.format("Error adding host DNS address mapping for DNS name = %s, and IP address = %s", dnsNameAddress.getAddress(), ipAddress.getAddress()), ex);
383 } finally {
384 db.releaseSingleUserCaseWriteLock();
385 }
386 }
387
401 public void addHostNameAndIpMapping(HostAddress dnsNameAddress, HostAddress ipAddress, Long time, Content source, final SleuthkitCase.CaseDbTransaction caseDbTransaction) throws TskCoreException {
402
403 if (Objects.isNull(caseDbTransaction)) {
404 throw new TskCoreException(String.format("Error adding host DNS address mapping for DNS name = %s, and IP address = %s, null caseDbTransaction passed to addHostNameAndIpMapping", dnsNameAddress.getAddress(), ipAddress.getAddress()));
405 }
406 try {
407 addHostNameAndIpMapping(dnsNameAddress, ipAddress, time, source, caseDbTransaction.getConnection());
408 } catch (SQLException ex) {
409 throw new TskCoreException(String.format("Error adding host DNS address mapping for DNS name = %s, and IP address = %s", dnsNameAddress.getAddress(), ipAddress.getAddress()), ex);
410 }
411 }
412
424 private void addHostNameAndIpMapping(HostAddress dnsNameAddress, HostAddress ipAddress, Long time, Content source, final CaseDbConnection connection) throws SQLException, TskCoreException {
425
426 if (dnsNameAddress.getAddressType() != HostAddress.HostAddressType.HOSTNAME) {
427 throw new TskCoreException("IllegalArguments passed to addHostNameAndIpMapping: A host name address is expected.");
428 }
429 if ((ipAddress.getAddressType() != HostAddress.HostAddressType.IPV4) && (ipAddress.getAddressType() != HostAddress.HostAddressType.IPV6)) {
430 throw new TskCoreException("IllegalArguments passed to addHostNameAndIpMapping:An IPv4/IPv6 address is expected.");
431 }
432 if (Objects.isNull(connection)) {
433 throw new TskCoreException("IllegalArguments passed to addHostNameAndIpMapping: null connection passed to addHostNameAndIpMapping");
434 }
435
436 String insertSQL = db.getInsertOrIgnoreSQL(" INTO tsk_host_address_dns_ip_map(dns_address_id, ip_address_id, source_obj_id, time) "
437 + " VALUES(?, ?, ?, ?) ");
438
439 PreparedStatement preparedStatement = connection.getPreparedStatement(insertSQL, Statement.NO_GENERATED_KEYS);
440
441 preparedStatement.clearParameters();
442 preparedStatement.setLong(1, dnsNameAddress.getId());
443 preparedStatement.setLong(2, ipAddress.getId());
444 preparedStatement.setLong(3, source.getId());
445 if (time != null) {
446 preparedStatement.setLong(4, time);
447 } else {
448 preparedStatement.setNull(4, java.sql.Types.BIGINT);
449 }
450 connection.executeUpdate(preparedStatement);
451 recentHostNameAndIpMappingCache.put(ipAddress.getId(), DEFAULT_MAPPING_CACHE_VALUE);
452 recentHostNameAndIpMappingCache.put(dnsNameAddress.getId(), DEFAULT_MAPPING_CACHE_VALUE);
453 }
454
467 public boolean hostNameAndIpMappingExists(long addressObjectId) throws TskCoreException {
468
469 Byte isPresent = recentHostNameAndIpMappingCache.getIfPresent(addressObjectId);
470
471 if (Objects.nonNull(isPresent)) {
472 return true;
473 }
474
475 String queryString = "SELECT count(*) as mappingCount FROM tsk_host_address_dns_ip_map WHERE ip_address_id = ? OR dns_address_id = ? ";
476
477 db.acquireSingleUserCaseReadLock();
478 try (CaseDbConnection connection = this.db.getConnection();
479 PreparedStatement ps = connection.getPreparedStatement(queryString, Statement.NO_GENERATED_KEYS);) {
480 ps.clearParameters();
481 ps.setLong(1, addressObjectId);
482 ps.setLong(2, addressObjectId);
483 try (ResultSet rs = ps.executeQuery()) {
484 if (!rs.next()) {
485 return false;
486 } else {
487 boolean status = rs.getLong("mappingCount") > 0;
488 if (status) {
489 recentHostNameAndIpMappingCache.put(addressObjectId, DEFAULT_MAPPING_CACHE_VALUE);
490 }
491 return status;
492 }
493 }
494 } catch (SQLException ex) {
495 throw new TskCoreException("Error looking up host address / Ip mapping for address = " + addressObjectId, ex);
496 } finally {
497 db.releaseSingleUserCaseReadLock();
498 }
499 }
500
514 public Optional<Long> hostAddressExists(HostAddress.HostAddressType type, String address) throws TskCoreException {
515
516 HostAddress hostAddress = recentHostAddressCache.getIfPresent(createRecentHostAddressKey(type, address));
517 if (Objects.nonNull(hostAddress)) {
518 return Optional.of(hostAddress.getId());
519 }
520
521 HostAddress.HostAddressType addressType = type;
522 if (type.equals(HostAddress.HostAddressType.DNS_AUTO)) {
523 addressType = getDNSType(address);
524 }
525 String normalizedAddress = getNormalizedAddress(address);
526
527 String queryString = "SELECT id, address_type, address FROM tsk_host_addresses"
528 + " WHERE address = ? AND address_type = ?";
529
530 db.acquireSingleUserCaseReadLock();
531 try (CaseDbConnection connection = this.db.getConnection();
532 PreparedStatement query = connection.getPreparedStatement(queryString, Statement.NO_GENERATED_KEYS);) {
533 query.clearParameters();
534 query.setString(1, normalizedAddress.toLowerCase());
535 query.setInt(2, addressType.getId());
536 try (ResultSet rs = query.executeQuery()) {
537 if (!rs.next()) {
538 return Optional.empty(); // no match found
539 } else {
540 long objId = rs.getLong("id");
541 int addrType = rs.getInt("address_type");
542 String addr = rs.getString("address");
543 HostAddress hostAddr = new HostAddress(db, objId, HostAddress.HostAddressType.fromID(addrType), addr);
544 recentHostAddressCache.put(createRecentHostAddressKey(addrType, normalizedAddress), hostAddr);
545 return Optional.of(objId);
546 }
547 }
548 } catch (SQLException ex) {
549 throw new TskCoreException(String.format("Error getting host address with type = %s and address = %s", type.getName(), address), ex);
550 } finally {
551 db.releaseSingleUserCaseReadLock();
552 }
553 }
554
564 public List<HostAddress> getIpAddress(String hostname) throws TskCoreException {
565 String queryString = "SELECT ip_address_id FROM tsk_host_address_dns_ip_map as map "
566 + " JOIN tsk_host_addresses as addresses "
567 + " ON map.dns_address_id = addresses.id "
568 + " WHERE addresses.address_type = " + HostAddress.HostAddressType.HOSTNAME.getId()
569 + " AND addresses.address = ?";
570
571 db.acquireSingleUserCaseReadLock();
572 try (CaseDbConnection connection = this.db.getConnection()) {
573 List<HostAddress> IpAddresses = new ArrayList<>();
574 PreparedStatement query = connection.getPreparedStatement(queryString, Statement.NO_GENERATED_KEYS);
575 query.clearParameters();
576 query.setString(1, hostname.toLowerCase());
577 try (ResultSet rs = query.executeQuery()) {
578 while (rs.next()) {
579 long ipAddressObjId = rs.getLong("ip_address_id");
580 IpAddresses.add(HostAddressManager.this.getHostAddress(ipAddressObjId, connection));
581 recentHostNameAndIpMappingCache.put(ipAddressObjId, DEFAULT_MAPPING_CACHE_VALUE);
582 }
583 return IpAddresses;
584 }
585 } catch (SQLException ex) {
586 throw new TskCoreException(String.format("Error getting host addresses for host name: " + hostname), ex);
587 } finally {
588 db.releaseSingleUserCaseReadLock();
589 }
590 }
591
601 List<HostAddress> getHostNameByIp(String ipAddress) throws TskCoreException {
602 String queryString = "SELECT dns_address_id FROM tsk_host_address_dns_ip_map as map "
603 + " JOIN tsk_host_addresses as addresses "
604 + " ON map.ip_address_id = addresses.id "
605 + " WHERE ( addresses.address_type = " + HostAddress.HostAddressType.IPV4.getId()
606 + " OR addresses.address_type = " + HostAddress.HostAddressType.IPV6.getId() + ")"
607 + " AND addresses.address = ?";
608
610 try (CaseDbConnection connection = this.db.getConnection()) {
611 List<HostAddress> dnsNames = new ArrayList<>();
612 PreparedStatement query = connection.getPreparedStatement(queryString, Statement.NO_GENERATED_KEYS);
613 query.clearParameters();
614 query.setString(1, ipAddress.toLowerCase());
615 try (ResultSet rs = query.executeQuery()) {
616 while (rs.next()) {
617 long dnsAddressId = rs.getLong("dns_address_id");
618 dnsNames.add(HostAddressManager.this.getHostAddress(dnsAddressId, connection));
619 recentHostNameAndIpMappingCache.put(dnsAddressId, DEFAULT_MAPPING_CACHE_VALUE);
620 }
621 return dnsNames;
622 }
623 } catch (SQLException ex) {
624 throw new TskCoreException(String.format("Error getting host addresses for IP address: " + ipAddress), ex);
625 } finally {
626 db.releaseSingleUserCaseReadLock();
627 }
628 }
629
636 public void addUsage(Content content, HostAddress hostAddress) throws TskCoreException {
637
638 String key = content.getDataSource().getId() + "#" + hostAddress.getId() + "#" + content.getId();
639 Boolean cachedValue = hostAddressUsageCache.getIfPresent(key);
640 if (null != cachedValue) {
641 return;
642 }
643
644 final String insertSQL = db.getInsertOrIgnoreSQL(" INTO tsk_host_address_usage(addr_obj_id, obj_id, data_source_obj_id) "
645 + " VALUES(" + hostAddress.getId() + ", " + content.getId() + ", " + content.getDataSource().getId() + ") ");
646
647 db.acquireSingleUserCaseWriteLock();
648 try (CaseDbConnection connection = this.db.getConnection();
649 Statement s = connection.createStatement()) {
650 connection.executeUpdate(s, insertSQL);
651 hostAddressUsageCache.put(key, true);
652 } catch (SQLException ex) {
653 throw new TskCoreException(String.format("Error associating host address %s with artifact with id %d", hostAddress.getAddress(), content.getId()), ex);
654 } finally {
655 db.releaseSingleUserCaseWriteLock();
656 }
657 }
658
659 private final String ADDRESS_USAGE_QUERY = "SELECT addresses.id as id, addresses.address_type as address_type, addresses.address as address "
660 + " FROM tsk_host_address_usage as usage "
661 + " JOIN tsk_host_addresses as addresses "
662 + " ON usage.addr_obj_id = addresses.id ";
663
673 public List<HostAddress> getHostAddressesUsedByContent(Content content) throws TskCoreException {
674 String queryString = ADDRESS_USAGE_QUERY
675 + " WHERE usage.obj_id = " + content.getId();
676
677 return getHostAddressesUsed(queryString);
678 }
679
689 public List<HostAddress> getHostAddressesUsedOnDataSource(Content dataSource) throws TskCoreException {
690 String queryString = ADDRESS_USAGE_QUERY
691 + " WHERE usage.data_source_obj_id = " + dataSource.getId();
692
693 return getHostAddressesUsed(queryString);
694 }
695
705 private List<HostAddress> getHostAddressesUsed(String addressesUsedSQL) throws TskCoreException {
706
707 List<HostAddress> addressesUsed = new ArrayList<>();
708
710 try (CaseDbConnection connection = this.db.getConnection();
711 Statement s = connection.createStatement();
712 ResultSet rs = connection.executeQuery(s, addressesUsedSQL)) {
713
714 while (rs.next()) {
715 addressesUsed.add(new HostAddress(db, rs.getLong("id"), HostAddress.HostAddressType.fromID(rs.getInt("address_type")), rs.getString("address")));
716 }
717 return addressesUsed;
718 } catch (SQLException ex) {
719 throw new TskCoreException(String.format("Error getting host addresses used with query string = %s", addressesUsedSQL), ex);
720 } finally {
722 }
723 }
724
732 private HostAddress.HostAddressType getDNSType(String address) {
733 if (isIPv4(address)) {
734 return HostAddress.HostAddressType.IPV4;
735 } else if (isIPv6(address)) {
736 return HostAddress.HostAddressType.IPV6;
737 } else {
738 return HostAddress.HostAddressType.HOSTNAME;
739 }
740 }
741
742 private static final Pattern IPV4_PATTERN =
743 Pattern.compile("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!$)|$)){4}$");
751 private static boolean isIPv4(String ipAddress) {
752 if (ipAddress != null) {
753 return IPV4_PATTERN.matcher(ipAddress).matches();
754 }
755 return false;
756 }
757
758
759 // IPV6 address examples:
760 // Standard: 684D:1111:222:3333:4444:5555:6:77
761 // Compressed: 1234:fd2:5621:1:89::4500
762 // With zone/interface specifier: fe80::1ff:fe23:4567:890a%eth2
763 // fe80::1ff:fe23:4567:890a%3
764 private static final Pattern IPV6_STD_PATTERN =
765 Pattern.compile("^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}(%.+)?$");
766 private static final Pattern IPV6_HEX_COMPRESSED_PATTERN =
767 Pattern.compile("^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)(%.+)?$");
768
769
770 private static boolean isIPv6StdAddress(final String input) {
771 return IPV6_STD_PATTERN.matcher(input).matches();
772 }
773 private static boolean isIPv6HexCompressedAddress(final String input) {
774 return IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches();
775 }
776
784 private static boolean isIPv6(String ipAddress) {
785
786 if (ipAddress != null) {
787 return isIPv6StdAddress(ipAddress) || isIPv6HexCompressedAddress(ipAddress);
788 }
789
790 return false;
791 }
792
803 private static String getNormalizedAddress(String address) {
804
805 String normalizedAddress = address;
806
807 if (isIPv6(address)) {
808 normalizedAddress = getNormalizedIPV6Address(address);
809 }
810
811 return normalizedAddress;
812 }
813
825 private static String getNormalizedIPV6Address(String address) {
826
827 String normalizedAddress = address;
828 if ( normalizedAddress.contains("%") ) {
829 normalizedAddress = normalizedAddress.substring(0, normalizedAddress.indexOf("%"));
830 }
831
832 return normalizedAddress;
833 }
834}
835
Optional< Long > hostAddressExists(HostAddress.HostAddressType type, String address)
void assignHostToAddress(Host host, HostAddress hostAddress, Long time, Content source)
List< HostAddress > getIpAddress(String hostname)
HostAddress newHostAddress(HostAddress.HostAddressType type, String address)
List< HostAddress > getHostAddressesAssignedTo(Host host)
void addHostNameAndIpMapping(HostAddress dnsNameAddress, HostAddress ipAddress, Long time, Content source)
List< HostAddress > getHostAddressesUsedOnDataSource(Content dataSource)
List< HostAddress > getHostAddressesUsedByContent(Content content)
void addUsage(Content content, HostAddress hostAddress)
boolean hostNameAndIpMappingExists(long addressObjectId)
void addHostNameAndIpMapping(HostAddress dnsNameAddress, HostAddress ipAddress, Long time, Content source, final SleuthkitCase.CaseDbTransaction caseDbTransaction)
Optional< HostAddress > getHostAddress(HostAddress.HostAddressType type, String address)
static HostAddressType fromID(int typeId)

Copyright © 2011-2024 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.