use of javax.crypto.CipherInputStream in project apjp by jvansteirteghem.
the class HTTPRequest method getHTTPResponseMessage.
public HTTPResponseMessage getHTTPResponseMessage() throws HTTPRequestException {
try {
HTTPMessageHeader[] httpRequestMessage1Headers1 = httpRequestMessage.getHTTPMessageHeaders();
HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1Headers1[0];
String httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
logger.log(2, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Value1);
String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[1];
String[] httpRequestMessage1Header1Values2 = httpRequestMessage1Header1Value2.split("/", -1);
String httpRequestMessage1Header1Value3 = httpRequestMessage1Header1Values2[0];
if (httpRequestMessage1Header1Value3.equalsIgnoreCase("http:")) {
httpRequestMessage1Header1Value2 = "";
for (int j = 3; j < httpRequestMessage1Header1Values2.length; j = j + 1) {
httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Value2 + "/" + httpRequestMessage1Header1Values2[j];
}
httpRequestMessage1Header1Values1[1] = httpRequestMessage1Header1Value2;
}
httpRequestMessage1Header1Values1[2] = "HTTP/1.0";
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
for (int j = 1; j < httpRequestMessage1Header1Values1.length; j = j + 1) {
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[j];
}
httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
for (int j = 1; j < httpRequestMessage1Headers1.length; j = j + 1) {
httpRequestMessage1Header1 = httpRequestMessage1Headers1[j];
httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
// 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Charset")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Encoding")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Language")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Allow")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Authorization")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Connection")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Date")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expect")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expires")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("From")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Host")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Match")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Modified-Since")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-None-Match")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Range")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Unmodified-Since")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Max-Forwards")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Authorization")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Range")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Referer")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("TE")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("User-Agent")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Via")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Warning")) {
}
logger.log(3, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Key1 + ": " + httpRequestMessage1Header1Value1);
}
httpRequestMessage.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
SecretKeySpec secretKeySpec = new SecretKeySpec(APJP.APJP_KEY.getBytes(), "ARCFOUR");
Cipher outputCipher = Cipher.getInstance("ARCFOUR");
outputCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
CipherOutputStream cipherOutputStream = new CipherOutputStream(urlConnection.getOutputStream(), outputCipher);
HTTPMessageHeader[] httpRequestMessage1Headers2 = httpRequestMessage.getHTTPMessageHeaders();
HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1Headers2[0];
String httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
cipherOutputStream.write((httpRequestMessage1Header2Value1 + "\r\n").getBytes());
for (int j = 1; j < httpRequestMessage1Headers2.length; j = j + 1) {
httpRequestMessage1Header2 = httpRequestMessage1Headers2[j];
httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
cipherOutputStream.write((httpRequestMessage1Header2Key1 + ": " + httpRequestMessage1Header2Value1 + "\r\n").getBytes());
}
cipherOutputStream.write(("\r\n").getBytes());
httpRequestMessage.read(cipherOutputStream);
Cipher inputCipher = Cipher.getInstance("ARCFOUR");
inputCipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
CipherInputStream cipherInputStream = new CipherInputStream(urlConnection.getInputStream(), inputCipher);
HTTPResponseMessage httpResponseMessage1 = new HTTPResponseMessage(httpRequestMessage, cipherInputStream);
httpResponseMessage1.read();
HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
logger.log(2, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Value1);
String[] httpResponseMessage1Header1Values1 = httpResponseMessage1Header1Value1.split(" ");
httpResponseMessage1Header1Values1[0] = "HTTP/1.0";
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Values1[0];
for (int j = 1; j < httpResponseMessage1Header1Values1.length; j = j + 1) {
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Value1 + " " + httpResponseMessage1Header1Values1[j];
}
httpResponseMessage1Header1.setValue(httpResponseMessage1Header1Value1);
for (int j = 1; j < httpResponseMessage1Headers1.length; j = j + 1) {
httpResponseMessage1Header1 = httpResponseMessage1Headers1[j];
httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
// 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Accept-Ranges")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Age")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Allow")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Connection")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Date")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("ETag")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Expires")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Location")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Authenticate")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Retry-After")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Server")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Vary")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Via")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Warning")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("WWW-Authenticate")) {
}
logger.log(3, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1);
}
httpResponseMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
return httpResponseMessage1;
} catch (Exception e) {
throw new HTTPRequestException("HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE", e);
}
}
use of javax.crypto.CipherInputStream in project apjp by jvansteirteghem.
the class HTTPSRequest method getHTTPResponseMessage.
public HTTPResponseMessage getHTTPResponseMessage() throws HTTPSRequestException {
try {
HTTPMessageHeader[] httpRequestMessage1Headers1 = httpRequestMessage.getHTTPMessageHeaders();
HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1Headers1[0];
String httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
logger.log(2, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Value1);
String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[1];
String[] httpRequestMessage1Header1Values2 = httpRequestMessage1Header1Value2.split("/", -1);
String httpRequestMessage1Header1Value3 = httpRequestMessage1Header1Values2[0];
if (httpRequestMessage1Header1Value3.equalsIgnoreCase("https:")) {
httpRequestMessage1Header1Value2 = "";
for (int j = 3; j < httpRequestMessage1Header1Values2.length; j = j + 1) {
httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Value2 + "/" + httpRequestMessage1Header1Values2[j];
}
httpRequestMessage1Header1Values1[1] = httpRequestMessage1Header1Value2;
}
httpRequestMessage1Header1Values1[2] = "HTTP/1.0";
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
for (int j = 1; j < httpRequestMessage1Header1Values1.length; j = j + 1) {
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[j];
}
httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
for (int j = 1; j < httpRequestMessage1Headers1.length; j = j + 1) {
httpRequestMessage1Header1 = httpRequestMessage1Headers1[j];
httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
// 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Charset")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Encoding")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Language")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Allow")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Authorization")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Connection")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Date")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expect")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expires")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("From")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Host")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Match")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Modified-Since")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-None-Match")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Range")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Unmodified-Since")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Max-Forwards")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Authorization")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Range")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Referer")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("TE")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
} else // 1.0
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("User-Agent")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Via")) {
} else // 1.1
if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Warning")) {
}
logger.log(3, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Key1 + ": " + httpRequestMessage1Header1Value1);
}
httpRequestMessage.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
SecretKeySpec secretKeySpec = new SecretKeySpec(APJP.APJP_KEY.getBytes(), "ARCFOUR");
Cipher outputCipher = Cipher.getInstance("ARCFOUR");
outputCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
CipherOutputStream cipherOutputStream = new CipherOutputStream(urlConnection.getOutputStream(), outputCipher);
HTTPMessageHeader[] httpRequestMessage1Headers2 = httpRequestMessage.getHTTPMessageHeaders();
HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1Headers2[0];
String httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
cipherOutputStream.write((httpRequestMessage1Header2Value1 + "\r\n").getBytes());
for (int j = 1; j < httpRequestMessage1Headers2.length; j = j + 1) {
httpRequestMessage1Header2 = httpRequestMessage1Headers2[j];
httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
cipherOutputStream.write((httpRequestMessage1Header2Key1 + ": " + httpRequestMessage1Header2Value1 + "\r\n").getBytes());
}
cipherOutputStream.write(("\r\n").getBytes());
httpRequestMessage.read(cipherOutputStream);
Cipher inputCipher = Cipher.getInstance("ARCFOUR");
inputCipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
CipherInputStream cipherInputStream = new CipherInputStream(urlConnection.getInputStream(), inputCipher);
HTTPResponseMessage httpResponseMessage1 = new HTTPResponseMessage(httpRequestMessage, cipherInputStream);
httpResponseMessage1.read();
HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
logger.log(2, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Value1);
String[] httpResponseMessage1Header1Values1 = httpResponseMessage1Header1Value1.split(" ");
httpResponseMessage1Header1Values1[0] = "HTTP/1.0";
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Values1[0];
for (int j = 1; j < httpResponseMessage1Header1Values1.length; j = j + 1) {
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Value1 + " " + httpResponseMessage1Header1Values1[j];
}
httpResponseMessage1Header1.setValue(httpResponseMessage1Header1Value1);
for (int j = 1; j < httpResponseMessage1Headers1.length; j = j + 1) {
httpResponseMessage1Header1 = httpResponseMessage1Headers1[j];
httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
// 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Accept-Ranges")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Age")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Allow")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Connection")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Date")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("ETag")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Expires")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Location")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Authenticate")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Retry-After")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Server")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Vary")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Via")) {
} else // 1.1
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Warning")) {
} else // 1.0
if (httpResponseMessage1Header1Key1.equalsIgnoreCase("WWW-Authenticate")) {
}
logger.log(3, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1);
}
httpResponseMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
return httpResponseMessage1;
} catch (Exception e) {
throw new HTTPSRequestException("HTTPS_REQUEST/GET_HTTP_RESPONSE_MESSAGE", e);
}
}
use of javax.crypto.CipherInputStream in project wycheproof by google.
the class CipherInputStreamTest method testCorruptDecryptEmpty.
@SuppressWarnings("InsecureCryptoUsage")
public void testCorruptDecryptEmpty(Iterable<TestVector> tests) throws Exception {
for (TestVector t : tests) {
Cipher cipher = Cipher.getInstance(t.algorithm);
cipher.init(Cipher.DECRYPT_MODE, t.key, t.params);
cipher.updateAAD(t.aad);
byte[] ct = Arrays.copyOf(t.ct, t.ct.length);
ct[ct.length - 1] ^= (byte) 1;
InputStream is = new ByteArrayInputStream(ct);
CipherInputStream cis = new CipherInputStream(is, cipher);
try {
byte[] result = new byte[t.pt.length];
int totalLength = 0;
int length = 0;
do {
length = cis.read(result, totalLength, result.length - totalLength);
if (length > 0) {
totalLength += length;
}
} while (length >= 0 && totalLength != result.length);
cis.close();
fail("this should fail");
} catch (IOException ex) {
// expected
}
}
}
use of javax.crypto.CipherInputStream in project wycheproof by google.
the class CipherInputStreamTest method testEncrypt.
@SuppressWarnings("InsecureCryptoUsage")
public void testEncrypt(Iterable<TestVector> tests) throws Exception {
for (TestVector t : tests) {
Cipher cipher = Cipher.getInstance(t.algorithm);
cipher.init(Cipher.ENCRYPT_MODE, t.key, t.params);
cipher.updateAAD(t.aad);
InputStream is = new ByteArrayInputStream(t.pt);
CipherInputStream cis = new CipherInputStream(is, cipher);
byte[] result = new byte[t.ct.length];
int totalLength = 0;
int length = 0;
do {
length = cis.read(result, totalLength, result.length - totalLength);
if (length > 0) {
totalLength += length;
}
} while (length >= 0 && totalLength != result.length);
assertEquals(-1, cis.read());
assertEquals(TestUtil.bytesToHex(t.ct), TestUtil.bytesToHex(result));
cis.close();
}
}
use of javax.crypto.CipherInputStream in project wycheproof by google.
the class CipherInputStreamTest method testCorruptDecrypt.
/**
* JDK-8016171 : CipherInputStream masks ciphertext tampering with AEAD ciphers in decrypt mode
* Further description of the bug is here:
* https://blog.heckel.xyz/2014/03/01/cipherinputstream-for-aead-modes-is-broken-in-jdk7-gcm/
* BouncyCastle claims that this bug is fixed in version 1.51. However, the test below still fails
* with BouncyCastle v 1.52. A possible explanation is that BouncyCastle has its own
* implemenatation of CipherInputStream (org.bouncycastle.crypto.io.CipherInputStream).
*/
@SuppressWarnings("InsecureCryptoUsage")
public void testCorruptDecrypt(Iterable<TestVector> tests) throws Exception {
for (TestVector t : tests) {
Cipher cipher = Cipher.getInstance(t.algorithm);
cipher.init(Cipher.DECRYPT_MODE, t.key, t.params);
cipher.updateAAD(t.aad);
byte[] ct = Arrays.copyOf(t.ct, t.ct.length);
ct[ct.length - 1] ^= (byte) 1;
InputStream is = new ByteArrayInputStream(ct);
CipherInputStream cis = new CipherInputStream(is, cipher);
try {
byte[] result = new byte[t.pt.length];
int totalLength = 0;
int length = 0;
do {
length = cis.read(result, totalLength, result.length - totalLength);
if (length > 0) {
totalLength += length;
}
} while (length >= 0 && totalLength != result.length);
cis.close();
if (result.length > 0) {
fail("this should fail; decrypted:" + TestUtil.bytesToHex(result) + " pt: " + TestUtil.bytesToHex(t.pt));
}
} catch (IOException ex) {
// expected
}
}
}
Aggregations