Skip to content

Commit

Permalink
Return GET request in HTTPS fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Aug 17, 2020
1 parent 3b3a216 commit c8da886
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
Expand Up @@ -99,7 +99,7 @@ private String initServerVersion() {
}

private String httpVersion = "HTTP/1.1";

private String httpVersion_2 = "HTTP/2";
private static String htmlDocumentContent = HelperUtils.getRandomString(32, false);

private static String htmlTitleContent = HelperUtils.getRandomString(32, false);
Expand Down Expand Up @@ -177,11 +177,11 @@ public List<Packet> processMessage(Packet requestPacket) {
this.request = request;

assert request != null;
if (request.startsWith("G")) {
if (request.isEmpty()) {
//weird if clause but required for https
responsePackets.add(buildPacket(STATUS_CODE_200, GET));
checkProfile();
} else if (!request.contains(httpVersion)) {
} else if (!request.contains(httpVersion) && (!request.contains(httpVersion_2))) {
responsePackets.add(buildPacket(STATUS_CODE_505, ""));
checkProfile();
} else if (request.contains(GET)) {
Expand Down
33 changes: 20 additions & 13 deletions src/main/java/de/tudarmstadt/informatik/hostage/protocol/HTTPS.java
Expand Up @@ -31,30 +31,37 @@ public class HTTPS extends HTTP implements SSLProtocol {

@Override
public SSLContext getSSLContext() {
SSLContext sslContext = null;
try {
ProviderInstaller.installIfNeeded(MainActivity.getContext());
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(getKeyManager().getKeyManagers(), null, null);
sslContext.createSSLEngine();
} catch (Exception e) {
e.printStackTrace();
}
return sslContext;
}

/**
* KeyManager Factory
* @return self signed certificate
*/
private KeyManagerFactory getKeyManager(){
String keyStoreName = "https_cert.bks";
char[] keyStorePassword = "password".toCharArray();
KeyStore keyStore;
KeyManagerFactory keyManagerFactory = null;
try {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(
Hostage.getContext().getAssets().open(keyStoreName),
keyStorePassword);
keyStore.load(Hostage.getContext().getAssets().open(keyStoreName), keyStorePassword);
keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePassword);
} catch (Exception e) {
e.printStackTrace();
}
SSLContext sslContext = null;
try {
ProviderInstaller.installIfNeeded(MainActivity.getContext());
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
sslContext.createSSLEngine();
} catch (Exception e) {
e.printStackTrace();
}
return sslContext;

return keyManagerFactory;
}

@Override
Expand Down

0 comments on commit c8da886

Please sign in to comment.