@@ -377,20 +377,49 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
377377 help = 'Retrieve cryptographic algorithms for the given components' ,
378378 )
379379 p_crypto_algorithms .add_argument (
380- '--range' ,
381- '-r' ,
382- type = str ,
380+ '--with-range' ,
381+ action = 'store_true' ,
383382 help = 'Returns the list of versions in the specified range that contains cryptographic algorithms' ,
384383 )
385384 p_crypto_algorithms .set_defaults (func = crypto_algorithms )
386385
386+ # GetEncryptionHints and GetHintsInRange gRPC APIs
387+ p_crypto_hints = crypto_sub .add_parser (
388+ 'hints' ,
389+ description = f'Show Encryption hints: { __version__ } ' ,
390+ help = 'Retrieve encryption hints for the given components' ,
391+ )
392+ p_crypto_hints .add_argument (
393+ '--with-range' ,
394+ action = 'store_true' ,
395+ help = 'Returns the list of versions in the specified range that contains encryption hints' ,
396+ )
397+ p_crypto_hints .set_defaults (func = crypto_hints )
398+
399+ p_crypto_versions_in_range = crypto_sub .add_parser (
400+ 'versions-in-range' ,
401+ aliases = ['vr' ],
402+ description = f'Show versions in range: { __version__ } ' ,
403+ help = "Given a list of PURLS and version ranges, get a list of versions that do/don't contain crypto algorithms" ,
404+ )
405+ p_crypto_versions_in_range .set_defaults (func = crypto_versions_in_range )
406+
387407 # Common purl Component sub-command options
388- for p in [c_vulns , c_semgrep , c_provenance , p_crypto_algorithms ]:
408+ for p in [c_vulns , c_semgrep , c_provenance , p_crypto_algorithms , p_crypto_hints , p_crypto_versions_in_range ]:
389409 p .add_argument ('--purl' , '-p' , type = str , nargs = '*' , help = 'Package URL - PURL to process.' )
390410 p .add_argument ('--input' , '-i' , type = str , help = 'Input file name' )
391411
392412 # Common Component sub-command options
393- for p in [c_vulns , c_search , c_versions , c_semgrep , c_provenance , p_crypto_algorithms ]:
413+ for p in [
414+ c_vulns ,
415+ c_search ,
416+ c_versions ,
417+ c_semgrep ,
418+ c_provenance ,
419+ p_crypto_algorithms ,
420+ p_crypto_hints ,
421+ p_crypto_versions_in_range ,
422+ ]:
394423 p .add_argument (
395424 '--timeout' ,
396425 '-M' ,
@@ -620,6 +649,8 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
620649 p_folder_scan ,
621650 p_folder_hash ,
622651 p_crypto_algorithms ,
652+ p_crypto_hints ,
653+ p_crypto_versions_in_range ,
623654 ]:
624655 p .add_argument ('--output' , '-o' , type = str , help = 'Output result file name (optional - default stdout).' )
625656
@@ -705,6 +736,8 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
705736 p_folder_scan ,
706737 p_cs ,
707738 p_crypto_algorithms ,
739+ p_crypto_hints ,
740+ p_crypto_versions_in_range ,
708741 ]:
709742 p .add_argument (
710743 '--key' , '-k' , type = str , help = 'SCANOSS API Key token (optional - not required for default OSSKB URL)'
@@ -731,7 +764,19 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
731764 )
732765
733766 # Global GRPC options
734- for p in [p_scan , c_vulns , c_search , c_versions , c_semgrep , c_provenance , p_folder_scan , p_cs , p_crypto_algorithms ]:
767+ for p in [
768+ p_scan ,
769+ c_vulns ,
770+ c_search ,
771+ c_versions ,
772+ c_semgrep ,
773+ c_provenance ,
774+ p_folder_scan ,
775+ p_cs ,
776+ p_crypto_algorithms ,
777+ p_crypto_hints ,
778+ p_crypto_versions_in_range ,
779+ ]:
735780 p .add_argument (
736781 '--api2url' , type = str , help = 'SCANOSS gRPC API 2.0 URL (optional - default: https://api.osskb.org)'
737782 )
@@ -786,6 +831,8 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
786831 p_folder_hash ,
787832 p_cs ,
788833 p_crypto_algorithms ,
834+ p_crypto_hints ,
835+ p_crypto_versions_in_range ,
789836 ]:
790837 p .add_argument ('--debug' , '-d' , action = 'store_true' , help = 'Enable debug messages' )
791838 p .add_argument ('--trace' , '-t' , action = 'store_true' , help = 'Enable trace messages, including API posts' )
@@ -1457,6 +1504,88 @@ def crypto_algorithms(parser, args):
14571504 sys .exit (1 )
14581505
14591506
1507+ def crypto_hints (parser , args ):
1508+ """
1509+ Run the "crypto hints" sub-command
1510+ Parameters
1511+ ----------
1512+ parser: ArgumentParser
1513+ command line parser object
1514+ args: Namespace
1515+ Parsed arguments
1516+ """
1517+ if (not args .purl and not args .input ) or (args .purl and args .input ):
1518+ print_stderr ('Please specify an input file or purl to decorate (--purl or --input)' )
1519+ parser .parse_args ([args .subparser , args .subparsercmd , '-h' ])
1520+ sys .exit (1 )
1521+ if args .ca_cert and not os .path .exists (args .ca_cert ):
1522+ print_stderr (f'Error: Certificate file does not exist: { args .ca_cert } .' )
1523+ sys .exit (1 )
1524+
1525+ try :
1526+ config = create_cryptography_config_from_args (args )
1527+ grpc_config = create_grpc_config_from_args (args )
1528+ client = ScanossGrpc (** asdict (grpc_config ))
1529+
1530+ # TODO: Add PAC file support
1531+ # pac_file = get_pac_file(config.pac)
1532+
1533+ cryptography = Cryptography (config = config , client = client )
1534+ cryptography .get_encryption_hints ()
1535+ cryptography .present (output_file = args .output )
1536+ except ScanossGrpcError as e :
1537+ print_stderr (f'API ERROR: { e } ' )
1538+ sys .exit (1 )
1539+ except Exception as e :
1540+ if args .debug :
1541+ import traceback
1542+
1543+ traceback .print_exc ()
1544+ print_stderr (f'ERROR: { e } ' )
1545+ sys .exit (1 )
1546+
1547+
1548+ def crypto_versions_in_range (parser , args ):
1549+ """
1550+ Run the "crypto versions-in-range" sub-command
1551+ Parameters
1552+ ----------
1553+ parser: ArgumentParser
1554+ command line parser object
1555+ args: Namespace
1556+ Parsed arguments
1557+ """
1558+ if (not args .purl and not args .input ) or (args .purl and args .input ):
1559+ print_stderr ('Please specify an input file or purl to decorate (--purl or --input)' )
1560+ parser .parse_args ([args .subparser , args .subparsercmd , '-h' ])
1561+ sys .exit (1 )
1562+ if args .ca_cert and not os .path .exists (args .ca_cert ):
1563+ print_stderr (f'Error: Certificate file does not exist: { args .ca_cert } .' )
1564+ sys .exit (1 )
1565+
1566+ try :
1567+ config = create_cryptography_config_from_args (args )
1568+ grpc_config = create_grpc_config_from_args (args )
1569+ client = ScanossGrpc (** asdict (grpc_config ))
1570+
1571+ # TODO: Add PAC file support
1572+ # pac_file = get_pac_file(config.pac)
1573+
1574+ cryptography = Cryptography (config = config , client = client )
1575+ cryptography .get_versions_in_range ()
1576+ cryptography .present (output_file = args .output )
1577+ except ScanossGrpcError as e :
1578+ print_stderr (f'API ERROR: { e } ' )
1579+ sys .exit (1 )
1580+ except Exception as e :
1581+ if args .debug :
1582+ import traceback
1583+
1584+ traceback .print_exc ()
1585+ print_stderr (f'ERROR: { e } ' )
1586+ sys .exit (1 )
1587+
1588+
14601589def comp_vulns (parser , args ):
14611590 """
14621591 Run the "component vulns" sub-command
0 commit comments