Java Code Examples for java.security.KeyStore.CallbackHandlerProtection

The following are Jave code examples for showing how to use CallbackHandlerProtection of the java.security.KeyStore class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mi-firma-android   File: CeresKeyStoreImpl.java   View Source Code Vote up 5 votes
/** {@inheritDoc} */
 @Override
 public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
 	if (param != null) {
 		final ProtectionParameter pp = param.getProtectionParameter();
 		if (pp instanceof KeyStore.CallbackHandlerProtection) {
 			if (((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler() == null) {
 				throw new IllegalArgumentException("El CallbackHandler no puede ser nulo"); //$NON-NLS-1$
 			}
 			this.cryptoCard = new Ceres(
 					CeresProvider.getDefaultApduConnection(),
 					new JseCryptoHelper()
 				);
 			this.cryptoCard.setCallbackHandler(((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler());
 		}
 		else if (pp instanceof KeyStore.PasswordProtection) {
 			final PasswordCallback pwc = new CeresPasswordCallback((PasswordProtection) pp);
 			this.cryptoCard = new Ceres(
 					CeresProvider.getDefaultApduConnection(),
 					new JseCryptoHelper()
 				);
 			this.cryptoCard.setPasswordCallback(pwc);
 		}
 		else {
     		Logger.getLogger("es.gob.jmulticard").warning( //$NON-NLS-1$
 				"Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO") //$NON-NLS-1$ //$NON-NLS-2$
	);
 		}
 	}
 	else {
  	this.cryptoCard = new Ceres(
	CeresProvider.getDefaultApduConnection(),
	new JseCryptoHelper()
);
 	}

 	userCertAliases = Arrays.asList(this.cryptoCard.getAliases());
 }
 
Example 2
Project: mi-firma-android   File: DnieKeyStoreImpl.java   View Source Code Vote up 5 votes
/** {@inheritDoc} */
  @Override
  public KeyStore.Entry engineGetEntry(final String alias,
  		                             final ProtectionParameter protParam) {

  	if(protParam instanceof KeyStore.CallbackHandlerProtection) {
  		// Establecemos el CallbackHandler
  		final CallbackHandler chp = ((KeyStore.CallbackHandlerProtection) protParam).getCallbackHandler();
  		if(chp != null) {
  			this.cryptoCard.setCallbackHandler(chp);
  		}
  	}
  	else if (protParam instanceof KeyStore.PasswordProtection) {
  		// Establecemos el PasswordCallback
  		final PasswordCallback pwc = new CachePasswordCallback(((KeyStore.PasswordProtection)protParam).getPassword());
  		this.cryptoCard.setPasswordCallback(pwc);
  	}
  	else {
  		LOGGER.warning(
 				"Se ha proporcionado un ProtectionParameter de tipo no soportado, se ignorara: " + (protParam != null ? protParam.getClass().getName() : "NULO") //$NON-NLS-1$ //$NON-NLS-2$
	);
  	}
  	if (!engineContainsAlias(alias)) {
  		return null;
  	}
  	final PrivateKey key = (PrivateKey) engineGetKey(
	alias,
	null // Le pasamos null porque ya hemos establecido el PasswordCallback o el CallbackHander antes
);
  	return new PrivateKeyEntry(key, engineGetCertificateChain(alias));
  }
 
Example 3
Project: mi-firma-android   File: DnieKeyStoreImpl.java   View Source Code Vote up 4 votes
/** {@inheritDoc} */
 @Override
 public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
 	if (param != null) {
 		final ProtectionParameter pp = param.getProtectionParameter();
 		if (pp instanceof KeyStore.CallbackHandlerProtection) {
 			if (((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler() == null) {
 				throw new IllegalArgumentException("El CallbackHandler no puede ser nulo"); //$NON-NLS-1$
 			}
 			this.cryptoCard = DnieFactory.getDnie(
		DnieProvider.getDefaultApduConnection(),
		null,
		new JseCryptoHelper(),
		((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler()
	);
 		}
 		else if (pp instanceof KeyStore.PasswordProtection) {
 			final PasswordCallback pwc = new DniePasswordCallback((PasswordProtection) pp);
 			this.cryptoCard = DnieFactory.getDnie(
		DnieProvider.getDefaultApduConnection(),
		pwc,
		new JseCryptoHelper(),
		null
	);
 		}
 		else {
 			LOGGER.warning(
 				"Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO") //$NON-NLS-1$ //$NON-NLS-2$
	);
 		}
 	}
 	else {
  	this.cryptoCard = DnieFactory.getDnie(
	DnieProvider.getDefaultApduConnection(),
	null,
	new JseCryptoHelper(),
	null
);
 	}

 	this.aliases = Arrays.asList(this.cryptoCard.getAliases());
 }