Coverage Report - org.owasp.dependencycheck.analyzer.HintAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
HintAnalyzer
93%
31/33
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 org.owasp.dependencycheck.analyzer.exception.AnalysisException;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Iterator;
 23  
 import java.util.Set;
 24  
 import org.owasp.dependencycheck.Engine;
 25  
 import org.owasp.dependencycheck.dependency.Confidence;
 26  
 import org.owasp.dependencycheck.dependency.Dependency;
 27  
 import org.owasp.dependencycheck.dependency.Evidence;
 28  
 
 29  
 /**
 30  
  *
 31  
  * @author Jeremy Long <jeremy.long@owasp.org>
 32  
  */
 33  
 public class HintAnalyzer extends AbstractAnalyzer implements Analyzer {
 34  
 
 35  
     //<editor-fold defaultstate="collapsed" desc="All standard implmentation details of Analyzer">
 36  
     /**
 37  
      * The name of the analyzer.
 38  
      */
 39  
     private static final String ANALYZER_NAME = "Hint Analyzer";
 40  
     /**
 41  
      * The phase that this analyzer is intended to run in.
 42  
      */
 43  1
     private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.PRE_IDENTIFIER_ANALYSIS;
 44  
     /**
 45  
      * The set of file extensions supported by this analyzer.
 46  
      */
 47  1
     private static final Set<String> EXTENSIONS = null;
 48  
 
 49  
     /**
 50  
      * Returns a list of file EXTENSIONS supported by this analyzer.
 51  
      *
 52  
      * @return a list of file EXTENSIONS supported by this analyzer.
 53  
      */
 54  
     public Set<String> getSupportedExtensions() {
 55  132
         return EXTENSIONS;
 56  
     }
 57  
 
 58  
     /**
 59  
      * Returns the name of the analyzer.
 60  
      *
 61  
      * @return the name of the analyzer.
 62  
      */
 63  
     public String getName() {
 64  9
         return ANALYZER_NAME;
 65  
     }
 66  
 
 67  
     /**
 68  
      * Returns whether or not this analyzer can process the given extension.
 69  
      *
 70  
      * @param extension the file extension to test for support.
 71  
      * @return whether or not the specified file extension is supported by this analyzer.
 72  
      */
 73  
     public boolean supportsExtension(String extension) {
 74  9
         return true;
 75  
     }
 76  
 
 77  
     /**
 78  
      * Returns the phase that the analyzer is intended to run in.
 79  
      *
 80  
      * @return the phase that the analyzer is intended to run in.
 81  
      */
 82  
     public AnalysisPhase getAnalysisPhase() {
 83  6
         return ANALYSIS_PHASE;
 84  
     }
 85  
     //</editor-fold>
 86  
 
 87  
     /**
 88  
      * The HintAnalyzer uses knowledge about a dependency to add additional information to help in identification of
 89  
      * identifiers or vulnerabilities.
 90  
      *
 91  
      * @param dependency The dependency being analyzed
 92  
      * @param engine The scanning engine
 93  
      * @throws AnalysisException is thrown if there is an exception analyzing the dependency.
 94  
      */
 95  
     @Override
 96  
     public void analyze(Dependency dependency, Engine engine) throws AnalysisException {
 97  15
         final Evidence springTest1 = new Evidence("Manifest",
 98  
                 "Implementation-Title",
 99  
                 "Spring Framework",
 100  
                 Confidence.HIGH);
 101  
 
 102  15
         final Evidence springTest2 = new Evidence("Manifest",
 103  
                 "Implementation-Title",
 104  
                 "org.springframework.core",
 105  
                 Confidence.HIGH);
 106  
 
 107  15
         final Evidence springTest3 = new Evidence("Manifest",
 108  
                 "Bundle-Vendor",
 109  
                 "SpringSource",
 110  
                 Confidence.HIGH);
 111  
 
 112  15
         Set<Evidence> evidence = dependency.getProductEvidence().getEvidence();
 113  15
         if (evidence.contains(springTest1) || evidence.contains(springTest2)) {
 114  2
             dependency.getProductEvidence().addEvidence("hint analyzer", "product", "springsource_spring_framework", Confidence.HIGH);
 115  2
             dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "SpringSource", Confidence.HIGH);
 116  2
             dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH);
 117  
         }
 118  
 
 119  15
         evidence = dependency.getVendorEvidence().getEvidence();
 120  15
         if (evidence.contains(springTest3)) {
 121  2
             dependency.getProductEvidence().addEvidence("hint analyzer", "product", "springsource_spring_framework", Confidence.HIGH);
 122  2
             dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH);
 123  
         }
 124  15
         final Iterator<Evidence> itr = dependency.getVendorEvidence().iterator();
 125  15
         final ArrayList<Evidence> newEntries = new ArrayList<Evidence>();
 126  121
         while (itr.hasNext()) {
 127  106
             final Evidence e = itr.next();
 128  106
             if ("sun".equalsIgnoreCase(e.getValue(false))) {
 129  2
                 final Evidence newEvidence = new Evidence(e.getSource() + " (hint)", e.getName(), "oracle", e.getConfidence());
 130  2
                 newEntries.add(newEvidence);
 131  2
             } else if ("oracle".equalsIgnoreCase(e.getValue(false))) {
 132  0
                 final Evidence newEvidence = new Evidence(e.getSource() + " (hint)", e.getName(), "sun", e.getConfidence());
 133  0
                 newEntries.add(newEvidence);
 134  
             }
 135  106
         }
 136  15
         for (Evidence e : newEntries) {
 137  2
             dependency.getVendorEvidence().addEvidence(e);
 138  2
         }
 139  
 
 140  15
     }
 141  
 }