public BadRandom getBadSecureRandom() { return new BadRandom(getRandom(), null); }
public BasicTlsServer(KeyStore keyStore, String password, String protocol, int port) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException { this.port = port; KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); keyManagerFactory.init(keyStore, password.toCharArray()); KeyManager[] keyManagers = keyManagerFactory.getKeyManagers(); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509"); trustManagerFactory.init(keyStore); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); sslContext = SSLContext.getInstance(protocol); sslContext.init(keyManagers, trustManagers, new BadRandom()); cipherSuites = sslContext.getServerSocketFactory().getSupportedCipherSuites(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Provider: " + sslContext.getProvider()); LOGGER.debug("Supported cipher suites (" + sslContext.getServerSocketFactory().getSupportedCipherSuites().length + ")"); for (String c : sslContext.getServerSocketFactory().getSupportedCipherSuites()) { LOGGER.debug(" " + c); } } }
protected SSLContext getAllowAllContext() { SSLContext allowAllContext = null; try { allowAllContext = SSLContext.getInstance("TLS"); allowAllContext.getClientSessionContext().setSessionCacheSize(1); // Trust everything allowAllContext.init(null, new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }, new BadRandom()); } catch (NoSuchAlgorithmException | KeyManagementException E) { LOGGER.warn(E); } return allowAllContext; }
private static BigInteger calculatePrivate(DHParameters dhParams) { int limit = dhParams.getL(); if (limit != 0) { int minWeight = limit >>> 2; for (;;) { BigInteger x = new BigInteger(limit, new BadRandom()).setBit(limit - 1); if (WNafUtil.getNafWeight(x) >= minWeight) { return x; } } } BigInteger min = TWO; int m = dhParams.getM(); if (m != 0) { min = ONE.shiftLeft(m - 1); } BigInteger q = dhParams.getQ(); if (q == null) { q = dhParams.getP(); } BigInteger max = q.subtract(TWO); int minWeight = max.bitLength() >>> 2; for (;;) { BigInteger x = BigIntegers.createRandomInRange(min, max, new BadRandom()); if (WNafUtil.getNafWeight(x) >= minWeight) { return x; } } }
message.setPointLength(message.getPoint().getValue().length); ParametersWithRandom params = new ParametersWithRandom(new ECPrivateKeyParameters( tokenBindingECPrivateKey.getS(), generateEcParameters), new BadRandom(new Random(0), new byte[0])); ECDSASigner signer = new ECDSASigner(); signer.init(true, params);