title: javax.net.ssl.SSLException: Received fatal alert: bad_record_mac
body: <p>I'm getting a <code>javax.net.ssl.SSLException: Received fatal alert: bad_record_mac</code> for an HTTPS connection.  This doesn't happen for every request -- if I send the same request in 10 times I only get this error once or twice.</p>
  <p>I have the following code to validate the certificate:</p>
  <pre><code>TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
              public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                  return null;
              }
  
              public void checkClientTrusted(X509Certificate[] certs, String authType) {
              }
  
              public void checkServerTrusted(X509Certificate[] certs, String authType) {
              }
  
          } };
  
          try {
              SSLContext sslContext = null;
                  try {
                      sslContext = SSLContext.getInstance(&quot;SSLv3&quot;);
                      
                  } catch (NoSuchAlgorithmException e3) {
                      logException(Arrays.toString(e3.getStackTrace()));          
              }
  
              sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
              SSLSocketFactory factory = sslContext.getSocketFactory();
              HttpsURLConnection.setDefaultSSLSocketFactory(factory);
          } catch (KeyManagementException e) {
              logException(Arrays.toString(e.getStackTrace()));
          }
  
          // Create all-trusting host name verifier
          HostnameVerifier allHostsValid = new HostnameVerifier() {
              public boolean verify(String hostname, SSLSession session) {
                  return true;
              }
          };
          // Install the all-trusting host verifier
          HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
          /*
           * end of the fix
           */ 
  </code></pre>
  <p>I've set two system properties in my main method:</p>
  <pre><code>System.setProperty(&quot;jsse.enableSNIExtension&quot;, &quot;false&quot;);
          System.setProperty(&quot;https.protocols&quot;, &quot;SSLv3&quot;);
  </code></pre>
  <p>But nothing helps.</p>