String getInitialResponse(String host, String authzid, String user, String passwd) throws MessagingException, IOException { // return "authzid<NUL>user<NUL>passwd" ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream b64os = new BASE64EncoderStream(bos, Integer.MAX_VALUE); if (authzid != null) b64os.write(ASCIIUtility.getBytes(authzid)); b64os.write(0); b64os.write(ASCIIUtility.getBytes(user)); b64os.write(0); b64os.write(ASCIIUtility.getBytes(passwd)); b64os.flush(); // complete the encoding return ASCIIUtility.toString(bos.toByteArray()); }
/** * Convert the bytes within the specified range of the given byte * array into a signed integer . The range extends from * <code>start</code> till, but not including <code>end</code>. * * @param b the bytes * @param start the first byte offset * @param end the last byte offset * @return the integer value * @exception NumberFormatException for conversion errors */ public static int parseInt(byte[] b, int start, int end) throws NumberFormatException { return parseInt(b, start, end, 10); }
/** * Extract a long number, starting at the current position. Updates the * internal index to beyond the number. Returns -1 if a long number * was not found. * * @return a long */ public long readLong() { // Skip leading spaces skipSpaces(); int start = index; while (index < size && Character.isDigit((char)buffer[index])) index++; if (index > start) { try { return ASCIIUtility.parseLong(buffer, start, index); } catch (NumberFormatException nex) { } } return -1; }
int resp; logger.fine("Begin authentication ..."); b64os.write(bytes); b64os.flush(); String cnonce = bos.toString("iso-8859-1"); // really ASCII? bos.reset(); ASCIIUtility.getBytes(user + ":" + realm + ":" + passwd))); md5.update(ASCIIUtility.getBytes(":" + nonce + ":" + cnonce)); clientResponse = toHex(md5.digest()) + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":"; md5.update(ASCIIUtility.getBytes("AUTHENTICATE:" + uri)); md5.update(ASCIIUtility.getBytes(clientResponse + toHex(md5.digest()))); result.append(",response=" + toHex(md5.digest())); if (logger.isLoggable(Level.FINE)) logger.fine("Response => " + result.toString()); b64os.write(ASCIIUtility.getBytes(result.toString())); b64os.flush(); return bos.toByteArray();
if (ba.length > 0) { ba = BASE64EncoderStream.encode(ba); irs = ASCIIUtility.toString(ba, 0, ba.length); } else irs = "="; ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] CRLF = { (byte)'\r', (byte)'\n'}; ASCIIUtility.toString(ba, 0, ba.length) + " :"); ba = sc.evaluateChallenge(ba); os.write(CRLF); // write out empty line os.flush(); // flush the stream bos.reset(); // reset buffer ASCIIUtility.toString(ba, 0, ba.length) + " :"); ba = BASE64EncoderStream.encode(ba); if (isXGWTRUSTEDAPP) bos.write(ASCIIUtility.getBytes("XGWTRUSTEDAPP ")); os.write(bos.toByteArray()); // write out line } else if (r.isTagged() && r.getTag().equals(tag))
logger.fine("AUTHENTICATE PLAIN command trace suppressed"); suspendTracing(); } catch (Exception ex) { r = Response.byeResponse(ex); done = true; ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream b64os = new BASE64EncoderStream(bos, Integer.MAX_VALUE); try { r = readResponse(); if (r.isContinuation()) { b64os.write(ASCIIUtility.getBytes(s)); b64os.flush(); // complete the encoding bos.write(CRLF); // CRLF termination os.write(bos.toByteArray()); // write out line os.flush(); // flush the stream bos.reset(); // reset buffer } else if (r.isTagged() && r.getTag().equals(tag)) logger.fine("AUTHENTICATE PLAIN command result: " + r); handleLoginResult(r);
!(in instanceof BufferedInputStream) && !(in instanceof SharedInputStream)) in = new BufferedInputStream(in); } catch (Exception ex) { throw new MessagingException("No inputstream from datasource", ex); throw new MessagingException("Missing boundary parameter"); return; else throw new MessagingException("Missing start boundary"); byte[] bndbytes = ASCIIUtility.getBytes(boundary); int bl = bndbytes.length; buf = new ByteArrayOutputStream(); else end = sin.getPosition(); buf.write(previnbuf, 0, prevSize - 1); in.reset(); skipFully(in, 1); buf.write(previnbuf, 0, prevSize);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); int segment; for (segment = 0; ; segment++) { bos.write(ASCIIUtility.getBytes((String)v)); charset = MimeUtility.getDefaultJavaCharset(); if (charset != null) mv.value = bos.toString(charset); else mv.value = bos.toString();
logger.fine("AUTHENTICATE XOAUTH2 command trace suppressed"); suspendTracing(); String resp = "user=" + u + "\001auth=Bearer " + p + "\001\001"; byte[] ba = BASE64EncoderStream.encode( ASCIIUtility.getBytes(resp)); String irs = ASCIIUtility.toString(ba, 0, ba.length); args.writeAtom(irs); } catch (Exception ex) { r = Response.byeResponse(ex); done = true; try { r = readResponse(); if (r.isContinuation()) { ASCIIUtility.getBytes(resp)); os.write(b); // write out response os.write(CRLF); // CRLF termination os.flush(); // flush the stream } else if (r.isTagged() && r.getTag().equals(tag)) logger.fine("AUTHENTICATE XOAUTH2 command result: " + r); handleLoginResult(r);
/** * Parse the InputStream setting the <code>headers</code> and * <code>content</code> fields appropriately. Also resets the * <code>modified</code> flag. <p> * * This method is intended for use by subclasses that need to * control when the InputStream is parsed. * * @param is The message input stream * @exception MessagingException for failures */ protected void parse(InputStream is) throws MessagingException { if (!(is instanceof ByteArrayInputStream) && !(is instanceof BufferedInputStream) && !(is instanceof SharedInputStream)) is = new BufferedInputStream(is); headers = createInternetHeaders(is); if (is instanceof SharedInputStream) { SharedInputStream sis = (SharedInputStream)is; contentStream = sis.newStream(sis.getPosition(), -1); } else { try { content = ASCIIUtility.getBytes(is); } catch (IOException ioex) { throw new MessagingException("IOException", ioex); } } modified = false; }
public void writeln(String s) throws MessagingException { try { byte[] bytes = ASCIIUtility.getBytes(s); out.write(bytes); out.write(newline); } catch (Exception ex) { throw new MessagingException("IOException", ex); } }
byte[] pb = ASCIIUtility.getBytes(preamble); los.write(pb); throw new MessagingException("Empty multipart: " + contentType);
if (logger.isLoggable(Level.FINE)) { logger.fine("SASL Mechanisms:"); for (int i = 0; i < mechs.length; i++) logger.fine(" " + mechs[i]); logger.fine(""); if (ba.length > 0) { ba = BASE64EncoderStream.encode(ba); ir = ASCIIUtility.toString(ba, 0, ba.length); } else ir = "="; byte[] ba = null; if (!sc.isComplete()) { ba = ASCIIUtility.getBytes(responseText(pr)); if (ba.length > 0) ba = BASE64DecoderStream.decode(ba); if (logger.isLoggable(Level.FINE)) logger.fine("SASL challenge: " + ASCIIUtility.toString(ba, 0, ba.length) + " :"); ba = sc.evaluateChallenge(ba); if (logger.isLoggable(Level.FINE)) logger.fine("SASL response: " + ASCIIUtility.toString(ba, 0, ba.length) + " :"); ba = BASE64EncoderStream.encode(ba); resp = pr.simpleCommand(ba);
/** * Allow the client to authenticate the server based on its * response. * * @param serverResponse the response that was received from the server * @return true if server is authenticated * @exception IOException for character conversion failures */ public boolean authServer(String serverResponse) throws IOException { Map<String, String> map = tokenize(serverResponse); // DIGEST-MD5 computation, server response (order critical) md5.update(ASCIIUtility.getBytes(":" + uri)); md5.update(ASCIIUtility.getBytes(clientResponse + toHex(md5.digest()))); String text = toHex(md5.digest()); if (!text.equals(map.get("rspauth"))) { if (logger.isLoggable(Level.FINE)) logger.fine("Expected => rspauth=" + text); return false; // server NOT authenticated by client !!! } return true; }
skipSpaces(); return ASCIIUtility.toString(buffer, start, copyto); else return new ByteArray(buffer, start, copyto-start); count = ASCIIUtility.parseInt(buffer, start, index); } catch (NumberFormatException nex) { return ASCIIUtility.toString(buffer, start, start + count); else return new ByteArray(buffer, start, count); int start = index; // track this, so that we can use to String s = readDelimString(ASTRING_CHAR_DELIM); if (returnString) return s;
/** * Convert the String to either ASCII or UTF-8 bytes * depending on allowutf8. */ private byte[] toBytes(String s) { if (allowutf8) return s.getBytes(StandardCharsets.UTF_8); else // don't use StandardCharsets.US_ASCII because it rejects non-ASCII return ASCIIUtility.getBytes(s); }
skipSpaces(); return toString(buffer, start, copyto); else return new ByteArray(buffer, start, copyto-start); count = ASCIIUtility.parseInt(buffer, start, index); } catch (NumberFormatException nex) { return toString(buffer, start, start + count); else return new ByteArray(buffer, start, count);