synapse 2.169.0__py311-none-any.whl → 2.171.0__py311-none-any.whl

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.

Potentially problematic release.


This version of synapse might be problematic. Click here for more details.

Files changed (41) hide show
  1. synapse/cortex.py +99 -3
  2. synapse/datamodel.py +5 -0
  3. synapse/lib/ast.py +70 -12
  4. synapse/lib/cell.py +76 -7
  5. synapse/lib/layer.py +75 -6
  6. synapse/lib/lmdbslab.py +17 -0
  7. synapse/lib/node.py +7 -0
  8. synapse/lib/snap.py +22 -4
  9. synapse/lib/storm.py +1 -1
  10. synapse/lib/stormlib/cortex.py +1 -1
  11. synapse/lib/stormlib/model.py +339 -40
  12. synapse/lib/stormtypes.py +58 -1
  13. synapse/lib/types.py +36 -1
  14. synapse/lib/version.py +2 -2
  15. synapse/lib/view.py +94 -15
  16. synapse/models/files.py +40 -0
  17. synapse/models/inet.py +8 -4
  18. synapse/models/infotech.py +355 -17
  19. synapse/tests/files/cpedata.json +525034 -0
  20. synapse/tests/test_cortex.py +108 -0
  21. synapse/tests/test_lib_ast.py +66 -0
  22. synapse/tests/test_lib_cell.py +112 -0
  23. synapse/tests/test_lib_layer.py +52 -1
  24. synapse/tests/test_lib_lmdbslab.py +36 -0
  25. synapse/tests/test_lib_scrape.py +72 -71
  26. synapse/tests/test_lib_snap.py +16 -1
  27. synapse/tests/test_lib_storm.py +118 -0
  28. synapse/tests/test_lib_stormlib_cortex.py +15 -0
  29. synapse/tests/test_lib_stormlib_model.py +427 -0
  30. synapse/tests/test_lib_stormtypes.py +147 -15
  31. synapse/tests/test_lib_types.py +21 -0
  32. synapse/tests/test_lib_view.py +77 -0
  33. synapse/tests/test_model_files.py +52 -0
  34. synapse/tests/test_model_inet.py +63 -1
  35. synapse/tests/test_model_infotech.py +187 -26
  36. synapse/tests/utils.py +42 -9
  37. {synapse-2.169.0.dist-info → synapse-2.171.0.dist-info}/METADATA +1 -1
  38. {synapse-2.169.0.dist-info → synapse-2.171.0.dist-info}/RECORD +41 -40
  39. {synapse-2.169.0.dist-info → synapse-2.171.0.dist-info}/LICENSE +0 -0
  40. {synapse-2.169.0.dist-info → synapse-2.171.0.dist-info}/WHEEL +0 -0
  41. {synapse-2.169.0.dist-info → synapse-2.171.0.dist-info}/top_level.txt +0 -0
synapse/lib/view.py CHANGED
@@ -196,10 +196,6 @@ class View(s_nexus.Pusher): # type: ignore
196
196
  async def _setMergeRequest(self, mergeinfo):
197
197
  self.reqParentQuorum()
198
198
 
199
- if self.hasKids():
200
- mesg = 'Cannot add a merge request to a view with children.'
201
- raise s_exc.BadState(mesg=mesg)
202
-
203
199
  s_schemas.reqValidMerge(mergeinfo)
204
200
  lkey = self.bidn + b'merge:req'
205
201
  self.core.slab.put(lkey, s_msgpack.en(mergeinfo), db='view:meta')
@@ -450,8 +446,7 @@ class View(s_nexus.Pusher): # type: ignore
450
446
  await self.core.feedBeholder('view:merge:fini', {'view': self.iden, 'merge': merge, 'merge': merge, 'votes': votes})
451
447
 
452
448
  # remove the view and top layer
453
- await self.core.delView(self.iden)
454
- await self.core.delLayer(self.layers[0].iden)
449
+ await self.core.delViewWithLayer(self.iden)
455
450
 
456
451
  except Exception as e: # pragma: no cover
457
452
  logger.exception(f'Error while merging view: {self.iden}')
@@ -713,7 +708,10 @@ class View(s_nexus.Pusher): # type: ignore
713
708
  layers.extend(view.layers)
714
709
 
715
710
  self.layers = layers
716
- await self.info.set('layers', [layr.iden for layr in layers])
711
+ layridens = [layr.iden for layr in layers]
712
+ await self.info.set('layers', layridens)
713
+
714
+ await self.core.feedBeholder('view:setlayers', {'iden': self.iden, 'layers': layridens}, gates=[self.iden, layridens[0]])
717
715
 
718
716
  async def pack(self):
719
717
  d = {'iden': self.iden}
@@ -1112,10 +1110,6 @@ class View(s_nexus.Pusher): # type: ignore
1112
1110
  mesg = 'Circular dependency of view parents is not supported.'
1113
1111
  raise s_exc.BadArg(mesg=mesg)
1114
1112
 
1115
- if parent.getMergeRequest() is not None:
1116
- mesg = 'You may not set the parent to a view with a pending merge request.'
1117
- raise s_exc.BadState(mesg=mesg)
1118
-
1119
1113
  if self.parent is not None:
1120
1114
  if self.parent.iden == parent.iden:
1121
1115
  return valu
@@ -1254,6 +1248,95 @@ class View(s_nexus.Pusher): # type: ignore
1254
1248
 
1255
1249
  todo.append(child)
1256
1250
 
1251
+ async def insertParentFork(self, useriden, name=None):
1252
+ '''
1253
+ Insert a new View between a forked View and its parent.
1254
+
1255
+ Returns:
1256
+ New view definition with the same perms as the current fork.
1257
+ '''
1258
+ if not self.isafork():
1259
+ mesg = f'View ({self.iden}) is not a fork, cannot insert a new fork between it and parent.'
1260
+ raise s_exc.BadState(mesg=mesg)
1261
+
1262
+ ctime = s_common.now()
1263
+ layriden = s_common.guid()
1264
+
1265
+ ldef = {
1266
+ 'iden': layriden,
1267
+ 'created': ctime,
1268
+ 'creator': useriden,
1269
+ 'lockmemory': self.core.conf.get('layers:lockmemory'),
1270
+ 'logedits': self.core.conf.get('layers:logedits'),
1271
+ 'readonly': False
1272
+ }
1273
+
1274
+ vdef = {
1275
+ 'iden': s_common.guid(),
1276
+ 'created': ctime,
1277
+ 'creator': useriden,
1278
+ 'parent': self.parent.iden,
1279
+ 'layers': [layriden] + [lyr.iden for lyr in self.parent.layers]
1280
+ }
1281
+
1282
+ if name is not None:
1283
+ vdef['name'] = name
1284
+
1285
+ s_layer.reqValidLdef(ldef)
1286
+ s_schemas.reqValidView(vdef)
1287
+
1288
+ return await self._push('view:forkparent', ldef, vdef)
1289
+
1290
+ @s_nexus.Pusher.onPush('view:forkparent', passitem=True)
1291
+ async def _insertParentFork(self, ldef, vdef, nexsitem):
1292
+
1293
+ s_layer.reqValidLdef(ldef)
1294
+ s_schemas.reqValidView(vdef)
1295
+
1296
+ if self.getMergeRequest() is not None:
1297
+ await self._delMergeRequest()
1298
+
1299
+ await self.core._addLayer(ldef, nexsitem)
1300
+ await self.core._addView(vdef)
1301
+
1302
+ forkiden = vdef.get('iden')
1303
+ self.parent = self.core.reqView(forkiden)
1304
+ await self.info.set('parent', forkiden)
1305
+
1306
+ mesg = {'iden': self.iden, 'name': 'parent', 'valu': forkiden}
1307
+ await self.core.feedBeholder('view:set', mesg, gates=[self.iden, self.layers[0].iden])
1308
+
1309
+ await self._calcForkLayers()
1310
+
1311
+ for view in self.core.views.values():
1312
+ if view.isForkOf(self.iden):
1313
+ await view._calcForkLayers()
1314
+
1315
+ self.core._calcViewsByLayer()
1316
+
1317
+ authgate = await self.core.getAuthGate(self.iden)
1318
+ if authgate is None: # pragma: no cover
1319
+ return await self.parent.pack()
1320
+
1321
+ for userinfo in authgate.get('users'):
1322
+ useriden = userinfo.get('iden')
1323
+ if (user := self.core.auth.user(useriden)) is None: # pragma: no cover
1324
+ logger.warning(f'View {self.iden} AuthGate refers to unknown user {useriden}')
1325
+ continue
1326
+
1327
+ await user.setRules(userinfo.get('rules'), gateiden=forkiden, nexs=False)
1328
+ await user.setAdmin(userinfo.get('admin'), gateiden=forkiden, logged=False)
1329
+
1330
+ for roleinfo in authgate.get('roles'):
1331
+ roleiden = roleinfo.get('iden')
1332
+ if (role := self.core.auth.role(roleiden)) is None: # pragma: no cover
1333
+ logger.warning(f'View {self.iden} AuthGate refers to unknown role {roleiden}')
1334
+ continue
1335
+
1336
+ await role.setRules(roleinfo.get('rules'), gateiden=forkiden, nexs=False)
1337
+
1338
+ return await self.parent.pack()
1339
+
1257
1340
  async def fork(self, ldef=None, vdef=None):
1258
1341
  '''
1259
1342
  Make a new view inheriting from this view with the same layers and a new write layer on top
@@ -1272,10 +1355,6 @@ class View(s_nexus.Pusher): # type: ignore
1272
1355
  if vdef is None:
1273
1356
  vdef = {}
1274
1357
 
1275
- if self.getMergeRequest() is not None:
1276
- mesg = 'Cannot fork a view which has a merge request.'
1277
- raise s_exc.BadState(mesg=mesg)
1278
-
1279
1358
  ldef = await self.core.addLayer(ldef)
1280
1359
  layriden = ldef.get('iden')
1281
1360
 
synapse/models/files.py CHANGED
@@ -408,6 +408,9 @@ class FileModule(s_module.CoreModule):
408
408
  'doc': 'A section inside a Mach-O binary denoting a named region of bytes inside a segment.',
409
409
  }),
410
410
 
411
+ ('file:mime:lnk', ('guid', {}), {
412
+ 'doc': 'The GUID of the metadata pulled from a Windows shortcut or LNK file.',
413
+ }),
411
414
  ),
412
415
 
413
416
  'forms': (
@@ -699,6 +702,43 @@ class FileModule(s_module.CoreModule):
699
702
  'doc': 'The file offset to the beginning of the section'}),
700
703
  )),
701
704
 
705
+ ('file:mime:lnk', {}, (
706
+ ('flags', ('int', {}), {
707
+ 'doc': 'The flags specified by the LNK header that control the structure of the LNK file.'}),
708
+ ('entry:primary', ('file:path', {}), {
709
+ 'doc': 'The primary file path contained within the FileEntry structure of the LNK file.'}),
710
+ ('entry:secondary', ('file:path', {}), {
711
+ 'doc': 'The secondary file path contained within the FileEntry structure of the LNK file.'}),
712
+ ('entry:extended', ('file:path', {}), {
713
+ 'doc': 'The extended file path contained within the extended FileEntry structure of the LNK file.'}),
714
+ ('entry:localized', ('file:path', {}), {
715
+ 'doc': 'The localized file path contained within the extended FileEntry structure of the LNK file.'}),
716
+ ('entry:icon', ('file:path', {}), {
717
+ 'doc': 'The icon file path contained within the StringData structure of the LNK file.'}),
718
+ ('environment:path', ('file:path', {}), {
719
+ 'doc': 'The target file path contained within the EnvironmentVariableDataBlock structure of the LNK file.'}),
720
+ ('environment:icon', ('file:path', {}), {
721
+ 'doc': 'The icon file path contained within the IconEnvironmentDataBlock structure of the LNK file.'}),
722
+ ('working', ('file:path', {}), {
723
+ 'doc': 'The working directory used when activating the link target.'}),
724
+ ('relative', ('str', {'strip': True}), {
725
+ 'doc': 'The relative target path string contained within the StringData structure of the LNK file.'}),
726
+ ('arguments', ('it:cmd', {}), {
727
+ 'doc': 'The command line arguments passed to the target file when the LNK file is activated.'}),
728
+ ('desc', ('str', {}), {
729
+ 'disp': {'hint': 'text'},
730
+ 'doc': 'The description of the LNK file contained within the StringData section of the LNK file.'}),
731
+ ('target:attrs', ('int', {}), {
732
+ 'doc': 'The attributes of the target file according to the LNK header.'}),
733
+ ('target:size', ('int', {}), {
734
+ 'doc': 'The size of the target file according to the LNK header. The LNK format specifies that this is only the lower 32 bits of the target file size.'}),
735
+ ('target:created', ('time', {}), {
736
+ 'doc': 'The creation time of the target file according to the LNK header.'}),
737
+ ('target:accessed', ('time', {}), {
738
+ 'doc': 'The access time of the target file according to the LNK header.'}),
739
+ ('target:written', ('time', {}), {
740
+ 'doc': 'The write time of the target file according to the LNK header.'}),
741
+ )),
702
742
  ),
703
743
 
704
744
  }
synapse/models/inet.py CHANGED
@@ -23,7 +23,7 @@ import synapse.lookup.iana as s_l_iana
23
23
  logger = logging.getLogger(__name__)
24
24
  drivre = regex.compile(r'^\w[:|]')
25
25
  fqdnre = regex.compile(r'^[\w._-]+$', regex.U)
26
- srv6re = regex.compile(r'^\[([a-f0-9\.:]+)\]:(\d+)$')
26
+ srv6re = regex.compile(r'^\[([a-f0-9\.:]+)\](?::(\d+))?$', regex.IGNORECASE)
27
27
 
28
28
  udots = regex.compile(r'[\u3002\uff0e\uff61]')
29
29
 
@@ -142,11 +142,15 @@ class Addr(s_types.Str):
142
142
  if v6v4addr is not None:
143
143
  subs['ipv4'] = v6v4addr
144
144
 
145
- port = self.modl.type('inet:port').norm(port)[0]
146
145
  subs['ipv6'] = ipv6
147
- subs['port'] = port
148
146
 
149
- return f'{proto}://[{ipv6}]:{port}', {'subs': subs}
147
+ portstr = ''
148
+ if port is not None:
149
+ port = self.modl.type('inet:port').norm(port)[0]
150
+ subs['port'] = port
151
+ portstr = f':{port}'
152
+
153
+ return f'{proto}://[{ipv6}]{portstr}', {'subs': subs}
150
154
 
151
155
  mesg = f'Invalid IPv6 w/port ({orig})'
152
156
  raise s_exc.BadTypeValu(valu=orig, name=self.name, mesg=mesg)