@anonympins/fingerprint 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -436,6 +436,41 @@ class RequestUtils
436
436
  if (($metrics['keystrokeLatency'] ?? 0) > 0 && $metrics['keystrokeLatency'] < 40) $score += 25;
437
437
  if (($metrics['keystrokeLatency'] ?? 0) > 1000) $score += 15;
438
438
 
439
+ // NOUVEAU: Analyse de digraphie/trigraphie (dwell & flight times)
440
+ $dwellTimes = $metrics['keystrokeDwellTimes'] ?? [];
441
+ $flightTimes = $metrics['keystrokeFlightTimes'] ?? [];
442
+
443
+ if (count($dwellTimes) >= 5) {
444
+ $meanDwell = array_sum($dwellTimes) / count($dwellTimes);
445
+ $varDwell = array_reduce($dwellTimes, fn($carry, $item) => $carry + pow($item - $meanDwell, 2), 0) / count($dwellTimes);
446
+ $stdDevDwell = sqrt($varDwell);
447
+
448
+ if ($stdDevDwell < 2.0) {
449
+ $score += 35.0;
450
+ }
451
+ if ($meanDwell < 15.0) {
452
+ $score += 25.0;
453
+ }
454
+ }
455
+
456
+ if (count($flightTimes) >= 5) {
457
+ $times = array_column($flightTimes, 'time');
458
+ $meanFlight = array_sum($times) / count($times);
459
+ $varFlight = array_reduce($times, fn($carry, $item) => $carry + pow($item - $meanFlight, 2), 0) / count($times);
460
+ $stdDevFlight = sqrt($varFlight);
461
+
462
+ if ($stdDevFlight < 3.0) {
463
+ $score += 35.0;
464
+ }
465
+ if ($meanFlight < 25.0) {
466
+ $score += 25.0;
467
+ }
468
+ $benfordDev = Optimization::benfordTest($times);
469
+ if ($benfordDev > 0.18) {
470
+ $score += 30.0;
471
+ }
472
+ }
473
+
439
474
  // Analyse de Benford sur les segments de mouvement de la souris
440
475
  if (count($mouseAnalysis['segments']) > 10) {
441
476
  $benfordDeviation = Optimization::benfordTest($mouseAnalysis['segments']);
@@ -471,6 +506,42 @@ class RequestUtils
471
506
  return ['behaviorScore' => min(100.0, $score)];
472
507
  }
473
508
 
509
+ /**
510
+ * Calcule un score basé sur la régularité d'affichage (V-Sync) et l'utilisation suspecte d'OffscreenCanvas.
511
+ * @return array{'renderingAnomalyScore': float}
512
+ */
513
+ public static function getRenderingAnomalyScore(RequestContext $context): array
514
+ {
515
+ $behaviorHeader = $context->getHeader('x-behavior-metrics');
516
+ if (!$behaviorHeader) {
517
+ return ['renderingAnomalyScore' => 0.0];
518
+ }
519
+
520
+ $metrics = json_decode($behaviorHeader, true);
521
+ if (json_last_error() !== JSON_ERROR_NONE || !isset($metrics['rendering'])) {
522
+ return ['renderingAnomalyScore' => 0.0];
523
+ }
524
+
525
+ $rendering = $metrics['rendering'];
526
+ $score = 0.0;
527
+
528
+ if (!empty($rendering['offscreenAnom'])) {
529
+ $score += 100.0;
530
+ }
531
+
532
+ $fps = (float)($rendering['fps'] ?? 0.0);
533
+ $jitter = (float)($rendering['jitter'] ?? 0.0);
534
+
535
+ if ($fps > 250.0 || ($fps > 0.0 && $fps < 15.0)) {
536
+ $score += 50.0;
537
+ }
538
+ if ($jitter > 6.0) {
539
+ $score += min(80.0, ($jitter - 6.0) * 10.0);
540
+ }
541
+
542
+ return ['renderingAnomalyScore' => min(100.0, $score)];
543
+ }
544
+
474
545
  /**
475
546
  * Analyse basique d'un User-Agent.
476
547
  * @return array{browser?: string, os?: string, device?: string}
@@ -1587,6 +1658,55 @@ class RequestUtils
1587
1658
  return ['tcpAnomalyScore' => $tcpAnomalyScore];
1588
1659
  }
1589
1660
 
1661
+ /**
1662
+ * Détecte les anomalies de flux QUIC/HTTP3 par rapport au User-Agent.
1663
+ * @param RequestContext $context
1664
+ * @return array{'quicAnomalyScore': float}
1665
+ */
1666
+ public static function getQuicAnomalyScore(RequestContext $context): array
1667
+ {
1668
+ $quicFp = $context->getHeader('x-quic-fp') ?? $context->quicFingerprint ?? null;
1669
+ if (empty($quicFp) || !is_string($quicFp)) {
1670
+ return ['quicAnomalyScore' => 0.0];
1671
+ }
1672
+
1673
+ $parts = explode(';', $quicFp);
1674
+ if (count($parts) < 2) {
1675
+ return ['quicAnomalyScore' => 0.0];
1676
+ }
1677
+
1678
+ $params = [];
1679
+ foreach (explode(',', $parts[1]) as $p) {
1680
+ $kv = explode('=', $p, 2);
1681
+ if (count($kv) === 2) {
1682
+ $params[$kv[0]] = $kv[1];
1683
+ }
1684
+ }
1685
+ $priorityOrder = $parts[2] ?? '';
1686
+
1687
+ $ua = $context->getHeader('user-agent') ?? '';
1688
+ $uaParts = self::parseUserAgent($ua);
1689
+ $browser = $uaParts['browser'] ?? null;
1690
+
1691
+ if (empty($browser)) {
1692
+ return ['quicAnomalyScore' => 0.0];
1693
+ }
1694
+
1695
+ $anomaly = 0.0;
1696
+ if (str_starts_with($browser, 'Chrome') || str_starts_with($browser, 'Edge')) {
1697
+ $maxData = isset($params['1']) ? (int)$params['1'] : 0;
1698
+ $maxStreams = isset($params['4']) ? (int)$params['4'] : 0;
1699
+ if ($maxData > 0 && $maxData < 1048576) $anomaly += 40.0;
1700
+ if ($maxStreams > 0 && $maxStreams !== 100) $anomaly += 30.0;
1701
+ if (!empty($priorityOrder) && !str_contains($priorityOrder, 'u=')) $anomaly += 30.0;
1702
+ } elseif (str_starts_with($browser, 'Firefox')) {
1703
+ $maxData = isset($params['1']) ? (int)$params['1'] : 0;
1704
+ if ($maxData > 0 && $maxData > 5000000) $anomaly += 40.0;
1705
+ }
1706
+
1707
+ return ['quicAnomalyScore' => max(0.0, min(100.0, $anomaly))];
1708
+ }
1709
+
1590
1710
  /**
1591
1711
  * Vérifie si un ticket de clearance (PoW) est valide, en supportant la tolérance au roaming.
1592
1712
  *