/** * Translates the specified SVNBase64 string (as per Preferences.get(byte[])) * into a byte array. * * @throws IllegalArgumentException * if <tt>s</tt> is not a valid SVNBase64 string. */ public static int base64ToByteArray(StringBuffer s, byte[] buffer) { return base64ToByteArray(s, buffer, false); }
/** * Translates the specified SVNBase64 string (as per Preferences.get(byte[])) * into a byte array. * * @throws IllegalArgumentException * if <tt>s</tt> is not a valid SVNBase64 string. */ public static int base64ToByteArray(StringBuffer s, byte[] buffer) { return base64ToByteArray(s, buffer, false); }
/** * Translates the specified SVNBase64 string (as per Preferences.get(byte[])) * into a byte array. * * @throws IllegalArgumentException * if <tt>s</tt> is not a valid SVNBase64 string. */ public static int base64ToByteArray(StringBuffer s, byte[] buffer) { return base64ToByteArray(s, buffer, false); }
public static int base64ToByteArray(char[] s, byte[] buffer) { try { return base64ToByteArray(s, buffer, false); } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("Invalid SVNBase64 string: " + s.toString(), e); } }
public void respondTo(String challenge) { if (challenge == null) { myToken = new byte[0]; myTokenLength = 0; } else { myToken = new byte[(challenge.length() * 3 + 3) / 4]; myTokenLength = SVNBase64.base64ToByteArray(new StringBuffer(challenge), myToken); } }
/** * Translates the specified SVNBase64 string (as per Preferences.get(byte[])) * into a byte array. * * @throws IllegalArgumentException * if <tt>s</tt> is not a valid SVNBase64 string. */ public static int base64ToByteArray(StringBuffer s, byte[] buffer) { try { return base64ToByteArray(s, buffer, false); } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("Invalid SVNBase64 string: " + s.toString(), e); } }
private static int base64ToByteArray(StringBuffer sb, byte[] result, boolean alternate) { return base64ToByteArray(sb.toString().toCharArray(), result, alternate); }
private static byte[] fromBase64(String src) { if (src == null) { return new byte[0]; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < src.length(); i++) { char ch = src.charAt(i); if (!Character.isWhitespace(ch) && ch != '\n' && ch != '\r') { bos.write((byte) ch & 0xFF); } } byte[] cbytes = new byte[src.length()]; try { src = new String(bos.toByteArray(), "US-ASCII"); } catch (UnsupportedEncodingException e) { // } int clength = SVNBase64.base64ToByteArray(new StringBuffer(src), cbytes); byte[] result = new byte[clength]; // strip trailing -1s. for(int i = clength - 1; i>=0; i--) { if (i == -1) { clength--; } } System.arraycopy(cbytes, 0, result, 0, clength); return result; }
private static byte[] fromBase64(String src) { if (src == null) { return new byte[0]; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (int i = 0; i < src.length(); i++) { char ch = src.charAt(i); if (!Character.isWhitespace(ch) && ch != '\n' && ch != '\r') { bos.write((byte) ch & 0xFF); } } byte[] cbytes = new byte[src.length()]; try { src = new String(bos.toByteArray(), "US-ASCII"); } catch (UnsupportedEncodingException e) { // } int clength = SVNBase64.base64ToByteArray(new StringBuffer(src), cbytes); byte[] result = new byte[clength]; // strip trailing -1s. for(int i = clength - 1; i>=0; i--) { if (i == -1) { clength--; } } System.arraycopy(cbytes, 0, result, 0, clength); return result; }
public String generateType3Msg(String userName, char[] password, String domain, String ws, String token) throws NTLMEngineException { final byte[] buffer = new byte[token.length()]; final int length = SVNBase64.base64ToByteArray(new StringBuffer(token), buffer); final byte[] tokenBytes = new byte[length]; System.arraycopy(buffer, 0, tokenBytes, 0, length); try { final Class<?> type2MessageClass = Class.forName("jcifs.ntlmssp.Type2Message"); final Class<?> type3MessageClass = Class.forName("jcifs.ntlmssp.Type3Message"); final Constructor<?> type2Constructor = type2MessageClass.getConstructor(byte[].class); final Constructor<?> type3Constructor = type3MessageClass.getConstructor(type2MessageClass, String.class, String.class, String.class, String.class, Integer.TYPE); final Object type2MessageObject = type2Constructor.newInstance(tokenBytes); final Method getFlags = type2MessageClass.getMethod("getFlags"); final int type2Flags = (Integer) getFlags.invoke(type2MessageObject); final int type3Flags = type2Flags & (~(0x00010000 /*NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN*/ | 0x00020000 /*NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER*/)); final Object type3MessageObject = type3Constructor.newInstance(type2MessageObject, new String(password), domain, userName, ws, type3Flags); final Method toByteArray = type3MessageClass.getMethod("toByteArray"); final byte[] message = (byte[]) toByteArray.invoke(type3MessageObject); return SVNBase64.byteArrayToBase64(message); } catch (Exception e) { throw new NTLMEngineException(e.getMessage(), e); } } }
public void respondTo(String challenge) { SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, "NEGOTIATE: respond to, challenge: " + challenge); if (challenge == null) { myToken = new byte[0]; myTokenLength = 0; } else { myToken = new byte[(challenge.length() * 3 + 3) / 4]; myTokenLength = SVNBase64.base64ToByteArray(new StringBuffer(challenge), myToken); } SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, "NEGOTIATE: respond to, token length: " + myTokenLength); }
public void respondTo(String challenge) { SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, "NEGOTIATE: respond to, challenge: " + challenge); if (challenge == null) { myToken = new byte[0]; myTokenLength = 0; } else { myToken = new byte[(challenge.length() * 3 + 3) / 4]; myTokenLength = SVNBase64.base64ToByteArray(new StringBuffer(challenge), myToken); } SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, "NEGOTIATE: respond to, token length: " + myTokenLength); }
/** Constructor to use when message contents are known */ NTLMMessage(final String messageBody, final int expectedType) throws NTLMEngineException { final byte[] buffer = new byte[messageBody.length()]; int length = SVNBase64.base64ToByteArray(new StringBuffer(messageBody), buffer); messageContents = new byte[length]; System.arraycopy(buffer, 0, messageContents, 0, length); // Look for NTLM message if (messageContents.length < SIGNATURE.length) { throw new NTLMEngineException("NTLM message decoding error - packet too short"); } int i = 0; while (i < SIGNATURE.length) { if (messageContents[i] != SIGNATURE[i]) { throw new NTLMEngineException( "NTLM message expected - instead got unrecognized bytes"); } i++; } // Check to be sure there's a type 2 message indicator next final int type = readULong(SIGNATURE.length); if (type != expectedType) { throw new NTLMEngineException("NTLM type " + Integer.toString(expectedType) + " message expected - instead got type " + Integer.toString(type)); } currentOutputPosition = messageContents.length; }
protected SVNPropertyValue createPropertyValueFromBase64(DAVElement element, String propertyName, StringBuffer cdata) { StringBuffer sb = SVNBase64.normalizeBase64(cdata); byte[] buffer = allocateBuffer(sb.length()); int length = SVNBase64.base64ToByteArray(sb, buffer); if (useStringProperty(element, propertyName)) { String str; try { str = new String(buffer, 0, length, "UTF-8"); } catch (UnsupportedEncodingException e) { str = new String(buffer, 0, length); } return SVNPropertyValue.create(str); } return SVNPropertyValue.create(propertyName, buffer, 0, length); }
protected void endElement(DAVElement parent, DAVElement element, StringBuffer cdata) throws SVNException { if (element == APPLY_TEXT_DELTA) { setDeltaProcessing(false); } else if (element == CHANGE_FILE_PROPERTY || element == CHANGE_DIR_PROPERTY) { if (cdata != null && !"".equals(cdata) && myPropertyName == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_MALFORMED_DATA, "Got cdata content for a prop delete"); SVNErrorManager.error(err); } if (myPropertyName != null) { String value = cdata.toString(); byte[] buffer = allocateBuffer(cdata.length()); int length = SVNBase64.base64ToByteArray(new StringBuffer(cdata.toString().trim()), buffer); try { value = new String(buffer, 0, length, "UTF-8"); } catch (UnsupportedEncodingException e) { value = new String(buffer, 0, length); } if (element == CHANGE_FILE_PROPERTY) { myEditor.changeFileProperty(myPath, myPropertyName, value); } else { myEditor.changeDirProperty(myPropertyName, value); } } } }
public static String getAuthHeader(String token, SVNNTSecurityParameters params) throws SVNException { byte[] input = null; if (token != null) { StringBuffer tokenBuffer = new StringBuffer(token); byte[] tmp = new byte[tokenBuffer.length()]; StringBuffer sb = SVNBase64.normalizeBase64(tokenBuffer); int resultLength = SVNBase64.base64ToByteArray(sb, tmp); input = new byte[resultLength]; System.arraycopy(tmp, 0, input, 0, resultLength); } byte[] nextTokenBytes = getNextToken(params, input); if (nextTokenBytes == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Internal authentication error"); SVNErrorManager.error(err, SVNLogType.DEFAULT); } return SVNBase64.byteArrayToBase64(nextTokenBytes); }
public static String getAuthHeader(String token, SVNNTSecurityParameters params) throws SVNException { byte[] input = null; if (token != null) { StringBuffer tokenBuffer = new StringBuffer(token); byte[] tmp = new byte[tokenBuffer.length()]; StringBuffer sb = SVNBase64.normalizeBase64(tokenBuffer); int resultLength = SVNBase64.base64ToByteArray(sb, tmp); input = new byte[resultLength]; System.arraycopy(tmp, 0, input, 0, resultLength); } byte[] nextTokenBytes = getNextToken(params, input); if (nextTokenBytes == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.IO_ERROR, "Internal authentication error"); SVNErrorManager.error(err, SVNLogType.DEFAULT); } return SVNBase64.byteArrayToBase64(nextTokenBytes); }
public void storeProperty(DAVElementProperty property) throws DAVException { DAVElement propName = property.getName(); String propValue = property.getFirstValue(false); String reposPropName = getReposPropName(propName); SVNPropertyValue value = null; Map attributes = property.getAttributes(); if (attributes != null) { for (Iterator attrsIter = attributes.keySet().iterator(); attrsIter.hasNext();) { String attrName = (String) attrsIter.next(); if (ServletDAVHandler.ENCODING_ATTR.equals(attrName)) { String encodingType = (String) attributes.get(attrName); if (ServletDAVHandler.BASE64_ENCODING.equals(encodingType)) { byte[] buffer = new byte[propValue.length()]; int length = SVNBase64.base64ToByteArray(new StringBuffer(propValue), buffer); value = SVNPropertyValue.create(reposPropName, buffer, 0, length); } else { throw new DAVException("Unknown property encoding", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 0); } break; } } } if (value == null) { value = SVNPropertyValue.create(propValue); } saveValue(propName, value); }
protected void endElement(DAVElement parent, DAVElement element, StringBuffer cdata) throws SVNException { if (element == APPLY_TEXT_DELTA) { setDeltaProcessing(false); } else if (element == CHANGE_FILE_PROPERTY || element == CHANGE_DIR_PROPERTY) { if (cdata != null && !"".equals(cdata.toString()) && myPropertyName == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_MALFORMED_DATA, "Got cdata content for a prop delete"); SVNErrorManager.error(err, SVNLogType.NETWORK); } if (myPropertyName != null) { StringBuffer sb = SVNBase64.normalizeBase64(cdata); byte[] buffer = allocateBuffer(sb.length()); int length = SVNBase64.base64ToByteArray(sb, buffer); SVNPropertyValue property = SVNPropertyValue.create(myPropertyName, buffer, 0, length); if (element == CHANGE_FILE_PROPERTY) { myEditor.changeFileProperty(myPath, myPropertyName, property); } else { myEditor.changeDirProperty(myPropertyName, property); } } } } }
protected void endElement(DAVElement parent, DAVElement element, StringBuffer cdata) throws SVNException { if (element == APPLY_TEXT_DELTA) { setDeltaProcessing(false); } else if (element == CHANGE_FILE_PROPERTY || element == CHANGE_DIR_PROPERTY) { if (cdata != null && !"".equals(cdata.toString()) && myPropertyName == null) { SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_DAV_MALFORMED_DATA, "Got cdata content for a prop delete"); SVNErrorManager.error(err, SVNLogType.NETWORK); } if (myPropertyName != null) { StringBuffer sb = SVNBase64.normalizeBase64(cdata); byte[] buffer = allocateBuffer(sb.length()); int length = SVNBase64.base64ToByteArray(sb, buffer); SVNPropertyValue property = SVNPropertyValue.create(myPropertyName, buffer, 0, length); if (element == CHANGE_FILE_PROPERTY) { myEditor.changeFileProperty(myPath, myPropertyName, property); } else { myEditor.changeDirProperty(myPropertyName, property); } } } } }