List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider
public BouncyCastleProvider()
From source file:de.mendelson.util.security.PKCS122JKS.java
/** Creates a new instance of PEMUtil *@param logger Logger to log the information to *//*from ww w .j av a 2 s . c om*/ public PKCS122JKS(Logger logger) { this.logger = logger; //forget it to work without BC at this point, the SUN JCE provider //could not handle pcks12 Security.addProvider(new BouncyCastleProvider()); }
From source file:de.mendelson.util.security.PKCS122PKCS12.java
/** Creates a new instance of PEMUtil *@param logger Logger to log the information to *//* www.j a v a 2s . c om*/ public PKCS122PKCS12(Logger logger) { this.logger = logger; //forget it to work without BC at this point, the SUN JCE provider //could not handle pcks12 Security.addProvider(new BouncyCastleProvider()); }
From source file:de.norvos.MainApplication.java
License:Open Source License
/** * Initializes all libraries./*from www . j a v a 2 s .co m*/ */ private static void initLibraries() { Security.addProvider(new BouncyCastleProvider()); AxolotlLoggerProvider.setProvider(new AxolotlLoggerImpl()); }
From source file:de.perdian.apps.devlauncher.impl.ConnectorListener.java
License:Apache License
private Key ensureKeyInStore(Path keystoreFile, KeyStore keyStore) throws GeneralSecurityException, IOException { Key key = this.lookupKeyFromStore(keyStore); if (key == null) { log.info("Creating new TLS key to enable HTTPS access"); // No key available, so we have to create the key from scratch and // make it available in the store Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(1024); KeyPair keyPair = keyPairGenerator.generateKeyPair(); X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator(); v3CertGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis())); v3CertGen.setIssuerDN(new X509Principal("CN=" + "localhost" + ", OU=None, O=None L=None, C=None")); v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30)); v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365 * 10))); v3CertGen.setSubjectDN(new X509Principal("CN=" + "localhost" + ", OU=None, O=None L=None, C=None")); v3CertGen.setPublicKey(keyPair.getPublic()); v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption"); X509Certificate certificate = v3CertGen.generateX509Certificate(keyPair.getPrivate()); // Store the key (including the certificate) into the keystore keyStore.setKeyEntry(TLS_KEY_NAME, keyPair.getPrivate(), TLS_KEY_PASSWORD.toCharArray(), new java.security.cert.Certificate[] { certificate }); // Write the keystore into the target file log.debug("Updating KeyStore at: " + keystoreFile); if (!Files.exists(keystoreFile.getParent())) { Files.createDirectories(keystoreFile.getParent()); }/*from www. j a v a 2s. co m*/ try (OutputStream keyStoreStream = new BufferedOutputStream(Files.newOutputStream(keystoreFile))) { keyStore.store(keyStoreStream, KEYSTORE_PASSWORD.toCharArray()); keyStoreStream.flush(); } } return key; }
From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java
License:Open Source License
/** * Creates SignatureWrappingOracle, parses the document and searches for all the SignatureValue and KeyInfo elements * //from w w w .j av a 2 s. c o m * @param document * @param replaceAllcertificates * @throws SignatureFakingException */ public SignatureFakingOracle(final Document document, final boolean replaceAllcertificates) throws SignatureFakingException { Security.addProvider(new BouncyCastleProvider()); signatureValueElements = new LinkedList<Node>(); keyInfoElements = new LinkedList<Node>(); certificates = new LinkedList<String>(); certHandlers = new LinkedList<CertificateHandler>(); doc = document; replaceAll = replaceAllcertificates; crawlSignatureElements(); Logging.getInstance().log(getClass(), "found " + signatureValueElements.size() + " SignatureValue elements", Logging.DEBUG); crawlKeyInfoElements(); Logging.getInstance().log(getClass(), "found " + keyInfoElements.size() + " KeyInfo elements containing X509 certificates", Logging.DEBUG); }
From source file:de.rub.nds.tlsattacker.attacks.ec.ECComputationCorrectness.java
License:Apache License
public ECComputationCorrectness() { Security.addProvider(new BouncyCastleProvider()); }
From source file:de.rub.nds.tlsattacker.attacks.ec.ECTestJDK.java
License:Apache License
public ECTestJDK() { Security.addProvider(new BouncyCastleProvider()); }
From source file:de.rub.nds.tlsattacker.attacks.pkcs1.BleichenbacherAttackPlaintextTest.java
License:Apache License
@Test public final void testBleichenbacherAttack() throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048);//from w w w. jav a 2s . c om KeyPair keyPair = keyPairGenerator.genKeyPair(); SecureRandom sr = new SecureRandom(); byte[] plainBytes = new byte[PREMASTER_SECRET_LENGTH]; sr.nextBytes(plainBytes); byte[] cipherBytes; Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic()); cipherBytes = cipher.doFinal(plainBytes); cipher = Cipher.getInstance("RSA/None/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate()); byte[] message = cipher.doFinal(cipherBytes); Pkcs1Oracle oracle = new StdPlainPkcs1Oracle(keyPair.getPublic(), TestPkcs1Oracle.OracleType.TTT, cipher.getBlockSize()); Bleichenbacher attacker = new Bleichenbacher(message, oracle, true); attacker.attack(); BigInteger solution = attacker.getSolution(); Assert.assertArrayEquals("The computed solution for Bleichenbacher must be equal to the original message", message, solution.toByteArray()); }
From source file:de.rub.nds.tlsattacker.attacks.pkcs1.MangerAttackPlaintextTest.java
License:Apache License
@Test public final void testMangerAttack() throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(2048);// w w w . ja v a2 s.c om KeyPair keyPair = keyPairGenerator.genKeyPair(); Random sr = new Random(); byte[] plainBytes = new byte[PREMASTER_SECRET_LENGTH]; sr.nextBytes(plainBytes); byte[] cipherBytes; Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic()); cipherBytes = cipher.doFinal(plainBytes); cipher = Cipher.getInstance("RSA/None/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate()); byte[] message = cipher.doFinal(cipherBytes); Pkcs1Oracle oracle = new StdPlainPkcs1Oracle(keyPair.getPublic(), TestPkcs1Oracle.OracleType.MANGER_0x00, cipher.getBlockSize()); // we are handling plaintexts, so we insert raw message there Manger attacker = new Manger(message, oracle); attacker.attack(); BigInteger solution = attacker.getSolution(); Assert.assertArrayEquals("The computed solution for Manger attack must be equal to the original message", message, solution.toByteArray()); // test with a message not starting with 0x00 message = ArrayConverter.concatenate(new byte[] { 1 }, message); System.out.println(ArrayConverter.bytesToHexString(message)); attacker = new Manger(message, oracle); attacker.attack(); solution = attacker.getSolution(); Assert.assertArrayEquals("The computed solution for Manger attack must be equal to the original message", message, solution.toByteArray()); }
From source file:de.rub.nds.tlsattacker.attacks.pkcs1.MangerAttackPlaintextTest.java
License:Apache License
@Test @Ignore/*from w w w . ja v a 2s . co m*/ public final void testMangerAttackPerformance() throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(4096); KeyPair keyPair = keyPairGenerator.genKeyPair(); List<Long> queries = new LinkedList<>(); for (int i = 0; i < 100; i++) { Random sr = new Random(); byte[] plainBytes = new byte[PREMASTER_SECRET_LENGTH]; sr.nextBytes(plainBytes); byte[] cipherBytes; Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic()); cipherBytes = cipher.doFinal(plainBytes); cipher = Cipher.getInstance("RSA/None/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate()); byte[] message = cipher.doFinal(cipherBytes); Pkcs1Oracle oracle = new StdPlainPkcs1Oracle(keyPair.getPublic(), TestPkcs1Oracle.OracleType.MANGER_0x00, cipher.getBlockSize()); // we are handling plaintexts, so we insert raw message there Manger attacker = new Manger(message, oracle); attacker.attack(); BigInteger solution = attacker.getSolution(); Assert.assertArrayEquals( "The computed solution for Manger attack must be equal to the original message", message, solution.toByteArray()); queries.add(oracle.getNumberOfQueries()); } Collections.sort(queries); System.out.println(queries); }