Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/com/telesign/util/TeleSignRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.SignatureException;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -27,6 +30,8 @@
import java.util.TreeMap;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;

import org.apache.commons.codec.binary.Base64;

Expand Down Expand Up @@ -320,7 +325,8 @@ public String executeRequest() throws IOException {
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(readTimeout);
connection.setRequestProperty("Authorization", auth_header);

setTLSProtocol();

if (post) {

connection.setRequestProperty("Content-Length", Integer.toString(body.length()));
Expand Down Expand Up @@ -365,7 +371,6 @@ public String executeRequest() throws IOException {
in.close();
}
catch (IOException e) {

System.err.println("IOException while reading from input stream " + e.getMessage());
}

Expand Down Expand Up @@ -497,4 +502,26 @@ private String encode(String data, String key) throws java.security.SignatureEx

return result;
}

/**
* Set the TLS protocol to TLSv1.2
*/
private void setTLSProtocol() {
SSLContext sslContext;
try {
// setting ssl instance to TLSv1.2
sslContext = SSLContext.getInstance("TLSv1.2");

// sslContext initialize
sslContext.init(null,null,new SecureRandom());

// typecasting ssl with HttpsUrlConnection and setting sslcontext
((HttpsURLConnection)connection).setSSLSocketFactory(sslContext.getSocketFactory());
} catch (NoSuchAlgorithmException e1) {
System.err.println("Error signing request " + e1.getMessage());
}
catch (KeyManagementException e) {
System.err.println("Error signing request " + e.getMessage());
}
}
}
Loading