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()); } }
// lame way to communicate with the coprocessor, // since it is loaded by a different class loader @Override public void prePut( final ObserverContext<RegionCoprocessorEnvironment> c, final Put put, final WALEdit edit, final Durability durability) throws IOException { if (put.getAttribute("ttl") != null) { Cell cell = put.getFamilyCellMap().values().iterator().next().get(0); KeyValue kv = KeyValueUtil.ensureKeyValue(cell); ttls.put(TableName.valueOf(kv.getQualifier()), Bytes.toLong(kv.getValue())); c.bypass(); } else if (put.getAttribute("versions") != null) { Cell cell = put.getFamilyCellMap().values().iterator().next().get(0); KeyValue kv = KeyValueUtil.ensureKeyValue(cell); versions.put(TableName.valueOf(kv.getQualifier()), Bytes.toInt(kv.getValue())); c.bypass(); } }