Merge staging/1.2.0 changes back to master.

This commit is contained in:
Virtually Nick
2020-06-13 21:49:06 -04:00
23 changed files with 780 additions and 539 deletions

View File

@@ -23,6 +23,7 @@ import com.google.inject.Inject;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.environment.Environment;
import org.apache.guacamole.properties.EnumGuacamoleProperty;
import org.apache.guacamole.properties.IntegerGuacamoleProperty;
import org.apache.guacamole.properties.StringGuacamoleProperty;
import org.apache.guacamole.totp.TOTPGenerator;
@@ -80,8 +81,8 @@ public class ConfigurationService {
* default, this will be "sha1". Legal values are "sha1", "sha256", and
* "sha512".
*/
private static final TOTPModeProperty TOTP_MODE =
new TOTPModeProperty() {
private static final EnumGuacamoleProperty<TOTPGenerator.Mode> TOTP_MODE =
new EnumGuacamoleProperty<TOTPGenerator.Mode>(TOTPGenerator.Mode.class) {
@Override
public String getName() { return "totp-mode"; }

View File

@@ -1,62 +0,0 @@
/*
* 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.guacamole.auth.totp.conf;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.GuacamoleServerException;
import org.apache.guacamole.properties.GuacamoleProperty;
import org.apache.guacamole.totp.TOTPGenerator;
/**
* A GuacamoleProperty whose value is a TOTP generation method. The string
* values "sha1", "sha256", and "sha512" are each parsed to their corresponding
* values within the TOTPGenerator.Mode enum. All other string values result in
* parse errors.
*/
public abstract class TOTPModeProperty
implements GuacamoleProperty<TOTPGenerator.Mode> {
@Override
public TOTPGenerator.Mode parseValue(String value)
throws GuacamoleException {
// If no value provided, return null.
if (value == null)
return null;
// SHA1
if (value.equals("sha1"))
return TOTPGenerator.Mode.SHA1;
// SHA256
if (value.equals("sha256"))
return TOTPGenerator.Mode.SHA256;
// SHA512
if (value.equals("sha512"))
return TOTPGenerator.Mode.SHA512;
// The provided value is not legal
throw new GuacamoleServerException("TOTP mode must be one of "
+ "\"sha1\", \"sha256\", or \"sha512\".");
}
}

View File

@@ -25,6 +25,7 @@ import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.guacamole.properties.EnumGuacamoleProperty.PropertyValue;
/*
* NOTE: This TOTP implementation is based on the TOTP reference implementation
@@ -124,18 +125,21 @@ public class TOTPGenerator {
* TOTP mode which generates hashes using SHA1. TOTP in SHA1 mode
* requires 160-bit keys.
*/
@PropertyValue("sha1")
SHA1("HmacSHA1", 20),
/**
* TOTP mode which generates hashes using SHA256. TOTP in SHA256 mode
* requires 256-bit keys.
*/
@PropertyValue("sha256")
SHA256("HmacSHA256", 32),
/**
* TOTP mode which generates hashes using SHA512. TOTP in SHA512 mode
* requires 512-bit keys.
*/
@PropertyValue("sha512")
SHA512("HmacSHA512", 64);
/**