diff --git a/zap/gradle/japicmp.yaml b/zap/gradle/japicmp.yaml
index a8b3c09a0e8..673557a0aea 100644
--- a/zap/gradle/japicmp.yaml
+++ b/zap/gradle/japicmp.yaml
@@ -2,7 +2,20 @@
#
# Any binary incompatible changes deemed acceptable should be added to this file.
---
-packageExcludes: []
+packageExcludes:
+ - "ch.csnc.extension.httpclient"
+ - "ch.csnc.extension.ui"
+ - "ch.csnc.extension.util"
+ - "org.zaproxy.zap.extension.spider"
+ - "org.zaproxy.zap.spider"
+ - "org.zaproxy.zap.spider.filters"
+ - "org.zaproxy.zap.spider.parser"
fieldExcludes: []
-classExcludes: []
-methodExcludes: []
\ No newline at end of file
+classExcludes:
+ - "org.parosproxy.paros.extension.option.OptionsCertificatePanel"
+ - "org.parosproxy.paros.extension.option.OptionsParamCertificate"
+ - "org.parosproxy.paros.network.SSLConnector"
+methodExcludes:
+ - "org.parosproxy.paros.model.OptionsParam#getCertificateParam()"
+ - "org.parosproxy.paros.model.OptionsParam#getExperimentalFeaturesParam()"
+ - "org.parosproxy.paros.model.OptionsParam#setCertificateParam(org.parosproxy.paros.extension.option.OptionsParamCertificate)"
\ No newline at end of file
diff --git a/zap/src/main/java/ch/csnc/extension/httpclient/AliasCertificate.java b/zap/src/main/java/ch/csnc/extension/httpclient/AliasCertificate.java
deleted file mode 100644
index 1dd9d5dae70..00000000000
--- a/zap/src/main/java/ch/csnc/extension/httpclient/AliasCertificate.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * This file is part of WebScarab, an Open Web Application Security
- * Project utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 2004 Rogan Dawes
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version.
- *
- * As of October 2014 Rogan Dawes granted the OWASP ZAP Project permission to
- * redistribute this code under the Apache License, Version 2.0:
- *
- *
- * 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 ch.csnc.extension.httpclient;
-
-import java.security.cert.Certificate;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class AliasCertificate {
-
- private Certificate certificate;
- private String alias;
-
- AliasCertificate(Certificate certificate, String alias) {
- this.setCertificate(certificate);
- this.setAlias(alias);
- }
-
- public void setCertificate(Certificate certificate) {
- this.certificate = certificate;
- }
-
- public Certificate getCertificate() {
- return certificate;
- }
-
- public void setAlias(String alias) {
- this.alias = alias;
- }
-
- public String getAlias() {
- return alias;
- }
-
- public String getName() {
-
- String cn = getCN();
-
- if (cn == null || cn.length() == 0) {
- return getAlias();
- } else {
- return cn + " [" + getAlias() + "]";
- }
- }
-
- public String getCN() {
-
- String dn = getCertificate().toString();
-
- int i = 0;
- i = dn.indexOf("CN=");
- if (i == -1) {
- return null;
- }
- // get the remaining DN without CN=
- dn = dn.substring(i + 3);
-
- char[] dncs = dn.toCharArray();
- for (i = 0; i < dncs.length; i++) {
- if (dncs[i] == ',' && i > 0 && dncs[i - 1] != '\\') {
- break;
- }
- }
- return dn.substring(0, i);
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/httpclient/AliasKeyManager.java b/zap/src/main/java/ch/csnc/extension/httpclient/AliasKeyManager.java
deleted file mode 100644
index 0370bc7076c..00000000000
--- a/zap/src/main/java/ch/csnc/extension/httpclient/AliasKeyManager.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This file is part of WebScarab, an Open Web Application Security
- * Project utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 2004 Rogan Dawes
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version.
- *
- * As of October 2014 Rogan Dawes granted the OWASP ZAP Project permission to
- * redistribute this code under the Apache License, Version 2.0:
- *
- *
- * 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 ch.csnc.extension.httpclient;
-
-import java.net.Socket;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.Certificate;
-import java.security.cert.X509Certificate;
-import javax.net.ssl.X509KeyManager;
-
-/**
- * A KeyManager implementation that only ever selects a single alias, rather than considering the
- * "best" alias for the circumstances
- *
- * @author rdawes
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class AliasKeyManager implements X509KeyManager {
-
- private KeyStore _ks;
- private String _alias;
- private String _keyPassword;
-
- /**
- * Creates a new instance of AliasKeyManager
- *
- * @param ks The KeyStore that contains the keypair to use
- * @param alias the alias of the certificate to use
- * @param keyPassword the password for the key (not the keystore)
- */
- public AliasKeyManager(KeyStore ks, String alias, String keyPassword) {
- _ks = ks;
- _alias = alias;
- _keyPassword = keyPassword;
- }
-
- @Override
- public String chooseClientAlias(String[] str, Principal[] principal, Socket socket) {
- return _alias;
- }
-
- @Override
- public String chooseServerAlias(String str, Principal[] principal, Socket socket) {
- return _alias;
- }
-
- @Override
- public X509Certificate[] getCertificateChain(String alias) {
- try {
- Certificate[] certs = _ks.getCertificateChain(alias);
- if (certs == null) return null;
- X509Certificate[] x509certs = new X509Certificate[certs.length];
- for (int i = 0; i < certs.length; i++) {
- x509certs[i] = (X509Certificate) certs[i];
- }
- return x509certs;
- } catch (KeyStoreException kse) {
- kse.printStackTrace();
- return null;
- }
- }
-
- @Override
- public String[] getClientAliases(String str, Principal[] principal) {
- return new String[] {_alias};
- }
-
- @Override
- public PrivateKey getPrivateKey(String alias) {
- try {
- return (PrivateKey) _ks.getKey(alias, _keyPassword.toCharArray());
- } catch (KeyStoreException kse) {
- kse.printStackTrace();
- return null;
- } catch (NoSuchAlgorithmException nsao) {
- nsao.printStackTrace();
- return null;
- } catch (UnrecoverableKeyException uke) {
- uke.printStackTrace();
- return null;
- }
- }
-
- @Override
- public String[] getServerAliases(String str, Principal[] principal) {
- return new String[] {_alias};
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/httpclient/PKCS11Configuration.java b/zap/src/main/java/ch/csnc/extension/httpclient/PKCS11Configuration.java
deleted file mode 100644
index f0ecdd62ad9..00000000000
--- a/zap/src/main/java/ch/csnc/extension/httpclient/PKCS11Configuration.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2014 The ZAP Development Team
- *
- * 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 ch.csnc.extension.httpclient;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import org.apache.commons.lang3.StringUtils;
-
-/**
- * A representation of PKCS#11 provider configuration. Used to create configurations for instances
- * of {@code sun.security.pkcs11.SunPKCS11} and {@code
- * com.ibm.crypto.pkcs11impl.provider.IBMPKCS11Impl}.
- *
- *
Note: Only the mandatory attributes, name and library, and the
- * optional attributes, description, slot and slotListIndex are implemented.
- *
- * @see Sun
- * PKCS#11 Configuration
- * @see IBM
- * PKCS#11 Configuration
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class PKCS11Configuration {
-
- private final String name;
-
- private final String library;
-
- private final String description;
-
- private final int slotId;
-
- private final int slotListIndex;
-
- private PKCS11Configuration(
- String name, String library, String description, int slotId, int slotListIndex) {
- super();
-
- this.name = name;
- this.library = library;
- this.description = description;
- this.slotId = slotId;
- this.slotListIndex = slotListIndex;
- }
-
- public String getName() {
- return name;
- }
-
- public String getLibrary() {
- return library;
- }
-
- public String getDescription() {
- return description;
- }
-
- public int getSlotListIndex() {
- return slotListIndex;
- }
-
- public int getSlotId() {
- return slotId;
- }
-
- @Override
- public String toString() {
- StringBuilder sbConfiguration = new StringBuilder(150);
- sbConfiguration
- .append("name = \"")
- .append(escapeBackslashesAndQuotationMarks(name))
- .append("\"\n");
- sbConfiguration.append("library = ").append(library).append('\n');
-
- if (description != null && !description.isEmpty()) {
- sbConfiguration.append("description = ").append(description).append('\n');
- }
-
- if (slotListIndex != -1) {
- sbConfiguration.append("slotListIndex = ").append(slotListIndex);
- } else {
- sbConfiguration.append("slot = ").append(slotId);
- }
- sbConfiguration.append('\n');
-
- return sbConfiguration.toString();
- }
-
- private static String escapeBackslashesAndQuotationMarks(String value) {
- String[] searchValues = new String[] {"\\", "\""};
- String[] replacementValues = new String[] {"\\\\", "\\\""};
-
- return StringUtils.replaceEach(value, searchValues, replacementValues);
- }
-
- public InputStream toInpuStream() {
- return new ByteArrayInputStream(toString().getBytes(StandardCharsets.UTF_8));
- }
-
- public static PCKS11ConfigurationBuilder builder() {
- return new PCKS11ConfigurationBuilder();
- }
-
- public static final class PCKS11ConfigurationBuilder {
-
- private String name;
-
- private String library;
-
- private String description;
-
- private int slotId;
-
- private int slotListIndex;
-
- private PCKS11ConfigurationBuilder() {
- slotId = -1;
- slotListIndex = 0;
- }
-
- public PCKS11ConfigurationBuilder setName(String name) {
- if (name == null || name.isEmpty()) {
- throw new IllegalArgumentException("Parameter name must not be null or empty.");
- }
- this.name = name;
- return this;
- }
-
- public PCKS11ConfigurationBuilder setLibrary(String library) {
- if (library == null || library.isEmpty()) {
- throw new IllegalArgumentException("Parameter library must not be null or empty.");
- }
- this.library = library;
- return this;
- }
-
- public PCKS11ConfigurationBuilder setDescription(String description) {
- this.description = description;
- return this;
- }
-
- public PCKS11ConfigurationBuilder setSlotListIndex(int slotListIndex) {
- if (slotListIndex < 0) {
- throw new IllegalArgumentException(
- "Parameter slotListIndex must be greater or equal to zero.");
- }
- this.slotListIndex = slotListIndex;
- this.slotId = -1;
- return this;
- }
-
- public final PCKS11ConfigurationBuilder setSlotId(int slotId) {
- if (slotId < 0) {
- throw new IllegalArgumentException(
- "Parameter slotId must be greater or equal to zero.");
- }
- this.slotId = slotId;
- this.slotListIndex = -1;
- return this;
- }
-
- public PKCS11Configuration build() {
- validateBuilderState();
- return new PKCS11Configuration(name, library, description, slotId, slotListIndex);
- }
-
- private void validateBuilderState() {
- if (name == null) {
- throw new IllegalStateException("A name must be set.");
- }
- if (library == null) {
- throw new IllegalStateException("A library must be set.");
- }
- }
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/httpclient/SSLContextManager.java b/zap/src/main/java/ch/csnc/extension/httpclient/SSLContextManager.java
deleted file mode 100644
index eee6b12bc77..00000000000
--- a/zap/src/main/java/ch/csnc/extension/httpclient/SSLContextManager.java
+++ /dev/null
@@ -1,590 +0,0 @@
-/*
- * This file is part of WebScarab, an Open Web Application Security
- * Project utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 2004 Rogan Dawes
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version.
- *
- * As of October 2014 Rogan Dawes granted the OWASP ZAP Project permission to
- * redistribute this code under the Apache License, Version 2.0:
- *
- *
- * 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 ch.csnc.extension.httpclient;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.SecureRandom;
-import java.security.Security;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSessionContext;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.io.FileUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class SSLContextManager {
-
- /** The canonical class name of Sun PKCS#11 Provider. */
- public static final String SUN_PKCS11_CANONICAL_CLASS_NAME = "sun.security.pkcs11.SunPKCS11";
-
- /** The canonical class name of IBMPKCS11Impl Provider. */
- public static final String IBM_PKCS11_CANONICAL_CLASS_NAME =
- "com.ibm.crypto.pkcs11impl.provider.IBMPKCS11Impl";
-
- /**
- * @deprecated (2.11.0) Use {@link #IBM_PKCS11_CANONICAL_CLASS_NAME}
- */
- @Deprecated
- public static final String IBM_PKCS11_CONONICAL_CLASS_NAME = IBM_PKCS11_CANONICAL_CLASS_NAME;
-
- /** The name of Sun PKCS#11 Provider. */
- private static final String SUN_PKCS11_PROVIDER_NAME = "SunPKCS11";
-
- /**
- * The name for providers of type PKCS#11.
- *
- * @see #isProviderAvailable(String)
- */
- public static final String PKCS11_PROVIDER_TYPE = "PKCS11";
-
- /**
- * The name of the {@code KeyStore} type of Sun PKCS#11 Provider.
- *
- * @see KeyStore#getInstance(String, Provider)
- */
- private static final String SUN_PKCS11_KEYSTORE_TYPE = "PKCS11";
-
- /**
- * The name of the {@code KeyStore} type of IBMPKCS11Impl Provider.
- *
- * @see KeyStore#getInstance(String, Provider)
- */
- private static final String IBM_PKCS11_KEYSTORE_TYPE = "PKCS11IMPLKS";
-
- /**
- * Flag that indicates if the check for Java 9 and SunPKCS11 was already done.
- *
- * @see #isJava9SunPKCS11()
- */
- private static Boolean java9SunPKCS11;
-
- private Map _contextMaps = new TreeMap<>();
- private SSLContext _noClientCertContext;
- private String _defaultKey = null;
- private Map> _aliasPasswords = new HashMap<>();
- private List _keyStores = new ArrayList<>();
- private Map _keyStoreDescriptions = new HashMap<>();
- private Map _keyStorePasswords = new HashMap<>();
-
- private static Logger log = LogManager.getLogger(SSLContextManager.class);
-
- private static TrustManager[] _trustAllCerts =
- new TrustManager[] {
- new X509TrustManager() {
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
-
- @Override
- public void checkClientTrusted(X509Certificate[] certs, String authType) {}
-
- @Override
- public void checkServerTrusted(X509Certificate[] certs, String authType) {}
- }
- };
-
- private int _defaultKeystoreIndex = -1;
- private int _defaultAliasIndex = -1;
-
- /** Creates a new instance of SSLContextManager */
- public SSLContextManager() {
- try {
- _noClientCertContext = SSLContext.getInstance("SSL");
- _noClientCertContext.init(null, _trustAllCerts, new SecureRandom());
- } catch (NoSuchAlgorithmException nsao) {
- log.error("Could not get an instance of the SSL algorithm: " + nsao.getMessage(), nsao);
- } catch (KeyManagementException kme) {
- log.error("Error initialising the SSL Context: " + kme.getMessage(), kme);
- }
-
- try {
- initMSCAPI();
- } catch (Exception e) {
- }
- }
-
- public boolean isProviderAvailable(String type) {
- try {
- if (type.equals(PKCS11_PROVIDER_TYPE)) {
- try {
- Class.forName(SUN_PKCS11_CANONICAL_CLASS_NAME);
- return true;
- } catch (Throwable ignore) {
- Class.forName(IBM_PKCS11_CANONICAL_CLASS_NAME);
- return true;
- }
- } else if (type.equals("msks")) {
- Class.forName("se.assembla.jce.provider.ms.MSProvider");
- return true;
- }
- } catch (Throwable ignore) {
- }
- return false;
- }
-
- private int addKeyStore(KeyStore ks, String description, String password) {
- int index = _keyStores.indexOf(ks);
- if (index == -1) {
- _keyStores.add(ks);
- index = _keyStores.size() - 1;
- }
- _keyStoreDescriptions.put(ks, description);
- _keyStorePasswords.put(ks, password);
- return index;
- }
-
- public boolean removeKeyStore(int keystoreIndex) {
- boolean isDefaultKeyStore = (keystoreIndex == _defaultKeystoreIndex);
- KeyStore ks = _keyStores.get(keystoreIndex);
-
- _keyStores.remove(ks);
- _keyStoreDescriptions.remove(ks);
- _keyStorePasswords.remove(ks);
-
- if (isDefaultKeyStore) {
- _defaultKeystoreIndex = -1;
- _defaultAliasIndex = -1;
- }
- return isDefaultKeyStore;
- }
-
- public int getKeyStoreCount() {
- return _keyStores.size();
- }
-
- public String getKeyStoreDescription(int keystoreIndex) {
- return _keyStoreDescriptions.get(_keyStores.get(keystoreIndex));
- }
-
- public String getKeyStorePassword(int keystoreIndex) {
- return _keyStorePasswords.get(_keyStores.get(keystoreIndex));
- }
-
- public int getAliasCount(int keystoreIndex) {
- return getAliases(_keyStores.get(keystoreIndex)).size();
- }
-
- public String getAliasAt(int keystoreIndex, int aliasIndex) {
- return getAliases(_keyStores.get(keystoreIndex)).get(aliasIndex).getAlias();
- }
-
- private List getAliases(KeyStore ks) {
- List aliases = new ArrayList<>();
- try {
- Enumeration en = ks.aliases();
-
- boolean isIbm = isIbmPKCS11Provider();
- while (en.hasMoreElements()) {
- String alias = en.nextElement();
- // Sun's and IBM's KeyStore implementations behave differently...
- // With IBM's KeyStore impl #getCertificate(String) returns null when
- // #isKeyEntry(String) returns true.
- // If IBM add all certificates and let the user choose the correct one.
- if (ks.isKeyEntry(alias) || (isIbm && ks.isCertificateEntry(alias))) {
- Certificate cert = ks.getCertificate(alias);
- // IBM: Maybe we should check the KeyUsage?
- // ((X509Certificate) cert).getKeyUsage()[0]
- AliasCertificate aliasCert = new AliasCertificate(cert, alias);
- aliases.add(aliasCert);
- }
- }
- } catch (KeyStoreException kse) {
- kse.printStackTrace();
- }
- return aliases;
- }
-
- public List getAliases(int ks) {
- return getAliases(_keyStores.get(ks));
- }
-
- public Certificate getCertificate(int keystoreIndex, int aliasIndex) {
- try {
- KeyStore ks = _keyStores.get(keystoreIndex);
- String alias = getAliasAt(keystoreIndex, aliasIndex);
- return ks.getCertificate(alias);
- } catch (Exception e) {
- return null;
- }
- }
-
- public String getFingerPrint(Certificate cert) throws KeyStoreException {
- if (!(cert instanceof X509Certificate)) {
- return null;
- }
-
- StringBuilder buff = new StringBuilder();
- X509Certificate x509 = (X509Certificate) cert;
-
- try {
- String fingerprint = DigestUtils.md5Hex(cert.getEncoded());
- for (int i = 0; i < fingerprint.length(); i += 2) {
- buff.append(fingerprint.substring(i, i + 1)).append(":");
- }
- buff.deleteCharAt(buff.length() - 1);
- } catch (CertificateEncodingException e) {
- throw new KeyStoreException(e.getMessage());
- }
-
- String dn = x509.getSubjectX500Principal().getName();
-
- log.info("Fingerprint is " + buff.toString().toUpperCase());
-
- return buff.toString().toUpperCase() + " " + dn;
- }
-
- public boolean isKeyUnlocked(int keystoreIndex, int aliasIndex) {
- KeyStore ks = _keyStores.get(keystoreIndex);
- String alias = getAliasAt(keystoreIndex, aliasIndex);
-
- Map, ?> pwmap = _aliasPasswords.get(ks);
- if (pwmap == null) {
- return false;
- }
-
- return pwmap.containsKey(alias);
- }
-
- public void setDefaultKey(int keystoreIndex, int aliasIndex) throws KeyStoreException {
-
- _defaultKeystoreIndex = keystoreIndex;
- _defaultAliasIndex = aliasIndex;
-
- if ((_defaultKeystoreIndex == -1) || (_defaultAliasIndex == -1)) {
- _defaultKey = "";
- } else {
- _defaultKey = getFingerPrint(getCertificate(keystoreIndex, aliasIndex));
- }
- }
-
- public String getDefaultKey() {
- return _defaultKey;
- }
-
- public Certificate getDefaultCertificate() {
- return getCertificate(_defaultKeystoreIndex, _defaultAliasIndex);
- }
-
- public int initMSCAPI()
- throws KeyStoreException,
- NoSuchProviderException,
- IOException,
- NoSuchAlgorithmException,
- CertificateException {
- try {
- if (!isProviderAvailable("msks")) {
- return -1;
- }
-
- Provider mscapi =
- (Provider)
- Class.forName("se.assembla.jce.provider.ms.MSProvider")
- .getDeclaredConstructor()
- .newInstance();
- Security.addProvider(mscapi);
-
- // init the key store
- KeyStore ks = KeyStore.getInstance("msks", "assembla");
- ks.load(null, null);
-
- return addKeyStore(ks, "Microsoft CAPI Store", null);
-
- } catch (Exception e) {
- log.error("Error instantiating the MSCAPI provider: " + e.getMessage(), e);
- return -1;
- }
- }
-
- /*
- * public int initCryptoApi() throws KeyStoreException,
- * NoSuchAlgorithmException, CertificateException, IOException{
- *
- * Provider mscapi = new sun.security.mscapi.SunMSCAPI();
- * Security.addProvider(mscapi);
- *
- * KeyStore ks = KeyStore.getInstance("Windows-MY"); ks.load(null, null);
- *
- * return addKeyStore(ks, "CryptoAPI", null); }
- */
- public int initPKCS11(PKCS11Configuration configuration, String kspassword)
- throws IOException,
- KeyStoreException,
- CertificateException,
- NoSuchAlgorithmException,
- ClassNotFoundException,
- SecurityException,
- NoSuchMethodException,
- IllegalArgumentException,
- InstantiationException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (!isProviderAvailable(PKCS11_PROVIDER_TYPE)) {
- return -1;
- }
-
- Provider pkcs11 = createPKCS11Provider(configuration);
-
- Security.addProvider(pkcs11);
-
- // init the key store
- KeyStore ks = getPKCS11KeyStore(pkcs11.getName());
- ks.load(null, kspassword == null ? null : kspassword.toCharArray());
- return addKeyStore(ks, "PKCS#11: " + configuration.getName(), ""); // do not store pin code
- }
-
- private static Provider createPKCS11Provider(PKCS11Configuration configuration)
- throws ClassNotFoundException,
- NoSuchMethodException,
- InstantiationException,
- IllegalAccessException,
- InvocationTargetException,
- IOException {
- Provider pkcs11 = null;
- if (isSunPKCS11Provider()) {
- if (isJava9SunPKCS11()) {
- Provider provider = Security.getProvider(SUN_PKCS11_PROVIDER_NAME);
- Method configure = provider.getClass().getMethod("configure", String.class);
- File configFile = File.createTempFile("pkcs11", ".cfg");
- configFile.deleteOnExit();
- FileUtils.write(configFile, configuration.toString(), StandardCharsets.UTF_8);
- pkcs11 = (Provider) configure.invoke(provider, configFile.getAbsolutePath());
- } else {
- pkcs11 =
- createInstance(
- SUN_PKCS11_CANONICAL_CLASS_NAME,
- InputStream.class,
- configuration.toInpuStream());
- }
- } else if (isIbmPKCS11Provider()) {
- pkcs11 =
- createInstance(
- IBM_PKCS11_CANONICAL_CLASS_NAME,
- BufferedReader.class,
- new BufferedReader(
- new InputStreamReader(configuration.toInpuStream())));
- }
- return pkcs11;
- }
-
- private static Provider createInstance(String name, Class> paramClass, Object param)
- throws ClassNotFoundException,
- NoSuchMethodException,
- InstantiationException,
- IllegalAccessException,
- InvocationTargetException {
- Class> instanceClass = Class.forName(name);
- Constructor> c = instanceClass.getConstructor(new Class>[] {paramClass});
- return (Provider) c.newInstance(new Object[] {param});
- }
-
- private static boolean isSunPKCS11Provider() {
- try {
- Class.forName(SUN_PKCS11_CANONICAL_CLASS_NAME);
- return true;
- } catch (Throwable ignore) {
- }
- return false;
- }
-
- private static boolean isJava9SunPKCS11() {
- if (java9SunPKCS11 != null) {
- return java9SunPKCS11;
- }
-
- java9SunPKCS11 = Boolean.FALSE;
- try {
- Provider provider = Security.getProvider(SUN_PKCS11_PROVIDER_NAME);
- if (provider != null) {
- provider.getClass().getMethod("configure", String.class);
- java9SunPKCS11 = Boolean.TRUE;
- }
- } catch (NoSuchMethodException ignore) {
- // The provider/method is available only in Java 9+.
- }
- return java9SunPKCS11;
- }
-
- private static boolean isIbmPKCS11Provider() {
- try {
- Class.forName(IBM_PKCS11_CANONICAL_CLASS_NAME);
- return true;
- } catch (Throwable ignore) {
- }
- return false;
- }
-
- private static KeyStore getPKCS11KeyStore(String providerName) throws KeyStoreException {
- String keyStoreType = SUN_PKCS11_KEYSTORE_TYPE;
- if (isIbmPKCS11Provider()) {
- keyStoreType = IBM_PKCS11_KEYSTORE_TYPE;
- }
- return KeyStore.getInstance(keyStoreType, Security.getProvider(providerName));
- }
-
- public int loadPKCS12Certificate(String filename, String ksPassword)
- throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
-
- // Get Filename
- File file = new File(filename);
- if (!file.exists()) {
- throw new FileNotFoundException(filename + " could not be found");
- }
- String name = file.getName();
-
- // Open the file
- try (InputStream is = new FileInputStream(file)) {
- // create the keystore
- KeyStore ks = KeyStore.getInstance("PKCS12");
- ks.load(is, ksPassword == null ? null : ksPassword.toCharArray());
- return addKeyStore(ks, "PKCS#12: " + name, ksPassword);
- }
- }
-
- public boolean unlockKeyWithDefaultPassword(int keystoreIndex, int aliasIndex)
- throws KeyManagementException, KeyStoreException {
-
- return unlockKey(keystoreIndex, aliasIndex, getKeyStorePassword(keystoreIndex));
- }
-
- public boolean unlockKey(int keystoreIndex, int aliasIndex, String keyPassword)
- throws KeyStoreException, KeyManagementException {
-
- KeyStore ks = _keyStores.get(keystoreIndex);
- String alias = getAliasAt(keystoreIndex, aliasIndex);
-
- AliasKeyManager akm = new AliasKeyManager(ks, alias, keyPassword);
-
- try {
- akm.getPrivateKey(alias).toString();
- } catch (NullPointerException ex) {
- log.error("Could not get private key: " + ex.getMessage(), ex);
- return false;
- }
-
- String fingerprint = getFingerPrint(getCertificate(keystoreIndex, aliasIndex));
-
- if (fingerprint == null) {
- log.info("No fingerprint found");
- return false;
- }
-
- SSLContext sc;
- try {
- sc = SSLContext.getInstance("SSL");
- } catch (NoSuchAlgorithmException nsao) {
- log.error("Could not get an instance of the SSL algorithm: " + nsao.getMessage(), nsao);
- return false;
- }
-
- sc.init(new KeyManager[] {akm}, _trustAllCerts, new SecureRandom());
-
- String key = fingerprint;
- if (key.indexOf(" ") > 0) {
- key = key.substring(0, key.indexOf(" "));
- }
-
- _contextMaps.put(key, sc);
- log.info("Key has been unlocked.");
-
- return true;
- }
-
- public void invalidateSessions() {
- invalidateSession(_noClientCertContext);
- Iterator it = _contextMaps.keySet().iterator();
- while (it.hasNext()) {
- invalidateSession(_contextMaps.get(it.next()));
- }
- }
-
- private void invalidateSession(SSLContext sc) {
- SSLSessionContext sslsc = sc.getClientSessionContext();
- if (sslsc != null) {
- int timeout = sslsc.getSessionTimeout();
- // force sessions to be timed out
- sslsc.setSessionTimeout(1);
- sslsc.setSessionTimeout(timeout);
- }
- sslsc = sc.getServerSessionContext();
- if (sslsc != null) {
- int timeout = sslsc.getSessionTimeout();
- // force sessions to be timed out
- sslsc.setSessionTimeout(1);
- sslsc.setSessionTimeout(timeout);
- }
- }
-
- public SSLContext getSSLContext(String fingerprint) {
- log.info("Requested SSLContext for " + fingerprint);
-
- if (fingerprint == null || fingerprint.equals("none")) {
- return _noClientCertContext;
- }
-
- if (fingerprint.indexOf(" ") > 0) {
- fingerprint = fingerprint.substring(0, fingerprint.indexOf(" "));
- }
-
- return _contextMaps.get(fingerprint);
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/ui/AliasTableModel.java b/zap/src/main/java/ch/csnc/extension/ui/AliasTableModel.java
deleted file mode 100644
index c262e935538..00000000000
--- a/zap/src/main/java/ch/csnc/extension/ui/AliasTableModel.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * 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.
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version
- * by Compass Security AG.
- *
- * As of October 2014 Compass Security AG granted the OWASP ZAP Project
- * permission to redistribute this code under the Apache License, Version 2.0.
- */
-package ch.csnc.extension.ui;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.swing.table.AbstractTableModel;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-@SuppressWarnings("serial")
-public class AliasTableModel extends AbstractTableModel {
-
- private static final long serialVersionUID = -4387633069248206563L;
-
- private int _ks = -1;
- private List _aliases = new ArrayList<>();
- private ch.csnc.extension.httpclient.SSLContextManager _sslcm;
-
- public AliasTableModel(ch.csnc.extension.httpclient.SSLContextManager contextManager) {
- _sslcm = contextManager;
- }
-
- public void setKeystore(int ks) {
- _ks = ks;
- _aliases.clear();
- if (_ks > -1) {
- _aliases = _sslcm.getAliases(_ks);
- }
- fireTableDataChanged();
- }
-
- public void removeKeystore() {
- _ks = -1;
- _aliases.clear();
- fireTableDataChanged();
- }
-
- public String getAlias(int row) {
- return _aliases.get(row).getAlias();
- }
-
- @Override
- public int getColumnCount() {
- return 1;
- }
-
- @Override
- public int getRowCount() {
- return _aliases.size();
- }
-
- @Override
- public Object getValueAt(int row, int col) {
- return _aliases.get(row).getName();
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/ui/CertificateView.java b/zap/src/main/java/ch/csnc/extension/ui/CertificateView.java
deleted file mode 100644
index 1952c68442e..00000000000
--- a/zap/src/main/java/ch/csnc/extension/ui/CertificateView.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * 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.
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version
- * by Compass Security AG.
- *
- * As of October 2014 Compass Security AG granted the OWASP ZAP Project
- * permission to redistribute this code under the Apache License, Version 2.0.
- */
-package ch.csnc.extension.ui;
-
-import javax.swing.GroupLayout;
-import javax.swing.JButton;
-import javax.swing.JScrollPane;
-import javax.swing.LayoutStyle;
-import org.parosproxy.paros.Constant;
-import org.parosproxy.paros.view.AbstractFrame;
-import org.zaproxy.zap.utils.ZapTextArea;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class CertificateView extends AbstractFrame {
-
- private static final long serialVersionUID = -7284926693579230812L;
-
- /**
- * Creates new form Certificate
- *
- * @param certificate the certificate to view/display.
- */
- public CertificateView(String certificate) {
- setTitle(Constant.messages.getString("view.cert.title"));
-
- JButton closeButton = new JButton(Constant.messages.getString("view.cert.button.close"));
- closeButton.addActionListener(
- e -> {
- setVisible(false);
- dispose();
- });
-
- ZapTextArea certificateTextArea = new ZapTextArea(certificate);
- certificateTextArea.setEditable(false);
-
- JScrollPane certificateScrollPane = new JScrollPane(certificateTextArea);
-
- GroupLayout layout = new GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(
- GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.TRAILING)
- .addComponent(
- closeButton,
- GroupLayout.PREFERRED_SIZE,
- 93,
- GroupLayout.PREFERRED_SIZE)
- .addComponent(
- certificateScrollPane,
- GroupLayout.DEFAULT_SIZE,
- 658,
- Short.MAX_VALUE))
- .addContainerGap()));
- layout.setVerticalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(
- GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(
- certificateScrollPane,
- GroupLayout.DEFAULT_SIZE,
- 439,
- Short.MAX_VALUE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(closeButton)
- .addContainerGap()));
- pack();
-
- setVisible(true);
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/ui/DriverTableModel.java b/zap/src/main/java/ch/csnc/extension/ui/DriverTableModel.java
deleted file mode 100644
index b0723e39509..00000000000
--- a/zap/src/main/java/ch/csnc/extension/ui/DriverTableModel.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * 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.
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version
- * by Compass Security AG.
- *
- * As of October 2014 Compass Security AG granted the OWASP ZAP Project
- * permission to redistribute this code under the Apache License, Version 2.0.
- */
-package ch.csnc.extension.ui;
-
-import java.util.Vector;
-import javax.swing.table.AbstractTableModel;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-@SuppressWarnings("serial")
-public class DriverTableModel extends AbstractTableModel {
-
- private static final long serialVersionUID = -9114670362713975727L;
-
- private ch.csnc.extension.util.DriverConfiguration driverConfig;
- private Vector names;
- private Vector paths;
- private Vector slots;
- private Vector slotListIndexes;
-
- public DriverTableModel(ch.csnc.extension.util.DriverConfiguration driverConfig) {
- this.driverConfig = driverConfig;
- this.driverConfig.addChangeListener(e -> fireTableDataChanged());
-
- names = driverConfig.getNames();
- paths = driverConfig.getPaths();
- slots = driverConfig.getSlots();
- slotListIndexes = driverConfig.getSlotIndexes();
- }
-
- @Override
- public int getColumnCount() {
- return 4;
- }
-
- @Override
- public int getRowCount() {
- return names.size();
- }
-
- @Override
- public Object getValueAt(int row, int column) {
- if (column == 0) {
- return names.get(row);
- }
- if (column == 1) {
- return paths.get(row);
- }
- if (column == 2) {
- return slots.get(row);
- }
- if (column == 3) {
- return slotListIndexes.get(row);
- }
-
- return "";
- }
-
- /*default*/ int getPreferredWith(int column) {
- if (column == 0) {
- return 75;
- }
- if (column == 1) {
- return 300;
- }
- if (column == 2) {
- return 15;
- }
- if (column == 3) {
- return 15;
- }
- return 0;
- }
-
- /* default */ void addDriver(String name, String path, int slot, int slotListIndex) {
- names.add(name);
- paths.add(path);
- slots.add(slot);
- slotListIndexes.add(slotListIndex);
-
- updateConfiguration();
- }
-
- /* default */ void deleteDriver(int index) {
- names.remove(index);
- paths.remove(index);
- slots.remove(index);
- slotListIndexes.remove(index);
-
- updateConfiguration();
- }
-
- private void updateConfiguration() {
- driverConfig.setNames(names);
- driverConfig.setPaths(paths);
- driverConfig.setSlots(slots);
- driverConfig.setSlotListIndexes(slotListIndexes);
- driverConfig.write();
- }
-
- @Override
- public String getColumnName(int columnNumber) {
- if (columnNumber == 0) {
- return "Name";
- } else if (columnNumber == 1) {
- return "Path";
- } else if (columnNumber == 2) {
- return "Slot";
- } else if (columnNumber == 3) {
- return "SlotListIndex";
- } else {
- throw new IllegalArgumentException("Invalid column number: " + columnNumber);
- }
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/ui/DriversView.java b/zap/src/main/java/ch/csnc/extension/ui/DriversView.java
deleted file mode 100644
index eb60c57016b..00000000000
--- a/zap/src/main/java/ch/csnc/extension/ui/DriversView.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * 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.
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version
- * by Compass Security AG.
- *
- * As of October 2014 Compass Security AG granted the OWASP ZAP Project
- * permission to redistribute this code under the Apache License, Version 2.0.
- */
-package ch.csnc.extension.ui;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import javax.swing.GroupLayout;
-import javax.swing.JButton;
-import javax.swing.JFileChooser;
-import javax.swing.JLabel;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-import javax.swing.LayoutStyle;
-import javax.swing.SwingConstants;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import org.parosproxy.paros.Constant;
-import org.parosproxy.paros.model.Model;
-import org.parosproxy.paros.view.AbstractFrame;
-import org.zaproxy.zap.utils.ZapTextField;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class DriversView extends AbstractFrame {
-
- private static final long serialVersionUID = -7502331281272992501L;
-
- private DriverTableModel driverTableModel;
- private JTable driverTable;
-
- private JButton addButton;
- private JButton browseButton;
- private JButton closeButton;
- private JButton deleteButton;
-
- private JScrollPane driverScrollPane;
-
- private JLabel fileLabel;
- private ZapTextField fileTextField;
-
- private JLabel nameLabel;
- private ZapTextField nameTextField;
-
- private JLabel slotLabel;
- private ZapTextField slotTextField;
-
- private JLabel slotListIndexLabel;
- private ZapTextField slotListIndexTextField;
-
- /**
- * Creates new form Drivers
- *
- * @param driverConfig
- */
- public DriversView(ch.csnc.extension.util.DriverConfiguration driverConfig) {
- this.driverTableModel = new DriverTableModel(driverConfig);
- initComponents();
- setVisible(true);
- }
-
- /**
- * This method is called from within the constructor to initialize the form. WARNING: Do NOT
- * modify this code. The content of this method is always regenerated by the Form Editor.
- */
- private void initComponents() {
- fileLabel = new JLabel();
- fileTextField = new ZapTextField();
- browseButton = new JButton();
- nameLabel = new JLabel();
- nameTextField = new ZapTextField();
- slotLabel = new JLabel();
- slotTextField = new ZapTextField();
- slotListIndexLabel = new JLabel();
- slotListIndexTextField = new ZapTextField();
- addButton = new JButton();
- deleteButton = new JButton();
- closeButton = new JButton();
- driverScrollPane = new JScrollPane();
- driverTable = new JTable();
-
- setTitle(Constant.messages.getString("certificates.pkcs11.drivers.title"));
- fileLabel.setText(Constant.messages.getString("certificates.pkcs11.drivers.label.path"));
-
- browseButton.setText(
- Constant.messages.getString("certificates.pkcs11.drivers.button.browse"));
- browseButton.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent evt) {
- browseButtonActionPerformed(evt);
- }
- });
-
- nameLabel.setText(Constant.messages.getString("certificates.pkcs11.drivers.label.name"));
-
- slotLabel.setText(Constant.messages.getString("certificates.pkcs11.drivers.label.slot"));
-
- slotListIndexLabel.setText(
- Constant.messages.getString("certificates.pkcs11.drivers.label.slotIndex"));
-
- addButton.setText(Constant.messages.getString("certificates.pkcs11.drivers.button.add"));
- addButton.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent evt) {
- addButtonActionPerformed(evt);
- }
- });
-
- deleteButton.setText(
- Constant.messages.getString("certificates.pkcs11.drivers.button.delete"));
- deleteButton.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent evt) {
- deleteButtonActionPerformed(evt);
- }
- });
-
- closeButton.setText(
- Constant.messages.getString("certificates.pkcs11.drivers.button.close"));
- closeButton.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent evt) {
- closeButtonActionPerformed(evt);
- }
- });
-
- driverTable.setModel(driverTableModel);
- driverScrollPane.setViewportView(driverTable);
-
- // When experimental SlotListIndex support is used, the slotTextField is disabled (and vice
- // versa),
- // as only one of these parameters is actually used.
- if (!Model.getSingleton()
- .getOptionsParam()
- .getExperimentalFeaturesParam()
- .isExperimentalSliSupportEnabled()) {
- slotTextField.setEnabled(false);
- }
-
- final GroupLayout layout = new GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.LEADING)
- .addComponent(fileLabel)
- .addComponent(nameLabel)
- .addComponent(slotLabel)
- .addComponent(slotListIndexLabel)
- .addGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout
- .Alignment
- .TRAILING,
- false)
- .addComponent(
- nameTextField,
- GroupLayout
- .Alignment
- .LEADING)
- .addComponent(
- slotTextField,
- GroupLayout
- .Alignment
- .LEADING)
- .addComponent(
- slotListIndexTextField,
- GroupLayout
- .Alignment
- .LEADING)
- .addComponent(
- fileTextField,
- GroupLayout
- .Alignment
- .LEADING,
- GroupLayout
- .DEFAULT_SIZE,
- 322,
- Short
- .MAX_VALUE))
- .addPreferredGap(
- LayoutStyle
- .ComponentPlacement
- .RELATED)
- .addGroup(
- layout.createParallelGroup(
- GroupLayout
- .Alignment
- .LEADING)
- .addComponent(
- addButton,
- GroupLayout
- .DEFAULT_SIZE,
- 80,
- Short
- .MAX_VALUE)
- .addComponent(
- browseButton))))
- .addContainerGap(165, Short.MAX_VALUE))
- .addGroup(
- GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addGap(499, 499, 499)
- .addComponent(
- closeButton,
- GroupLayout.DEFAULT_SIZE,
- 74,
- Short.MAX_VALUE)
- .addContainerGap())
- .addGroup(
- layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(
- driverScrollPane,
- GroupLayout.DEFAULT_SIZE,
- 561,
- Short.MAX_VALUE)
- .addContainerGap())
- .addGroup(
- GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addContainerGap(499, Short.MAX_VALUE)
- .addComponent(deleteButton)
- .addContainerGap()));
- layout.setVerticalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(
- GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(fileLabel)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.LEADING,
- false)
- .addComponent(
- browseButton, 0, 0, Short.MAX_VALUE)
- .addComponent(fileTextField))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(nameLabel)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.BASELINE)
- .addComponent(
- nameTextField,
- GroupLayout.PREFERRED_SIZE,
- GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(slotLabel)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.BASELINE)
- .addComponent(
- slotTextField,
- GroupLayout.PREFERRED_SIZE,
- GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE))
- .addGap(28, 28, 28)
- .addComponent(slotListIndexLabel)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.BASELINE)
- .addComponent(
- slotListIndexTextField,
- GroupLayout.PREFERRED_SIZE,
- GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE)
- .addComponent(
- addButton,
- GroupLayout.PREFERRED_SIZE,
- 19,
- GroupLayout.PREFERRED_SIZE))
- .addGap(28, 28, 28)
- .addComponent(
- driverScrollPane,
- GroupLayout.PREFERRED_SIZE,
- 195,
- GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(deleteButton)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED,
- 9,
- Short.MAX_VALUE)
- .addComponent(
- closeButton,
- GroupLayout.PREFERRED_SIZE,
- 10,
- GroupLayout.PREFERRED_SIZE)
- .addContainerGap()));
-
- layout.linkSize(
- SwingConstants.VERTICAL,
- new Component[] {
- addButton, browseButton, closeButton, deleteButton, fileTextField, nameTextField
- });
-
- for (int i = 0; i < driverTableModel.getColumnCount(); i++) {
- driverTable
- .getColumnModel()
- .getColumn(i)
- .setPreferredWidth(driverTableModel.getPreferredWith(i));
- }
-
- pack();
- }
-
- private void browseButtonActionPerformed(ActionEvent evt) {
- final JFileChooser fc = new JFileChooser();
- // TODO Support so and dynlib files as well
- fc.setFileFilter(new FileNameExtensionFilter("DLL/dylib", "dll", "dylib"));
-
- final int state = fc.showOpenDialog(null);
-
- if (state == JFileChooser.APPROVE_OPTION) {
- fileTextField.setText(fc.getSelectedFile().toString());
- }
- }
-
- private void addButtonActionPerformed(ActionEvent evt) {
- final String name = nameTextField.getText();
- final String file = fileTextField.getText();
- int slot = -1;
- int slotListindex = -1;
- try {
- slot = Integer.parseInt(slotTextField.getText());
- } catch (final Exception e) {
- slotTextField.setText("0");
- }
- try {
- slotListindex = Integer.parseInt(slotListIndexTextField.getText());
- } catch (final Exception e) {
- slotListIndexTextField.setText("0");
- }
-
- if (name != null
- && name.trim().length() > 0
- && file != null
- && file.trim().length() > 0
- && slot > -1
- && slotListindex > -1) {
- driverTableModel.addDriver(name, file, slot, slotListindex);
-
- nameTextField.setText("");
- fileTextField.setText("");
- slotTextField.setText("0");
- slotListIndexTextField.setText("0");
- }
- }
-
- private void deleteButtonActionPerformed(ActionEvent evt) {
- final int selrow = driverTable.getSelectedRow();
- if (selrow > -1) {
- driverTableModel.deleteDriver(selrow);
-
- nameTextField.setText("");
- fileTextField.setText("");
- slotTextField.setText("0");
- slotListIndexTextField.setText("0");
- }
- }
-
- private void closeButtonActionPerformed(ActionEvent evt) {
- setVisible(false);
- dispose();
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/util/DriverConfiguration.java b/zap/src/main/java/ch/csnc/extension/util/DriverConfiguration.java
deleted file mode 100644
index 3cbee2502e6..00000000000
--- a/zap/src/main/java/ch/csnc/extension/util/DriverConfiguration.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * 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.
- *
- * Please note that this file was originally released under the
- * GNU General Public License as published by the Free Software Foundation;
- * either version 2 of the License, or (at your option) any later version
- * by Compass Security AG.
- *
- * As of October 2014 Compass Security AG granted the OWASP ZAP Project
- * permission to redistribute this code under the Apache License, Version 2.0.
- */
-package ch.csnc.extension.util;
-
-import java.io.File;
-import java.net.URL;
-import java.util.List;
-import java.util.Vector;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-import javax.swing.event.EventListenerList;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.zaproxy.zap.utils.ZapXmlConfiguration;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class DriverConfiguration {
- private File file = null;
- private URL url;
-
- private Vector names;
- private Vector paths;
- private Vector slots;
- private Vector slotListIndexes;
-
- private final Logger logger = LogManager.getLogger(this.getClass());
-
- private EventListenerList eventListeners = new EventListenerList();
- private ChangeEvent changeEvent;
-
- public DriverConfiguration(URL url) {
- this.url = url;
- load();
- }
-
- public DriverConfiguration(File file) {
- this.file = file;
- load();
- }
-
- private void load() {
- names = new Vector<>();
- paths = new Vector<>();
- slots = new Vector<>();
- slotListIndexes = new Vector<>();
-
- try {
- ZapXmlConfiguration configuration =
- file != null ? new ZapXmlConfiguration(file) : new ZapXmlConfiguration(url);
- List drivers = configuration.configurationsAt("driver");
- for (HierarchicalConfiguration driver : drivers) {
- names.add(driver.getString("name", ""));
- paths.add(driver.getString("path", ""));
- slots.add(getInt(driver.getString("slot")));
- slotListIndexes.add(getInt(driver.getString("slotListIndex")));
- }
-
- } catch (ConfigurationException e) {
- logger.error("Failed to read the configuration from " + (file != null ? file : url), e);
- }
- }
-
- /**
- * Gets an integer from the given string.
- *
- *
If the given string is {@code null} or does not have an integer, zero is returned.
- *
- * @param string the string with the integer value
- * @return an integer
- */
- private int getInt(String string) {
- if (string != null) {
- try {
- return Integer.parseInt(string);
- } catch (NumberFormatException e) {
- logger.error("Failed to extract an integer from: " + string);
- }
- }
- return 0;
- }
-
- public void write() {
- if (file == null) {
- fireStateChanged();
- return;
- }
-
- ZapXmlConfiguration configuration = new ZapXmlConfiguration();
- configuration.setRootElementName("driverConfiguration");
-
- for (int i = 0; i < names.size(); i++) {
- String baseKey = "driver(" + i + ").";
- configuration.setProperty(baseKey + "name", names.get(i));
- configuration.setProperty(baseKey + "path", paths.get(i));
- configuration.setProperty(baseKey + "slot", slots.get(i).toString());
- configuration.setProperty(baseKey + "slotListIndex", slotListIndexes.get(i).toString());
- }
-
- try {
- configuration.save(file);
- } catch (ConfigurationException e) {
- logger.error("Failed to save driver configuration to " + file, e);
- }
-
- fireStateChanged();
- }
-
- private void fireStateChanged() {
- Object[] listeners = eventListeners.getListenerList();
- for (int i = listeners.length - 2; i >= 0; i -= 2) {
- if (listeners[i] == ChangeListener.class) {
- if (changeEvent == null) {
- changeEvent = new ChangeEvent(this);
- }
- ((ChangeListener) listeners[i + 1]).stateChanged(changeEvent);
- }
- }
- }
-
- public Vector getNames() {
- return names;
- }
-
- public void setNames(Vector names) {
- this.names = names;
- }
-
- public Vector getPaths() {
- return paths;
- }
-
- public void setPaths(Vector paths) {
- this.paths = paths;
- }
-
- public Vector getSlots() {
- return slots;
- }
-
- public void setSlots(Vector slots) {
- this.slots = slots;
- }
-
- public Vector getSlotIndexes() {
- return slotListIndexes;
- }
-
- public void setSlotListIndexes(Vector slotListIndexes) {
- this.slotListIndexes = slotListIndexes;
- }
-
- public void addChangeListener(ChangeListener listener) {
- eventListeners.add(ChangeListener.class, listener);
- }
-
- public void removeChangeListener(ChangeListener listener) {
- eventListeners.remove(ChangeListener.class, listener);
- }
-}
diff --git a/zap/src/main/java/ch/csnc/extension/util/OptionsParamExperimentalSliSupport.java b/zap/src/main/java/ch/csnc/extension/util/OptionsParamExperimentalSliSupport.java
deleted file mode 100644
index a5221e6a4d0..00000000000
--- a/zap/src/main/java/ch/csnc/extension/util/OptionsParamExperimentalSliSupport.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2011 The ZAP Development Team
- *
- * 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 ch.csnc.extension.util;
-
-import org.parosproxy.paros.common.AbstractParam;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class OptionsParamExperimentalSliSupport extends AbstractParam {
-
- public static final String EXPERIMENTAL_SLOT_LIST_INDEXES =
- "certificate.experimentalSlotListIndex";
- private boolean expSliSupportEnabled = false;
-
- public OptionsParamExperimentalSliSupport() {}
-
- @Override
- protected void parse() {
- expSliSupportEnabled = getBoolean(EXPERIMENTAL_SLOT_LIST_INDEXES, false);
- }
-
- /**
- * @deprecated (2.11.0) Use {@link #isExperimentalSliSupportEnabled()}
- */
- @Deprecated
- public boolean isExerimentalSliSupportEnabled() {
- return isExperimentalSliSupportEnabled();
- }
-
- public boolean isExperimentalSliSupportEnabled() {
- return expSliSupportEnabled;
- }
-
- public void setSlotListIndexSupport(boolean expSliSupportEnabled) {
- this.expSliSupportEnabled = expSliSupportEnabled;
- getConfig().setProperty(EXPERIMENTAL_SLOT_LIST_INDEXES, expSliSupportEnabled);
- }
-}
diff --git a/zap/src/main/java/org/parosproxy/paros/extension/option/OptionsCertificatePanel.java b/zap/src/main/java/org/parosproxy/paros/extension/option/OptionsCertificatePanel.java
deleted file mode 100644
index 528ec46be9e..00000000000
--- a/zap/src/main/java/org/parosproxy/paros/extension/option/OptionsCertificatePanel.java
+++ /dev/null
@@ -1,1374 +0,0 @@
-/*
- *
- * Paros and its related class files.
- *
- * Paros is an HTTP/HTTPS proxy for assessing web application security.
- * Copyright (C) 2003-2004 Chinotec Technologies Company
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the Clarified Artistic License
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Clarified Artistic License for more details.
- *
- * You should have received a copy of the Clarified Artistic License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-// ZAP: 2011/04/16 i18n
-// ZAP: 2012/04/25 Added @Override annotation to the appropriate methods.
-// ZAP: 2013/01/23 Clean up of exception handling/logging.
-// ZAP: 2013/03/03 Issue 546: Remove all template Javadoc comments
-// ZAP: 2013/12/03 Issue 933: Automatically determine install dir
-// ZAP: 2014/03/23 Issue 412: Enable unsafe SSL/TLS renegotiation option not saved
-// ZAP: 2014/08/14 Issue 1184: Improve support for IBM JDK
-// ZAP: 2016/06/28: File chooser for PKCS#12 files now also accepts .pfx files
-// ZAP: 2017/01/09 Remove method no longer needed.
-// ZAP: 2017/01/23 Select first alias of selected keystore
-// ZAP: 2017/08/16 Tidy up usage of CertificateView.
-// ZAP: 2017/08/16 Show error message if failed to activate the certificate.
-// ZAP: 2017/08/17 Reduce code duplication when showing cert/keystore errors
-// ZAP: 2017/12/12 Use first alias by default (Issue 3879).
-// ZAP: 2017/12/13 Do not allow to edit the name/key of active cert.
-// ZAP: 2018/02/14 Remove unnecessary boxing / unboxing
-// ZAP: 2018/03/29 Use FileNameExtensionFilter.
-// ZAP: 2018/07/12 Fallback to bundled drivers.xml file.
-// ZAP: 2018/09/19 GUI support for setting client certificate from CLI
-// ZAP: 2019/06/01 Normalise line endings.
-// ZAP: 2019/06/05 Normalise format/style.
-// ZAP: 2020/11/26 Use Log4j 2 classes for logging.
-// ZAP: 2022/05/21 Remove unsafe SSL/TLS renegotiation option.
-// ZAP: 2022/05/29 Deprecate the class.
-// ZAP: 2022/08/05 Address warns with Java 18 (Issue 7389).
-// ZAP: 2022/09/21 Use format specifiers instead of concatenation when logging.
-package org.parosproxy.paros.extension.option;
-
-// TODO: Buttons should be gray
-import java.awt.CardLayout;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.security.KeyStoreException;
-import java.security.ProviderException;
-import java.security.cert.Certificate;
-import javax.swing.DefaultListModel;
-import javax.swing.JDialog;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JPasswordField;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.jdesktop.swingx.JXHyperlink;
-import org.parosproxy.paros.Constant;
-import org.parosproxy.paros.model.Model;
-import org.parosproxy.paros.model.OptionsParam;
-import org.parosproxy.paros.view.AbstractParamPanel;
-import org.zaproxy.zap.utils.ZapTextField;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-@SuppressWarnings("serial")
-public class OptionsCertificatePanel extends AbstractParamPanel {
-
- private static final long serialVersionUID = 4350957038174673492L;
-
- // Maximum number of login attempts per smartcard
- private static final int MAX_LOGIN_ATTEMPTS = 3;
-
- private javax.swing.JButton addPkcs11Button;
- private javax.swing.JButton addPkcs12Button;
- private javax.swing.JScrollPane aliasScrollPane;
- private javax.swing.JTable aliasTable;
- private javax.swing.JButton browseButton;
- private javax.swing.JLabel certificateLabel;
- private javax.swing.JPanel certificatePanel;
- private ZapTextField certificateTextField;
- private javax.swing.JTabbedPane certificatejTabbedPane;
- private javax.swing.JButton deleteButton;
- private javax.swing.JButton driverButton;
- private javax.swing.JComboBox driverComboBox;
- private javax.swing.JLabel driverLabel;
- private javax.swing.JLabel fileLabel;
- private ZapTextField fileTextField;
- private javax.swing.JList keyStoreList;
- private javax.swing.JPanel keyStorePanel;
- private javax.swing.JScrollPane keyStoreScrollPane;
- private javax.swing.JLabel passwordPkcs11Label;
- private javax.swing.JLabel passwordPkcs12Label;
- private javax.swing.JPanel pkcs11Panel;
- private javax.swing.JPasswordField pkcs11PasswordField;
- private javax.swing.JPanel pkcs12Panel;
- private javax.swing.JPasswordField pkcs12PasswordField;
- private javax.swing.JButton setActiveButton;
- private javax.swing.JButton showActiveCertificateButton;
- private javax.swing.JButton showAliasButton;
- private javax.swing.JLabel textLabel;
- private javax.swing.JCheckBox useClientCertificateCheckBox;
- private javax.swing.JCheckBox usePkcs11ExperimentalSliSupportCheckBox;
-
- private ch.csnc.extension.httpclient.SSLContextManager contextManager;
- private DefaultListModel keyStoreListModel;
- private ch.csnc.extension.ui.AliasTableModel aliasTableModel;
- private ch.csnc.extension.util.DriverConfiguration driverConfig;
-
- // Issue 182
- private boolean retry = true;
- // Used if certificate is set from commandline
- private boolean overrideEnableClientCertificate = false;
-
- // Keep track of login attempts on PKCS11 smartcards to avoid blocking the smartcard
- private static int login_attempts = 0;
-
- private static final Logger logger = LogManager.getLogger(OptionsCertificatePanel.class);
-
- public OptionsCertificatePanel() {
- super();
- initialize();
- }
-
- /** This method initializes this */
- private void initialize() {
-
- contextManager =
- Model.getSingleton().getOptionsParam().getCertificateParam().getSSLContextManager();
-
- keyStoreListModel = new DefaultListModel<>();
- aliasTableModel = new ch.csnc.extension.ui.AliasTableModel(contextManager);
-
- this.setLayout(new CardLayout());
- this.setName(Constant.messages.getString("options.cert.title"));
-
- JPanel certificatePanel = getPanelCertificate();
- this.add(certificatePanel, certificatePanel.getName());
-
- driverConfig = createDriverConfiguration();
- updateDriverComboBox();
- driverConfig.addChangeListener(e -> updateDriverComboBox());
-
- Certificate cert = contextManager.getDefaultCertificate();
- if (cert != null) {
- certificateTextField.setText(cert.toString());
- }
-
- if (contextManager.getKeyStoreCount() != 0) {
- overrideEnableClientCertificate = true;
- }
- }
-
- private static ch.csnc.extension.util.DriverConfiguration createDriverConfiguration() {
- String fileName = "drivers.xml";
- Path path = Paths.get(Constant.getZapInstall(), "xml", fileName);
- if (Files.exists(path)) {
- return new ch.csnc.extension.util.DriverConfiguration(path.toFile());
- }
- return new ch.csnc.extension.util.DriverConfiguration(
- OptionsCertificatePanel.class.getResource(
- "/org/zaproxy/zap/resources/" + fileName));
- }
-
- private void updateDriverComboBox() {
- driverComboBox.removeAllItems();
- for (String name : driverConfig.getNames()) {
- driverComboBox.addItem(name);
- }
- driverComboBox.repaint();
- }
-
- /**
- * This method initializes panelCertificate
- *
- * @return javax.swing.JPanel
- */
- private JPanel getPanelCertificate() {
- if (certificatePanel == null) {
-
- // **************************************************************************
- // begin netbeans code
- // **************************************************************************
- certificatePanel = new javax.swing.JPanel();
- certificatejTabbedPane = new javax.swing.JTabbedPane();
- keyStorePanel = new javax.swing.JPanel();
- setActiveButton = new javax.swing.JButton();
- showAliasButton = new javax.swing.JButton();
- aliasScrollPane = new javax.swing.JScrollPane();
- aliasTable = new javax.swing.JTable();
- deleteButton = new javax.swing.JButton();
- keyStoreScrollPane = new javax.swing.JScrollPane();
- keyStoreList = new javax.swing.JList<>();
- pkcs12Panel = new javax.swing.JPanel();
- fileLabel = new javax.swing.JLabel();
- fileTextField = new ZapTextField();
- browseButton = new javax.swing.JButton();
- passwordPkcs12Label = new javax.swing.JLabel();
- addPkcs12Button = new javax.swing.JButton();
- pkcs12PasswordField = new javax.swing.JPasswordField();
- pkcs11Panel = new javax.swing.JPanel();
- driverLabel = new javax.swing.JLabel();
- driverComboBox = new javax.swing.JComboBox<>();
- driverButton = new javax.swing.JButton();
- passwordPkcs11Label = new javax.swing.JLabel();
- addPkcs11Button = new javax.swing.JButton();
- pkcs11PasswordField = new javax.swing.JPasswordField();
- useClientCertificateCheckBox = new javax.swing.JCheckBox();
- textLabel = new javax.swing.JLabel();
- certificateLabel = new javax.swing.JLabel();
- certificateTextField = new ZapTextField();
- showActiveCertificateButton = new javax.swing.JButton();
- usePkcs11ExperimentalSliSupportCheckBox = new javax.swing.JCheckBox();
-
- certificatejTabbedPane.setEnabled(false);
-
- setActiveButton.setText(Constant.messages.getString("options.cert.button.setactive"));
- setActiveButton.setEnabled(false);
- setActiveButton.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- try {
- setActiveButtonActionPerformed(evt);
- } catch (ProviderException e) {
- showKeyStoreCertError(e.toString());
- logger.error(e.getMessage(), e);
- }
- }
- });
-
- showAliasButton.setText("->");
- showAliasButton.setEnabled(false);
- showAliasButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
- showAliasButton.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- showAliasButtonActionPerformed(evt);
- }
- });
-
- aliasTable.setModel(aliasTableModel);
- aliasTable.setTableHeader(null);
- aliasScrollPane.setViewportView(aliasTable);
-
- deleteButton.setText(Constant.messages.getString("options.cert.button.delete"));
- deleteButton.setEnabled(false);
- deleteButton.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- deleteButtonActionPerformed(evt);
- }
- });
-
- keyStoreList.setModel(keyStoreListModel);
- keyStoreList.addListSelectionListener(
- new ListSelectionListener() {
-
- @Override
- public void valueChanged(ListSelectionEvent evt) {
- keyStoreListSelectionChanged();
- }
- });
- keyStoreScrollPane.setViewportView(keyStoreList);
-
- javax.swing.GroupLayout keyStorePanelLayout =
- new javax.swing.GroupLayout(keyStorePanel);
- keyStorePanel.setLayout(keyStorePanelLayout);
- keyStorePanelLayout.setHorizontalGroup(
- keyStorePanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- keyStorePanelLayout
- .createSequentialGroup()
- .addGroup(
- keyStorePanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.LEADING)
- .addComponent(deleteButton)
- .addComponent(
- keyStoreScrollPane,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- 181,
- Short.MAX_VALUE))
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addGroup(
- keyStorePanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.LEADING)
- .addGroup(
- keyStorePanelLayout
- .createSequentialGroup()
- .addComponent(
- setActiveButton)
- .addPreferredGap(
- javax.swing
- .LayoutStyle
- .ComponentPlacement
- .RELATED,
- 100,
- Short.MAX_VALUE)
- .addComponent(
- showAliasButton))
- .addComponent(
- aliasScrollPane,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- 202,
- Short.MAX_VALUE))));
- keyStorePanelLayout.setVerticalGroup(
- keyStorePanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- keyStorePanelLayout
- .createSequentialGroup()
- .addGroup(
- keyStorePanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.LEADING)
- .addComponent(
- aliasScrollPane,
- 0,
- 0,
- Short.MAX_VALUE)
- .addComponent(
- keyStoreScrollPane,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- 95,
- Short.MAX_VALUE))
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addGroup(
- keyStorePanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.BASELINE)
- .addComponent(deleteButton)
- .addComponent(
- setActiveButton,
- javax.swing.GroupLayout
- .PREFERRED_SIZE,
- 18,
- javax.swing.GroupLayout
- .PREFERRED_SIZE)
- .addComponent(showAliasButton))));
-
- keyStorePanelLayout.linkSize(
- javax.swing.SwingConstants.VERTICAL,
- new java.awt.Component[] {deleteButton, setActiveButton, showAliasButton});
-
- certificatejTabbedPane.addTab(
- Constant.messages.getString("options.cert.tab.keystore"), keyStorePanel);
-
- fileLabel.setText(Constant.messages.getString("options.cert.label.file"));
-
- browseButton.setText(Constant.messages.getString("options.cert.button.browse"));
- browseButton.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- browseButtonActionPerformed(evt);
- }
- });
-
- passwordPkcs12Label.setText(Constant.messages.getString("options.cert.label.password"));
-
- addPkcs12Button.setText(Constant.messages.getString("options.cert.button.keystore"));
- addPkcs12Button.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addPkcs12ButtonActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout pkcs12PanelLayout = new javax.swing.GroupLayout(pkcs12Panel);
- pkcs12Panel.setLayout(pkcs12PanelLayout);
- pkcs12PanelLayout.setHorizontalGroup(
- pkcs12PanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- pkcs12PanelLayout
- .createSequentialGroup()
- .addGroup(
- pkcs12PanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.LEADING)
- .addGroup(
- javax.swing.GroupLayout
- .Alignment.TRAILING,
- pkcs12PanelLayout
- .createSequentialGroup()
- .addContainerGap()
- .addComponent(
- fileTextField,
- javax.swing
- .GroupLayout
- .DEFAULT_SIZE,
- 296,
- Short.MAX_VALUE)
- .addPreferredGap(
- javax.swing
- .LayoutStyle
- .ComponentPlacement
- .RELATED)
- .addComponent(
- browseButton))
- .addGroup(
- pkcs12PanelLayout
- .createSequentialGroup()
- .addGap(12, 12, 12)
- .addComponent(
- fileLabel))
- .addGroup(
- pkcs12PanelLayout
- .createSequentialGroup()
- .addContainerGap()
- .addComponent(
- passwordPkcs12Label))
- .addGroup(
- javax.swing.GroupLayout
- .Alignment.TRAILING,
- pkcs12PanelLayout
- .createSequentialGroup()
- .addContainerGap(
- 270,
- Short.MAX_VALUE)
- .addComponent(
- addPkcs12Button))
- .addGroup(
- pkcs12PanelLayout
- .createSequentialGroup()
- .addContainerGap()
- .addComponent(
- pkcs12PasswordField,
- javax.swing
- .GroupLayout
- .DEFAULT_SIZE,
- 369,
- Short
- .MAX_VALUE)))
- .addContainerGap()));
- pkcs12PanelLayout.setVerticalGroup(
- pkcs12PanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- pkcs12PanelLayout
- .createSequentialGroup()
- .addComponent(fileLabel)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addGroup(
- pkcs12PanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.BASELINE)
- .addComponent(browseButton)
- .addComponent(
- fileTextField,
- javax.swing.GroupLayout
- .PREFERRED_SIZE,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- javax.swing.GroupLayout
- .PREFERRED_SIZE))
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(passwordPkcs12Label)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(
- pkcs12PasswordField,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(addPkcs12Button)
- .addGap(70, 70, 70)));
-
- pkcs12PanelLayout.linkSize(
- javax.swing.SwingConstants.VERTICAL,
- new java.awt.Component[] {
- addPkcs12Button, browseButton, fileTextField, pkcs12PasswordField
- });
-
- certificatejTabbedPane.addTab(
- Constant.messages.getString("options.cert.tab.pkcs"), pkcs12Panel);
-
- driverLabel.setText(Constant.messages.getString("options.cert.label.driver"));
-
- driverButton.setText("...");
- driverButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
- driverButton.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- driverButtonActionPerformed(evt);
- }
- });
-
- passwordPkcs11Label.setText(Constant.messages.getString("options.cert.label.pincode"));
-
- addPkcs11Button.setText(Constant.messages.getString("options.cert.button.pkcs11"));
- addPkcs11Button.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- addPkcs11ButtonActionPerformed(evt);
- }
- });
-
- usePkcs11ExperimentalSliSupportCheckBox.setText(
- Constant.messages.getString(
- "certificates.pkcs11.label.experimentalSliSupport"));
- usePkcs11ExperimentalSliSupportCheckBox.setBorder(
- javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- usePkcs11ExperimentalSliSupportCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
- usePkcs11ExperimentalSliSupportCheckBox.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- usePkcs11ExperimentalSliSupportCheckBoxActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout pkcs11PanelLayout = new javax.swing.GroupLayout(pkcs11Panel);
- pkcs11Panel.setLayout(pkcs11PanelLayout);
- pkcs11PanelLayout.setHorizontalGroup(
- pkcs11PanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- pkcs11PanelLayout
- .createSequentialGroup()
- .addContainerGap()
- .addGroup(
- pkcs11PanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.LEADING)
- .addComponent(
- pkcs11PasswordField,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- 369,
- Short.MAX_VALUE)
- .addComponent(driverLabel)
- .addComponent(passwordPkcs11Label)
- .addGroup(
- pkcs11PanelLayout
- .createSequentialGroup()
- .addComponent(
- driverComboBox,
- 0,
- 336,
- Short.MAX_VALUE)
- .addPreferredGap(
- javax.swing
- .LayoutStyle
- .ComponentPlacement
- .RELATED)
- .addComponent(
- driverButton))
- .addComponent(
- usePkcs11ExperimentalSliSupportCheckBox)
- .addComponent(
- addPkcs11Button,
- javax.swing.GroupLayout
- .Alignment.TRAILING))
- .addContainerGap()));
- pkcs11PanelLayout.setVerticalGroup(
- pkcs11PanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- pkcs11PanelLayout
- .createSequentialGroup()
- .addComponent(driverLabel)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addGroup(
- pkcs11PanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.BASELINE)
- .addComponent(driverButton)
- .addComponent(
- driverComboBox,
- javax.swing.GroupLayout
- .PREFERRED_SIZE,
- 17,
- javax.swing.GroupLayout
- .PREFERRED_SIZE))
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(passwordPkcs11Label)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(
- pkcs11PasswordField,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(usePkcs11ExperimentalSliSupportCheckBox)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(addPkcs11Button)
- .addGap(58, 58, 58)));
-
- pkcs11PanelLayout.linkSize(
- javax.swing.SwingConstants.VERTICAL,
- new java.awt.Component[] {
- addPkcs11Button, driverButton, driverComboBox, pkcs11PasswordField
- });
-
- certificatejTabbedPane.addTab(
- Constant.messages.getString("options.cert.tab.pkcs11"), pkcs11Panel);
-
- useClientCertificateCheckBox.setText(
- Constant.messages.getString("options.cert.label.useclientcert"));
- useClientCertificateCheckBox.setBorder(
- javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
- useClientCertificateCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
- useClientCertificateCheckBox.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- useClientCertificateCheckBoxActionPerformed(evt);
- }
- });
-
- textLabel.setText(Constant.messages.getString("options.cert.label.addkeystore"));
-
- certificateLabel.setText(Constant.messages.getString("options.cert.label.activecerts"));
-
- certificateTextField.setEnabled(false);
- certificateTextField.setEditable(false);
-
- showActiveCertificateButton.setText("->");
- showActiveCertificateButton.setActionCommand(">");
- showActiveCertificateButton.setEnabled(false);
- showActiveCertificateButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
- showActiveCertificateButton.addActionListener(
- new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- showActiveCertificateButtonActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout certificatePanelLayout =
- new javax.swing.GroupLayout(certificatePanel);
- certificatePanel.setLayout(certificatePanelLayout);
- certificatePanelLayout.setHorizontalGroup(
- certificatePanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- certificatePanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- certificatePanelLayout
- .createSequentialGroup()
- .addComponent(
- textLabel,
- 0,
- 0,
- Short.MAX_VALUE)
- .addContainerGap())
- .addGroup(
- certificatePanelLayout
- .createSequentialGroup()
- .addGap(2, 2, 2)
- .addGroup(
- certificatePanelLayout
- .createParallelGroup(
- javax.swing
- .GroupLayout
- .Alignment
- .LEADING)
- .addComponent(
- certificatejTabbedPane,
- javax.swing
- .GroupLayout
- .DEFAULT_SIZE,
- 394,
- Short.MAX_VALUE)
- .addGroup(
- certificatePanelLayout
- .createSequentialGroup()
- .addGroup(
- certificatePanelLayout
- .createParallelGroup(
- javax
- .swing
- .GroupLayout
- .Alignment
- .LEADING)
- .addComponent(
- useClientCertificateCheckBox)
- .addComponent(
- certificateLabel)
- .addGroup(
- javax
- .swing
- .GroupLayout
- .Alignment
- .TRAILING,
- certificatePanelLayout
- .createSequentialGroup()
- .addComponent(
- certificateTextField,
- javax
- .swing
- .GroupLayout
- .DEFAULT_SIZE,
- 363,
- Short
- .MAX_VALUE)
- .addPreferredGap(
- javax
- .swing
- .LayoutStyle
- .ComponentPlacement
- .UNRELATED)
- .addComponent(
- showActiveCertificateButton)
- .addPreferredGap(
- javax
- .swing
- .LayoutStyle
- .ComponentPlacement
- .RELATED)))
- .addContainerGap())))));
- certificatePanelLayout.setVerticalGroup(
- certificatePanelLayout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- certificatePanelLayout
- .createSequentialGroup()
- .addContainerGap()
- .addComponent(textLabel)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .UNRELATED)
- .addComponent(useClientCertificateCheckBox)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(
- certificatejTabbedPane,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 152,
- Short.MAX_VALUE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addComponent(certificateLabel)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement
- .RELATED)
- .addGroup(
- certificatePanelLayout
- .createParallelGroup(
- javax.swing.GroupLayout
- .Alignment.BASELINE)
- .addComponent(
- certificateTextField,
- javax.swing.GroupLayout
- .PREFERRED_SIZE,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- javax.swing.GroupLayout
- .PREFERRED_SIZE)
- .addComponent(
- showActiveCertificateButton,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- javax.swing.GroupLayout
- .DEFAULT_SIZE,
- Short.MAX_VALUE))
- .addContainerGap()));
-
- certificatePanelLayout.linkSize(
- javax.swing.SwingConstants.VERTICAL,
- new java.awt.Component[] {certificateTextField, showActiveCertificateButton});
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(
- certificatePanel,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE));
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addComponent(
- certificatePanel,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE)
- .addContainerGap()));
-
- // **************************************************************************
- // end netbeans code
- // **************************************************************************
- }
- return certificatePanel;
- }
-
- private static void showKeyStoreCertError(String errorMessage) {
- showCertError("options.cert.error.accesskeystore", errorMessage);
- }
-
- private static void showCertError(String i18nKeyBaseMessage, String errorMessage) {
- JOptionPane.showMessageDialog(
- null,
- new String[] {Constant.messages.getString(i18nKeyBaseMessage), errorMessage},
- Constant.messages.getString("options.cert.error"),
- JOptionPane.ERROR_MESSAGE);
- }
-
- private void keyStoreListSelectionChanged() {
- int keystore = keyStoreList.getSelectedIndex();
- try {
- aliasTableModel.setKeystore(keystore);
- } catch (Exception e) {
- showKeyStoreCertError(e.toString());
- logger.error(e.getMessage(), e);
- }
- }
-
- private void showActiveCertificateButtonActionPerformed(
- java.awt.event.ActionEvent
- evt) { // GEN-FIRST:event_showActiveCertificateButtonActionPerformed
- Certificate cert = contextManager.getDefaultCertificate();
- if (cert != null) {
- showCertificate(cert);
- }
- } // GEN-LAST:event_showActiveCertificateButtonActionPerformed
-
- private void addPkcs11ButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addPkcs11ButtonActionPerformed
- String name = null;
- try {
- final int indexSelectedDriver = driverComboBox.getSelectedIndex();
- name = driverConfig.getNames().get(indexSelectedDriver);
- if (name.equals("")) {
- return;
- }
-
- String library = driverConfig.getPaths().get(indexSelectedDriver);
- if (library.equals("")) {
- return;
- }
-
- int slot = driverConfig.getSlots().get(indexSelectedDriver);
- if (slot < 0) {
- return;
- }
-
- int slotListIndex = driverConfig.getSlotIndexes().get(indexSelectedDriver);
- if (slotListIndex < 0) {
- return;
- }
-
- String kspass = new String(pkcs11PasswordField.getPassword());
- if (kspass.equals("")) {
- kspass = null;
- }
-
- ch.csnc.extension.httpclient.PKCS11Configuration.PCKS11ConfigurationBuilder
- confBuilder = ch.csnc.extension.httpclient.PKCS11Configuration.builder();
- confBuilder.setName(name).setLibrary(library);
- if (usePkcs11ExperimentalSliSupportCheckBox.isSelected()) {
- confBuilder.setSlotListIndex(slotListIndex);
- } else {
- confBuilder.setSlotId(slot);
- }
-
- int ksIndex = contextManager.initPKCS11(confBuilder.build(), kspass);
-
- if (ksIndex == -1) {
- logger.error(
- "The required PKCS#11 provider is not available ("
- + ch.csnc.extension.httpclient.SSLContextManager
- .SUN_PKCS11_CANONICAL_CLASS_NAME
- + " or "
- + ch.csnc.extension.httpclient.SSLContextManager
- .IBM_PKCS11_CANONICAL_CLASS_NAME
- + ").");
- showErrorMessageSunPkcs11ProviderNotAvailable();
- return;
- }
-
- // The PCKS11 driver/smartcard was initialized properly: reset login attempts
- login_attempts = 0;
- keyStoreListModel.insertElementAt(
- contextManager.getKeyStoreDescription(ksIndex), ksIndex);
- // Issue 182
- retry = true;
-
- certificatejTabbedPane.setSelectedIndex(0);
- activateFirstOnlyAliasOfKeyStore(ksIndex);
-
- driverComboBox.setSelectedIndex(-1);
- pkcs11PasswordField.setText("");
-
- } catch (InvocationTargetException e) {
- if (e.getCause() instanceof ProviderException) {
- if ("Error parsing configuration".equals(e.getCause().getMessage())) {
- // There was a problem with the configuration provided:
- // - Missing library.
- // - Malformed configuration.
- // - ...
- logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(false, name, e);
- } else if ("Initialization failed".equals(e.getCause().getMessage())) {
- // The initialisation may fail because of:
- // - no smart card reader or smart card detected.
- // - smart card is in use by other application.
- // - ...
-
- // Issue 182: Try to instantiate the PKCS11 provider twice if there are
- // conflicts with other software (e.g.. Firefox), that is accessing it too.
- if (retry) {
- // Try two times only
- retry = false;
- addPkcs11ButtonActionPerformed(evt);
- } else {
- JOptionPane.showMessageDialog(
- null,
- new String[] {
- Constant.messages.getString("options.cert.error"),
- Constant.messages.getString("options.cert.error.pkcs11")
- },
- Constant.messages.getString("options.cert.label.client.cert"),
- JOptionPane.ERROR_MESSAGE);
- // Error message changed to explain that user should try to add it again...
- retry = true;
- logger.warn("Couldn't add key from {}", name, e);
- }
- } else {
- logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(false, name, e);
- }
- } else {
- logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(false, name, e);
- }
- } catch (java.io.IOException e) {
- if (e.getMessage().equals("load failed")
- && e.getCause()
- .getClass()
- .getName()
- .equals("javax.security.auth.login.FailedLoginException")) {
- // Exception due to a failed login attempt: BAD PIN or password
- login_attempts++;
- String attempts = " (" + login_attempts + "/" + MAX_LOGIN_ATTEMPTS + ") ";
- if (login_attempts == (MAX_LOGIN_ATTEMPTS - 1)) {
- // Last attempt before blocking the smartcard
- JOptionPane.showMessageDialog(
- null,
- new String[] {
- Constant.messages.getString("options.cert.error"),
- Constant.messages.getString("options.cert.error.wrongpassword"),
- Constant.messages.getString("options.cert.error.wrongpasswordlast"),
- attempts
- },
- Constant.messages.getString("options.cert.label.client.cert"),
- JOptionPane.ERROR_MESSAGE);
- logger.warn(
- "PKCS#11: Incorrect PIN or password {}: {} *LAST TRY BEFORE BLOCKING*",
- attempts,
- name);
- } else {
- JOptionPane.showMessageDialog(
- null,
- new String[] {
- Constant.messages.getString("options.cert.error"),
- Constant.messages.getString("options.cert.error.wrongpassword"),
- attempts
- },
- Constant.messages.getString("options.cert.label.client.cert"),
- JOptionPane.ERROR_MESSAGE);
- logger.warn("PKCS#11: Incorrect PIN or password {}:{}", attempts, name);
- }
- } else {
- logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(false, name, e);
- }
- } catch (KeyStoreException e) {
- logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(false, name, e);
- } catch (Exception e) {
- logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(true, name, e);
- }
- } // GEN-LAST:event_addPkcs11ButtonActionPerformed
-
- private void activateFirstOnlyAliasOfKeyStore(int ksIndex) {
- if (ksIndex < 0 || ksIndex >= keyStoreList.getModel().getSize()) {
- return;
- }
-
- keyStoreList.setSelectedIndex(ksIndex);
- if (aliasTable.getRowCount() != 0) {
- aliasTable.setRowSelectionInterval(0, 0);
-
- if (aliasTable.getRowCount() == 1 && !isCertActive()) {
- setActiveAction();
- }
- }
- }
-
- private boolean isCertActive() {
- String currentKey = contextManager.getDefaultKey();
- return currentKey != null && !currentKey.isEmpty();
- }
-
- private void showErrorMessageSunPkcs11ProviderNotAvailable() {
- final String sunReference =
- Constant.messages.getString("options.cert.error.pkcs11notavailable.sun.hyperlink");
- final String ibmReference =
- Constant.messages.getString("options.cert.error.pkcs11notavailable.ibm.hyperlink");
- Object[] hyperlinks = new Object[2];
- try {
- JXHyperlink hyperlinkLabel = new JXHyperlink();
- hyperlinkLabel.setURI(URI.create(sunReference));
- hyperlinkLabel.setText(
- Constant.messages.getString(
- "options.cert.error.pkcs11notavailable.sun.hyperlink.text"));
- hyperlinks[0] = hyperlinkLabel;
-
- hyperlinkLabel = new JXHyperlink();
- hyperlinkLabel.setURI(URI.create(ibmReference));
- hyperlinkLabel.setText(
- Constant.messages.getString(
- "options.cert.error.pkcs11notavailable.ibm.hyperlink.text"));
- hyperlinks[1] = hyperlinkLabel;
- } catch (UnsupportedOperationException e) {
- // Show plain text instead of a hyperlink if the current platform doesn't support
- // Desktop.
- hyperlinks[0] = sunReference;
- hyperlinks[1] = ibmReference;
- }
-
- JOptionPane.showMessageDialog(
- null,
- new Object[] {
- Constant.messages.getString("options.cert.error"),
- Constant.messages.getString("options.cert.error.pkcs11notavailable"),
- hyperlinks
- },
- Constant.messages.getString("options.cert.label.client.cert"),
- JOptionPane.ERROR_MESSAGE);
- }
-
- private void logAndShowGenericErrorMessagePkcs11CouldNotBeAdded(
- boolean isErrorLevel, String name, Exception e) {
- if (pkcs11PasswordField.getPassword().length == 0) {
- JOptionPane.showMessageDialog(
- null,
- new String[] {
- Constant.messages.getString("options.cert.error"),
- Constant.messages.getString("options.cert.error.password.blank")
- },
- Constant.messages.getString("options.cert.label.client.cert"),
- JOptionPane.ERROR_MESSAGE);
- } else {
- JOptionPane.showMessageDialog(
- null,
- new String[] {
- Constant.messages.getString("options.cert.error"),
- Constant.messages.getString("options.cert.error.password")
- },
- Constant.messages.getString("options.cert.label.client.cert"),
- JOptionPane.ERROR_MESSAGE);
- if (isErrorLevel) {
- logger.error("Couldn't add key from {}", name, e);
- } else {
- logger.warn("Couldn't add key from {}", name, e);
- }
- }
- }
-
- private void driverButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_driverButtonActionPerformed
- new JDialog(new ch.csnc.extension.ui.DriversView(driverConfig), true);
- } // GEN-LAST:event_driverButtonActionPerformed
-
- private void addPkcs12ButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addPkcs12ButtonActionPerformed
- if (fileTextField.getText().equals("")) {
- return;
- }
- String kspass = new String(pkcs12PasswordField.getPassword());
- if (kspass.equals("")) {
- // pcks#12 file with empty password is not supported by java
- showCertError(
- "options.cert.error.pkcs12nopass",
- Constant.messages.getString("options.cert.error.usepassfile"));
- return;
- }
-
- int ksIndex;
- try {
- ksIndex = contextManager.loadPKCS12Certificate(fileTextField.getText(), kspass);
- keyStoreListModel.insertElementAt(
- contextManager.getKeyStoreDescription(ksIndex), ksIndex);
- } catch (Exception e) {
- showKeyStoreCertError(Constant.messages.getString("options.cert.error.password"));
- logger.error(e.getMessage(), e);
- return;
- }
-
- certificatejTabbedPane.setSelectedIndex(0);
- activateFirstOnlyAliasOfKeyStore(ksIndex);
-
- fileTextField.setText("");
- pkcs12PasswordField.setText("");
- } // GEN-LAST:event_addPkcs12ButtonActionPerformed
-
- private void browseButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_browseButtonActionPerformed
- JFileChooser fc = new JFileChooser();
- fc.setFileFilter(
- new FileNameExtensionFilter(
- Constant.messages.getString("options.cert.label.client.cert")
- + " (*.p12, *.pfx)",
- "p12",
- "pfx"));
-
- int state = fc.showOpenDialog(null);
-
- if (state == JFileChooser.APPROVE_OPTION) {
- fileTextField.setText(fc.getSelectedFile().toString());
- }
- } // GEN-LAST:event_browseButtonActionPerformed
-
- private void showAliasButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_showAliasButtonActionPerformed
- int keystore = keyStoreList.getSelectedIndex();
- if (keystore >= 0) {
- int alias = aliasTable.getSelectedRow();
- Certificate cert = contextManager.getCertificate(keystore, alias);
- if (cert != null) {
- showCertificate(cert);
- }
- }
- } // GEN-LAST:event_showAliasButtonActionPerformed
-
- /**
- * Shows a second {@link JFrame} displaying the content of the certificate
- *
- * @param cert
- */
- @SuppressWarnings("unused")
- private void showCertificate(Certificate cert) {
- if (cert != null) {
- new ch.csnc.extension.ui.CertificateView(cert.toString());
- }
- }
-
- private void setActiveButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_setActiveButtonActionPerformed
- setActiveAction();
- } // GEN-LAST:event_setActiveButtonActionPerformed
-
- private void setActiveAction() {
- int ks = keyStoreList.getSelectedIndex();
- int alias = aliasTable.getSelectedRow();
- if (ks > -1 && alias > -1) {
- if (!contextManager.isKeyUnlocked(ks, alias)) {
-
- try {
- if (!contextManager.unlockKeyWithDefaultPassword(ks, alias)) {
- String password = getPassword();
-
- if (!contextManager.unlockKey(ks, alias, password)) {
- JOptionPane.showMessageDialog(
- null,
- new String[] {
- Constant.messages.getString(
- "options.cert.error.accesskeystore")
- },
- Constant.messages.getString("options.cert.error"),
- JOptionPane.ERROR_MESSAGE);
- }
- }
- } catch (Exception e) {
- showKeyStoreCertError(e.toString());
- }
- }
- Certificate cert = contextManager.getCertificate(ks, alias);
- try {
- contextManager.getFingerPrint(cert);
- } catch (KeyStoreException kse) {
- showCertError("options.cert.error.fingerprint", kse.toString());
- }
-
- try {
- contextManager.setDefaultKey(ks, alias);
-
- OptionsParamCertificate certParam =
- Model.getSingleton().getOptionsParam().getCertificateParam();
- certParam.setActiveCertificate();
-
- } catch (KeyStoreException e) {
- logger.error(e.getMessage(), e);
- }
- certificateTextField.setText(contextManager.getDefaultKey());
- }
- }
-
- public String getPassword() {
- JPasswordField askPasswordField = new JPasswordField();
- int result =
- JOptionPane.showConfirmDialog(
- this,
- askPasswordField,
- Constant.messages.getString("options.cert.label.enterpassword"),
- JOptionPane.OK_CANCEL_OPTION);
- if (result == JOptionPane.OK_OPTION) {
- return new String(askPasswordField.getPassword());
- } else return null;
- }
-
- private void deleteButtonActionPerformed(
- java.awt.event.ActionEvent evt) { // GEN-FIRST:event_deleteButtonActionPerformed
- int index = keyStoreList.getSelectedIndex();
- if (index >= 0) {
- boolean isDefaultKeyStore = contextManager.removeKeyStore(index);
- if (isDefaultKeyStore) {
- certificateTextField.setText("");
- }
- keyStoreListModel.removeElementAt(keyStoreList.getSelectedIndex());
- aliasTableModel.removeKeystore();
- }
- } // GEN-LAST:event_deleteButtonActionPerformed
-
- private void useClientCertificateCheckBoxActionPerformed(
- java.awt.event.ActionEvent
- evt) { // GEN-FIRST:event_useClientCertificateCheckBoxActionPerformed
- // The enable unsafe SSL renegotiation checkbox is independent of using a client certificate
- // (although commonly related)
- // enableUnsafeSSLRenegotiationCheckBox.setEnabled(useClientCertificateCheckBox.isSelected());
-
- // keyStore tab
- certificatejTabbedPane.setEnabled(useClientCertificateCheckBox.isSelected());
-
- keyStoreScrollPane.setEnabled(useClientCertificateCheckBox.isSelected());
- keyStoreList.setEnabled(useClientCertificateCheckBox.isSelected());
-
- aliasScrollPane.setEnabled(useClientCertificateCheckBox.isSelected());
- aliasTable.setEnabled(useClientCertificateCheckBox.isSelected());
-
- deleteButton.setEnabled(useClientCertificateCheckBox.isSelected());
- setActiveButton.setEnabled(useClientCertificateCheckBox.isSelected());
- showAliasButton.setEnabled(useClientCertificateCheckBox.isSelected());
-
- // pkcs12 tab
- fileTextField.setEnabled(useClientCertificateCheckBox.isSelected());
- browseButton.setEnabled(useClientCertificateCheckBox.isSelected());
- pkcs12PasswordField.setEnabled(useClientCertificateCheckBox.isSelected());
- addPkcs12Button.setEnabled(useClientCertificateCheckBox.isSelected());
-
- // pkcs11 tab
- driverComboBox.setEnabled(useClientCertificateCheckBox.isSelected());
- driverButton.setEnabled(useClientCertificateCheckBox.isSelected());
- pkcs11PasswordField.setEnabled(useClientCertificateCheckBox.isSelected());
- addPkcs11Button.setEnabled(useClientCertificateCheckBox.isSelected());
- usePkcs11ExperimentalSliSupportCheckBox.setEnabled(
- useClientCertificateCheckBox.isSelected());
- usePkcs11ExperimentalSliSupportCheckBox.setSelected(
- Model.getSingleton()
- .getOptionsParam()
- .getExperimentalFeaturesParam()
- .isExperimentalSliSupportEnabled());
-
- // actual certificate fields
- certificateTextField.setEnabled(useClientCertificateCheckBox.isSelected());
- showActiveCertificateButton.setEnabled(useClientCertificateCheckBox.isSelected());
- } // GEN-LAST:event_useClientCertificateCheckBoxActionPerformed
-
- private void usePkcs11ExperimentalSliSupportCheckBoxActionPerformed(
- java.awt.event.ActionEvent evt) {
- Model.getSingleton()
- .getOptionsParam()
- .getExperimentalFeaturesParam()
- .setSlotListIndexSupport(usePkcs11ExperimentalSliSupportCheckBox.isSelected());
- }
-
- // TODO remove
- private OptionsCertificatePanel getContentPane() {
- return this;
- }
-
- @Override
- public void initParam(Object obj) {
- OptionsParam options = (OptionsParam) obj;
- OptionsParamCertificate certParam = options.getCertificateParam();
-
- // Should only run once after startup if client certificate is set from commandline
- if (overrideEnableClientCertificate) {
- certParam.setEnableCertificate(true);
- overrideEnableClientCertificate = false;
- }
- keyStoreListModel.clear();
- for (int i = 0; i < contextManager.getKeyStoreCount(); i++) {
- keyStoreListModel.addElement(contextManager.getKeyStoreDescription(i));
- }
- Certificate cert = contextManager.getDefaultCertificate();
- if (cert != null) {
- certificateTextField.setText(cert.toString());
- }
- useClientCertificateCheckBox.setSelected(certParam.isUseClientCert());
- useClientCertificateCheckBoxActionPerformed(null);
-
- // getBtnLocation().setEnabled(getChkUseClientCertificate().isSelected());
- // getTxtLocation().setText(options.getCertificateParam().getClientCertLocation());
- }
-
- @Override
- public void saveParam(Object obj) throws Exception {
- OptionsParam options = (OptionsParam) obj;
- OptionsParamCertificate certParam = options.getCertificateParam();
- certParam.setEnableCertificate(useClientCertificateCheckBox.isSelected());
- }
-
- @Override
- public String getHelpIndex() {
- // ZAP: added help index
- return "ui.dialogs.options.certificate";
- }
-} // @jve:decl-index=0:visual-constraint="10,10"
diff --git a/zap/src/main/java/org/parosproxy/paros/extension/option/OptionsParamCertificate.java b/zap/src/main/java/org/parosproxy/paros/extension/option/OptionsParamCertificate.java
deleted file mode 100644
index a73078f1604..00000000000
--- a/zap/src/main/java/org/parosproxy/paros/extension/option/OptionsParamCertificate.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- *
- * Paros and its related class files.
- *
- * Paros is an HTTP/HTTPS proxy for assessing web application security.
- * Copyright (C) 2003-2004 Chinotec Technologies Company
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the Clarified Artistic License
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Clarified Artistic License for more details.
- *
- * You should have received a copy of the Clarified Artistic License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-// ZAP: 2012/04/25 Added @Override annotation to the appropriate method.
-// ZAP: 2013/01/25 Removed the "(non-Javadoc)" comments.
-// ZAP: 2013/03/03 Issue 546: Remove all template Javadoc comments
-// ZAP: 2014/03/23 Issue 412: Enable unsafe SSL/TLS renegotiation option not saved
-// ZAP: 2014/08/14 Issue 1184: Improve support for IBM JDK
-// ZAP: 2017/09/26 Use helper methods to read the configurations.
-// ZAP: 2018/02/14 Remove unnecessary boxing / unboxing
-// ZAP: 2018/08/01 Added support for setting and persisting client cert from CLI
-// ZAP: 2019/06/01 Normalise line endings.
-// ZAP: 2019/06/05 Normalise format/style.
-// ZAP: 2020/11/26 Use Log4j 2 classes for logging.
-// ZAP: 2022/05/21 Disable unsafe SSL/TLS renegotiation option.
-// ZAP: 2022/05/29 Deprecate the class.
-// ZAP: 2022/06/07 Address deprecation warnings with SSLConnector.
-package org.parosproxy.paros.extension.option;
-
-import java.io.File;
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import org.apache.commons.httpclient.protocol.Protocol;
-import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.parosproxy.paros.common.AbstractParam;
-
-/**
- * @deprecated (2.12.0) No longer in use.
- */
-@Deprecated
-public class OptionsParamCertificate extends AbstractParam {
-
- private static final Logger logger = LogManager.getLogger(OptionsParamCertificate.class);
-
- private static final String CERTIFICATE_BASE_KEY = "certificate";
-
- private static final String USE_CLIENT_CERT = CERTIFICATE_BASE_KEY + ".use";
- private static final String PERSIST_CLIENT_CERT = CERTIFICATE_BASE_KEY + ".persist";
- private static final String CLIENT_CERT_LOCATION = CERTIFICATE_BASE_KEY + ".pkcs12.path";
- private static final String CLIENT_CERT_PASSWORD = CERTIFICATE_BASE_KEY + ".pkcs12.password";
- private static final String CLIENT_CERT_INDEX = CERTIFICATE_BASE_KEY + ".pkcs12.index";
-
- private boolean useClientCert = false;
- private String clientCertLocation = "";
- private String clientCertPassword = "";
- private int clientCertIndex = 0;
-
- public OptionsParamCertificate() {}
-
- @Override
- protected void parse() {
-
- clientCertCheck();
- saveClientCertSettings();
- }
-
- /**
- * Saves the client cert settings if the flag is set explicitly. Only works for the CLI
- * currently.
- */
- private void saveClientCertSettings() {
-
- if (getBoolean(PERSIST_CLIENT_CERT, false)) {
- logger.warn("Saving Client Certificate settings: password will be found in config");
- setUseClientCert(getBoolean(USE_CLIENT_CERT, false));
- setClientCertLocation(getString(CLIENT_CERT_LOCATION, ""));
- setClientCertPassword(getString(CLIENT_CERT_PASSWORD, ""));
- setClientCertIndex(getInt(CLIENT_CERT_INDEX, 0));
-
- } else {
- // Default to clear settings
- setUseClientCert(false);
- setClientCertLocation("");
- setClientCertPassword("");
- setClientCertIndex(0);
- }
- }
-
- /**
- * Enables ClientCertificate from -config CLI parameters Requires location, password and a flag
- * to use client certificate.
- */
- private void clientCertCheck() {
-
- boolean enableClientCert = getBoolean(USE_CLIENT_CERT, false);
- String certPath = getString(CLIENT_CERT_LOCATION, "");
- String certPass = getString(CLIENT_CERT_PASSWORD, "");
- int certIndex = getInt(CLIENT_CERT_INDEX, 0);
-
- if (enableClientCert && !certPath.isEmpty() && !certPass.isEmpty()) {
- try {
-
- ch.csnc.extension.httpclient.SSLContextManager contextManager =
- getSSLContextManager();
- int ksIndex = contextManager.loadPKCS12Certificate(certPath, certPass);
- contextManager.unlockKey(ksIndex, certIndex, certPass);
- contextManager.setDefaultKey(ksIndex, certIndex);
-
- setActiveCertificate();
- setEnableCertificate(true);
-
- logger.info("Client Certificate enabled from CLI");
- logger.info("Use -config certificate.persist=true to save settings");
-
- } catch (IOException
- | CertificateException
- | NoSuchAlgorithmException
- | KeyStoreException
- | KeyManagementException ex) {
- logger.error("The certificate could not be enabled due to an error", ex);
- }
- }
- }
-
- public String getClientCertPassword() {
- return clientCertPassword;
- }
-
- public void setClientCertPassword(String clientCertPassword) {
- this.clientCertPassword = clientCertPassword;
- getConfig().setProperty(CLIENT_CERT_PASSWORD, clientCertPassword);
- }
-
- /**
- * @return Returns the client cert location.
- */
- public String getClientCertLocation() {
- return clientCertLocation;
- }
-
- public void setClientCertLocation(String clientCertLocation) {
- if (clientCertLocation != null && !clientCertLocation.equals("")) {
- File file = new File(clientCertLocation);
- if (!file.exists()) {
- setUseClientCert(false);
- return;
- }
- } else {
- setUseClientCert(false);
- }
- this.clientCertLocation = clientCertLocation;
- getConfig().setProperty(CLIENT_CERT_LOCATION, clientCertLocation);
- }
-
- public int getClientCertIndex() {
- return clientCertIndex;
- }
-
- public void setClientCertIndex(int clientCertIdx) {
- this.clientCertIndex = clientCertIdx;
- getConfig().setProperty(CLIENT_CERT_INDEX, Integer.toString(clientCertIndex));
- }
-
- public boolean isUseClientCert() {
- return useClientCert;
- }
-
- private void setUseClientCert(boolean isUse) {
- useClientCert = isUse;
- getConfig().setProperty(USE_CLIENT_CERT, Boolean.toString(useClientCert));
- }
-
- public void setEnableCertificate(boolean enabled) {
- ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory();
-
- if (sslFactory instanceof org.parosproxy.paros.network.SSLConnector) {
- org.parosproxy.paros.network.SSLConnector ssl =
- (org.parosproxy.paros.network.SSLConnector) sslFactory;
- ssl.setEnableClientCert(enabled);
-
- setUseClientCert(enabled);
- }
- }
-
- public void setActiveCertificate() {
-
- ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory();
-
- if (sslFactory instanceof org.parosproxy.paros.network.SSLConnector) {
- org.parosproxy.paros.network.SSLConnector ssl =
- (org.parosproxy.paros.network.SSLConnector) sslFactory;
- ssl.setActiveCertificate();
- }
- }
-
- public ch.csnc.extension.httpclient.SSLContextManager getSSLContextManager() {
-
- ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory();
- if (sslFactory instanceof org.parosproxy.paros.network.SSLConnector) {
- org.parosproxy.paros.network.SSLConnector ssl =
- (org.parosproxy.paros.network.SSLConnector) sslFactory;
-
- return ssl.getSSLContextManager();
- }
- return null;
- }
-
- /**
- * Tells whether or not the unsafe SSL renegotiation is enabled.
- *
- * @return {@code true} if the unsafe SSL renegotiation is enabled, {@code false} otherwise.
- * @see #setAllowUnsafeSslRenegotiation(boolean)
- */
- public boolean isAllowUnsafeSslRenegotiation() {
- return false;
- }
-
- /**
- * Sets whether or not the unsafe SSL renegotiation is enabled.
- *
- *
Calling this method changes the system property
- * "sun.security.ssl.allowUnsafeRenegotiation" and "com.ibm.jsse2.renegotiate". It must be set
- * before establishing any SSL connection. Further changes after establishing a SSL connection
- * will have no effect on the renegotiation but the value will be saved and restored next time
- * ZAP is restarted.
- *
- * @param allow {@code true} if the unsafe SSL renegotiation should be enabled, {@code false}
- * otherwise.
- * @see #isAllowUnsafeSslRenegotiation()
- */
- public void setAllowUnsafeSslRenegotiation(boolean allow) {}
-}
diff --git a/zap/src/main/java/org/parosproxy/paros/model/OptionsParam.java b/zap/src/main/java/org/parosproxy/paros/model/OptionsParam.java
index 571d2a5b3ea..7fc27f8b972 100644
--- a/zap/src/main/java/org/parosproxy/paros/model/OptionsParam.java
+++ b/zap/src/main/java/org/parosproxy/paros/model/OptionsParam.java
@@ -85,10 +85,6 @@ public class OptionsParam extends AbstractParam {
private OptionsParamView viewParam = new OptionsParamView();
- @SuppressWarnings("deprecation")
- private org.parosproxy.paros.extension.option.OptionsParamCertificate certificateParam =
- new org.parosproxy.paros.extension.option.OptionsParamCertificate();
-
// ZAP: Added many instance variables for new functionality.
private OptionsParamCheckForUpdates checkForUpdatesParam = new OptionsParamCheckForUpdates();
private OptionsParamApi apiParam = new OptionsParamApi();
@@ -103,10 +99,6 @@ public List getTokensNames() {
}
};
- @SuppressWarnings("deprecation")
- private ch.csnc.extension.util.OptionsParamExperimentalSliSupport experimentalFeaturesParam =
- new ch.csnc.extension.util.OptionsParamExperimentalSliSupport();
-
/** The database configurations. */
// ZAP: Added the instance variable.
private DatabaseParam databaseParam = new DatabaseParam();
@@ -177,25 +169,6 @@ public OptionsParamCheckForUpdates getCheckForUpdatesParam() {
return checkForUpdatesParam;
}
- /**
- * @param certificateParam The certificateParam to set.
- * @deprecated (2.12.0)
- */
- @Deprecated
- public void setCertificateParam(
- org.parosproxy.paros.extension.option.OptionsParamCertificate certificateParam) {
- this.certificateParam = certificateParam;
- }
-
- /**
- * @return Returns the certificateParam.
- * @deprecated (2.12.0)
- */
- @Deprecated
- public org.parosproxy.paros.extension.option.OptionsParamCertificate getCertificateParam() {
- return certificateParam;
- }
-
public void addParamSet(AbstractParam paramSet) {
paramSetList.add(paramSet);
abstractParamsMap.put(paramSet.getClass(), paramSet);
@@ -315,15 +288,6 @@ public OptionsParamApi getApiParam() {
return apiParam;
}
- /**
- * @deprecated (2.12.0)
- */
- @Deprecated
- public ch.csnc.extension.util.OptionsParamExperimentalSliSupport
- getExperimentalFeaturesParam() {
- return experimentalFeaturesParam;
- }
-
/**
* Gets the database configurations.
*
diff --git a/zap/src/main/java/org/parosproxy/paros/network/SSLConnector.java b/zap/src/main/java/org/parosproxy/paros/network/SSLConnector.java
index b24dd91d6aa..63850cbe0ca 100644
--- a/zap/src/main/java/org/parosproxy/paros/network/SSLConnector.java
+++ b/zap/src/main/java/org/parosproxy/paros/network/SSLConnector.java
@@ -194,9 +194,6 @@ public class SSLConnector
@SuppressWarnings("deprecation")
private static org.parosproxy.paros.security.SslCertificateService sslCertificateService;
- @SuppressWarnings("deprecation")
- private static ch.csnc.extension.httpclient.SSLContextManager sslContextManager = null;
-
/*
* If relaxedTrust then we ignore all of the 'usual' https checks.
* This is needed in order to test sites with custom certs
@@ -218,39 +215,6 @@ public SSLConnector(boolean relaxedTrust) {
clientSSLSockFactory = getClientSocketFactory(SSL);
misconfiguredHosts = new LRUMap(10);
}
- // ZAP: removed ServerSocketFaktory
- if (sslContextManager == null) {
- sslContextManager = new ch.csnc.extension.httpclient.SSLContextManager();
- }
- }
-
- @SuppressWarnings("deprecation")
- public ch.csnc.extension.httpclient.SSLContextManager getSSLContextManager() {
- return sslContextManager;
- }
-
- @SuppressWarnings("deprecation")
- public void setEnableClientCert(boolean enabled) {
- if (enabled) {
- if (clientSSLSockCertFactory == null) {
- return;
- }
-
- clientSSLSockFactory = clientSSLSockCertFactory;
- logger.info("ClientCert enabled using: {}", sslContextManager.getDefaultKey());
- } else {
- clientSSLSockFactory = getClientSocketFactory(SSL);
- logger.info("ClientCert disabled");
- }
- }
-
- @SuppressWarnings("deprecation")
- public void setActiveCertificate() {
-
- SSLContext sslcont = sslContextManager.getSSLContext(sslContextManager.getDefaultKey());
- clientSSLSockCertFactory =
- createDecoratedClientSslSocketFactory(sslcont.getSocketFactory());
- logger.info("ActiveCertificate set to: {}", sslContextManager.getDefaultKey());
}
// ZAP: removed server socket methods
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/DialogAddDomainAlwaysInScope.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/DialogAddDomainAlwaysInScope.java
deleted file mode 100644
index e375445bd46..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/DialogAddDomainAlwaysInScope.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2014 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import java.awt.Dialog;
-import java.util.regex.Pattern;
-import javax.swing.GroupLayout;
-import javax.swing.JCheckBox;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-import org.parosproxy.paros.Constant;
-import org.zaproxy.zap.utils.ZapTextField;
-import org.zaproxy.zap.view.AbstractFormDialog;
-
-@SuppressWarnings("serial")
-/**
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-class DialogAddDomainAlwaysInScope extends AbstractFormDialog {
-
- private static final long serialVersionUID = -7356390753317082681L;
-
- private static final String DIALOG_TITLE =
- Constant.messages.getString("spider.options.domains.in.scope.add.title");
-
- private static final String CONFIRM_BUTTON_LABEL =
- Constant.messages.getString("spider.options.domains.in.scope.add.button.confirm");
-
- private static final String DOMAIN_FIELD_LABEL =
- Constant.messages.getString("spider.options.domains.in.scope.field.label.domain");
- private static final String REGEX_FIELD_LABEL =
- Constant.messages.getString("spider.options.domains.in.scope.field.label.regex");
- private static final String ENABLED_FIELD_LABEL =
- Constant.messages.getString("spider.options.domains.in.scope.field.label.enabled");
-
- private static final String TITLE_INVALID_REGEX_DIALOG =
- Constant.messages.getString(
- "spider.options.domains.in.scope.warning.invalid.regex.title");
- private static final String TEXT_INVALID_REGEX_DIALOG =
- Constant.messages.getString(
- "spider.options.domains.in.scope.warning.invalid.regex.text");
-
- private ZapTextField domainTextField;
- private JCheckBox regexCheckBox;
- private JCheckBox enabledCheckBox;
-
- protected org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher domainAlwaysInScope;
-
- private ConfirmButtonValidatorDocListener confirmButtonValidatorDocListener;
-
- public DialogAddDomainAlwaysInScope(Dialog owner) {
- super(owner, DIALOG_TITLE);
- }
-
- protected DialogAddDomainAlwaysInScope(Dialog owner, String title) {
- super(owner, title);
- }
-
- @Override
- protected JPanel getFieldsPanel() {
- JPanel fieldsPanel = new JPanel();
-
- GroupLayout layout = new GroupLayout(fieldsPanel);
- fieldsPanel.setLayout(layout);
- layout.setAutoCreateGaps(true);
- layout.setAutoCreateContainerGaps(true);
-
- JLabel domainLabel = new JLabel(DOMAIN_FIELD_LABEL);
- JLabel regexLabel = new JLabel(REGEX_FIELD_LABEL);
- JLabel enabledLabel = new JLabel(ENABLED_FIELD_LABEL);
-
- layout.setHorizontalGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
- .addComponent(domainLabel)
- .addComponent(enabledLabel)
- .addComponent(regexLabel))
- .addGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(getDomainTextField())
- .addComponent(getEnabledCheckBox())
- .addComponent(getRegexCheckBox())));
-
- layout.setVerticalGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(domainLabel)
- .addComponent(getDomainTextField()))
- .addGroup(
- layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(regexLabel)
- .addComponent(getRegexCheckBox()))
- .addGroup(
- layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(enabledLabel)
- .addComponent(getEnabledCheckBox())));
-
- return fieldsPanel;
- }
-
- @Override
- protected String getConfirmButtonLabel() {
- return CONFIRM_BUTTON_LABEL;
- }
-
- @Override
- protected void init() {
- getDomainTextField().setText("");
- getRegexCheckBox().setSelected(false);
- getEnabledCheckBox().setSelected(true);
- domainAlwaysInScope = null;
- }
-
- @Override
- protected boolean validateFields() {
- if (getRegexCheckBox().isSelected()) {
- try {
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher.createPattern(
- getDomainTextField().getText());
- } catch (IllegalArgumentException e) {
- JOptionPane.showMessageDialog(
- this,
- TEXT_INVALID_REGEX_DIALOG,
- TITLE_INVALID_REGEX_DIALOG,
- JOptionPane.INFORMATION_MESSAGE);
- getDomainTextField().requestFocusInWindow();
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- protected void performAction() {
- String value = getDomainTextField().getText();
- if (getRegexCheckBox().isSelected()) {
- Pattern pattern =
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher.createPattern(value);
- domainAlwaysInScope = new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(pattern);
- } else {
- domainAlwaysInScope = new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(value);
- }
-
- domainAlwaysInScope.setEnabled(getEnabledCheckBox().isSelected());
- }
-
- @Override
- protected void clearFields() {
- getDomainTextField().setText("");
- getDomainTextField().discardAllEdits();
- }
-
- public org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher getDomainAlwaysInScope() {
- return domainAlwaysInScope;
- }
-
- protected ZapTextField getDomainTextField() {
- if (domainTextField == null) {
- domainTextField = new ZapTextField(25);
- domainTextField
- .getDocument()
- .addDocumentListener(getConfirmButtonValidatorDocListener());
- }
-
- return domainTextField;
- }
-
- protected JCheckBox getRegexCheckBox() {
- if (regexCheckBox == null) {
- regexCheckBox = new JCheckBox();
- }
- return regexCheckBox;
- }
-
- protected JCheckBox getEnabledCheckBox() {
- if (enabledCheckBox == null) {
- enabledCheckBox = new JCheckBox();
- }
-
- return enabledCheckBox;
- }
-
- public void clear() {
- this.domainAlwaysInScope = null;
- }
-
- private ConfirmButtonValidatorDocListener getConfirmButtonValidatorDocListener() {
- if (confirmButtonValidatorDocListener == null) {
- confirmButtonValidatorDocListener = new ConfirmButtonValidatorDocListener();
- }
- return confirmButtonValidatorDocListener;
- }
-
- private class ConfirmButtonValidatorDocListener implements DocumentListener {
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- checkAndEnableConfirmButton();
- }
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- checkAndEnableConfirmButton();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- checkAndEnableConfirmButton();
- }
-
- private void checkAndEnableConfirmButton() {
- boolean enabled = (getDomainTextField().getDocument().getLength() > 0);
- setConfirmButtonEnabled(enabled);
- }
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/DialogModifyDomainAlwaysInScope.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/DialogModifyDomainAlwaysInScope.java
deleted file mode 100644
index 94700e17b5f..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/DialogModifyDomainAlwaysInScope.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2014 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import java.awt.Dialog;
-import org.parosproxy.paros.Constant;
-
-/**
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-class DialogModifyDomainAlwaysInScope extends DialogAddDomainAlwaysInScope {
-
- private static final long serialVersionUID = -4031122965844883255L;
-
- private static final String DIALOG_TITLE =
- Constant.messages.getString("spider.options.domains.in.scope.modify.title");
-
- private static final String CONFIRM_BUTTON_LABEL =
- Constant.messages.getString("spider.options.domains.in.scope.modify.button.confirm");
-
- protected DialogModifyDomainAlwaysInScope(Dialog owner) {
- super(owner, DIALOG_TITLE);
- }
-
- @Override
- protected String getConfirmButtonLabel() {
- return CONFIRM_BUTTON_LABEL;
- }
-
- public void setDomainAlwaysInScope(
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher excludedDomain) {
- this.domainAlwaysInScope = excludedDomain;
- }
-
- @Override
- protected void init() {
- getDomainTextField().setText(domainAlwaysInScope.getValue());
- getDomainTextField().discardAllEdits();
-
- getRegexCheckBox().setSelected(domainAlwaysInScope.isRegex());
-
- getEnabledCheckBox().setSelected(domainAlwaysInScope.isEnabled());
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/DomainsAlwaysInScopeTableModel.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/DomainsAlwaysInScopeTableModel.java
deleted file mode 100644
index a5233f5904f..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/DomainsAlwaysInScopeTableModel.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2014 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.parosproxy.paros.Constant;
-import org.zaproxy.zap.view.AbstractMultipleOptionsTableModel;
-
-@SuppressWarnings("serial")
-/**
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-class DomainsAlwaysInScopeTableModel
- extends AbstractMultipleOptionsTableModel<
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher> {
-
- private static final long serialVersionUID = -5411351965957264957L;
-
- private static final String[] COLUMN_NAMES = {
- Constant.messages.getString("spider.options.domains.in.scope.table.header.enabled"),
- Constant.messages.getString("spider.options.domains.in.scope.table.header.regex"),
- Constant.messages.getString("spider.options.domains.in.scope.table.header.value")
- };
-
- private static final int COLUMN_COUNT = COLUMN_NAMES.length;
-
- private List domainsInScope =
- new ArrayList<>(5);
-
- public DomainsAlwaysInScopeTableModel() {
- super();
- }
-
- @Override
- public String getColumnName(int col) {
- return COLUMN_NAMES[col];
- }
-
- @Override
- public int getColumnCount() {
- return COLUMN_COUNT;
- }
-
- @Override
- public int getRowCount() {
- return domainsInScope.size();
- }
-
- @Override
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return (columnIndex == 0);
- }
-
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- switch (columnIndex) {
- case 0:
- return getElement(rowIndex).isEnabled();
- case 1:
- return getElement(rowIndex).isRegex();
- case 2:
- return getElement(rowIndex).getValue();
- }
- return null;
- }
-
- @Override
- public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
- if (columnIndex == 0 && aValue instanceof Boolean) {
- domainsInScope.get(rowIndex).setEnabled((Boolean) aValue);
- fireTableCellUpdated(rowIndex, columnIndex);
- }
- }
-
- @Override
- public Class> getColumnClass(int c) {
- if (c == 0 || c == 1) {
- return Boolean.class;
- }
- return String.class;
- }
-
- public List getDomainsAlwaysInScope() {
- return domainsInScope;
- }
-
- public void setDomainsAlwaysInScope(
- List domainsInScope) {
- this.domainsInScope = new ArrayList<>(domainsInScope.size());
-
- for (org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher excludedDomain : domainsInScope) {
- this.domainsInScope.add(
- new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(excludedDomain));
- }
-
- fireTableDataChanged();
- }
-
- @Override
- public List getElements() {
- return domainsInScope;
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/ExtensionSpider.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/ExtensionSpider.java
deleted file mode 100644
index 93d64cb6daf..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/ExtensionSpider.java
+++ /dev/null
@@ -1,898 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2010 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import java.awt.Dimension;
-import java.awt.EventQueue;
-import java.awt.event.KeyEvent;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.parosproxy.paros.Constant;
-import org.parosproxy.paros.control.Control;
-import org.parosproxy.paros.control.Control.Mode;
-import org.parosproxy.paros.extension.ExtensionAdaptor;
-import org.parosproxy.paros.extension.ExtensionHook;
-import org.parosproxy.paros.extension.SessionChangedListener;
-import org.parosproxy.paros.model.Session;
-import org.parosproxy.paros.model.SiteNode;
-import org.zaproxy.zap.extension.help.ExtensionHelp;
-import org.zaproxy.zap.model.Context;
-import org.zaproxy.zap.model.ScanController;
-import org.zaproxy.zap.model.StructuralNode;
-import org.zaproxy.zap.model.StructuralSiteNode;
-import org.zaproxy.zap.model.Target;
-import org.zaproxy.zap.users.User;
-import org.zaproxy.zap.view.ZapMenuItem;
-
-/**
- * The ExtensionSpider is the Extension that controls the Spider.
- *
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-@SuppressWarnings("removal")
-public class ExtensionSpider extends ExtensionAdaptor
- implements SessionChangedListener, ScanController {
-
- private org.zaproxy.zap.model.ValueGenerator generator =
- new org.zaproxy.zap.model.DefaultValueGenerator();
-
- public static final int EXTENSION_ORDER = 30;
-
- /** The Constant logger. */
- private static final Logger log = LogManager.getLogger(ExtensionSpider.class);
-
- /** The Constant defining the NAME of the extension. */
- public static final String NAME = "ExtensionSpider";
-
- /** The spider panel. */
- private SpiderPanel spiderPanel = null;
-
- SpiderDialog spiderDialog = null;
-
- private PopupMenuItemSpiderDialog popupMenuItemSpiderDialog;
-
- private PopupMenuItemSpiderDialogWithContext popupMenuItemSpiderDialogWithContext;
-
- /** The options spider panel. */
- private OptionsSpiderPanel optionsSpiderPanel = null;
-
- /** The params for the spider. */
- private org.zaproxy.zap.spider.SpiderParam params = null;
-
- private List customParsers;
- private List customFetchFilters;
- private List customParseFilters;
-
- private SpiderAPI spiderApi;
-
- private SpiderScanController scanController = null;
-
- private Icon icon;
-
- private boolean panelSwitch = true;
-
- /**
- * The list of excluded patterns of sites. Patterns are added here with the ExcludeFromSpider
- * Popup Menu.
- */
- private List excludeList = Collections.emptyList();
-
- private ZapMenuItem menuItemCustomScan = null;
-
- /** Instantiates a new spider extension. */
- public ExtensionSpider() {
- super(NAME);
- initialize();
- }
-
- /** This method initializes this extension. */
- private void initialize() {
- this.setOrder(EXTENSION_ORDER);
- this.customParsers = new LinkedList<>();
- this.customFetchFilters = new LinkedList<>();
- this.customParseFilters = new LinkedList<>();
- this.scanController = new SpiderScanController(this);
- }
-
- public void setValueGenerator(org.zaproxy.zap.model.ValueGenerator generator) {
- if (generator == null) {
- throw new IllegalArgumentException("Parameter generator must not be null.");
- }
- this.generator = generator;
- }
-
- public org.zaproxy.zap.model.ValueGenerator getValueGenerator() {
- return generator;
- }
-
- @Override
- public String getUIName() {
- return Constant.messages.getString("spider.name");
- }
-
- @Override
- public void hook(ExtensionHook extensionHook) {
- super.hook(extensionHook);
- // Register for listeners
- extensionHook.addSessionListener(this);
-
- // Initialize views
- if (getView() != null) {
- extensionHook.getHookMenu().addToolsMenuItem(getMenuItemCustomScan());
- extensionHook.getHookView().addStatusPanel(getSpiderPanel());
- extensionHook.getHookView().addOptionPanel(getOptionsSpiderPanel());
- extensionHook.getHookMenu().addPopupMenuItem(getPopupMenuItemSpiderDialog());
- extensionHook.getHookMenu().addPopupMenuItem(getPopupMenuItemSpiderDialogWithContext());
- ExtensionHelp.enableHelpKey(getSpiderPanel(), "ui.tabs.spider");
- }
-
- // Register the params
- extensionHook.addOptionsParamSet(getSpiderParam());
-
- // Register as an API implementor
- spiderApi = new SpiderAPI(this);
- spiderApi.addApiOptions(getSpiderParam());
- extensionHook.addApiImplementor(spiderApi);
- }
-
- private PopupMenuItemSpiderDialog getPopupMenuItemSpiderDialog() {
- if (popupMenuItemSpiderDialog == null) {
- popupMenuItemSpiderDialog = new PopupMenuItemSpiderDialog(this);
- }
- return popupMenuItemSpiderDialog;
- }
-
- private PopupMenuItemSpiderDialogWithContext getPopupMenuItemSpiderDialogWithContext() {
- if (popupMenuItemSpiderDialogWithContext == null) {
- popupMenuItemSpiderDialogWithContext = new PopupMenuItemSpiderDialogWithContext(this);
- }
- return popupMenuItemSpiderDialogWithContext;
- }
-
- @Override
- public List getActiveActions() {
- List activeSpiders = scanController.getActiveScans();
- if (activeSpiders.isEmpty()) {
- return null;
- }
-
- String spiderActionPrefix = Constant.messages.getString("spider.activeActionPrefix");
- List activeActions = new ArrayList<>(activeSpiders.size());
- for (SpiderScan activeSpider : activeSpiders) {
- activeActions.add(
- MessageFormat.format(spiderActionPrefix, activeSpider.getDisplayName()));
- }
- return activeActions;
- }
-
- /**
- * Gets the spider parameters (options).
- *
- * @return the spider parameters
- */
- protected org.zaproxy.zap.spider.SpiderParam getSpiderParam() {
- if (params == null) {
- params = new org.zaproxy.zap.spider.SpiderParam();
- }
- return params;
- }
-
- /**
- * Gets the spider panel.
- *
- * @return the spider panel
- */
- protected SpiderPanel getSpiderPanel() {
- if (spiderPanel == null) {
- spiderPanel = new SpiderPanel(this, getSpiderParam());
- }
- return spiderPanel;
- }
-
- @Override
- public void sessionAboutToChange(Session session) {
- // Shut all of the scans down and remove them
- this.scanController.reset();
- if (hasView()) {
- this.getSpiderPanel().reset();
- if (spiderDialog != null) {
- spiderDialog.reset();
- }
- }
- }
-
- @Override
- public void sessionChanged(final Session session) {
- if (EventQueue.isDispatchThread()) {
- sessionChangedEventHandler(session);
- } else {
- try {
- EventQueue.invokeAndWait(
- new Runnable() {
- @Override
- public void run() {
- sessionChangedEventHandler(session);
- }
- });
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- }
- }
- }
-
- /**
- * Session changed event handler.
- *
- * @param session the session
- */
- private void sessionChangedEventHandler(Session session) {
- // Clear all scans
- if (hasView()) {
- this.getSpiderPanel().reset();
- }
- if (session == null) {
- // Closedown
- return;
- }
- }
-
- /**
- * Gets the options spider panel.
- *
- * @return the options spider panel
- */
- private OptionsSpiderPanel getOptionsSpiderPanel() {
- if (optionsSpiderPanel == null) {
- optionsSpiderPanel = new OptionsSpiderPanel();
- }
- return optionsSpiderPanel;
- }
-
- /**
- * Sets the exclude list.
- *
- * @param ignoredRegexs the new exclude list
- */
- public void setExcludeList(List ignoredRegexs) {
- if (ignoredRegexs == null || ignoredRegexs.isEmpty()) {
- excludeList = Collections.emptyList();
- return;
- }
-
- this.excludeList = ignoredRegexs;
- }
-
- /**
- * Gets the exclude list.
- *
- * @return the exclude list
- */
- public List getExcludeList() {
- return excludeList;
- }
-
- @Override
- public String getAuthor() {
- return Constant.ZAP_TEAM;
- }
-
- @Override
- public String getDescription() {
- return Constant.messages.getString("spider.desc");
- }
-
- @Override
- public void sessionScopeChanged(Session session) {
- if (hasView()) {
- this.getSpiderPanel().sessionScopeChanged(session);
- }
- }
-
- @Override
- public void sessionModeChanged(Mode mode) {
- if (Mode.safe.equals(mode)) {
- this.scanController.stopAllScans();
- }
-
- if (hasView()) {
- this.getSpiderPanel().sessionModeChanged(mode);
- getMenuItemCustomScan().setEnabled(!Mode.safe.equals(mode));
- }
- }
-
- /**
- * Start scan node.
- *
- * @param node the node
- */
- public void startScanNode(SiteNode node) {
- Target target = new Target(node);
- target.setRecurse(true);
- this.startScan(target, null, null);
- }
-
- /**
- * Start the scan of an URL (Node) from the POV of a User.
- *
- * @param node the node
- */
- public void startScanNode(SiteNode node, User user) {
- Target target = new Target(node);
- target.setRecurse(true);
- this.startScan(target, user, null);
- }
-
- /** Start scan all in scope. */
- public void startScanAllInScope() {
- Target target = new Target(true);
- target.setRecurse(true);
- this.startScan(target, null, null);
- }
-
- /**
- * Start scan.
- *
- * @param startNode the start node
- */
- public void startScan(SiteNode startNode) {
- Target target = new Target(startNode);
- target.setRecurse(true);
- this.startScan(target, null, null);
- }
-
- /** Start scan all in context, from the POV of an User. */
- public void startScanAllInContext(Context context, User user) {
- Target target = new Target(context);
- target.setRecurse(true);
- this.startScan(target, user, null);
- }
-
- @Override
- public void destroy() {
- // Shut all of the scans down
- this.stopAllScans();
- if (hasView()) {
- this.getSpiderPanel().reset();
- }
- }
-
- /**
- * Gets the custom parsers loaded.
- *
- * @return the custom parsers
- */
- public List getCustomParsers() {
- return customParsers;
- }
-
- /**
- * Gets the custom fetch filters loaded.
- *
- * @return the custom fetch filters
- */
- public List getCustomFetchFilters() {
- return customFetchFilters;
- }
-
- /**
- * Gets the custom parse filters loaded.
- *
- * @return the custom parse filters
- */
- public List getCustomParseFilters() {
- return customParseFilters;
- }
-
- /**
- * Adds a new custom Spider Parser. The parser is added at the beginning of the parsers list so
- * it will be processed before other already loaded parsers and before the default parsers.
- *
- *
This method should be used to customize the Spider from any other extension of ZAP. The
- * parsers added will be loaded whenever starting any scan.
- *
- * @param parser the parser
- * @throws IllegalArgumentException if the given parameter is {@code null}.
- * @see #removeCustomParser(org.zaproxy.zap.spider.parser.SpiderParser)
- */
- public void addCustomParser(org.zaproxy.zap.spider.parser.SpiderParser parser) {
- validateParameterNonNull(parser, "parser");
- this.customParsers.add(parser);
- }
-
- private static void validateParameterNonNull(Object object, String name) {
- if (object == null) {
- throw new IllegalArgumentException("Parameter " + name + " must not be null.");
- }
- }
-
- /**
- * Removes the given spider parser.
- *
- *
Nothing happens if the given parser was not previously added.
- *
- * @param parser the parser
- * @throws IllegalArgumentException if the given parameter is {@code null}.
- * @since 2.6.0
- * @see #addCustomParser(org.zaproxy.zap.spider.parser.SpiderParser)
- */
- public void removeCustomParser(org.zaproxy.zap.spider.parser.SpiderParser parser) {
- validateParameterNonNull(parser, "parser");
- this.customParsers.remove(parser);
- }
-
- /**
- * Adds a custom fetch filter that would be used during the spidering.
- *
- *
This method should be used to customize the Spider from any other extension of ZAP. The
- * filters added will be loaded whenever starting any scan.
- *
- * @param filter the filter
- * @throws IllegalArgumentException if the given parameter is {@code null}.
- * @see #removeCustomFetchFilter(org.zaproxy.zap.spider.filters.FetchFilter)
- */
- public void addCustomFetchFilter(org.zaproxy.zap.spider.filters.FetchFilter filter) {
- validateParameterNonNull(filter, "filter");
- this.customFetchFilters.add(filter);
- }
-
- /**
- * Removes the given fetch filter.
- *
- *
Nothing happens if the given filter was not previously added.
- *
- * @param filter the filter
- * @throws IllegalArgumentException if the given parameter is {@code null}.
- * @since 2.6.0
- * @see #addCustomFetchFilter(org.zaproxy.zap.spider.filters.FetchFilter)
- */
- public void removeCustomFetchFilter(org.zaproxy.zap.spider.filters.FetchFilter filter) {
- validateParameterNonNull(filter, "filter");
- this.customFetchFilters.remove(filter);
- }
-
- /**
- * Adds a custom parse filter that would be used during the spidering.
- *
- *
This method should be used to customize the Spider from any other extension of ZAP. The
- * filters added will be loaded whenever starting any scan.
- *
- * @param filter the filter
- * @throws IllegalArgumentException if the given parameter is {@code null}.
- * @see #removeCustomParseFilter(org.zaproxy.zap.spider.filters.ParseFilter)
- */
- public void addCustomParseFilter(org.zaproxy.zap.spider.filters.ParseFilter filter) {
- validateParameterNonNull(filter, "filter");
- this.customParseFilters.add(filter);
- }
-
- /**
- * Removes the given parse filter.
- *
- *
Nothing happens if the given filter was not previously added.
- *
- * @param filter the filter
- * @throws IllegalArgumentException if the given parameter is {@code null}.
- * @since 2.6.0
- * @see #addCustomParseFilter(org.zaproxy.zap.spider.filters.ParseFilter)
- */
- public void removeCustomParseFilter(org.zaproxy.zap.spider.filters.ParseFilter filter) {
- validateParameterNonNull(filter, "filter");
- this.customParseFilters.remove(filter);
- }
-
- /**
- * Starts a new spider scan using the given target and, optionally, spidering from the
- * perspective of a user and with custom configurations.
- *
- *
The spider scan will use the most appropriate display name created from the given target,
- * user and custom configurations.
- *
- * @param target the target that will be spidered
- * @param user the user that will be used to spider, might be {@code null}
- * @param customConfigurations other custom configurations for the spider, might be {@code null}
- * @return the ID of the spider scan
- * @since 2.5.0
- * @see #startScan(String, Target, User, Object[])
- * @throws IllegalStateException if the target or custom configurations are not allowed in the
- * current {@link org.parosproxy.paros.control.Control.Mode mode}.
- */
- public int startScan(Target target, User user, Object[] customConfigurations) {
- return startScan(
- createDisplayName(target, customConfigurations),
- target,
- user,
- customConfigurations);
- }
-
- /**
- * Creates the display name for the given target and, optionally, the given custom
- * configurations.
- *
- * @param target the target that will be spidered
- * @param customConfigurations other custom configurations for the spider, might be {@code null}
- * @return a {@code String} containing the display name, never {@code null}
- */
- private String createDisplayName(Target target, Object[] customConfigurations) {
- org.zaproxy.zap.spider.filters.HttpPrefixFetchFilter subtreeFecthFilter =
- getUriPrefixFecthFilter(customConfigurations);
- if (subtreeFecthFilter != null) {
- return abbreviateDisplayName(subtreeFecthFilter.getNormalisedPrefix());
- }
-
- if (target.getContext() != null) {
- return Constant.messages.getString("context.prefixName", target.getContext().getName());
- } else if (target.isInScopeOnly()) {
- return Constant.messages.getString("target.allInScope");
- } else if (target.getStartNode() == null) {
- if (customConfigurations != null) {
- for (Object customConfiguration : customConfigurations) {
- if (customConfiguration instanceof URI) {
- return abbreviateDisplayName(((URI) customConfiguration).toString());
- }
- }
- }
- return Constant.messages.getString("target.empty");
- }
- return abbreviateDisplayName(target.getStartNode().getHierarchicNodeName(false));
- }
-
- /**
- * Gets the {@code HttpPrefixFetchFilter} from the given {@code customConfigurations}.
- *
- * @param customConfigurations the custom configurations of the spider
- * @return the {@code HttpPrefixFetchFilter} found, {@code null} otherwise.
- */
- private org.zaproxy.zap.spider.filters.HttpPrefixFetchFilter getUriPrefixFecthFilter(
- Object[] customConfigurations) {
- if (customConfigurations != null) {
- for (Object customConfiguration : customConfigurations) {
- if (customConfiguration
- instanceof org.zaproxy.zap.spider.filters.HttpPrefixFetchFilter) {
- return (org.zaproxy.zap.spider.filters.HttpPrefixFetchFilter)
- customConfiguration;
- }
- }
- }
- return null;
- }
-
- /**
- * Abbreviates (the middle of) the given display name if greater than 30 characters.
- *
- * @param displayName the display name that might be abbreviated
- * @return the, possibly, abbreviated display name
- */
- private static String abbreviateDisplayName(String displayName) {
- return StringUtils.abbreviateMiddle(displayName, "..", 30);
- }
-
- /**
- * Starts a new spider scan, with the given display name, using the given target and,
- * optionally, spidering from the perspective of a user and with custom configurations.
- *
- *
Note: The preferred method to start the scan is with {@link
- * #startScan(Target, User, Object[])}, unless a custom display name is really needed.
- *
- * @param target the target that will be spidered
- * @param user the user that will be used to spider, might be {@code null}
- * @param customConfigurations other custom configurations for the spider, might be {@code null}
- * @return the ID of the spider scan
- * @throws IllegalStateException if the target or custom configurations are not allowed in the
- * current {@link org.parosproxy.paros.control.Control.Mode mode}.
- */
- @SuppressWarnings({"fallthrough"})
- @Override
- public int startScan(
- String displayName, Target target, User user, Object[] customConfigurations) {
- switch (Control.getSingleton().getMode()) {
- case safe:
- throw new IllegalStateException("Scans are not allowed in Safe mode");
- case protect:
- String uri = getTargetUriOutOfScope(target, customConfigurations);
- if (uri != null) {
- throw new IllegalStateException(
- "Scans are not allowed on targets not in scope when in Protected mode: "
- + uri);
- }
- // $FALL-THROUGH$
- case standard:
- case attack:
- // No problem
- break;
- }
-
- int id = this.scanController.startScan(displayName, target, user, customConfigurations);
- if (hasView()) {
- addScanToUi(this.scanController.getScan(id));
- }
- return id;
- }
-
- private void addScanToUi(final SpiderScan scan) {
- if (!EventQueue.isDispatchThread()) {
- EventQueue.invokeLater(
- new Runnable() {
-
- @Override
- public void run() {
- addScanToUi(scan);
- }
- });
- return;
- }
-
- this.getSpiderPanel().scannerStarted(scan);
- scan.setListener(getSpiderPanel()); // So the UI gets updated
- this.getSpiderPanel().switchView(scan);
- if (isPanelSwitch()) {
- this.getSpiderPanel().setTabFocus();
- }
- }
-
- /**
- * Returns true if the GUI will switch to the Spider panel when a scan is started.
- *
- * @since 2.11.0
- */
- public boolean isPanelSwitch() {
- return panelSwitch;
- }
-
- /**
- * Sets if the GUI will switch to the Spider panel when a scan is started. Code should only set
- * this to false just before starting a scan and reset it to true as soon as the scan has
- * started.
- *
- * @since 2.11.0
- */
- public void setPanelSwitch(boolean panelSwitch) {
- this.panelSwitch = panelSwitch;
- }
-
- /**
- * Returns the first URI that is out of scope in the given {@code target}.
- *
- * @param target the target that will be checked
- * @return a {@code String} with the first URI out of scope, {@code null} if none found
- * @since 2.5.0
- * @see Session#isInScope(String)
- */
- protected String getTargetUriOutOfScope(Target target) {
- return getTargetUriOutOfScope(target, null);
- }
-
- /**
- * Returns the first URI that is out of scope in the given {@code target} or {@code
- * contextSpecificObjects}.
- *
- * @param target the target that will be checked
- * @param contextSpecificObjects other {@code Objects} used to enhance the target
- * @return a {@code String} with the first URI out of scope, {@code null} if none found
- * @since 2.5.0
- * @see Session#isInScope(String)
- */
- protected String getTargetUriOutOfScope(Target target, Object[] contextSpecificObjects) {
- List nodes = target.getStartNodes();
- if (nodes != null) {
- for (StructuralNode node : nodes) {
- if (node == null) {
- continue;
- }
- if (node instanceof StructuralSiteNode) {
- SiteNode siteNode = ((StructuralSiteNode) node).getSiteNode();
- if (!siteNode.isIncludedInScope()) {
- return node.getURI().toString();
- }
- } else {
- String uri = node.getURI().toString();
- if (!isTargetUriInScope(uri)) {
- return uri;
- }
- }
- }
- }
- if (contextSpecificObjects != null) {
- for (Object obj : contextSpecificObjects) {
- if (obj instanceof URI) {
- String uri = ((URI) obj).toString();
- if (!isTargetUriInScope(uri)) {
- return uri;
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Tells whether or not the given {@code uri} is in scope.
- *
- * @param uri the uri that will be checked
- * @return {@code true} if the {@code uri} is in scope, {@code false} otherwise
- * @since 2.5.0
- * @see Session#isInScope(String)
- */
- protected boolean isTargetUriInScope(String uri) {
- if (uri == null) {
- return false;
- }
- return getModel().getSession().isInScope(uri);
- }
-
- @Override
- public List getAllScans() {
- return this.scanController.getAllScans();
- }
-
- @Override
- public List getActiveScans() {
- return this.scanController.getActiveScans();
- }
-
- @Override
- public SpiderScan getScan(int id) {
- return this.scanController.getScan(id);
- }
-
- @Override
- public void stopScan(int id) {
- this.scanController.stopScan(id);
- }
-
- @Override
- public void stopAllScans() {
- this.scanController.stopAllScans();
- }
-
- @Override
- public void pauseScan(int id) {
- this.scanController.pauseScan(id);
- if (hasView()) {
- // Update the UI in case this was initiated from the API
- this.getSpiderPanel().updateScannerUI();
- }
- }
-
- @Override
- public void pauseAllScans() {
- this.scanController.pauseAllScans();
- if (hasView()) {
- // Update the UI in case this was initiated from the API
- this.getSpiderPanel().updateScannerUI();
- }
- }
-
- @Override
- public void resumeScan(int id) {
- this.scanController.resumeScan(id);
- if (hasView()) {
- // Update the UI in case this was initiated from the API
- this.getSpiderPanel().updateScannerUI();
- }
- }
-
- @Override
- public void resumeAllScans() {
- this.scanController.resumeAllScans();
- if (hasView()) {
- // Update the UI in case this was initiated from the API
- this.getSpiderPanel().updateScannerUI();
- }
- }
-
- @Override
- public SpiderScan removeScan(int id) {
- return this.scanController.removeScan(id);
- }
-
- @Override
- public int removeAllScans() {
- return this.scanController.removeAllScans();
- }
-
- @Override
- public int removeFinishedScans() {
- return this.scanController.removeFinishedScans();
- }
-
- @Override
- public SpiderScan getLastScan() {
- return this.scanController.getLastScan();
- }
-
- private ZapMenuItem getMenuItemCustomScan() {
- if (menuItemCustomScan == null) {
- menuItemCustomScan =
- new ZapMenuItem(
- "menu.tools.spider",
- getView()
- .getMenuShortcutKeyStroke(
- KeyEvent.VK_S, KeyEvent.ALT_DOWN_MASK, false));
- menuItemCustomScan.setEnabled(Control.getSingleton().getMode() != Mode.safe);
-
- menuItemCustomScan.addActionListener(e -> showSpiderDialog((Target) null));
- }
-
- return menuItemCustomScan;
- }
-
- public void showSpiderDialog(SiteNode node) {
- showSpiderDialog(node != null ? new Target(node) : null);
- }
-
- /**
- * Shows the spider dialogue with the given target, if not already visible.
- *
- * @param target the target, might be {@code null}.
- * @since 2.8.0.
- */
- public void showSpiderDialog(Target target) {
- if (spiderDialog == null) {
- spiderDialog =
- new SpiderDialog(this, getView().getMainFrame(), new Dimension(700, 430));
- }
- if (spiderDialog.isVisible()) {
- // Its behind you! Actually not needed no the window is alwaysOnTop, but keeping in case
- // we change that ;)
- spiderDialog.toFront();
- return;
- }
- if (target != null) {
- spiderDialog.init(target);
- } else {
- // Keep the previous target
- spiderDialog.init(null);
- }
- spiderDialog.setVisible(true);
- }
-
- @Override
- public boolean supportsLowMemory() {
- return true;
- }
-
- /** No database tables used, so all supported */
- @Override
- public boolean supportsDb(String type) {
- return true;
- }
-
- /**
- * Gets the icon for spider related functionality.
- *
- * @return the icon
- */
- public Icon getIcon() {
- if (icon == null) {
- icon = new ImageIcon(ExtensionSpider.class.getResource("/resource/icon/16/spider.png"));
- }
- return icon;
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/OptionsSpiderPanel.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/OptionsSpiderPanel.java
deleted file mode 100644
index f3b461106e2..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/OptionsSpiderPanel.java
+++ /dev/null
@@ -1,649 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2012 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import java.awt.BorderLayout;
-import java.awt.CardLayout;
-import java.awt.Component;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import javax.swing.BorderFactory;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSlider;
-import javax.swing.ScrollPaneConstants;
-import javax.swing.SortOrder;
-import javax.swing.border.Border;
-import javax.swing.border.EmptyBorder;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-import javax.swing.plaf.basic.BasicComboBoxRenderer;
-import org.parosproxy.paros.Constant;
-import org.parosproxy.paros.model.Model;
-import org.parosproxy.paros.model.OptionsParam;
-import org.parosproxy.paros.view.AbstractParamPanel;
-import org.parosproxy.paros.view.View;
-import org.zaproxy.zap.utils.ZapNumberSpinner;
-import org.zaproxy.zap.utils.ZapTextArea;
-import org.zaproxy.zap.view.AbstractMultipleOptionsTablePanel;
-import org.zaproxy.zap.view.LayoutHelper;
-import org.zaproxy.zap.view.PositiveValuesSlider;
-
-/**
- * The Class OptionsSpiderPanel defines the Options Panel showed when configuring settings related
- * to the spider.
- *
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-public class OptionsSpiderPanel extends AbstractParamPanel {
-
- /** The Constant serialVersionUID. */
- private static final long serialVersionUID = -5623691753271231473L;
-
- /** The full panel for the spider options. */
- private JPanel panelSpider = null;
-
- // The controls for the options:
- private JSlider sliderMaxDepth = null;
- private JSlider sliderThreads = null;
- private ZapNumberSpinner durationNumberSpinner = null;
- private ZapNumberSpinner maxChildrenNumberSpinner;
- private ZapNumberSpinner maxParseSizeBytesNumberSpinner;
- private JCheckBox chkPostForm = null;
- private JCheckBox chkProcessForm = null;
- private JCheckBox parseComments = null;
- private JCheckBox parseRobotsTxt = null;
- private JCheckBox parseSitemapXml = null;
- private JCheckBox parseSVNEntries = null;
- private JCheckBox parseGit = null;
- private JCheckBox handleODataSpecificParameters = null;
- private JCheckBox chkSendRefererHeader;
- private JCheckBox chkAcceptCookies;
- private DomainsAlwaysInScopeMultipleOptionsPanel domainsAlwaysInScopePanel;
- private DomainsAlwaysInScopeTableModel domainsAlwaysInScopeTableModel;
- private ZapTextArea irrelevantUrlParameters;
-
- private JComboBox handleParameters =
- null;
-
- /** Instantiates a new options spider panel. */
- public OptionsSpiderPanel() {
- super();
- initialize();
- }
-
- /** This method initializes this options Panel. */
- private void initialize() {
- this.setLayout(new CardLayout());
- this.setName(Constant.messages.getString("spider.options.title"));
- if (Model.getSingleton().getOptionsParam().getViewParam().getWmUiHandlingOption() == 0) {
- this.setSize(314, 245);
- }
- this.add(getPanelSpider(), getPanelSpider().getName());
- }
-
- /**
- * This method initializes the main panel containing all option controls.
- *
- * @return the panel for the spider options.
- */
- private JPanel getPanelSpider() {
- if (panelSpider == null) {
-
- // Initialize the panel
- panelSpider = new JPanel(new BorderLayout());
- if (Model.getSingleton().getOptionsParam().getViewParam().getWmUiHandlingOption()
- == 0) {
- panelSpider.setSize(114, 150);
- }
- panelSpider.setName("");
-
- // Prepare the necessary labels
- JLabel domainsLabel = new JLabel();
- JLabel noThreadsLabel = new JLabel();
- JLabel maxDuration = new JLabel();
- JLabel maxDepthLabel = new JLabel();
- JLabel handleParametersLabel = new JLabel();
-
- maxDepthLabel.setText(Constant.messages.getString("spider.options.label.depth"));
- noThreadsLabel.setText(Constant.messages.getString("spider.options.label.threads"));
- maxDuration.setText(Constant.messages.getString("spider.options.label.duration"));
- domainsLabel.setText(Constant.messages.getString("spider.options.label.domains"));
- handleParametersLabel.setText(
- Constant.messages.getString("spider.options.label.handleparameters"));
-
- JPanel innerPanel = new JPanel(new GridBagLayout());
-
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.weightx = 1.0D;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.anchor = GridBagConstraints.NORTHWEST;
- Insets insets = new Insets(2, 2, 2, 2);
- gbc.insets = insets;
-
- // Add the components on the panel
- innerPanel.add(maxDepthLabel, gbc);
- innerPanel.add(getSliderMaxDepth(), gbc);
- innerPanel.add(noThreadsLabel, gbc);
- innerPanel.add(getSliderThreads(), gbc);
-
- JPanel inlineOptionsPanel = new JPanel(new GridBagLayout());
- inlineOptionsPanel.add(maxDuration, LayoutHelper.getGBC(0, 0, 1, 1.0D));
- inlineOptionsPanel.add(getDurationNumberSpinner(), LayoutHelper.getGBC(1, 0, 1, 1.0D));
-
- inlineOptionsPanel.add(
- new JLabel(Constant.messages.getString("spider.options.label.maxChildren")),
- LayoutHelper.getGBC(0, 1, 1, 1.0D));
- inlineOptionsPanel.add(
- getMaxChildrenNumberSpinner(), LayoutHelper.getGBC(1, 1, 1, 1.0D));
-
- inlineOptionsPanel.add(
- new JLabel(
- Constant.messages.getString("spider.options.label.maxParseSizeBytes")),
- LayoutHelper.getGBC(0, 2, 1, 1.0D));
- inlineOptionsPanel.add(
- getMaxParseSizeBytesNumberSpinner(), LayoutHelper.getGBC(1, 2, 1, 1.0D));
-
- innerPanel.add(inlineOptionsPanel, gbc);
-
- innerPanel.add(domainsLabel, gbc);
- gbc.fill = GridBagConstraints.BOTH;
- gbc.weighty = 1.0D;
- innerPanel.add(getDomainsAlwaysInScopePanel(), gbc);
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weighty = 0;
- innerPanel.add(getChkSendRefererHeader(), gbc);
- innerPanel.add(getChkAcceptCookies(), gbc);
- innerPanel.add(handleParametersLabel, gbc);
- innerPanel.add(getComboHandleParameters(), gbc);
- innerPanel.add(getChkProcessForm(), gbc);
- insets.left = 15;
- innerPanel.add(getChkPostForm(), gbc);
- insets.left = 2;
- innerPanel.add(getChkParseComments(), gbc);
- innerPanel.add(getChkParseRobotsTxt(), gbc);
- innerPanel.add(getChkParseSitemapXml(), gbc);
- innerPanel.add(getChkParseSVNEntries(), gbc);
- innerPanel.add(getChkParseGit(), gbc);
- innerPanel.add(getHandleODataSpecificParameters(), gbc);
-
- ZapTextArea irrelevantUrlParameters = getIrrelevantUrlParameters();
- JLabel label =
- new JLabel(
- Constant.messages.getString(
- "spider.options.label.irrelevantUrlParameters"));
- label.setLabelFor(irrelevantUrlParameters);
- JScrollPane irrelevantUrlParametersScrollPane = new JScrollPane();
- irrelevantUrlParametersScrollPane.setVerticalScrollBarPolicy(
- ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
- irrelevantUrlParametersScrollPane.setViewportView(irrelevantUrlParameters);
-
- innerPanel.add(label, gbc);
- innerPanel.add(irrelevantUrlParametersScrollPane, gbc);
-
- JScrollPane scrollPane = new JScrollPane(innerPanel);
- scrollPane.setBorder(BorderFactory.createEmptyBorder());
-
- panelSpider.add(scrollPane, BorderLayout.CENTER);
- }
- return panelSpider;
- }
-
- @Override
- public void initParam(Object obj) {
- OptionsParam options = (OptionsParam) obj;
-
- org.zaproxy.zap.spider.SpiderParam param =
- options.getParamSet(org.zaproxy.zap.spider.SpiderParam.class);
- getSliderMaxDepth().setValue(param.getMaxDepth());
- getSliderThreads().setValue(param.getThreadCount());
- getDurationNumberSpinner().setValue(param.getMaxDuration());
- getMaxChildrenNumberSpinner().setValue(param.getMaxChildren());
- getMaxParseSizeBytesNumberSpinner().setValue(param.getMaxParseSizeBytes());
- getDomainsAlwaysInScopeTableModel()
- .setDomainsAlwaysInScope(param.getDomainsAlwaysInScope());
- getDomainsAlwaysInScopePanel()
- .setRemoveWithoutConfirmation(param.isConfirmRemoveDomainAlwaysInScope());
- getChkProcessForm().setSelected(param.isProcessForm());
- getChkSendRefererHeader().setSelected(param.isSendRefererHeader());
- getChkAcceptCookies().setSelected(param.isAcceptCookies());
- getChkPostForm().setSelected(param.isPostForm());
- getChkParseComments().setSelected(param.isParseComments());
- getChkParseRobotsTxt().setSelected(param.isParseRobotsTxt());
- getChkParseSitemapXml().setSelected(param.isParseSitemapXml());
- getChkParseSVNEntries().setSelected(param.isParseSVNEntries());
- getChkParseGit().setSelected(param.isParseGit());
- getComboHandleParameters().setSelectedItem(param.getHandleParameters());
- getHandleODataSpecificParameters().setSelected(param.isHandleODataParametersVisited());
- getIrrelevantUrlParameters().setText(param.getIrrelevantUrlParametersAsString());
- getIrrelevantUrlParameters().discardAllEdits();
- }
-
- @Override
- public void saveParam(Object obj) throws Exception {
- OptionsParam options = (OptionsParam) obj;
- org.zaproxy.zap.spider.SpiderParam param =
- options.getParamSet(org.zaproxy.zap.spider.SpiderParam.class);
- param.setMaxDepth(getSliderMaxDepth().getValue());
- param.setThreadCount(getSliderThreads().getValue());
- param.setMaxDuration(getDurationNumberSpinner().getValue());
- param.setMaxChildren(getMaxChildrenNumberSpinner().getValue());
- param.setMaxParseSizeBytes(getMaxParseSizeBytesNumberSpinner().getValue());
- param.setDomainsAlwaysInScope(
- getDomainsAlwaysInScopeTableModel().getDomainsAlwaysInScope());
- param.setConfirmRemoveDomainAlwaysInScope(
- getDomainsAlwaysInScopePanel().isRemoveWithoutConfirmation());
- param.setSendRefererHeader(getChkSendRefererHeader().isSelected());
- param.setAcceptCookies(getChkAcceptCookies().isSelected());
- param.setProcessForm(getChkProcessForm().isSelected());
- param.setPostForm(getChkPostForm().isSelected());
- param.setParseComments(getChkParseComments().isSelected());
- param.setParseRobotsTxt(getChkParseRobotsTxt().isSelected());
- param.setParseSitemapXml(getChkParseSitemapXml().isSelected());
- param.setParseSVNEntries(getChkParseSVNEntries().isSelected());
- param.setParseGit(getChkParseGit().isSelected());
- param.setHandleParameters(
- (org.zaproxy.zap.spider.SpiderParam.HandleParametersOption)
- getComboHandleParameters().getSelectedItem());
- param.setHandleODataParametersVisited(getHandleODataSpecificParameters().isSelected());
- param.setIrrelevantUrlParameters(getIrrelevantUrlParameters().getText());
- }
-
- /**
- * This method initializes the slider for MaxDepth.
- *
- * @return the slider for max depth
- */
- private JSlider getSliderMaxDepth() {
- if (sliderMaxDepth == null) {
- sliderMaxDepth = new JSlider();
- sliderMaxDepth.setMaximum(19);
- sliderMaxDepth.setMinimum(0);
- sliderMaxDepth.setMinorTickSpacing(1);
- sliderMaxDepth.setPaintTicks(true);
- sliderMaxDepth.setPaintLabels(true);
- sliderMaxDepth.setName("");
- sliderMaxDepth.setMajorTickSpacing(1);
- sliderMaxDepth.setSnapToTicks(true);
- sliderMaxDepth.setPaintTrack(true);
- }
- return sliderMaxDepth;
- }
-
- /**
- * This method initializes the slider for maximum number of threads used.
- *
- * @return javax.swing.JSlider
- */
- private JSlider getSliderThreads() {
- if (sliderThreads == null) {
- sliderThreads = new PositiveValuesSlider(Constant.MAX_THREADS_PER_SCAN);
- }
- return sliderThreads;
- }
-
- private ZapNumberSpinner getDurationNumberSpinner() {
- if (durationNumberSpinner == null) {
- durationNumberSpinner = new ZapNumberSpinner(0, 0, Integer.MAX_VALUE);
- }
- return durationNumberSpinner;
- }
-
- private ZapNumberSpinner getMaxChildrenNumberSpinner() {
- if (maxChildrenNumberSpinner == null) {
- maxChildrenNumberSpinner = new ZapNumberSpinner(0, 0, Integer.MAX_VALUE);
- }
- return maxChildrenNumberSpinner;
- }
-
- private ZapNumberSpinner getMaxParseSizeBytesNumberSpinner() {
- if (maxParseSizeBytesNumberSpinner == null) {
- maxParseSizeBytesNumberSpinner = new ZapNumberSpinner(0, 0, Integer.MAX_VALUE);
- }
- return maxParseSizeBytesNumberSpinner;
- }
-
- private JCheckBox getChkSendRefererHeader() {
- if (chkSendRefererHeader == null) {
- chkSendRefererHeader =
- new JCheckBox(
- Constant.messages.getString("spider.options.label.sendRefererHeader"));
- }
- return chkSendRefererHeader;
- }
-
- private JCheckBox getChkAcceptCookies() {
- if (chkAcceptCookies == null) {
- chkAcceptCookies =
- new JCheckBox(
- Constant.messages.getString("spider.options.label.acceptcookies"));
- }
- return chkAcceptCookies;
- }
-
- /**
- * This method initializes the checkbox for POST form option. This option should not be enabled
- * if the forms are not processed at all.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkPostForm() {
- if (chkPostForm == null) {
- chkPostForm = new JCheckBox();
- chkPostForm.setText(Constant.messages.getString("spider.options.label.post"));
-
- if (!getChkProcessForm().isSelected()) {
- chkPostForm.setEnabled(false);
- }
- }
- return chkPostForm;
- }
-
- /**
- * This method initializes the checkbox for process form option.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkProcessForm() {
- if (chkProcessForm == null) {
- chkProcessForm = new JCheckBox();
- chkProcessForm.setText(Constant.messages.getString("spider.options.label.processform"));
-
- // Code for controlling the status of the chkPostForm
- chkProcessForm.addChangeListener(
- new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent ev) {
- if (chkProcessForm.isSelected()) {
- chkPostForm.setEnabled(true);
- } else {
- chkPostForm.setEnabled(false);
- }
- }
- });
- }
- return chkProcessForm;
- }
-
- /**
- * This method initializes the Parse Comments checkbox.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkParseComments() {
- if (parseComments == null) {
- parseComments = new JCheckBox();
- parseComments.setText(Constant.messages.getString("spider.options.label.comments"));
- }
- return parseComments;
- }
-
- /**
- * This method initializes the Parse robots.txt checkbox.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkParseRobotsTxt() {
- if (parseRobotsTxt == null) {
- parseRobotsTxt = new JCheckBox();
- parseRobotsTxt.setText(Constant.messages.getString("spider.options.label.robotstxt"));
- }
- return parseRobotsTxt;
- }
-
- /**
- * This method initializes the Parse sitemap.xml checkbox.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkParseSitemapXml() {
- if (parseSitemapXml == null) {
- parseSitemapXml = new JCheckBox();
- parseSitemapXml.setText(Constant.messages.getString("spider.options.label.sitemapxml"));
- }
- return parseSitemapXml;
- }
-
- /**
- * This method initializes the Parse "SVN Entries" checkbox.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkParseSVNEntries() {
- if (parseSVNEntries == null) {
- parseSVNEntries = new JCheckBox();
- parseSVNEntries.setText(Constant.messages.getString("spider.options.label.svnentries"));
- }
- return parseSVNEntries;
- }
-
- /**
- * This method initializes the Parse "Git" checkbox.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getChkParseGit() {
- if (parseGit == null) {
- parseGit = new JCheckBox();
- parseGit.setText(Constant.messages.getString("spider.options.label.git"));
- }
- return parseGit;
- }
-
- /**
- * This method initializes the Handle OData-specific parameters checkbox.
- *
- * @return javax.swing.JCheckBox
- */
- private JCheckBox getHandleODataSpecificParameters() {
- if (handleODataSpecificParameters == null) {
- handleODataSpecificParameters = new JCheckBox();
- handleODataSpecificParameters.setText(
- Constant.messages.getString("spider.options.label.handlehodataparameters"));
- }
- return handleODataSpecificParameters;
- }
-
- /**
- * This method initializes the combobox for HandleParameters option.
- *
- * @return the combo handle parameters
- */
- @SuppressWarnings("unchecked")
- private JComboBox
- getComboHandleParameters() {
- if (handleParameters == null) {
- handleParameters =
- new JComboBox<>(
- new org.zaproxy.zap.spider.SpiderParam.HandleParametersOption[] {
- org.zaproxy.zap.spider.SpiderParam.HandleParametersOption.USE_ALL,
- org.zaproxy.zap.spider.SpiderParam.HandleParametersOption
- .IGNORE_VALUE,
- org.zaproxy.zap.spider.SpiderParam.HandleParametersOption
- .IGNORE_COMPLETELY
- });
- handleParameters.setRenderer(new HandleParametersOptionRenderer());
- }
- return handleParameters;
- }
-
- private DomainsAlwaysInScopeMultipleOptionsPanel getDomainsAlwaysInScopePanel() {
- if (domainsAlwaysInScopePanel == null) {
- domainsAlwaysInScopePanel =
- new DomainsAlwaysInScopeMultipleOptionsPanel(
- getDomainsAlwaysInScopeTableModel());
- }
- return domainsAlwaysInScopePanel;
- }
-
- private DomainsAlwaysInScopeTableModel getDomainsAlwaysInScopeTableModel() {
- if (domainsAlwaysInScopeTableModel == null) {
- domainsAlwaysInScopeTableModel = new DomainsAlwaysInScopeTableModel();
- }
- return domainsAlwaysInScopeTableModel;
- }
-
- private ZapTextArea getIrrelevantUrlParameters() {
- if (irrelevantUrlParameters == null) {
- irrelevantUrlParameters = new ZapTextArea();
- irrelevantUrlParameters.setLineWrap(true);
- }
- return irrelevantUrlParameters;
- }
-
- /** A renderer for properly displaying the name of the HandleParametersOptions in a ComboBox. */
- private static class HandleParametersOptionRenderer extends BasicComboBoxRenderer {
- private static final long serialVersionUID = 3654541772447187317L;
- private static final Border BORDER = new EmptyBorder(2, 3, 3, 3);
-
- @Override
- @SuppressWarnings("rawtypes")
- public Component getListCellRendererComponent(
- JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
- if (value != null) {
- setBorder(BORDER);
- org.zaproxy.zap.spider.SpiderParam.HandleParametersOption item =
- (org.zaproxy.zap.spider.SpiderParam.HandleParametersOption) value;
- setText(item.getName());
- }
- return this;
- }
- }
-
- /**
- * This method initializes the help index.
- *
- * @return the help index
- */
- @Override
- public String getHelpIndex() {
- return "ui.dialogs.options.spider";
- }
-
- private static class DomainsAlwaysInScopeMultipleOptionsPanel
- extends AbstractMultipleOptionsTablePanel<
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher> {
-
- private static final long serialVersionUID = 2332044353650231701L;
-
- private static final String REMOVE_DIALOG_TITLE =
- Constant.messages.getString("spider.options.domains.in.scope.dialog.remove.title");
- private static final String REMOVE_DIALOG_TEXT =
- Constant.messages.getString("spider.options.domains.in.scope.dialog.remove.text");
-
- private static final String REMOVE_DIALOG_CONFIRM_BUTTON_LABEL =
- Constant.messages.getString(
- "spider.options.domains.in.scope.dialog.remove.button.confirm");
- private static final String REMOVE_DIALOG_CANCEL_BUTTON_LABEL =
- Constant.messages.getString(
- "spider.options.domains.in.scope.dialog.remove.button.cancel");
-
- private static final String REMOVE_DIALOG_CHECKBOX_LABEL =
- Constant.messages.getString(
- "spider.options.domains.in.scope.dialog.remove.checkbox.label");
-
- private DialogAddDomainAlwaysInScope addDialog = null;
- private DialogModifyDomainAlwaysInScope modifyDialog = null;
-
- public DomainsAlwaysInScopeMultipleOptionsPanel(DomainsAlwaysInScopeTableModel model) {
- super(model);
-
- getTable().setVisibleRowCount(5);
- getTable().setSortOrder(2, SortOrder.ASCENDING);
- }
-
- @Override
- public org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher showAddDialogue() {
- if (addDialog == null) {
- addDialog =
- new DialogAddDomainAlwaysInScope(
- View.getSingleton().getOptionsDialog(null));
- addDialog.pack();
- }
- addDialog.setVisible(true);
-
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher hostAuthentication =
- addDialog.getDomainAlwaysInScope();
- addDialog.clear();
-
- return hostAuthentication;
- }
-
- @Override
- public org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher showModifyDialogue(
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher e) {
- if (modifyDialog == null) {
- modifyDialog =
- new DialogModifyDomainAlwaysInScope(
- View.getSingleton().getOptionsDialog(null));
- modifyDialog.pack();
- }
- modifyDialog.setDomainAlwaysInScope(e);
- modifyDialog.setVisible(true);
-
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher excludedDomain =
- modifyDialog.getDomainAlwaysInScope();
- modifyDialog.clear();
-
- if (!excludedDomain.equals(e)) {
- return excludedDomain;
- }
-
- return null;
- }
-
- @Override
- public boolean showRemoveDialogue(org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher e) {
- JCheckBox removeWithoutConfirmationCheckBox =
- new JCheckBox(REMOVE_DIALOG_CHECKBOX_LABEL);
- Object[] messages = {REMOVE_DIALOG_TEXT, " ", removeWithoutConfirmationCheckBox};
- int option =
- JOptionPane.showOptionDialog(
- View.getSingleton().getMainFrame(),
- messages,
- REMOVE_DIALOG_TITLE,
- JOptionPane.OK_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE,
- null,
- new String[] {
- REMOVE_DIALOG_CONFIRM_BUTTON_LABEL,
- REMOVE_DIALOG_CANCEL_BUTTON_LABEL
- },
- null);
-
- if (option == JOptionPane.OK_OPTION) {
- setRemoveWithoutConfirmation(removeWithoutConfirmationCheckBox.isSelected());
-
- return true;
- }
-
- return false;
- }
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/PopupMenuItemSpiderDialog.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/PopupMenuItemSpiderDialog.java
deleted file mode 100644
index 269689ff6ce..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/PopupMenuItemSpiderDialog.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2017 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import org.parosproxy.paros.Constant;
-import org.parosproxy.paros.model.SiteNode;
-import org.zaproxy.zap.view.messagecontainer.http.HttpMessageContainer;
-import org.zaproxy.zap.view.popup.PopupMenuItemSiteNodeContainer;
-
-/**
- * A {@code PopupMenuItemSiteNodeContainer} that allows to show the Spider dialogue, for a selected
- * {@link SiteNode}.
- *
- * @see org.zaproxy.zap.extension.spider.ExtensionSpider#showSpiderDialog(SiteNode)
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@SuppressWarnings("serial")
-@Deprecated
-public class PopupMenuItemSpiderDialog extends PopupMenuItemSiteNodeContainer {
-
- private static final long serialVersionUID = 1L;
-
- private final ExtensionSpider extension;
-
- public PopupMenuItemSpiderDialog(ExtensionSpider extension) {
- super(Constant.messages.getString("spider.custom.popup"));
-
- this.setIcon(extension.getIcon());
- this.extension = extension;
- }
-
- @Override
- public boolean isSubMenu() {
- return true;
- }
-
- @Override
- public String getParentMenuName() {
- return Constant.messages.getString("attack.site.popup");
- }
-
- @Override
- public void performAction(SiteNode node) {
- extension.showSpiderDialog(node);
- }
-
- @Override
- protected boolean isEnableForInvoker(
- Invoker invoker, HttpMessageContainer httpMessageContainer) {
- switch (invoker) {
- case ALERTS_PANEL:
- case ACTIVE_SCANNER_PANEL:
- case FORCED_BROWSE_PANEL:
- case FUZZER_PANEL:
- return false;
- case HISTORY_PANEL:
- case SITES_PANEL:
- case SEARCH_PANEL:
- default:
- return true;
- }
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/PopupMenuItemSpiderDialogWithContext.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/PopupMenuItemSpiderDialogWithContext.java
deleted file mode 100644
index b188055d820..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/PopupMenuItemSpiderDialogWithContext.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2018 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import org.parosproxy.paros.model.Model;
-import org.zaproxy.zap.extension.stdmenus.PopupContextTreeMenu;
-import org.zaproxy.zap.model.Context;
-import org.zaproxy.zap.model.Target;
-
-/**
- * A {@code PopupContextTreeMenu} that allows to show the Spider dialogue for a selected {@link
- * Context}.
- *
- * @see ExtensionSpider#showSpiderDialog(Target)
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-public class PopupMenuItemSpiderDialogWithContext extends PopupContextTreeMenu {
-
- private static final long serialVersionUID = 1L;
-
- public PopupMenuItemSpiderDialogWithContext(ExtensionSpider extension) {
- super(false);
-
- this.setText(extension.getMessages().getString("spider.custom.popup"));
- this.setIcon(extension.getIcon());
-
- this.addActionListener(
- e -> {
- Context context = Model.getSingleton().getSession().getContext(getContextId());
- extension.showSpiderDialog(new Target(context));
- });
- }
-}
diff --git a/zap/src/main/java/org/zaproxy/zap/extension/spider/SpiderAPI.java b/zap/src/main/java/org/zaproxy/zap/extension/spider/SpiderAPI.java
deleted file mode 100644
index 0bcc14b27d5..00000000000
--- a/zap/src/main/java/org/zaproxy/zap/extension/spider/SpiderAPI.java
+++ /dev/null
@@ -1,754 +0,0 @@
-/*
- * Zed Attack Proxy (ZAP) and its related class files.
- *
- * ZAP is an HTTP/HTTPS proxy for assessing web application security.
- *
- * Copyright 2011 The ZAP Development Team
- *
- * 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 org.zaproxy.zap.extension.spider;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.PatternSyntaxException;
-import net.sf.json.JSONException;
-import net.sf.json.JSONObject;
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.URIException;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.parosproxy.paros.control.Control;
-import org.parosproxy.paros.db.DatabaseException;
-import org.parosproxy.paros.db.RecordHistory;
-import org.parosproxy.paros.db.TableHistory;
-import org.parosproxy.paros.model.HistoryReference;
-import org.parosproxy.paros.model.Model;
-import org.parosproxy.paros.model.Session;
-import org.parosproxy.paros.network.HttpMalformedHeaderException;
-import org.zaproxy.zap.extension.api.ApiAction;
-import org.zaproxy.zap.extension.api.ApiException;
-import org.zaproxy.zap.extension.api.ApiException.Type;
-import org.zaproxy.zap.extension.api.ApiImplementor;
-import org.zaproxy.zap.extension.api.ApiResponse;
-import org.zaproxy.zap.extension.api.ApiResponseElement;
-import org.zaproxy.zap.extension.api.ApiResponseList;
-import org.zaproxy.zap.extension.api.ApiResponseSet;
-import org.zaproxy.zap.extension.api.ApiView;
-import org.zaproxy.zap.extension.users.ExtensionUserManagement;
-import org.zaproxy.zap.model.Context;
-import org.zaproxy.zap.model.SessionStructure;
-import org.zaproxy.zap.model.StructuralNode;
-import org.zaproxy.zap.model.Target;
-import org.zaproxy.zap.users.User;
-import org.zaproxy.zap.utils.ApiUtils;
-
-/**
- * @deprecated (2.12.0) See the spider add-on in zap-extensions instead.
- */
-@Deprecated
-public class SpiderAPI extends ApiImplementor {
-
- private static final Logger log = LogManager.getLogger(SpiderAPI.class);
-
- /** The Constant PREFIX defining the name/prefix of the api. */
- private static final String PREFIX = "spider";
-
- /** The Constant ACTION_START_SCAN that defines the action of starting a new scan. */
- private static final String ACTION_START_SCAN = "scan";
-
- private static final String ACTION_START_SCAN_AS_USER = "scanAsUser";
-
- private static final String ACTION_PAUSE_SCAN = "pause";
- private static final String ACTION_RESUME_SCAN = "resume";
-
- /** The Constant ACTION_STOP_SCAN that defines the action of stopping a pending scan. */
- private static final String ACTION_STOP_SCAN = "stop";
-
- private static final String ACTION_PAUSE_ALL_SCANS = "pauseAllScans";
- private static final String ACTION_RESUME_ALL_SCANS = "resumeAllScans";
- private static final String ACTION_STOP_ALL_SCANS = "stopAllScans";
- private static final String ACTION_REMOVE_SCAN = "removeScan";
- private static final String ACTION_REMOVE_ALL_SCANS = "removeAllScans";
-
- private static final String ACTION_ADD_DOMAIN_ALWAYS_IN_SCOPE = "addDomainAlwaysInScope";
- private static final String ACTION_MODIFY_DOMAIN_ALWAYS_IN_SCOPE = "modifyDomainAlwaysInScope";
- private static final String ACTION_REMOVE_DOMAIN_ALWAYS_IN_SCOPE = "removeDomainAlwaysInScope";
- private static final String ACTION_ENABLE_ALL_DOMAINS_ALWAYS_IN_SCOPE =
- "enableAllDomainsAlwaysInScope";
- private static final String ACTION_DISABLE_ALL_DOMAINS_ALWAYS_IN_SCOPE =
- "disableAllDomainsAlwaysInScope";
-
- /**
- * The Constant VIEW_STATUS that defines the view which describes the current status of the
- * scan.
- */
- private static final String VIEW_STATUS = "status";
-
- /**
- * The Constant VIEW_RESULTS that defines the view which describes the urls found during the
- * scan.
- */
- private static final String VIEW_RESULTS = "results";
-
- private static final String VIEW_FULL_RESULTS = "fullResults";
- private static final String VIEW_SCANS = "scans";
- private static final String VIEW_ALL_URLS = "allUrls";
- private static final String VIEW_ADDED_NODES = "addedNodes";
-
- private static final String VIEW_DOMAINS_ALWAYS_IN_SCOPE = "domainsAlwaysInScope";
- private static final String VIEW_OPTION_DOMAINS_ALWAYS_IN_SCOPE = "optionDomainsAlwaysInScope";
- private static final String VIEW_OPTION_DOMAINS_ALWAYS_IN_SCOPE_ENABLED =
- "optionDomainsAlwaysInScopeEnabled";
-
- /** The Constant PARAM_URL that defines the parameter defining the url of the scan. */
- private static final String PARAM_URL = "url";
-
- private static final String PARAM_USER_ID = "userId";
- private static final String PARAM_CONTEXT_ID = "contextId";
- private static final String PARAM_CONTEXT_NAME = "contextName";
- private static final String PARAM_REGEX = "regex";
- private static final String PARAM_RECURSE = "recurse";
- private static final String PARAM_SCAN_ID = "scanId";
- private static final String PARAM_MAX_CHILDREN = "maxChildren";
- private static final String PARAM_SUBTREE_ONLY = "subtreeOnly";
- private static final String PARAM_VALUE = "value";
- private static final String PARAM_IDX = "idx";
- private static final String PARAM_IS_REGEX = "isRegex";
- private static final String PARAM_IS_ENABLED = "isEnabled";
-
- private static final String ACTION_EXCLUDE_FROM_SCAN = "excludeFromScan";
- private static final String ACTION_CLEAR_EXCLUDED_FROM_SCAN = "clearExcludedFromScan";
-
- private static final String VIEW_EXCLUDED_FROM_SCAN = "excludedFromScan";
-
- /** The spider extension. */
- private ExtensionSpider extension;
-
- /**
- * Instantiates a new spider API.
- *
- * @param extension the extension
- */
- public SpiderAPI(ExtensionSpider extension) {
- this.extension = extension;
- // Register the actions
- this.addApiAction(
- new ApiAction(
- ACTION_START_SCAN,
- null,
- new String[] {
- PARAM_URL,
- PARAM_MAX_CHILDREN,
- PARAM_RECURSE,
- PARAM_CONTEXT_NAME,
- PARAM_SUBTREE_ONLY
- }));
- this.addApiAction(
- new ApiAction(
- ACTION_START_SCAN_AS_USER,
- new String[] {PARAM_CONTEXT_ID, PARAM_USER_ID},
- new String[] {
- PARAM_URL, PARAM_MAX_CHILDREN, PARAM_RECURSE, PARAM_SUBTREE_ONLY
- }));
- this.addApiAction(new ApiAction(ACTION_PAUSE_SCAN, new String[] {PARAM_SCAN_ID}));
- this.addApiAction(new ApiAction(ACTION_RESUME_SCAN, new String[] {PARAM_SCAN_ID}));
- this.addApiAction(new ApiAction(ACTION_STOP_SCAN, null, new String[] {PARAM_SCAN_ID}));
- this.addApiAction(new ApiAction(ACTION_REMOVE_SCAN, new String[] {PARAM_SCAN_ID}));
- this.addApiAction(new ApiAction(ACTION_PAUSE_ALL_SCANS));
- this.addApiAction(new ApiAction(ACTION_RESUME_ALL_SCANS));
- this.addApiAction(new ApiAction(ACTION_STOP_ALL_SCANS));
- this.addApiAction(new ApiAction(ACTION_REMOVE_ALL_SCANS));
- this.addApiAction(new ApiAction(ACTION_CLEAR_EXCLUDED_FROM_SCAN));
- this.addApiAction(new ApiAction(ACTION_EXCLUDE_FROM_SCAN, new String[] {PARAM_REGEX}));
-
- this.addApiAction(
- new ApiAction(
- ACTION_ADD_DOMAIN_ALWAYS_IN_SCOPE,
- new String[] {PARAM_VALUE},
- new String[] {PARAM_IS_REGEX, PARAM_IS_ENABLED}));
- this.addApiAction(
- new ApiAction(
- ACTION_MODIFY_DOMAIN_ALWAYS_IN_SCOPE,
- new String[] {PARAM_IDX},
- new String[] {PARAM_VALUE, PARAM_IS_REGEX, PARAM_IS_ENABLED}));
- this.addApiAction(
- new ApiAction(ACTION_REMOVE_DOMAIN_ALWAYS_IN_SCOPE, new String[] {PARAM_IDX}));
- this.addApiAction(new ApiAction(ACTION_ENABLE_ALL_DOMAINS_ALWAYS_IN_SCOPE));
- this.addApiAction(new ApiAction(ACTION_DISABLE_ALL_DOMAINS_ALWAYS_IN_SCOPE));
-
- // Register the views
- this.addApiView(new ApiView(VIEW_STATUS, null, new String[] {PARAM_SCAN_ID}));
- this.addApiView(new ApiView(VIEW_RESULTS, null, new String[] {PARAM_SCAN_ID}));
- this.addApiView(new ApiView(VIEW_FULL_RESULTS, new String[] {PARAM_SCAN_ID}));
- this.addApiView(new ApiView(VIEW_SCANS));
- this.addApiView(new ApiView(VIEW_EXCLUDED_FROM_SCAN));
- this.addApiView(new ApiView(VIEW_ALL_URLS));
- this.addApiView(new ApiView(VIEW_ADDED_NODES, null, new String[] {PARAM_SCAN_ID}));
-
- this.addApiView(new ApiView(VIEW_DOMAINS_ALWAYS_IN_SCOPE));
- ApiView view = new ApiView(VIEW_OPTION_DOMAINS_ALWAYS_IN_SCOPE);
- view.setDeprecated(true);
- this.addApiView(view);
- view = new ApiView(VIEW_OPTION_DOMAINS_ALWAYS_IN_SCOPE_ENABLED);
- view.setDeprecated(true);
- this.addApiView(view);
- }
-
- @Override
- public String getPrefix() {
- return PREFIX;
- }
-
- @Override
- public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
- log.debug("Request for handleApiAction: {} (params: {})", name, params);
- SpiderScan scan;
- int maxChildren = -1;
- Context context = null;
-
- switch (name) {
- case ACTION_START_SCAN:
- // The action is to start a new Scan
- String url = ApiUtils.getOptionalStringParam(params, PARAM_URL);
- if (params.containsKey(PARAM_MAX_CHILDREN)) {
- String maxChildrenStr = params.getString(PARAM_MAX_CHILDREN);
- if (maxChildrenStr != null && maxChildrenStr.length() > 0) {
- try {
- maxChildren = Integer.parseInt(maxChildrenStr);
- } catch (NumberFormatException e) {
- throw new ApiException(Type.ILLEGAL_PARAMETER, PARAM_MAX_CHILDREN);
- }
- }
- }
- if (params.containsKey(PARAM_CONTEXT_NAME)) {
- String contextName = params.getString(PARAM_CONTEXT_NAME);
- if (!contextName.isEmpty()) {
- context = ApiUtils.getContextByName(contextName);
- }
- }
- int scanId =
- scanURL(
- url,
- null,
- maxChildren,
- this.getParam(params, PARAM_RECURSE, true),
- context,
- getParam(params, PARAM_SUBTREE_ONLY, false));
- return new ApiResponseElement(name, Integer.toString(scanId));
-
- case ACTION_START_SCAN_AS_USER:
- // The action is to start a new Scan from the perspective of a user
- String urlUserScan = ApiUtils.getOptionalStringParam(params, PARAM_URL);
- int userID = ApiUtils.getIntParam(params, PARAM_USER_ID);
- ExtensionUserManagement usersExtension =
- Control.getSingleton()
- .getExtensionLoader()
- .getExtension(ExtensionUserManagement.class);
- if (usersExtension == null) {
- throw new ApiException(Type.NO_IMPLEMENTOR, ExtensionUserManagement.NAME);
- }
- context = ApiUtils.getContextByParamId(params, PARAM_CONTEXT_ID);
- User user =
- usersExtension
- .getContextUserAuthManager(context.getId())
- .getUserById(userID);
- if (user == null) {
- throw new ApiException(Type.USER_NOT_FOUND, PARAM_USER_ID);
- }
- if (params.containsKey(PARAM_MAX_CHILDREN)) {
- String maxChildrenStr = params.getString(PARAM_MAX_CHILDREN);
- if (maxChildrenStr != null && maxChildrenStr.length() > 0) {
- try {
- maxChildren = Integer.parseInt(maxChildrenStr);
- } catch (NumberFormatException e) {
- throw new ApiException(Type.ILLEGAL_PARAMETER, PARAM_MAX_CHILDREN);
- }
- }
- }
- scanId =
- scanURL(
- urlUserScan,
- user,
- maxChildren,
- this.getParam(params, PARAM_RECURSE, true),
- context,
- getParam(params, PARAM_SUBTREE_ONLY, false));
-
- return new ApiResponseElement(name, Integer.toString(scanId));
-
- case ACTION_PAUSE_SCAN:
- scan = getSpiderScan(params);
- extension.pauseScan(scan.getScanId());
- break;
- case ACTION_RESUME_SCAN:
- scan = getSpiderScan(params);
- extension.resumeScan(scan.getScanId());
- break;
- case ACTION_STOP_SCAN:
- // The action is to stop a pending scan
- scan = getSpiderScan(params);
- extension.stopScan(scan.getScanId());
- break;
- case ACTION_REMOVE_SCAN:
- // Note that we're removing the scan with this call, not just getting it ;)
- scan = getSpiderScan(params);
- extension.removeScan(scan.getScanId());
- break;
- case ACTION_PAUSE_ALL_SCANS:
- extension.pauseAllScans();
- break;
- case ACTION_RESUME_ALL_SCANS:
- extension.resumeAllScans();
- break;
- case ACTION_STOP_ALL_SCANS:
- extension.stopAllScans();
- break;
- case ACTION_REMOVE_ALL_SCANS:
- extension.removeAllScans();
- break;
- case ACTION_CLEAR_EXCLUDED_FROM_SCAN:
- try {
- Session session = Model.getSingleton().getSession();
- session.setExcludeFromSpiderRegexs(new ArrayList<>());
- } catch (DatabaseException e) {
- throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
- }
- break;
- case ACTION_EXCLUDE_FROM_SCAN:
- String regex = params.getString(PARAM_REGEX);
- try {
- Session session = Model.getSingleton().getSession();
- session.addExcludeFromSpiderRegex(regex);
- } catch (DatabaseException e) {
- throw new ApiException(ApiException.Type.INTERNAL_ERROR, e.getMessage());
- } catch (PatternSyntaxException e) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_REGEX);
- }
- break;
-
- case ACTION_ADD_DOMAIN_ALWAYS_IN_SCOPE:
- try {
- String value = params.getString(PARAM_VALUE);
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher domainAlwaysInScope;
- if (getParam(params, PARAM_IS_REGEX, false)) {
- domainAlwaysInScope =
- new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher
- .createPattern(value));
- } else {
- domainAlwaysInScope =
- new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(value);
- }
- domainAlwaysInScope.setEnabled(getParam(params, PARAM_IS_ENABLED, true));
-
- List domainsAlwaysInScope =
- new ArrayList<>(extension.getSpiderParam().getDomainsAlwaysInScope());
- domainsAlwaysInScope.add(domainAlwaysInScope);
- extension.getSpiderParam().setDomainsAlwaysInScope(domainsAlwaysInScope);
- } catch (IllegalArgumentException e) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_VALUE, e);
- }
- break;
- case ACTION_MODIFY_DOMAIN_ALWAYS_IN_SCOPE:
- try {
- int idx = params.getInt(PARAM_IDX);
- if (idx < 0
- || idx >= extension.getSpiderParam().getDomainsAlwaysInScope().size()) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX);
- }
-
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher oldDomain =
- extension.getSpiderParam().getDomainsAlwaysInScope().get(idx);
- String value = getParam(params, PARAM_VALUE, oldDomain.getValue());
- if (value.isEmpty()) {
- value = oldDomain.getValue();
- }
-
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher newDomain;
- if (getParam(params, PARAM_IS_REGEX, oldDomain.isRegex())) {
- newDomain =
- new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(
- org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher
- .createPattern(value));
- } else {
- newDomain = new org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher(value);
- }
- newDomain.setEnabled(getParam(params, PARAM_IS_ENABLED, oldDomain.isEnabled()));
-
- if (oldDomain.equals(newDomain)) {
- break;
- }
-
- List domainsAlwaysInScope =
- new ArrayList<>(extension.getSpiderParam().getDomainsAlwaysInScope());
- domainsAlwaysInScope.set(idx, newDomain);
- extension.getSpiderParam().setDomainsAlwaysInScope(domainsAlwaysInScope);
- } catch (JSONException e) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX, e);
- } catch (IllegalArgumentException e) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_VALUE, e);
- }
- break;
- case ACTION_REMOVE_DOMAIN_ALWAYS_IN_SCOPE:
- try {
- int idx = params.getInt(PARAM_IDX);
- if (idx < 0
- || idx >= extension.getSpiderParam().getDomainsAlwaysInScope().size()) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX);
- }
-
- List domainsAlwaysInScope =
- new ArrayList<>(extension.getSpiderParam().getDomainsAlwaysInScope());
- domainsAlwaysInScope.remove(idx);
- extension.getSpiderParam().setDomainsAlwaysInScope(domainsAlwaysInScope);
- } catch (JSONException e) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_IDX, e);
- }
- break;
- case ACTION_ENABLE_ALL_DOMAINS_ALWAYS_IN_SCOPE:
- setDomainsAlwaysInScopeEnabled(true);
- break;
- case ACTION_DISABLE_ALL_DOMAINS_ALWAYS_IN_SCOPE:
- setDomainsAlwaysInScopeEnabled(false);
- break;
- default:
- throw new ApiException(ApiException.Type.BAD_ACTION);
- }
- return ApiResponseElement.OK;
- }
-
- private void setDomainsAlwaysInScopeEnabled(boolean enabled) {
- List domainsAlwaysInScope =
- extension.getSpiderParam().getDomainsAlwaysInScope();
- for (org.zaproxy.zap.spider.DomainAlwaysInScopeMatcher x :
- extension.getSpiderParam().getDomainsAlwaysInScope()) {
- x.setEnabled(enabled);
- }
- extension.getSpiderParam().setDomainsAlwaysInScope(domainsAlwaysInScope);
- }
-
- /**
- * Returns the specified GenericScanner2 or the last scan available.
- *
- * @param params the parameters of the API call
- * @return the GenericScanner2 with the given scan ID or, if not present, the last scan
- * available
- * @throws ApiException if there's no scan with the given scan ID
- * @see #PARAM_SCAN_ID
- */
- private SpiderScan getSpiderScan(JSONObject params) throws ApiException {
- SpiderScan spiderScan;
- int id = getParam(params, PARAM_SCAN_ID, -1);
- if (id == -1) {
- spiderScan = extension.getLastScan();
- } else {
- spiderScan = extension.getScan(id);
- }
-
- if (spiderScan == null) {
- throw new ApiException(ApiException.Type.DOES_NOT_EXIST, PARAM_SCAN_ID);
- }
-
- return spiderScan;
- }
-
- /**
- * Starts a spider scan at the given {@code url} and, optionally, with the perspective of the
- * given {@code user}.
- *
- * @param url the url to start the spider scan
- * @param user the user to scan as, or null if the scan is done without the perspective of any
- * user
- * @param maxChildren Max number of children to scan
- * @param recurse Whether or not to scan recursively
- * @param context the context that will be used during spider process, might be {@code null}
- * @param subtreeOnly if the scan should be done only under a site's subtree
- * @return the ID of the newly started scan
- * @throws ApiException if the {@code url} is not valid
- */
- private int scanURL(
- String url,
- User user,
- int maxChildren,
- boolean recurse,
- Context context,
- boolean subtreeOnly)
- throws ApiException {
- log.debug("API Spider scanning url: {}", url);
-
- boolean useUrl = true;
- if (url == null || url.isEmpty()) {
- if (context == null || !context.hasNodesInContextFromSiteTree()) {
- throw new ApiException(Type.MISSING_PARAMETER, PARAM_URL);
- }
- useUrl = false;
- } else if (context != null && !context.isInContext(url)) {
- throw new ApiException(Type.URL_NOT_IN_CONTEXT, PARAM_URL);
- }
-
- StructuralNode node = null;
- URI startURI = null;
- if (useUrl) {
- try {
- // Try to build uri
- startURI = new URI(url, true);
- } catch (URIException e) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_URL);
- }
- String scheme = startURI.getScheme();
- if (scheme == null
- || (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https"))) {
- throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, PARAM_URL);
- }
-
- node = getStartNode(startURI, recurse);
- }
- Target target = new Target();
- if (useUrl && node != null) {
- target.setStartNode(node);
- }
- target.setContext(context);
- target.setRecurse(recurse);
-
- switch (Control.getSingleton().getMode()) {
- case safe:
- throw new ApiException(ApiException.Type.MODE_VIOLATION);
- case protect:
- if ((useUrl && !Model.getSingleton().getSession().isInScope(url))
- || (context != null && !context.isInScope())) {
- throw new ApiException(ApiException.Type.MODE_VIOLATION);
- }
- // No problem
- break;
- case standard:
- // No problem
- break;
- case attack:
- // No problem
- break;
- }
-
- List