Fidestra commited on
Commit
cde1dc3
·
verified ·
1 Parent(s): fe8e910

Update app and verified guided capture together

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -1438,7 +1438,8 @@ def _same_country_zone(a, b):
1438
  return bool(a and b) and a.split('/')[0] == 'Australia' and b.split('/')[0] == 'Australia'
1439
 
1440
 
1441
- def earned_trust_points(signals, api, liveness=None, registry=None, liveness_route=False, reasons=None):
 
1442
  """Points per block: a block earns its points only if its own measurement ran and nothing in it
1443
  raised a flag. A check moved to shadow mode (logged, not scored) still withholds the points.
1444
  If `reasons` is a dict, it is filled with a short plain reason for every block that earns nothing."""
@@ -1490,6 +1491,10 @@ def earned_trust_points(signals, api, liveness=None, registry=None, liveness_rou
1490
  # Owner (7 Nov): N6 compares UTC offsets, so Australian states (Perth, Sydney) look like a mismatch.
1491
  # Two zones in the same country are not a mismatch. The row is still logged.
1492
  n6 = rows.get('N6', {})
 
 
 
 
1493
  if (n6.get('code') == 'GEO-02' or 'N6' in shadowed) and '\n' not in str(n6.get('result', '')):
1494
  parts = str(n6.get('result', '')).split(' [')[0].split(' vs ')
1495
  if len(parts) == 2 and _same_country_zone(parts[0].strip(), parts[1].strip()):
@@ -1571,6 +1576,17 @@ def tier3_scam(signals, api):
1571
  for s in list(signals) + list(api.get('shadow_signals') or []))
1572
 
1573
 
 
 
 
 
 
 
 
 
 
 
 
1574
  def install_earned_score(engine):
1575
  """Replace the deducted score with earned points; keep hard stops and missing-evidence step-ups."""
1576
  if not callable(getattr(engine, 'run_check', None)) or getattr(engine.run_check, '_earned_score', False):
@@ -1591,9 +1607,11 @@ def install_earned_score(engine):
1591
  api = result.get('api') if isinstance(result, dict) else None
1592
  if not isinstance(api, dict) or not isinstance(result.get('signals'), list):
1593
  return result
 
1594
  block_reasons = {}
1595
  points = earned_trust_points(result['signals'], api, _lv_device_liveness.get(), registry,
1596
- _lv_liveness_route.get(), reasons=block_reasons)
 
1597
  if not points['kinematics'] and 'kinematics' not in block_reasons:
1598
  block_reasons['kinematics'] = 'no head-movement instructions followed'
1599
  d_codes = {r.get('id'): r.get('code') for r in result['signals'] if isinstance(r, dict)}
 
1438
  return bool(a and b) and a.split('/')[0] == 'Australia' and b.split('/')[0] == 'Australia'
1439
 
1440
 
1441
+ def earned_trust_points(signals, api, liveness=None, registry=None, liveness_route=False, reasons=None,
1442
+ phone_ip=False):
1443
  """Points per block: a block earns its points only if its own measurement ran and nothing in it
1444
  raised a flag. A check moved to shadow mode (logged, not scored) still withholds the points.
1445
  If `reasons` is a dict, it is filled with a short plain reason for every block that earns nothing."""
 
1491
  # Owner (7 Nov): N6 compares UTC offsets, so Australian states (Perth, Sydney) look like a mismatch.
1492
  # Two zones in the same country are not a mismatch. The row is still logged.
1493
  n6 = rows.get('N6', {})
1494
+ # Owner (7 Nov): the phone's country is confirmed by the IP country. A phone-vs-ID mismatch (CON-02) is
1495
+ # excused only when the phone matches the IP; FATF or other phone flags still count.
1496
+ if phone_ip and rows.get('C2', {}).get('code') == 'CON-02':
1497
+ location = [k for k in location if k != 'C2']
1498
  if (n6.get('code') == 'GEO-02' or 'N6' in shadowed) and '\n' not in str(n6.get('result', '')):
1499
  parts = str(n6.get('result', '')).split(' [')[0].split(' vs ')
1500
  if len(parts) == 2 and _same_country_zone(parts[0].strip(), parts[1].strip()):
 
1576
  for s in list(signals) + list(api.get('shadow_signals') or []))
1577
 
1578
 
1579
+ def phone_matches_ip(signals, api):
1580
+ """True when the phone's country (C2) is the country the IP is located in (names from the core)."""
1581
+ c2 = next((r for r in signals if isinstance(r, dict) and r.get('id') == 'C2'), {})
1582
+ phone = re.match(r'Phone (\S+) vs', str(c2.get('result', '')))
1583
+ network = api.get('device_network') if isinstance(api.get('device_network'), dict) else {}
1584
+ ip_country = network.get('country')
1585
+ if not phone or not ip_country:
1586
+ return False
1587
+ return d.COUNTRY_NAMES.get(phone.group(1)) == ip_country
1588
+
1589
+
1590
  def install_earned_score(engine):
1591
  """Replace the deducted score with earned points; keep hard stops and missing-evidence step-ups."""
1592
  if not callable(getattr(engine, 'run_check', None)) or getattr(engine.run_check, '_earned_score', False):
 
1607
  api = result.get('api') if isinstance(result, dict) else None
1608
  if not isinstance(api, dict) or not isinstance(result.get('signals'), list):
1609
  return result
1610
+ phone_ip_match = phone_matches_ip(result['signals'], api)
1611
  block_reasons = {}
1612
  points = earned_trust_points(result['signals'], api, _lv_device_liveness.get(), registry,
1613
+ _lv_liveness_route.get(), reasons=block_reasons,
1614
+ phone_ip=phone_ip_match)
1615
  if not points['kinematics'] and 'kinematics' not in block_reasons:
1616
  block_reasons['kinematics'] = 'no head-movement instructions followed'
1617
  d_codes = {r.get('id'): r.get('code') for r in result['signals'] if isinstance(r, dict)}