11# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
22# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33
4- """A check to determine whether the source repository of a maven package can be independently verified."""
4+ """A check to determine whether the source repository of a package can be independently verified."""
55
66import logging
77
8- from packageurl import PackageURL
98from sqlalchemy import ForeignKey , Integer , String
109from sqlalchemy .orm import Mapped , mapped_column
1110
1413from macaron .repo_verifier .repo_verifier_base import RepositoryVerificationStatus
1514from macaron .slsa_analyzer .analyze_context import AnalyzeContext
1615from macaron .slsa_analyzer .checks .base_check import BaseCheck
17- from macaron .slsa_analyzer .checks .check_result import CheckResultData , CheckResultType , Confidence
16+ from macaron .slsa_analyzer .checks .check_result import CheckResultData , CheckResultType , Confidence , JustificationType
1817from macaron .slsa_analyzer .registry import registry
1918
2019logger : logging .Logger = logging .getLogger (__name__ )
2120
2221
23- class MavenRepoVerificationFacts (CheckFacts ):
24- """The ORM mapping for justifications in maven source repo check."""
22+ class ScmAuthenticityFacts (CheckFacts ):
23+ """The ORM mapping for justifications in scm authenticity check."""
2524
26- __tablename__ = "_maven_repo_verification_check "
25+ __tablename__ = "_scm_authenticity_check "
2726
2827 #: The primary key.
2928 id : Mapped [int ] = mapped_column (ForeignKey ("_check_facts.id" ), primary_key = True ) # noqa: A003
3029
31- group : Mapped [str ] = mapped_column (String , nullable = False )
32- artifact : Mapped [str ] = mapped_column (String , nullable = False )
33- version : Mapped [str ] = mapped_column (String , nullable = False )
30+ #: Repository link identified by Macaron's repo finder.
31+ repo_link : Mapped [str ] = mapped_column (String , nullable = True , info = {"justification" : JustificationType .HREF })
3432
35- # Repository link identified by Macaron's repo finder.
36- repo_link : Mapped [str ] = mapped_column (String , nullable = True )
33+ #: Number of stars on the repository.
34+ stars_count : Mapped [int | None ] = mapped_column (
35+ Integer , nullable = True , info = {"justification" : JustificationType .TEXT }
36+ )
3737
38- # Repository link identified by deps.dev.
39- deps_dev_repo_link : Mapped [str | None ] = mapped_column (String , nullable = True )
38+ #: Number of forks on the repository.
39+ fork_count : Mapped [int | None ] = mapped_column (
40+ Integer , nullable = True , info = {"justification" : JustificationType .TEXT }
41+ )
4042
41- # Number of stars on the repository identified by deps.dev .
42- deps_dev_stars_count : Mapped [int | None ] = mapped_column (Integer , nullable = True )
43+ #: The status of repo verification: passed, failed, or unknown .
44+ status : Mapped [str ] = mapped_column (String , nullable = False , info = { "justification" : JustificationType . TEXT } )
4345
44- # Number of forks on the repository identified by deps.dev .
45- deps_dev_fork_count : Mapped [int | None ] = mapped_column (Integer , nullable = True )
46+ #: The reason for the status .
47+ reason : Mapped [str ] = mapped_column (String , nullable = False , info = { "justification" : JustificationType . TEXT } )
4648
47- # The status of the check: passed, failed, or unknown.
48- status : Mapped [str ] = mapped_column (String , nullable = False )
49-
50- # The reason for the status.
51- reason : Mapped [str ] = mapped_column (String , nullable = False )
52-
53- # The build tool used to build the package.
54- build_tool : Mapped [str ] = mapped_column (String , nullable = False )
49+ #: The build tool used to build the package.
50+ build_tool : Mapped [str ] = mapped_column (String , nullable = False , info = {"justification" : JustificationType .TEXT })
5551
5652 __mapper_args__ = {
57- "polymorphic_identity" : "_maven_repo_verification_check" ,
53+ "polymorphic_identity" : __tablename__ ,
5854 }
5955
6056
61- class MavenRepoVerificationCheck (BaseCheck ):
62- """Check whether the claims of a source repository provenance made by a maven package can be independently verified ."""
57+ class ScmAuthenticityCheck (BaseCheck ):
58+ """Check whether the claims of a source repository provenance made by a package can be corroborated ."""
6359
6460 def __init__ (self ) -> None :
6561 """Initialize a check instance."""
66- check_id = "mcn_maven_repo_verification_1 "
62+ check_id = "mcn_scm_authenticity_1 "
6763 description = (
6864 "Check whether the claims of a source repository provenance"
69- " made by a maven package can be independently verified."
65+ " made by a package can be corroborated."
66+ " At this moment, this check only supports Maven packages"
67+ " and returns UNKNOWN for others."
7068 )
7169
7270 super ().__init__ (
@@ -87,15 +85,18 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
8785 CheckResultData
8886 The result of the check.
8987 """
88+ # Only support Maven at the moment.
89+ # TODO: Add support for other systems.
9090 if ctx .component .type != "maven" :
9191 return CheckResultData (result_tables = [], result_type = CheckResultType .UNKNOWN )
9292
93- deps_dev_repo_finder = DepsDevRepoFinder ()
94- deps_dev_repo_link = deps_dev_repo_finder .find_repo (PackageURL .from_string (ctx .component .purl ))
95- deps_dev_repo_info = deps_dev_repo_finder .get_project_info (deps_dev_repo_link )
96-
9793 stars_count : int | None = None
9894 fork_count : int | None = None
95+ deps_dev_repo_info : dict | None = None
96+
97+ repo_link = ctx .component .repository .remote_path if ctx .component .repository else None
98+ if repo_link :
99+ deps_dev_repo_info = DepsDevRepoFinder .get_project_info (repo_link )
99100
100101 if deps_dev_repo_info :
101102 stars_count = deps_dev_repo_info .get ("starsCount" )
@@ -105,18 +106,14 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
105106 result_tables : list [CheckFacts ] = []
106107 for verification_result in ctx .dynamic_data .get ("repo_verification" , []):
107108 result_tables .append (
108- MavenRepoVerificationFacts (
109- group = ctx .component .namespace ,
110- artifact = ctx .component .name ,
111- version = ctx .component .version ,
112- repo_link = ctx .component .repository .remote_path if ctx .component .repository else None ,
109+ ScmAuthenticityFacts (
110+ repo_link = repo_link ,
113111 reason = verification_result .reason ,
114112 status = verification_result .status .value ,
115113 build_tool = verification_result .build_tool .name ,
116114 confidence = Confidence .MEDIUM ,
117- deps_dev_repo_link = deps_dev_repo_link ,
118- deps_dev_stars_count = stars_count ,
119- deps_dev_fork_count = fork_count ,
115+ stars_count = stars_count ,
116+ fork_count = fork_count ,
120117 )
121118 )
122119
@@ -129,4 +126,4 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
129126 return CheckResultData (result_tables = result_tables , result_type = result_type )
130127
131128
132- registry .register (MavenRepoVerificationCheck ())
129+ registry .register (ScmAuthenticityCheck ())
0 commit comments