-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the writable key store source (used when browser proxying HTTPS…
…) to the java8 sources to avoid breaking older Android builds in the java7 build with use of Path, Paths etc. from java.nio
- Loading branch information
1 parent
d597aaf
commit e2809eb
Showing
8 changed files
with
122 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/github/tomakehurst/wiremock/common/ssl/KeyStoreSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.tomakehurst.wiremock.common.ssl; | ||
|
||
import com.github.tomakehurst.wiremock.common.Exceptions; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
public class KeyStoreSourceFactory { | ||
|
||
@SuppressWarnings("unchecked") | ||
public static KeyStoreSource getAppropriateForJreVersion(String path, String keyStoreType, char[] keyStorePassword) { | ||
try { | ||
final Class<?extends KeyStoreSource> theClass = (Class<? extends KeyStoreSource>) Class.forName("com.github.tomakehurst.wiremock.jetty94.WritableFileOrClasspathKeyStoreSource"); | ||
return safelyGetConstructor(theClass, String.class, String.class, char[].class).newInstance(path, keyStoreType, keyStorePassword); | ||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | InvocationTargetException e) { | ||
return new ReadOnlyFileOrClasspathKeyStoreSource(path, keyStoreType, keyStorePassword); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static <T> Constructor<T> safelyGetConstructor(Class<T> clazz, Class<?>... parameterTypes) { | ||
try { | ||
return clazz.getConstructor(parameterTypes); | ||
} catch (NoSuchMethodException e) { | ||
return Exceptions.throwUnchecked(e, Constructor.class); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ava/com/github/tomakehurst/wiremock/common/ssl/ReadOnlyFileOrClasspathKeyStoreSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.github.tomakehurst.wiremock.common.ssl; | ||
|
||
import com.google.common.io.Resources; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.security.KeyStore; | ||
import java.util.Objects; | ||
|
||
import static com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked; | ||
|
||
public class ReadOnlyFileOrClasspathKeyStoreSource extends KeyStoreSource { | ||
|
||
protected final String path; | ||
|
||
public ReadOnlyFileOrClasspathKeyStoreSource(String path, String keyStoreType, char[] keyStorePassword) { | ||
super(keyStoreType, keyStorePassword); | ||
this.path = path; | ||
} | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
@Override | ||
protected InputStream createInputStream() { | ||
try { | ||
if (exists()) { | ||
return new FileInputStream(path); | ||
} else { | ||
try { | ||
URL pathUrl = new URL(path); | ||
return pathUrl.openStream(); | ||
} catch (MalformedURLException ignored) { | ||
return Resources.getResource(path).openStream(); | ||
} | ||
} | ||
} catch (IOException e) { | ||
return throwUnchecked(e, InputStream.class); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean exists() { | ||
return new File(path).isFile(); | ||
} | ||
|
||
@Override | ||
public void save(KeyStore keyStore) {} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (!super.equals(o)) return false; | ||
ReadOnlyFileOrClasspathKeyStoreSource that = (ReadOnlyFileOrClasspathKeyStoreSource) o; | ||
return path.equals(that.path); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters