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