// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/Vulnerability.java
// public final class Vulnerability {
// 	private final SootClass clazz;
// 	private final SootMethod method;
// 	private final VulnerabilityType type;
// 	private final VulnerabilityState state;
// 
// 	public Vulnerability(SootClass clazz, VulnerabilityType type, VulnerabilityState state) {
// 		this.clazz = clazz;
// 		this.method = null;
// 		this.type = type;
// 		this.state = state;
// 	}
// 
// 	public Vulnerability(SootMethod method, VulnerabilityType type, VulnerabilityState state) {
// 		this.clazz = method.getDeclaringClass();
// 		this.method = method;
// 		this.type = type;
// 		this.state = state;
// 	}
// 
// 	public SootClass getClazz() {
// 		return clazz;
// 	}
// 
// 	public SootMethod getMethod() {
// 		return method;
// 	}
// 
// 	public VulnerabilityType getType() {
// 		return type;
// 	}
// 
// 	public VulnerabilityState getState() {
// 		return state;
// 	}
// 
// 	@Override
// 	public boolean equals(Object o) {
// 		if (this == o) return true;
// 		if (o == null || getClass() != o.getClass()) return false;
// 
// 		Vulnerability that = (Vulnerability) o;
// 
// 		if (!clazz.equals(that.clazz)) return false;
// 		if (method != null ? !method.equals(that.method) : that.method != null) return false;
// 		if (state != that.state) return false;
// 		if (type != that.type) return false;
// 
// 		return true;
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		int result = clazz.hashCode();
// 		result = 31 * result + (method != null ? method.hashCode() : 0);
// 		result = 31 * result + type.hashCode();
// 		result = 31 * result + state.hashCode();
// 		return result;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		if (method == null) {
// 			return clazz.getName() + "\t" + type + "\t" + state;
// 		} else {
// 			return clazz.getName() + "::" + method.getName() + "\t" + type + "\t" + state;
// 		}
// 	}
// }
// 
// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/VulnerabilityType.java
// public enum VulnerabilityType {
// 	PERMISSIVE_HOSTNAME_VERIFIER,
// 	PERMISSIVE_TRUST_MANAGER,
// 	INIT_HOSTNAME_VERIFIER,
// 	INIT_TRUST_MANAGER,
// 	HTTPS_CONNECTION_DEFAULT_HOSTNAME_VERIFIER,
// 	HTTPS_CONNECTION_USES_HOSTNAME_VERIFIER,
// 	SOCKET_USES_PERMISSIVE_TRUST_MANAGER
// }
// 
// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/tag/TrustManagerTag.java
// public final class TrustManagerTag extends VulnerabilityTag {
// 	public static final String NAME = "trust_manager";
// 
// 	public TrustManagerTag(VulnerabilityState state) {
// 		super(NAME, state);
// 	}
// }


import soot.*;
import soot.jimple.AbstractJimpleValueSwitch;
import soot.jimple.NewExpr;
import uk.ac.cam.gpe21.droidssl.analysis.Vulnerability;
import uk.ac.cam.gpe21.droidssl.analysis.VulnerabilityType;
import uk.ac.cam.gpe21.droidssl.analysis.tag.TrustManagerTag;
import java.util.Set;
/*
 * Copyright 2013-2014 Graham Edgecombe
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.ac.cam.gpe21.droidssl.analysis.trans;



public final class InitTrustManagerAnalyser extends IntraProceduralAnalyser {
	public InitTrustManagerAnalyser(Set<Vulnerability> vulnerabilities) {
		super(vulnerabilities);
	}

	@Override
	protected void analyse(SootClass clazz, final SootMethod method, Body body) {
		for (Unit unit : body.getUnits()) {
			for (ValueBox valueBox : unit.getUseBoxes()) {
				valueBox.getValue().apply(new AbstractJimpleValueSwitch() {
					@Override
					public void caseNewExpr(NewExpr value) {
						SootClass type = value.getBaseType().getSootClass();
						if (type.hasTag(TrustManagerTag.NAME)) {
							TrustManagerTag tag = (TrustManagerTag) type.getTag(TrustManagerTag.NAME);
// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/Vulnerability.java
// public final class Vulnerability {
// 	private final SootClass clazz;
// 	private final SootMethod method;
// 	private final VulnerabilityType type;
// 	private final VulnerabilityState state;
// 
// 	public Vulnerability(SootClass clazz, VulnerabilityType type, VulnerabilityState state) {
// 		this.clazz = clazz;
// 		this.method = null;
// 		this.type = type;
// 		this.state = state;
// 	}
// 
// 	public Vulnerability(SootMethod method, VulnerabilityType type, VulnerabilityState state) {
// 		this.clazz = method.getDeclaringClass();
// 		this.method = method;
// 		this.type = type;
// 		this.state = state;
// 	}
// 
// 	public SootClass getClazz() {
// 		return clazz;
// 	}
// 
// 	public SootMethod getMethod() {
// 		return method;
// 	}
// 
// 	public VulnerabilityType getType() {
// 		return type;
// 	}
// 
// 	public VulnerabilityState getState() {
// 		return state;
// 	}
// 
// 	@Override
// 	public boolean equals(Object o) {
// 		if (this == o) return true;
// 		if (o == null || getClass() != o.getClass()) return false;
// 
// 		Vulnerability that = (Vulnerability) o;
// 
// 		if (!clazz.equals(that.clazz)) return false;
// 		if (method != null ? !method.equals(that.method) : that.method != null) return false;
// 		if (state != that.state) return false;
// 		if (type != that.type) return false;
// 
// 		return true;
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		int result = clazz.hashCode();
// 		result = 31 * result + (method != null ? method.hashCode() : 0);
// 		result = 31 * result + type.hashCode();
// 		result = 31 * result + state.hashCode();
// 		return result;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		if (method == null) {
// 			return clazz.getName() + "\t" + type + "\t" + state;
// 		} else {
// 			return clazz.getName() + "::" + method.getName() + "\t" + type + "\t" + state;
// 		}
// 	}
// }
// 
// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/VulnerabilityType.java
// public enum VulnerabilityType {
// 	PERMISSIVE_HOSTNAME_VERIFIER,
// 	PERMISSIVE_TRUST_MANAGER,
// 	INIT_HOSTNAME_VERIFIER,
// 	INIT_TRUST_MANAGER,
// 	HTTPS_CONNECTION_DEFAULT_HOSTNAME_VERIFIER,
// 	HTTPS_CONNECTION_USES_HOSTNAME_VERIFIER,
// 	SOCKET_USES_PERMISSIVE_TRUST_MANAGER
// }
// 
// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/tag/TrustManagerTag.java
// public final class TrustManagerTag extends VulnerabilityTag {
// 	public static final String NAME = "trust_manager";
// 
// 	public TrustManagerTag(VulnerabilityState state) {
// 		super(NAME, state);
// 	}
// }


// Path: analysis/src/main/java/uk/ac/cam/gpe21/droidssl/analysis/trans/InitTrustManagerAnalyser.java
import soot.*;
import soot.jimple.AbstractJimpleValueSwitch;
import soot.jimple.NewExpr;
import uk.ac.cam.gpe21.droidssl.analysis.Vulnerability;
import uk.ac.cam.gpe21.droidssl.analysis.VulnerabilityType;
import uk.ac.cam.gpe21.droidssl.analysis.tag.TrustManagerTag;
import java.util.Set;

/*
 * Copyright 2013-2014 Graham Edgecombe
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.ac.cam.gpe21.droidssl.analysis.trans;



public final class InitTrustManagerAnalyser extends IntraProceduralAnalyser {
	public InitTrustManagerAnalyser(Set<Vulnerability> vulnerabilities) {
		super(vulnerabilities);
	}

	@Override
	protected void analyse(SootClass clazz, final SootMethod method, Body body) {
		for (Unit unit : body.getUnits()) {
			for (ValueBox valueBox : unit.getUseBoxes()) {
				valueBox.getValue().apply(new AbstractJimpleValueSwitch() {
					@Override
					public void caseNewExpr(NewExpr value) {
						SootClass type = value.getBaseType().getSootClass();
						if (type.hasTag(TrustManagerTag.NAME)) {
							TrustManagerTag tag = (TrustManagerTag) type.getTag(TrustManagerTag.NAME);
							vulnerabilities.add(new Vulnerability(method, VulnerabilityType.INIT_TRUST_MANAGER, tag.getState()));