示例#1
0
  /**
   * @param conn
   * @param fingerprint
   * @param sampleID
   * @return
   * @throws SQLException
   */
  private static void insertSampleSet(Connection conn, Fingerprint fingerprint, Integer sampleID)
      throws SQLException {
    if (fingerprint.getSampleSetID() == null) {
      /*
       * Insert whole new SampleSetID.
       */
      String query = "INSERT INTO `SampleSets`(`SampleID`) VALUES(?);";
      PreparedStatement insertSampleSet =
          conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);

      insertSampleSet.setInt(1, sampleID);
      insertSampleSet.execute();

      ResultSet rs = insertSampleSet.getGeneratedKeys();
      if (rs.next()) {
        fingerprint.setSampleSetID(rs.getInt(1));
      }
      rs.close();
      insertSampleSet.close();
    } else {
      /*
       * Insert new SampleID for existing SampleSetID.
       */
      String query = "INSERT INTO `SampleSets`(`SampleSetID`,`SampleID`) VALUES(?, ?);";
      PreparedStatement insertSampleSet = conn.prepareStatement(query);

      insertSampleSet.setInt(1, fingerprint.getSampleSetID());
      insertSampleSet.setInt(2, sampleID);
      insertSampleSet.execute();

      insertSampleSet.close();
    }
  }
示例#2
0
  /**
   * Returns the sampleID of the matching sample if we've seen this sample (with SampleSetID)
   * before. Otherwise returns null.
   *
   * @param conn
   * @param fingerprint
   * @return
   * @throws SQLException
   */
  private static Integer checkSampleChanged(Connection conn, Fingerprint fingerprint)
      throws SQLException {
    if (fingerprint.getSampleSetID() == null) {
      /*
       * We know we haven't seen this sample before because there's no SampleSetID.
       */
      return null;
    }

    /*
     * We have seen this user before. Check if their fingerprint has changed.
     */
    String query =
        "SELECT `Samples`.`SampleID` FROM `SampleSets` INNER JOIN `Samples` ON `SampleSets`.`SampleID` = `Samples`.`SampleID` WHERE `SampleSetID` = ?"
            + " AND `UserAgent`"
            + (fingerprint.getUser_agent() == null ? " IS NULL" : " = ?")
            + " AND `AcceptHeaders`"
            + (fingerprint.getAccept_headers() == null ? " IS NULL" : " = ?")
            + " AND `Platform`"
            + (fingerprint.getPlatform() == null ? " IS NULL" : " = ?")
            + " AND `PlatformFlash`"
            + (fingerprint.getPlatformFlash() == null ? " IS NULL" : " = ?")
            + " AND `PluginDetails`"
            + (fingerprint.getPluginDetails() == null ? " IS NULL" : " = ?")
            + " AND `TimeZone`"
            + (fingerprint.getTimeZone() == null ? " IS NULL" : " = ?")
            + " AND `ScreenDetails`"
            + (fingerprint.getScreenDetails() == null ? " IS NULL" : " = ?")
            + " AND `ScreenDetailsFlash`"
            + (fingerprint.getScreenDetailsFlash() == null ? " IS NULL" : " = ?")
            + " AND `LanguageFlash`"
            + (fingerprint.getLanguageFlash() == null ? " IS NULL" : " = ?")
            + " AND `Fonts`"
            + (fingerprint.getFonts() == null ? " IS NULL" : " = ?")
            + " AND `CookiesEnabled` = ?"
            + " AND `SuperCookie`"
            + (fingerprint.getSuperCookie() == null ? " IS NULL" : " = ?")
            + " AND `DoNotTrack`"
            + (fingerprint.getDoNotTrack() == null ? " IS NULL" : " = ?")
            + " AND `ClockDifference`"
            + (fingerprint.getClockDifference() == null ? " IS NULL" : " = ?")
            + " AND `DateTime`"
            + (fingerprint.getDateTime() == null ? " IS NULL" : " = ?")
            + " AND `MathTan`"
            + (fingerprint.getMathTan() == null ? " IS NULL" : " = ?")
            + " AND `UsingTor` = ?"
            + " AND `AdsBlocked`"
            + (fingerprint.getAdsBlocked() == null ? " IS NULL" : " = ?")
            + " AND `Canvas`"
            + (fingerprint.getCanvas() == null ? " IS NULL" : " = ?")
            + " AND `WebGLVendor`"
            + (fingerprint.getWebGLVendor() == null ? " IS NULL" : " = ?")
            + " AND `WebGLRenderer`"
            + (fingerprint.getWebGLRenderer() == null ? " IS NULL" : " = ?")
            + ";";
    PreparedStatement checkExists = conn.prepareStatement(query);

    int index = 1;
    checkExists.setInt(index, fingerprint.getSampleSetID());
    ++index;

    if (fingerprint.getUser_agent() != null) {
      checkExists.setString(index, fingerprint.getUser_agent());
      ++index;
    }
    if (fingerprint.getAccept_headers() != null) {
      checkExists.setString(index, fingerprint.getAccept_headers());
      ++index;
    }
    if (fingerprint.getPlatform() != null) {
      checkExists.setString(index, fingerprint.getPlatform());
      ++index;
    }
    if (fingerprint.getPlatformFlash() != null) {
      checkExists.setString(index, fingerprint.getPlatformFlash());
      ++index;
    }
    if (fingerprint.getPluginDetails() != null) {
      checkExists.setString(index, fingerprint.getPluginDetails());
      ++index;
    }
    if (fingerprint.getTimeZone() != null) {
      checkExists.setInt(index, fingerprint.getTimeZone());
      ++index;
    }
    if (fingerprint.getScreenDetails() != null) {
      checkExists.setString(index, fingerprint.getScreenDetails());
      ++index;
    }
    if (fingerprint.getScreenDetailsFlash() != null) {
      checkExists.setString(index, fingerprint.getScreenDetailsFlash());
      ++index;
    }
    if (fingerprint.getLanguageFlash() != null) {
      checkExists.setString(index, fingerprint.getLanguageFlash());
      ++index;
    }
    if (fingerprint.getFonts() != null) {
      checkExists.setString(index, fingerprint.getFonts());
      ++index;
    }
    checkExists.setBoolean(index, fingerprint.isCookiesEnabled());
    ++index;
    if (fingerprint.getSuperCookie() != null) {
      checkExists.setString(index, fingerprint.getSuperCookie());
      ++index;
    }
    if (fingerprint.getDoNotTrack() != null) {
      checkExists.setString(index, fingerprint.getDoNotTrack());
      ++index;
    }
    if (fingerprint.getClockDifference() != null) {
      checkExists.setLong(index, fingerprint.getClockDifference());
      ++index;
    }
    if (fingerprint.getDateTime() != null) {
      checkExists.setString(index, fingerprint.getDateTime());
      ++index;
    }
    if (fingerprint.getMathTan() != null) {
      checkExists.setString(index, fingerprint.getMathTan());
      ++index;
    }
    checkExists.setBoolean(index, fingerprint.isUsingTor());
    ++index;
    if (fingerprint.getAdsBlocked() != null) {
      checkExists.setBoolean(index, fingerprint.getAdsBlocked());
      ++index;
    }
    if (fingerprint.getCanvas() != null) {
      checkExists.setString(index, fingerprint.getCanvas());
      ++index;
    }
    if (fingerprint.getWebGLVendor() != null) {
      checkExists.setString(index, fingerprint.getWebGLVendor());
      ++index;
    }
    if (fingerprint.getWebGLRenderer() != null) {
      checkExists.setString(index, fingerprint.getWebGLRenderer());
      ++index;
    }

    ResultSet rs = checkExists.executeQuery();

    Integer sampleID = null;
    if (rs.next()) {
      /*
       * We've seen this sample before and the fingerprint hasn't changed,
       * don't log it.
       */
      sampleID = rs.getInt(1);
    }
    rs.close();
    checkExists.close();
    return sampleID;
  }