ctubbsii commented on a change in pull request #1798:
URL: https://github.com/apache/accumulo/pull/1798#discussion_r528858607
##########
File path:
server/base/src/main/java/org/apache/accumulo/server/security/handler/ZKSecurityTool.java
##########
@@ -99,6 +102,24 @@ public static boolean checkPass(byte[] password, byte[]
zkData) {
return saltedHash; // contains salt+hash(password+salt)
}
+ public static byte[] createPass(byte[] password) throws AccumuloException {
+ // we rely on default algorithm and hash length (SHA-512 and 8 byte)
+ String cryptHash = Crypt.crypt(password);
+ return cryptHash.getBytes(CRYPT_CHARSET);
+ }
+
+ public static boolean checkCryptPass(byte[] password, byte[] zkData) {
+ String zkDataString = new String(zkData, CRYPT_CHARSET);
+ String cryptHash;
+ try {
+ cryptHash = Crypt.crypt(password, zkDataString);
+ } catch (IllegalArgumentException e) {
+ log.error("Unrecognized hash format", e);
+ return false;
+ }
+ return MessageDigest.isEqual(zkData, cryptHash.getBytes(CRYPT_CHARSET));
Review comment:
What's the advantage of using `MessageDigest.isEqual`, vs. comparing as
Strings or comparing as the UTF-8 byte-array?
##########
File path:
server/base/src/test/java/org/apache/accumulo/server/security/handler/ZKAuthenticatorTest.java
##########
@@ -88,14 +90,40 @@ public void testTableConversion() {
@Test
public void testEncryption() {
+ byte[] rawPass = "myPassword".getBytes(Charset.forName("UTF-8"));
+ byte[] storedBytes;
+ try {
+ storedBytes = ZKSecurityTool.createPass(rawPass.clone());
+ assertTrue(ZKSecurityTool.checkCryptPass(rawPass.clone(), storedBytes));
+ } catch (AccumuloException e) {
+ log.error("{}", e.getMessage(), e);
+ fail();
+ }
Review comment:
You can simplify this JUnit test by just throwing this out of the
method. JUnit will show the details of the exception in its logs.
##########
File path: test/src/main/java/org/apache/accumulo/test/ZKAuthenticatorIT.java
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.nio.charset.Charset;
+
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.harness.AccumuloClusterHarness;
+import org.apache.accumulo.server.security.handler.ZKAuthenticator;
+import org.junit.Test;
+
+public class ZKAuthenticatorIT extends AccumuloClusterHarness {
Review comment:
If we can avoid running a full ZK instance using Mini, I think we
should. I think ZKAuthenticator can be tested fully using unit tests with
mocking, without a need to start up an instance of a cluster.
##########
File path:
server/base/src/main/java/org/apache/accumulo/server/security/handler/ZKAuthenticator.java
##########
@@ -52,6 +52,23 @@ public void initialize(ServerContext context) {
this.context = context;
zooCache = new ZooCache(context.getZooReaderWriter(), null);
ZKUserPath = Constants.ZROOT + "/" + context.getInstanceID() + "/users";
+ checkOutdatedHashes();
+ }
+
+ private void checkOutdatedHashes() {
+ try {
+ listUsers().forEach(user -> {
+ String zpath = ZKUserPath + "/" + user;
+ byte[] zkData = zooCache.get(zpath);
+ if (ZKSecurityTool.isOutdatedPass(zkData)) {
+ log.warn("Found user(s) with outdated password hash. These will be
re-hashed"
+ + " on successful authentication.");
+ return;
+ }
+ });
+ } catch (NullPointerException e) {
+ // initializeSecurity was not called yet, there could be no outdated
passwords stored
Review comment:
Could also avoid this by checking if the zk node exists first.
##########
File path:
server/base/src/main/java/org/apache/accumulo/server/security/handler/ZKAuthenticator.java
##########
@@ -52,6 +52,23 @@ public void initialize(ServerContext context) {
this.context = context;
zooCache = new ZooCache(context.getZooReaderWriter(), null);
ZKUserPath = Constants.ZROOT + "/" + context.getInstanceID() + "/users";
+ checkOutdatedHashes();
+ }
+
+ private void checkOutdatedHashes() {
+ try {
+ listUsers().forEach(user -> {
+ String zpath = ZKUserPath + "/" + user;
+ byte[] zkData = zooCache.get(zpath);
+ if (ZKSecurityTool.isOutdatedPass(zkData)) {
+ log.warn("Found user(s) with outdated password hash. These will be
re-hashed"
+ + " on successful authentication.");
Review comment:
One option is to provide the user name during these warnings. Another is
to provide single warning, rather than one per user, and then provide some
other mechanism to list outdated entries.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]