public static void createAndStoreCryptographicallyStrongTokenInSession(HttpSession session) { ByteArrayGuardAESCTR guard = new ByteArrayGuardAESCTR(); String clearText = "" + System.currentTimeMillis(); String result = guard.encrypt(clearText); try { result = URLEncoder.encode(result, "UTF-8"); } catch (UnsupportedEncodingException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unable to URL encode cryptographically strong token, storing clear text in session instead.", e); } result = clearText; } session.setAttribute(TOKEN_NAME, result); }
public ByteArrayGuardAESCTR() { try { setupKeyAndCharset(); } catch (Exception e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unexpected exception initializing encryption." + " No encryption will be performed.", e); } System.err.println("ERROR: Initializing Ciphers"); } }
/** Creates a new instance of ELFlash */ private ELFlash(ExternalContext extContext) { flashInnerMap = new ConcurrentHashMap<String,Map<String, Object>>(); WebConfiguration config = WebConfiguration.getInstance(extContext); String value; try { value = config.getOptionValue(WebContextInitParameter.NumberOfConcurrentFlashUsers); numberOfConcurentFlashUsers = Integer.parseInt(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number of concurrent flash users. Defaulting to {0}", numberOfConcurentFlashUsers); } } try { value = config.getOptionValue(WebContextInitParameter.NumberOfFlashesBetweenFlashReapings); numberOfFlashesBetweenFlashReapings = Long.parseLong(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number flashes between flash repaings. Defaulting to {0}", numberOfFlashesBetweenFlashReapings); } } distributable = config.isOptionEnabled(EnableDistributable); guard = new ByteArrayGuardAESCTR(); }
/** * <p>Encode the current state of the * PreviousNextFlashInfoManager to the cookie.</p> */ Cookie encode() { Cookie result = null; String value = ((null != previousRequestFlashInfo) ? previousRequestFlashInfo.encode() : "") + "_" + ((null != nextRequestFlashInfo) ? nextRequestFlashInfo.encode() : ""); String encryptedValue = guard.encrypt(value); try { result = new Cookie(FLASH_COOKIE_NAME, URLEncoder.encode(encryptedValue, "UTF-8")); } catch (UnsupportedEncodingException uee) { result = new Cookie(FLASH_COOKIE_NAME, encryptedValue); } if (1 == value.length()) { result.setMaxAge(0); } String requestContextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); if (requestContextPath.isEmpty()) { requestContextPath = "/"; } result.setPath(requestContextPath); return result; }
value = guard.decrypt(urlDecodedValue);
byte[] temp = concatBytes(iv, encdata);
/** Creates a new instance of ELFlash */ private ELFlash(ExternalContext extContext) { flashInnerMap = new ConcurrentHashMap<>(); WebConfiguration config = WebConfiguration.getInstance(extContext); String value; try { value = config.getOptionValue(WebContextInitParameter.NumberOfConcurrentFlashUsers); numberOfConcurentFlashUsers = Integer.parseInt(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number of concurrent flash users. Defaulting to {0}", numberOfConcurentFlashUsers); } } try { value = config.getOptionValue(WebContextInitParameter.NumberOfFlashesBetweenFlashReapings); numberOfFlashesBetweenFlashReapings = Long.parseLong(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number flashes between flash repaings. Defaulting to {0}", numberOfFlashesBetweenFlashReapings); } } distributable = config.isOptionEnabled(EnableDistributable); guard = new ByteArrayGuardAESCTR(); }
/** * <p>Encode the current state of the * PreviousNextFlashInfoManager to the cookie.</p> */ Cookie encode() { Cookie result = null; String value = ((null != previousRequestFlashInfo) ? previousRequestFlashInfo.encode() : "") + "_" + ((null != nextRequestFlashInfo) ? nextRequestFlashInfo.encode() : ""); String encryptedValue = guard.encrypt(value); try { result = new Cookie(FLASH_COOKIE_NAME, URLEncoder.encode(encryptedValue, "UTF-8")); } catch (UnsupportedEncodingException uee) { result = new Cookie(FLASH_COOKIE_NAME, encryptedValue); } if (1 == value.length()) { result.setMaxAge(0); } String requestContextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); if (requestContextPath.isEmpty()) { requestContextPath = "/"; } result.setPath(requestContextPath); return result; }
value = guard.decrypt(urlDecodedValue);
byte[] temp = concatBytes(iv, encdata);
public static void createAndStoreCryptographicallyStrongTokenInSession(HttpSession session) { ByteArrayGuardAESCTR guard = new ByteArrayGuardAESCTR(); String clearText = "" + System.currentTimeMillis(); String result = guard.encrypt(clearText); try { result = URLEncoder.encode(result, "UTF-8"); } catch (UnsupportedEncodingException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unable to URL encode cryptographically strong token, storing clear text in session instead.", e); } result = clearText; } session.setAttribute(TOKEN_NAME, result); }
public ByteArrayGuardAESCTR() { try { setupKeyAndCharset(); } catch (Exception e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unexpected exception initializing encryption." + " No encryption will be performed.", e); } System.err.println("ERROR: Initializing Ciphers"); } }
/** Creates a new instance of ELFlash */ private ELFlash(ExternalContext extContext) { flashInnerMap = new ConcurrentHashMap<>(); WebConfiguration config = WebConfiguration.getInstance(extContext); String value; try { value = config.getOptionValue(WebContextInitParameter.NumberOfConcurrentFlashUsers); numberOfConcurentFlashUsers = Integer.parseInt(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number of concurrent flash users. Defaulting to {0}", numberOfConcurentFlashUsers); } } try { value = config.getOptionValue(WebContextInitParameter.NumberOfFlashesBetweenFlashReapings); numberOfFlashesBetweenFlashReapings = Long.parseLong(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number flashes between flash repaings. Defaulting to {0}", numberOfFlashesBetweenFlashReapings); } } distributable = config.isOptionEnabled(EnableDistributable); guard = new ByteArrayGuardAESCTR(); }
/** * <p>Encode the current state of the * PreviousNextFlashInfoManager to the cookie.</p> */ Cookie encode() { Cookie result = null; String value = ((null != previousRequestFlashInfo) ? previousRequestFlashInfo.encode() : "") + "_" + ((null != nextRequestFlashInfo) ? nextRequestFlashInfo.encode() : ""); String encryptedValue = guard.encrypt(value); try { result = new Cookie(FLASH_COOKIE_NAME, URLEncoder.encode(encryptedValue, "UTF-8")); } catch (UnsupportedEncodingException uee) { result = new Cookie(FLASH_COOKIE_NAME, encryptedValue); } if (1 == value.length()) { result.setMaxAge(0); } String requestContextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); if (requestContextPath.isEmpty()) { requestContextPath = "/"; } result.setPath(requestContextPath); return result; }
value = guard.decrypt(urlDecodedValue);
public static void createAndStoreCryptographicallyStrongTokenInSession(HttpSession session) { ByteArrayGuardAESCTR guard = new ByteArrayGuardAESCTR(); String clearText = "" + System.currentTimeMillis(); String result = guard.encrypt(clearText); try { result = URLEncoder.encode(result, "UTF-8"); } catch (UnsupportedEncodingException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unable to URL encode cryptographically strong token, storing clear text in session instead.", e); } result = clearText; } session.setAttribute(TOKEN_NAME, result); }
public ByteArrayGuardAESCTR() { try { setupKeyAndCharset(); } catch (Exception e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unexpected exception initializing encryption." + " No encryption will be performed.", e); } System.err.println("ERROR: Initializing Ciphers"); } }
/** Creates a new instance of ELFlash */ private ELFlash(ExternalContext extContext) { flashInnerMap = new ConcurrentHashMap<>(); WebConfiguration config = WebConfiguration.getInstance(extContext); String value; try { value = config.getOptionValue(WebContextInitParameter.NumberOfConcurrentFlashUsers); numberOfConcurentFlashUsers = Integer.parseInt(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number of concurrent flash users. Defaulting to {0}", numberOfConcurentFlashUsers); } } try { value = config.getOptionValue(WebContextInitParameter.NumberOfFlashesBetweenFlashReapings); numberOfFlashesBetweenFlashReapings = Long.parseLong(value); } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to set number flashes between flash repaings. Defaulting to {0}", numberOfFlashesBetweenFlashReapings); } } distributable = config.isOptionEnabled(EnableDistributable); guard = new ByteArrayGuardAESCTR(); }
/** * <p>Encode the current state of the * PreviousNextFlashInfoManager to the cookie.</p> */ Cookie encode() { Cookie result = null; String value = ((null != previousRequestFlashInfo) ? previousRequestFlashInfo.encode() : "") + "_" + ((null != nextRequestFlashInfo) ? nextRequestFlashInfo.encode() : ""); String encryptedValue = guard.encrypt(value); try { result = new Cookie(FLASH_COOKIE_NAME, URLEncoder.encode(encryptedValue, "UTF-8")); } catch (UnsupportedEncodingException uee) { result = new Cookie(FLASH_COOKIE_NAME, encryptedValue); } if (1 == value.length()) { result.setMaxAge(0); } String requestContextPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); if (requestContextPath.isEmpty()) { requestContextPath = "/"; } result.setPath(requestContextPath); return result; }
value = guard.decrypt(urlDecodedValue);