title: Java SSL DH Keypair Generation - Prime Size Error
body: <p>I'm currently implementing Reddit OAuth2 login into my web app. The handshake and token exchange work fine when testing locally but when running on the server (hosted on 'OpenShift' DIY cartridge) I get the following error:</p>
  
  <pre><code>java.security.InvalidAlgorithmParameterException: Prime size must be 
  multiple of 64, and can only range from 512 to 1024 (inclusive)
  </code></pre>
  
  <p>Which is results in</p>
  
  <pre><code>java.lang.RuntimeException: Could not generate DH keypair 
  </code></pre>
  
  <p>I've been searching most of the day and have found different solutions ranging from changing Java version to using BouncyCastle. However, I'm using the <a href="http://github.com/fernandezpablo85/scribe-java" rel="noreferrer" title="Scribe">Scribe</a> library so I don't think I can implement BouncyCastle without forking and changing the base of scribe, which kind of defeats it's purpose. </p>
  
  <p>Installing <a href="http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html" rel="noreferrer" title="JCE Unlimited Strength">JCE Unlimited Strength</a> also came up but I can't do that on OpenShift as there's no root access (might be able to get one of their team to do it).</p>
  
  <p>The java versions in use are (taken from <code>java -version</code>):</p>
  
  <p>Local Testing Machine:</p>
  
  <pre><code>java version "1.7.0_51"
  OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-1ubuntu1)
  OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
  </code></pre>
  
  <p>OpenShift Server:</p>
  
  <pre><code>java version "1.7.0_51"
  OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-i386 u51-b02)
  OpenJDK Server VM (build 24.45-b08, mixed mode)
  </code></pre>
  
  <p>I'm at a loss as to what I can do to solve this. Hopefully I'm being stupid or am misunderstanding something, so any possible solutions would be great!</p>
  
  <p>--</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>The request code that returns the error (using Scribe, as I mentioned, so might not be much use). The token endpoint is <code>https://ssl.reddit.com/api/v1/access_token</code> using POST. As I said above, this works on my testing machine.</p>
  
  <pre><code>OAuthRequest request = new OAuthRequest(getAccessTokenVerb(), getAccessTokenEndpoint());
  
  request.addHeader("Authorization", "Basic"
      +Base64.encode((config.getApiKey()+":"+config.getApiSecret()).getBytes()));
  
  request.addBodyParameter("state", "none");
  request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
  request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
  request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
  request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
  request.addBodyParameter("grant_type", "authorization_code");
  
  Response response = request.send();  // Errors here from Request.createConnection in the Scribe code
  return getAccessTokenExtractor().extract(response.getBody());
  </code></pre>