public AuthenticatedSocket(InetAddress ia, int port, MessageDigest md, byte[] secret) throws IOException, AuthenticationException { super(ia, port); try { OutputStream output = this.getOutputStream(); InputStream input = this.getInputStream(); // Get challenge length byte[] challengeSize = new byte[4]; input.read(challengeSize); // Receive random challenge string byte[] challenge = new byte[Bytes.toInt(challengeSize)]; input.read(challenge); // Generate MD5 hash byte[] append = Bytes.append(challenge, secret); byte[] hash = md.digest(append); // Send time and hash strings output.write(hash); } catch (Exception e) { throw new AuthenticationException("Authentication failed: " + e.getMessage()); } }
private void _putObjectField(String name, Object val) { if (dbOnlyField(name) || name.equals("_transientFields")) return; if (DEBUG) System.out.println("\t put thing : " + name); if (name.equals("$where") && val instanceof String) { _put(CODE, name); _putValueString(val.toString()); return; } val = Bytes.applyEncodingHooks(val); if (val == null) putNull(name); else if (val instanceof Date) putDate(name, (Date) val); else if (val instanceof Number) putNumber(name, (Number) val); else if (val instanceof String) putString(name, val.toString()); else if (val instanceof ObjectId) putObjectId(name, (ObjectId) val); else if (val instanceof DBObject) putObject(name, (DBObject) val); else if (val instanceof Boolean) putBoolean(name, (Boolean) val); else if (val instanceof Pattern) putPattern(name, (Pattern) val); else if (val instanceof DBRegex) { putDBRegex(name, (DBRegex) val); } else if (val instanceof Map) putMap(name, (Map) val); else if (val instanceof List) putList(name, (List) val); else if (val instanceof byte[]) putBinary(name, (byte[]) val); else if (val instanceof DBBinary) putBinary(name, (DBBinary) val); else if (val.getClass().isArray()) putList(name, Arrays.asList((Object[]) val)); else if (val instanceof DBPointer) { // temporary - there's the notion of "special object" , but for simple level 0... DBPointer r = (DBPointer) val; putDBPointer(name, r._ns, (ObjectId) r._id); } else if (val instanceof DBRefBase) { putDBRef(name, (DBRefBase) val); } else if (val instanceof DBSymbol) { putSymbol(name, (DBSymbol) val); } else if (val instanceof DBUndefined) { putUndefined(name); } else if (val instanceof DBTimestamp) { putTimestamp(name, (DBTimestamp) val); } else throw new IllegalArgumentException("can't serialize " + val.getClass()); }