List of usage examples for java.security KeyStore aliases
public final Enumeration<String> aliases() throws KeyStoreException
From source file:org.kuali.rice.ksb.security.admin.service.impl.JavaSecurityManagementServiceImpl.java
public List<KeyStoreEntryDataContainer> getListOfModuleKeyStoreEntries() { List<KeyStoreEntryDataContainer> keyStoreEntries = new ArrayList<KeyStoreEntryDataContainer>(); try {//from w ww . jav a 2 s . com KeyStore moduleKeyStore = getModuleKeyStore(); // List the aliases for (Enumeration<String> enumer = moduleKeyStore.aliases(); enumer.hasMoreElements();) { String alias = (String) enumer.nextElement(); KeyStoreEntryDataContainer dataContainer = new KeyStoreEntryDataContainer(alias, moduleKeyStore.getCreationDate(alias)); KeyStore.PasswordProtection passwordProtection = null; if (moduleKeyStore.isKeyEntry(alias)) { passwordProtection = new KeyStore.PasswordProtection(getModuleKeyStorePassword().toCharArray()); } KeyStore.Entry entry = moduleKeyStore.getEntry(alias, passwordProtection); dataContainer.setType(entry.getClass()); keyStoreEntries.add(dataContainer); } } catch (KeyStoreException e) { e.printStackTrace(); throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new RuntimeException(e); } catch (UnrecoverableEntryException e) { e.printStackTrace(); throw new RuntimeException(e); } return keyStoreEntries; }
From source file:com.utest.webservice.client.rest.AuthSSLProtocolSocketFactory.java
@SuppressWarnings("unchecked") private SSLContext createSSLContext() { try {/*from w w w .ja va 2 s. c o m*/ KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (this.keystoreUrl != null) { KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword); if (true) { Enumeration aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { System.out.println("Certificate chain '" + alias + "':"); for (int c = 0; c < certs.length; c++) { if (certs[c] instanceof X509Certificate) { X509Certificate cert = (X509Certificate) certs[c]; System.out.println(" Certificate " + (c + 1) + ":"); System.out.println(" Subject DN: " + cert.getSubjectDN()); System.out.println(" Signature Algorithm: " + cert.getSigAlgName()); System.out.println(" Valid from: " + cert.getNotBefore()); System.out.println(" Valid until: " + cert.getNotAfter()); System.out.println(" Issuer: " + cert.getIssuerDN()); } } } } } keymanagers = createKeyManagers(keystore, this.keystorePassword); } if (this.truststoreUrl != null) { KeyStore keystore = createKeyStore(this.truststoreUrl, this.truststorePassword); if (true) { Enumeration aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); System.out.println("Trusted certificate '" + alias + "':"); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert != null && trustedcert instanceof X509Certificate) { X509Certificate cert = (X509Certificate) trustedcert; System.out.println(" Subject DN: " + cert.getSubjectDN()); System.out.println(" Signature Algorithm: " + cert.getSigAlgName()); System.out.println(" Valid from: " + cert.getNotBefore()); System.out.println(" Valid until: " + cert.getNotAfter()); System.out.println(" Issuer: " + cert.getIssuerDN()); } } } trustmanagers = createTrustManagers(keystore); } SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; } catch (NoSuchAlgorithmException e) { System.out.println(e.getMessage()); throw new AuthSSLInitializationError("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { System.out.println(e.getMessage()); throw new AuthSSLInitializationError("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { System.out.println(e.getMessage()); throw new AuthSSLInitializationError("Key management exception: " + e.getMessage()); } catch (IOException e) { System.out.println(e.getMessage()); throw new AuthSSLInitializationError("I/O error reading keystore/truststore file: " + e.getMessage()); } }
From source file:test.integ.be.e_contract.mycarenet.etee.SealTest.java
@Test public void testSeal() throws Exception { InputStream sealInputStream = SealTest.class.getResourceAsStream("/seal-fcorneli.der"); assertNotNull(sealInputStream);/*from w w w . j av a 2s . com*/ byte[] cmsData = IOUtils.toByteArray(sealInputStream); // check outer signature byte[] data = getVerifiedContent(cmsData); // decrypt content CMSEnvelopedDataParser cmsEnvelopedDataParser = new CMSEnvelopedDataParser(data); LOG.debug("content encryption algo: " + cmsEnvelopedDataParser.getContentEncryptionAlgorithm().getAlgorithm().getId()); RecipientInformationStore recipientInformationStore = cmsEnvelopedDataParser.getRecipientInfos(); Collection<RecipientInformation> recipients = recipientInformationStore.getRecipients(); RecipientInformation recipientInformation = recipients.iterator().next(); LOG.debug("recipient info type: " + recipientInformation.getClass().getName()); KeyTransRecipientInformation keyTransRecipientInformation = (KeyTransRecipientInformation) recipientInformation; // load eHealth encryption certificate KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12"); FileInputStream fileInputStream = new FileInputStream(this.config.getEHealthPKCS12Path()); eHealthKeyStore.load(fileInputStream, this.config.getEHealthPKCS12Password().toCharArray()); Enumeration<String> aliasesEnum = eHealthKeyStore.aliases(); aliasesEnum.nextElement(); // skip authentication certificate. String alias = aliasesEnum.nextElement(); X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore.getCertificate(alias); PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(alias, this.config.getEHealthPKCS12Password().toCharArray()); AsymmetricKeyParameter privKeyParams = PrivateKeyFactory.createKey(eHealthPrivateKey.getEncoded()); BcRSAKeyTransEnvelopedRecipient recipient = new BcRSAKeyTransEnvelopedRecipient(privKeyParams); byte[] decryptedContent = recipientInformation.getContent(recipient); assertNotNull(decryptedContent); LOG.debug("decrypted content size: " + decryptedContent.length); byte[] result = getVerifiedContent(decryptedContent); LOG.debug("result: " + new String(result)); }
From source file:test.integ.be.e_contract.mycarenet.tarification.TarificationClientTest.java
@Test public void testTarificationConsultation() throws Exception { // STS/* w ww .j a v a2s .co m*/ EHealthSTSClient client = new EHealthSTSClient( "https://services-acpt.ehealth.fgov.be/IAM/Saml11TokenService/Legacy/v1"); Security.addProvider(new BeIDProvider()); KeyStore keyStore = KeyStore.getInstance("BeID"); BeIDKeyStoreParameter beIDKeyStoreParameter = new BeIDKeyStoreParameter(); beIDKeyStoreParameter.addPPDUName("digipass 870"); beIDKeyStoreParameter.addPPDUName("digipass 875"); beIDKeyStoreParameter.addPPDUName("digipass 920"); keyStore.load(beIDKeyStoreParameter); PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null); X509Certificate authnCertificate = (X509Certificate) keyStore.getCertificate("Authentication"); KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12"); FileInputStream fileInputStream = new FileInputStream(this.config.getEHealthPKCS12Path()); eHealthKeyStore.load(fileInputStream, this.config.getEHealthPKCS12Password().toCharArray()); Enumeration<String> aliasesEnum = eHealthKeyStore.aliases(); String alias = aliasesEnum.nextElement(); X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore.getCertificate(alias); PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(alias, this.config.getEHealthPKCS12Password().toCharArray()); List<Attribute> attributes = new LinkedList<>(); attributes.add(new Attribute("urn:be:fgov:identification-namespace", "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin")); attributes.add(new Attribute("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin")); List<AttributeDesignator> attributeDesignators = new LinkedList<>(); attributeDesignators.add(new AttributeDesignator("urn:be:fgov:identification-namespace", "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin")); attributeDesignators .add(new AttributeDesignator("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin")); attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth", "urn:be:fgov:person:ssin:nurse:boolean")); Element assertion = client.requestAssertion(authnCertificate, authnPrivateKey, eHealthCertificate, eHealthPrivateKey, attributes, attributeDesignators); assertNotNull(assertion); String assertionString = client.toString(assertion); // Tarification TarificationClient tarificationClient = new TarificationClient( "https://services-acpt.ehealth.fgov.be/MyCareNet/Tarification/v1"); tarificationClient.setCredentials(eHealthPrivateKey, assertionString); ObjectFactory objectFactory = new ObjectFactory(); SendRequestType sendRequest = objectFactory.createSendRequestType(); DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); GregorianCalendar issueInstantCal = new GregorianCalendar(); DateTime issueInstantDateTime = new DateTime(); issueInstantCal.setTime(issueInstantDateTime.toDate()); XMLGregorianCalendar issueInstant = datatypeFactory.newXMLGregorianCalendar(issueInstantCal); sendRequest.setIssueInstant(issueInstant); // TODO... tarificationClient.tarificationConsultation(sendRequest); }
From source file:org.codice.ddf.admin.insecure.defaults.service.KeystoreValidator.java
private List<Certificate[]> getKeystoreCertificatesChains(KeyStore keystore) { List<Certificate[]> keystoreCertificateChains = new ArrayList<>(); try {// w ww . j a v a 2 s . c o m Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); Certificate[] certificateChain = keystore.getCertificateChain(alias); if (certificateChain != null) { keystoreCertificateChains.add(certificateChain); } else { Certificate certificate = keystore.getCertificate(alias); keystoreCertificateChains.add(new Certificate[] { certificate }); } } } catch (KeyStoreException e) { LOGGER.warn(String.format(GENERIC_INSECURE_DEFAULTS_MSG, keystorePath), e); } return keystoreCertificateChains; }
From source file:org.sufficientlysecure.keychain.ui.SettingsSmartPGPAuthorityFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); List<String> authorities = new LinkedList(); try {/*from w w w . jav a2 s . com*/ final KeyStore ks = SettingsSmartPGPAuthoritiesActivity.readKeystore(getActivity()); final Enumeration<String> it = ks.aliases(); while (it.hasMoreElements()) { authorities.add(it.nextElement()); } } catch (Exception e) { } mAuthorities = new ArrayList<>(authorities); mAdapter = new AuthorityListAdapter(mAuthorities); RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.smartpgp_authority_recycler_view); recyclerView.setAdapter(mAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); ItemTouchHelper.Callback callback = new ItemTouchHelperDragCallback(mAdapter); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(recyclerView); // for clicks recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), this)); // can't use item decoration because it doesn't move with drag and drop // recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null)); // We have a menu item to show in action bar. setHasOptionsMenu(true); }
From source file:gov.nist.toolkit.soap.axis2.AuthSSLProtocolSocketFactory.java
private SSLContext createSSLContext() throws IOException { try {//from ww w . j av a 2 s . c om KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (this.keystoreUrl != null) { KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword); if (LOG.isDebugEnabled()) { Enumeration aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { LOG.debug("Certificate chain '" + alias + "':"); for (int c = 0; c < certs.length; c++) { if (certs[c] instanceof X509Certificate) { X509Certificate cert = (X509Certificate) certs[c]; LOG.debug(" Certificate " + (c + 1) + ":"); LOG.debug(" Subject DN: " + cert.getSubjectDN()); LOG.debug(" Signature Algorithm: " + cert.getSigAlgName()); LOG.debug(" Valid from: " + cert.getNotBefore()); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Issuer: " + cert.getIssuerDN()); } } } } } keymanagers = createKeyManagers(keystore, this.keystorePassword); } if (this.truststoreUrl != null) { KeyStore keystore = createKeyStore(this.truststoreUrl, this.truststorePassword); if (LOG.isDebugEnabled()) { Enumeration aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); LOG.debug("Trusted certificate '" + alias + "':"); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert != null && trustedcert instanceof X509Certificate) { X509Certificate cert = (X509Certificate) trustedcert; LOG.debug(" Subject DN: " + cert.getSubjectDN()); LOG.debug(" Signature Algorithm: " + cert.getSigAlgName()); LOG.debug(" Valid from: " + cert.getNotBefore()); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Issuer: " + cert.getIssuerDN()); } } } trustmanagers = createTrustManagers(keystore); } SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); throw new IOException("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { LOG.error(e.getMessage(), e); throw new IOException("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { LOG.error(e.getMessage(), e); throw new IOException("Key management exception: " + e.getMessage()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new IOException("I/O error reading keystore/truststore file: " + e.getMessage()); } }
From source file:com.mgmtp.perfload.core.client.web.ssl.LtSSLSocketFactory.java
private SSLContext createSSLContext() { try {/*w w w. ja v a2 s .co m*/ KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (this.keyStoreUrl != null) { KeyStore keystore = createStore(this.keyStoreUrl, this.keyStorePassword, this.keyStoreType); if (log.isDebugEnabled()) { for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) { String alias = aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { log.debug("Certificate chain '{}':", alias); for (int i = 0; i < certs.length; ++i) { if (certs[i] instanceof X509Certificate) { log.debug(" Certificate {}:", i + 1); logCertificate((X509Certificate) certs[i]); } } } } } keymanagers = createKeyManagers(keystore, this.keyStorePassword); } if (this.trustStoreUrl != null) { KeyStore keystore = createStore(this.trustStoreUrl, this.trustStorePassword, this.trustStoreType); if (log.isDebugEnabled()) { for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) { String alias = aliases.nextElement(); log.debug("Trusted certificate '{}':", alias); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert instanceof X509Certificate) { logCertificate((X509Certificate) trustedcert); } } } trustmanagers = createTrustManagers(keystore); } SSLContext context = SSLContext.getInstance("SSL"); context.init(keymanagers, trustmanagers, null); return context; } catch (NoSuchAlgorithmException e) { throw new LtSSLInitializationException("Unsupported algorithm exception: " + e.getMessage(), e); } catch (KeyStoreException e) { throw new LtSSLInitializationException("Keystore exception: " + e.getMessage(), e); } catch (GeneralSecurityException e) { throw new LtSSLInitializationException("Key management exception: " + e.getMessage(), e); } catch (IOException e) { throw new LtSSLInitializationException( "I/O error reading key store/trust store file: " + e.getMessage(), e); } }
From source file:com.mgmtp.jfunk.web.ssl.JFunkSSLSocketFactory.java
private SSLContext createSSLContext() { try {/*from w w w. j av a 2s . c o m*/ KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (this.keyStoreUrl != null) { KeyStore keystore = createStore(this.keyStoreUrl, this.keyStorePassword, this.keyStoreType); if (log.isDebugEnabled()) { for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) { String alias = aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { log.debug("Certificate chain '{}':", alias); for (int i = 0; i < certs.length; ++i) { if (certs[i] instanceof X509Certificate) { log.debug(" Certificate {}:", i + 1); logCertificate((X509Certificate) certs[i]); } } } } } keymanagers = createKeyManagers(keystore, this.keyStorePassword); } if (this.trustStoreUrl != null) { KeyStore keystore = createStore(this.trustStoreUrl, this.trustStorePassword, this.trustStoreType); if (log.isDebugEnabled()) { for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) { String alias = aliases.nextElement(); log.debug("Trusted certificate '{}':", alias); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert instanceof X509Certificate) { logCertificate((X509Certificate) trustedcert); } } } trustmanagers = createTrustManagers(keystore); } SSLContext context = SSLContext.getInstance("SSL"); context.init(keymanagers, trustmanagers, null); return context; } catch (NoSuchAlgorithmException e) { throw new JFunkException("Unsupported algorithm exception: " + e.getMessage(), e); } catch (KeyStoreException e) { throw new JFunkException("Keystore exception: " + e.getMessage(), e); } catch (GeneralSecurityException e) { throw new JFunkException("Key management exception: " + e.getMessage(), e); } catch (IOException e) { throw new JFunkException("I/O error reading key store/trust store file: " + e.getMessage(), e); } }
From source file:eu.eidas.auth.engine.SAMLEngineUtils.java
public static List<Credential> getListOfCredential(KeyStore keyStore) throws SAMLEngineException { final List<Credential> trustCred = new ArrayList<Credential>(); try {/*www .j a v a 2 s . com*/ String aliasCert = null; X509Certificate certificate; for (final Enumeration<String> e = keyStore.aliases(); e.hasMoreElements();) { aliasCert = e.nextElement(); final BasicX509Credential credential = new BasicX509Credential(); certificate = (X509Certificate) keyStore.getCertificate(aliasCert); credential.setEntityCertificate(certificate); trustCred.add(credential); } } catch (KeyStoreException e) { LOG.warn("ERROR : KeyStoreException.", e.getMessage()); LOG.debug("ERROR : KeyStoreException.", e); throw new SAMLEngineException(e); } return trustCred; }