Coverage Report - org.owasp.dependencycheck.analyzer.HintAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
HintAnalyzer
94%
32/34
92%
13/14
2.4
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.analyzer;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.Iterator;
 22  
 import java.util.Set;
 23  
 import org.owasp.dependencycheck.Engine;
 24  
 import org.owasp.dependencycheck.dependency.Confidence;
 25  
 import org.owasp.dependencycheck.dependency.Dependency;
 26  
 import org.owasp.dependencycheck.dependency.Evidence;
 27  
 
 28  
 /**
 29  
  *
 30  
  * @author Jeremy Long <jeremy.long@owasp.org>
 31  
  */
 32  7
 public class HintAnalyzer extends AbstractAnalyzer implements Analyzer {
 33  
 
 34  
     //<editor-fold defaultstate="collapsed" desc="All standard implmentation details of Analyzer">
 35  
     /**
 36  
      * The name of the analyzer.
 37  
      */
 38  
     private static final String ANALYZER_NAME = "Hint Analyzer";
 39  
     /**
 40  
      * The phase that this analyzer is intended to run in.
 41  
      */
 42  1
     private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.PRE_IDENTIFIER_ANALYSIS;
 43  
     /**
 44  
      * The set of file extensions supported by this analyzer.
 45  
      */
 46  1
     private static final Set<String> EXTENSIONS = null;
 47  
 
 48  
     /**
 49  
      * Returns a list of file EXTENSIONS supported by this analyzer.
 50  
      *
 51  
      * @return a list of file EXTENSIONS supported by this analyzer.
 52  
      */
 53  
     public Set<String> getSupportedExtensions() {
 54  132
         return EXTENSIONS;
 55  
     }
 56  
 
 57  
     /**
 58  
      * Returns the name of the analyzer.
 59  
      *
 60  
      * @return the name of the analyzer.
 61  
      */
 62  
     public String getName() {
 63  9
         return ANALYZER_NAME;
 64  
     }
 65  
 
 66  
     /**
 67  
      * Returns whether or not this analyzer can process the given extension.
 68  
      *
 69  
      * @param extension the file extension to test for support.
 70  
      * @return whether or not the specified file extension is supported by this analyzer.
 71  
      */
 72  
     public boolean supportsExtension(String extension) {
 73  9
         return true;
 74  
     }
 75  
 
 76  
     /**
 77  
      * Returns the phase that the analyzer is intended to run in.
 78  
      *
 79  
      * @return the phase that the analyzer is intended to run in.
 80  
      */
 81  
     public AnalysisPhase getAnalysisPhase() {
 82  6
         return ANALYSIS_PHASE;
 83  
     }
 84  
     //</editor-fold>
 85  
 
 86  
     /**
 87  
      * The HintAnalyzer uses knowledge about a dependency to add additional information to help in identification of
 88  
      * identifiers or vulnerabilities.
 89  
      *
 90  
      * @param dependency The dependency being analyzed
 91  
      * @param engine The scanning engine
 92  
      * @throws AnalysisException is thrown if there is an exception analyzing the dependency.
 93  
      */
 94  
     @Override
 95  
     public void analyze(Dependency dependency, Engine engine) throws AnalysisException {
 96  15
         final Evidence springTest1 = new Evidence("Manifest",
 97  
                 "Implementation-Title",
 98  
                 "Spring Framework",
 99  
                 Confidence.HIGH);
 100  
 
 101  15
         final Evidence springTest2 = new Evidence("Manifest",
 102  
                 "Implementation-Title",
 103  
                 "org.springframework.core",
 104  
                 Confidence.HIGH);
 105  
 
 106  15
         final Evidence springTest3 = new Evidence("Manifest",
 107  
                 "Bundle-Vendor",
 108  
                 "SpringSource",
 109  
                 Confidence.HIGH);
 110  
 
 111  15
         Set<Evidence> evidence = dependency.getProductEvidence().getEvidence();
 112  15
         if (evidence.contains(springTest1) || evidence.contains(springTest2)) {
 113  2
             dependency.getProductEvidence().addEvidence("hint analyzer", "product", "springsource_spring_framework", Confidence.HIGH);
 114  2
             dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "SpringSource", Confidence.HIGH);
 115  2
             dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH);
 116  
         }
 117  
 
 118  15
         evidence = dependency.getVendorEvidence().getEvidence();
 119  15
         if (evidence.contains(springTest3)) {
 120  2
             dependency.getProductEvidence().addEvidence("hint analyzer", "product", "springsource_spring_framework", Confidence.HIGH);
 121  2
             dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH);
 122  
         }
 123  15
         final Iterator<Evidence> itr = dependency.getVendorEvidence().iterator();
 124  15
         final ArrayList<Evidence> newEntries = new ArrayList<Evidence>();
 125  121
         while (itr.hasNext()) {
 126  106
             final Evidence e = itr.next();
 127  106
             if ("sun".equalsIgnoreCase(e.getValue(false))) {
 128  2
                 final Evidence newEvidence = new Evidence(e.getSource() + " (hint)", e.getName(), "oracle", e.getConfidence());
 129  2
                 newEntries.add(newEvidence);
 130  2
             } else if ("oracle".equalsIgnoreCase(e.getValue(false))) {
 131  0
                 final Evidence newEvidence = new Evidence(e.getSource() + " (hint)", e.getName(), "sun", e.getConfidence());
 132  0
                 newEntries.add(newEvidence);
 133  
             }
 134  106
         }
 135  15
         for (Evidence e : newEntries) {
 136  2
             dependency.getVendorEvidence().addEvidence(e);
 137  2
         }
 138  
 
 139  15
     }
 140  
 }