Example usage for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME

List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME

Introduction

In this page you can find the example usage for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME.

Prototype

String PROVIDER_NAME

To view the source code for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME.

Click Source Link

Usage

From source file:org.gluu.oxtrust.action.UpdateTrustRelationshipAction.java

License:MIT License

/**
 * If there is no certificate selected, or certificate is invalid -
 * generates one./*from   w w  w  .  jav  a  2  s  . c o  m*/
 * 
 * @author Oleksiy Tataryn
 * @return certificate for generated SP
 * @throws CertificateEncodingException
 */
private String getCertForGeneratedSP() {
    X509Certificate cert = SSLService.instance().getCertificate(certWrapper.getStream());
    if (cert == null) {
        facesMessages.add(Severity.INFO,
                "Certificate were not provided, or was incorrect. Appliance will create a self-signed certificate.");
        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
            Security.addProvider(new BouncyCastleProvider());
        }
        try {
            JDKKeyPairGenerator.RSA keyPairGen = new JDKKeyPairGenerator.RSA();
            keyPairGen.initialize(2048);
            KeyPair pair = keyPairGen.generateKeyPair();
            StringWriter keyWriter = new StringWriter();
            PEMWriter pemFormatWriter = new PEMWriter(keyWriter);
            pemFormatWriter.writeObject(pair.getPrivate());
            pemFormatWriter.close();

            String url = trustRelationship.getUrl().replaceFirst(".*//", "");

            X509v3CertificateBuilder v3CertGen = new JcaX509v3CertificateBuilder(
                    new X500Name("CN=" + url + ", OU=None, O=None L=None, C=None"),
                    BigInteger.valueOf(new SecureRandom().nextInt()),
                    new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30),
                    new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365 * 10)),
                    new X500Name("CN=" + url + ", OU=None, O=None L=None, C=None"), pair.getPublic());
            cert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(v3CertGen.build(
                    new JcaContentSignerBuilder("MD5withRSA").setProvider("BC").build(pair.getPrivate())));
            org.apache.commons.codec.binary.Base64 encoder = new org.apache.commons.codec.binary.Base64(64);
            byte[] derCert = cert.getEncoded();
            String pemCertPre = new String(encoder.encode(derCert));
            log.debug(Shibboleth2ConfService.PUBLIC_CERTIFICATE_START_LINE);
            log.debug(pemCertPre);
            log.debug(Shibboleth2ConfService.PUBLIC_CERTIFICATE_END_LINE);

            saveCert(trustRelationship, pemCertPre);
            saveKey(trustRelationship, keyWriter.toString());

        } catch (Exception e) {

            e.printStackTrace();
        }

        //         String certName = applicationConfiguration.getCertDir() + File.separator + StringHelper.removePunctuation(applicationConfiguration.getOrgInum())
        //               + "-shib.crt";
        //         File certFile = new File(certName);
        //         if (certFile.exists()) {
        //            cert = SSLService.instance().getCertificate(certName);
        //         }
    }
    String certificate = null;
    if (cert != null) {
        try {
            certificate = new String(Base64.encode(cert.getEncoded()));
        } catch (CertificateEncodingException e) {
            certificate = null;
            facesMessages.add(Severity.ERROR,
                    "Failed to encode provided certificate. Please notify Gluu support about this.");
            log.error("Failed to encode certificate to DER", e);
        }
    } else {
        facesMessages.add(Severity.INFO,
                "Certificate were not provided, or was incorrect. Appliance will create a self-signed certificate.");
    }

    return certificate;
}

From source file:org.gluu.oxtrust.ldap.service.AppInitializer.java

License:MIT License

/**
 * Initialize components and schedule DS connection time checker
 *//*  w w w.j  a  va2  s . com*/
@Create
public void createApplicationComponents() throws ConfigurationException {
    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
        Security.addProvider(new BouncyCastleProvider());
    }

    log.debug("Creating application components");
    showBuildInfo();

    // Initialize local LDAP connection provider
    createConnectionProvider(oxTrustConfiguration.getLdapConfiguration(), "localLdapConfiguration",
            "connectionProvider");

    Events.instance().raiseEvent(OxTrustConfiguration.EVENT_INIT_CONFIGURATION);

    // Initialize central LDAP connection provider

    if (oxTrustConfiguration.getApplicationConfiguration().isUpdateApplianceStatus()) {
        createConnectionProvider(oxTrustConfiguration.getLdapCentralConfiguration(), "centralLdapConfiguration",
                "centralConnectionProvider");
    }
    initializeLdifArchiver();
    initiateLDAPAuthConf();

    // Initialize template engine
    TemplateService.instance().initTemplateEngine();

    // Initialize SubversionService
    SubversionService.instance().initSubversionService();

    // Initialize python interpreter
    PythonService.instance().initPythonInterpreter();

    //      checkAndUpdateLdapbaseConfiguration(); // We do not need to create ldapbase configuration any more because we 
    //supply working ldap data with either dashboard or python setup sript.

    startInviteCodesExpirationService();

    startStatusChecker();
    startDailyStatusChecker();
    startSvnSync();
    // Asynchronous metadata validation service
    startMetadataValidator();

    createShibbolethConfiguration();

    prepareConfigurations();

    logSizeChecker();
}

From source file:org.gudy.azureus2.core3.util.MD4Hasher.java

License:Open Source License

/**
 * Uses bouncy castle provider/*w ww . j  a va2  s  . c o m*/
 *
 */

public MD4Hasher() {
    try {
        md4 = MessageDigest.getInstance("MD4", BouncyCastleProvider.PROVIDER_NAME);

    } catch (Throwable e) {

        // should never get here

        Debug.printStackTrace(e);
    }
}

From source file:org.italiangrid.voms.asn1.VOMSACGenerator.java

License:Apache License

private ContentSigner getSigner(EnumSet<ACGenerationProperties> properties) {

    if (signer == null) {

        JcaContentSignerBuilder builder = new JcaContentSignerBuilder(
                aaCredential.getCertificate().getSigAlgName());

        builder.setProvider(BouncyCastleProvider.PROVIDER_NAME);
        try {/*w  ww  .  j  a v  a  2 s .  c o  m*/

            if (properties.contains(ACGenerationProperties.FAKE_SIGNATURE_BITS))
                signer = new RandomContentSigner(aaCredential.getCertificate().getSigAlgName());
            else
                signer = builder.build(aaCredential.getKey());

        } catch (OperatorCreationException e) {
            throw new VOMSError(e.getMessage(), e);
        }
    }
    return signer;
}

From source file:org.italiangrid.voms.asn1.VOMSACUtils.java

License:Apache License

/**
 * Deserializes the VOMS ACCerts extension
 * /*  w ww  .j a v  a2  s  .  c o  m*/
 * @param ac
 *          the VOMS {@link X509AttributeCertificateHolder}
 * @return the parsed array of {@link X509Certificate}
 */
private static X509Certificate[] deserializeACCerts(X509AttributeCertificateHolder ac) {

    List<X509Certificate> certs = new ArrayList<X509Certificate>();

    X509Extension e = ac.getExtension(VOMS_CERTS_OID);

    if (e == null)
        return null;

    ASN1Sequence certSeq = (ASN1Sequence) e.getParsedValue();
    if (certSeq.size() != 1)
        raiseACNonConformantError("unsupported accerts format.");

    // Down one level
    certSeq = (ASN1Sequence) certSeq.getObjectAt(0);

    @SuppressWarnings("unchecked")
    Enumeration<DERSequence> encodedCerts = certSeq.getObjects();

    CertificateFactory cf = null;

    try {
        cf = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME);
    } catch (Exception ex) {
        throw new VOMSError("Certificate factory creation error: " + ex.getMessage(), ex);
    }

    while (encodedCerts.hasMoreElements()) {

        DERSequence s = encodedCerts.nextElement();
        X509CertificateObject certObj = null;
        byte[] certData = null;
        X509Certificate theCert = null;

        try {

            certObj = new X509CertificateObject(
                    X509CertificateStructure.getInstance(ASN1Sequence.getInstance(s)));
            certData = certObj.getEncoded();
            theCert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certData));

        } catch (CertificateParsingException ex) {
            throw new VOMSError("Certificate parsing error: " + ex.getMessage(), ex);
        } catch (CertificateEncodingException ex) {
            throw new VOMSError("Certificate encoding error: " + ex.getMessage(), ex);
        } catch (CertificateException ex) {
            throw new VOMSError("Error generating certificate from parsed data: " + ex.getMessage(), ex);
        }

        certs.add(theCert);
    }

    return certs.toArray(new X509Certificate[certs.size()]);
}

From source file:org.jboss.as.test.integration.logging.syslogserver.TLSSyslogServer.java

License:Open Source License

/**
 * Removes Bouncy Castle from Security Manager.
 *///from  w w  w .jav  a  2 s.  co  m
public void removeBouncyCastle() {
    try {
        Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
    } catch (SecurityException ex) {
        LOGGER.warn("Cannot deregister BouncyCastleProvider", ex);
    }
}

From source file:org.jboss.as.test.integration.logging.syslogserver.TLSSyslogServer.java

License:Open Source License

/**
 * Adds Bouncy Castle to Security Manager.
 *///from  www .j a va2s .  c om
private void addBouncyCastle() {
    try {
        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
            Security.addProvider(new BouncyCastleProvider());
        }
    } catch (SecurityException ex) {
        LOGGER.warn("Cannot register BouncyCastleProvider", ex);
    }
}

From source file:org.jboss.as.test.integration.logging.syslogserver.TLSSyslogServer.java

License:Open Source License

/**
 * Returns <code>true</code> if Bouncy Castle has been added to the Security Manager.
 *//*from   w  ww  .  ja v a 2  s . c om*/
private boolean isBouncyCastleInstalled() {
    return Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) != null;
}

From source file:org.jboss.as.test.integration.security.loginmodules.LdapExtLDAPServerSetupTask.java

License:Open Source License

/**
 * Creates directory services, starts LDAP server and KDCServer
 *
 * @param managementClient/*from  w ww . j a  va2 s .c  om*/
 * @param containerId
 * @throws Exception
 * @see org.jboss.as.arquillian.api.ServerSetupTask#setup(org.jboss.as.arquillian.container.ManagementClient,
 * java.lang.String)
 */
public void setup(ManagementClient managementClient, String containerId) throws Exception {
    try {
        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
            Security.addProvider(new BouncyCastleProvider());
            removeBouncyCastle = true;
        }
    } catch (SecurityException ex) {
        LOGGER.warn("Cannot register BouncyCastleProvider", ex);
    }

    final String hostname = Utils.getSecondaryTestAddress(managementClient, false);
    createLdap1(hostname);
    createLdap2(hostname);
}

From source file:org.jboss.as.test.integration.security.loginmodules.LdapExtLDAPServerSetupTask.java

License:Open Source License

/**
 * Stops LDAP server and KDCServer and shuts down the directory service.
 *
 * @param managementClient/*w w  w .  j  a  va  2 s.  co  m*/
 * @param containerId
 * @throws Exception
 * @see org.jboss.as.arquillian.api.ServerSetupTask#tearDown(org.jboss.as.arquillian.container.ManagementClient,
 * java.lang.String)
 */
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
    ldapServer2.stop();
    directoryService2.shutdown();
    ldapServer1.stop();
    directoryService1.shutdown();
    KEYSTORE_FILE.delete();
    FileUtils.deleteDirectory(directoryService2.getInstanceLayout().getInstanceDirectory());
    FileUtils.deleteDirectory(directoryService1.getInstanceLayout().getInstanceDirectory());
    if (removeBouncyCastle) {
        try {
            Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
        } catch (SecurityException ex) {
            LOGGER.warn("Cannot deregister BouncyCastleProvider", ex);
        }
    }
}