| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.owasp.dependencycheck.suppression; |
| 20 | |
|
| 21 | |
import java.util.ArrayList; |
| 22 | |
import java.util.List; |
| 23 | |
import org.xml.sax.Attributes; |
| 24 | |
import org.xml.sax.SAXException; |
| 25 | |
import org.xml.sax.helpers.DefaultHandler; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 2 | public class SuppressionHandler extends DefaultHandler { |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public static final String SUPPRESS = "suppress"; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public static final String FILE_PATH = "filePath"; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public static final String SHA1 = "sha1"; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public static final String CVE = "cve"; |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public static final String CPE = "cpe"; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public static final String CWE = "cwe"; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
public static final String CVSS_BELOW = "cvssBelow"; |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | 2 | private List<SuppressionRule> suppressionRules = new ArrayList<SuppressionRule>(); |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public List<SuppressionRule> getSuppressionRules() { |
| 73 | 2 | return suppressionRules; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
private SuppressionRule rule; |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
private Attributes currentAttributes; |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
private StringBuffer currentText; |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
@Override |
| 98 | |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
| 99 | 40 | currentAttributes = null; |
| 100 | 40 | currentText = new StringBuffer(); |
| 101 | |
|
| 102 | 40 | if (SUPPRESS.equals(qName)) { |
| 103 | 10 | rule = new SuppressionRule(); |
| 104 | 30 | } else if (FILE_PATH.equals(qName)) { |
| 105 | 6 | currentAttributes = attributes; |
| 106 | |
} |
| 107 | 40 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
@Override |
| 118 | |
public void endElement(String uri, String localName, String qName) throws SAXException { |
| 119 | 40 | if (SUPPRESS.equals(qName)) { |
| 120 | 10 | suppressionRules.add(rule); |
| 121 | 10 | rule = null; |
| 122 | 30 | } else if (FILE_PATH.equals(qName)) { |
| 123 | 6 | final PropertyType pt = processPropertyType(); |
| 124 | 6 | rule.setFilePath(pt); |
| 125 | 6 | } else if (SHA1.equals(qName)) { |
| 126 | 2 | rule.setSha1(currentText.toString()); |
| 127 | 22 | } else if (CPE.equals(qName)) { |
| 128 | 4 | final PropertyType pt = processPropertyType(); |
| 129 | 4 | rule.addCpe(pt); |
| 130 | 4 | } else if (CWE.equals(qName)) { |
| 131 | 0 | rule.addCwe(currentText.toString()); |
| 132 | 18 | } else if (CVE.equals(qName)) { |
| 133 | 4 | rule.addCve(currentText.toString()); |
| 134 | 14 | } else if (CVSS_BELOW.equals(qName)) { |
| 135 | 2 | final float cvss = Float.parseFloat(currentText.toString()); |
| 136 | 2 | rule.addCvssBelow(cvss); |
| 137 | |
} |
| 138 | 40 | } |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
@Override |
| 149 | |
public void characters(char[] ch, int start, int length) throws SAXException { |
| 150 | 88 | currentText.append(ch, start, length); |
| 151 | 88 | } |
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
private PropertyType processPropertyType() { |
| 160 | 10 | final PropertyType pt = new PropertyType(); |
| 161 | 10 | pt.setValue(currentText.toString()); |
| 162 | 10 | if (currentAttributes != null && currentAttributes.getLength() > 0) { |
| 163 | 6 | final String regex = currentAttributes.getValue("regex"); |
| 164 | 6 | if (regex != null) { |
| 165 | 6 | pt.setRegex(Boolean.parseBoolean(regex)); |
| 166 | |
} |
| 167 | 6 | final String caseSensitive = currentAttributes.getValue("caseSensitive"); |
| 168 | 6 | if (regex != null) { |
| 169 | 6 | pt.setCaseSensitive(Boolean.parseBoolean(caseSensitive)); |
| 170 | |
} |
| 171 | |
} |
| 172 | 10 | return pt; |
| 173 | |
} |
| 174 | |
} |