github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/vulnsrc/redhat-oval/types.go (about)

     1  package redhatoval
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/khulnasoft-lab/tunnel-db/pkg/types"
     7  )
     8  
     9  type redhatOVAL struct {
    10  	Class    string
    11  	ID       string
    12  	Version  string
    13  	Metadata ovalMetadata
    14  	Criteria criteria
    15  }
    16  
    17  type ovalMetadata struct {
    18  	Title        string
    19  	AffectedList []affected
    20  	References   []reference
    21  	Description  string
    22  	Advisory     ovalAdvisory
    23  }
    24  
    25  type ovalAdvisory struct {
    26  	From            string
    27  	Severity        string
    28  	Rights          string
    29  	Issued          issued
    30  	Updated         updated
    31  	Cves            []ovalCVE
    32  	Bugzilla        []bugzilla
    33  	AffectedCpeList []string
    34  	Affected        affectedState
    35  }
    36  
    37  type criteria struct {
    38  	Operator   string
    39  	Criterias  []criteria
    40  	Criterions []criterion
    41  }
    42  
    43  type criterion struct {
    44  	TestRef string
    45  	Comment string
    46  }
    47  
    48  type affected struct {
    49  	Family    string
    50  	Platforms []string
    51  }
    52  
    53  type affectedState struct {
    54  	Resolution affectedResolution
    55  }
    56  
    57  type affectedResolution struct {
    58  	State string
    59  }
    60  
    61  type reference struct {
    62  	Source string
    63  	RefID  string
    64  	RefURL string
    65  }
    66  
    67  type issued struct {
    68  	Date string
    69  }
    70  
    71  type updated struct {
    72  	Date string
    73  }
    74  
    75  type ovalCVE struct {
    76  	CveID  string
    77  	Cvss2  string
    78  	Cvss3  string
    79  	Cwe    string
    80  	Impact string
    81  	Href   string
    82  	Public string
    83  }
    84  
    85  type bugzilla struct {
    86  	ID   string
    87  	Href string
    88  }
    89  
    90  type ovalTests struct {
    91  	RpminfoTests []rpminfoTest
    92  }
    93  
    94  type ovalObjects struct {
    95  	RpminfoObjects []rpminfoObject
    96  }
    97  
    98  type ovalStates struct {
    99  	RpminfoState []rpminfoState
   100  }
   101  
   102  type ovalstate struct {
   103  	Text     string
   104  	StateRef string
   105  }
   106  
   107  type ovalObject struct {
   108  	Text      string
   109  	ObjectRef string
   110  }
   111  
   112  type rpminfoTest struct {
   113  	Check          string
   114  	Comment        string
   115  	ID             string
   116  	Version        string
   117  	CheckExistence string
   118  	Object         ovalObject
   119  	State          ovalstate
   120  }
   121  
   122  type rpminfoObject struct {
   123  	ID      string
   124  	Version string
   125  	Name    string
   126  }
   127  
   128  type rpminfoState struct {
   129  	ID             string
   130  	Version        string
   131  	Arch           arch
   132  	Evr            evr
   133  	SignatureKeyID signatureKeyID
   134  }
   135  
   136  type signatureKeyID struct {
   137  	Text      string
   138  	Operation string
   139  }
   140  
   141  type arch struct {
   142  	Text      string
   143  	Datatype  string
   144  	Operation string
   145  }
   146  
   147  type evr struct {
   148  	Text      string
   149  	Datatype  string
   150  	Operation string
   151  }
   152  
   153  type pkg struct {
   154  	Name         string
   155  	FixedVersion string
   156  	Arches       []string
   157  }
   158  
   159  type bucket struct {
   160  	pkgName string
   161  	vulnID  string
   162  }
   163  
   164  type Advisory struct {
   165  	Entries []Entry `json:",omitempty"`
   166  }
   167  
   168  type Definition struct {
   169  	Entry Entry `json:",omitempty"`
   170  }
   171  
   172  // Entry holds the unique advisory information per platform.
   173  type Entry struct {
   174  	FixedVersion string `json:",omitempty"`
   175  	Cves         []CveEntry
   176  	Arches       []string     `json:",omitempty"`
   177  	Status       types.Status `json:"-"`
   178  
   179  	// For DB size optimization, CPE names will not be stored.
   180  	// CPE indices are stored instead.
   181  	AffectedCPEList    []string `json:"-"`
   182  	AffectedCPEIndices []int    `json:"Affected,omitempty"`
   183  }
   184  
   185  // _Entry is an internal struct for Entry to avoid infinite MarshalJSON loop.
   186  type _Entry Entry
   187  
   188  type dbEntry struct {
   189  	_Entry
   190  	IntStatus int `json:"Status,omitempty"`
   191  }
   192  
   193  // MarshalJSON customizes how an Entry is marshaled to JSON.
   194  func (e *Entry) MarshalJSON() ([]byte, error) {
   195  	entry := dbEntry{
   196  		_Entry:    _Entry(*e),
   197  		IntStatus: int(e.Status),
   198  	}
   199  	return json.Marshal(entry)
   200  }
   201  
   202  func (e *Entry) UnmarshalJSON(data []byte) error {
   203  	var entry dbEntry
   204  	if err := json.Unmarshal(data, &entry); err != nil {
   205  		return err
   206  	}
   207  	entry._Entry.Status = types.Status(entry.IntStatus)
   208  	*e = Entry(entry._Entry)
   209  	return nil
   210  }
   211  
   212  type CveEntry struct {
   213  	ID string `json:",omitempty"`
   214  
   215  	// Severity may differ depending on platform even though the advisories resolve the same CVE-ID.
   216  	Severity types.Severity `json:",omitempty"`
   217  }