From d34894de794ef23bc47801197f40bd84ec3532c7 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Wed, 16 Oct 2019 21:06:08 +0200 Subject: [PATCH] Replacing UUID code and removing plexus dependency --- redback-keys/redback-keys-api/pom.xml | 10 ---- .../redback/keys/AbstractKeyManager.java | 51 ++----------------- .../redback/keys/KeyNotFoundException.java | 2 - 3 files changed, 4 insertions(+), 59 deletions(-) diff --git a/redback-keys/redback-keys-api/pom.xml b/redback-keys/redback-keys-api/pom.xml index 728a84e1..2ffda534 100644 --- a/redback-keys/redback-keys-api/pom.xml +++ b/redback-keys/redback-keys-api/pom.xml @@ -34,16 +34,6 @@ Redback :: Key Management API - - org.codehaus.plexus - plexus-digest - - - org.codehaus.plexus - plexus-component-api - - - org.slf4j slf4j-api diff --git a/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/AbstractKeyManager.java b/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/AbstractKeyManager.java index b7fa2435..74bf8d53 100644 --- a/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/AbstractKeyManager.java +++ b/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/AbstractKeyManager.java @@ -16,17 +16,12 @@ package org.apache.archiva.redback.keys; * limitations under the License. */ -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.Calendar; -import java.util.List; -import java.util.Random; -import java.util.TimeZone; - -import org.codehaus.plexus.digest.Hex; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.security.SecureRandom; +import java.util.*; + /** * AbstractKeyManager * @@ -58,45 +53,7 @@ public abstract class AbstractKeyManager protected String generateUUID() throws KeyManagerException { - byte vfour[] = new byte[KEY_LENGTH]; - - if ( isRandomMode() == SECURE ) - { - if ( secureRandom == null ) - { - try - { - secureRandom = SecureRandom.getInstance( "SHA1PRNG" ); - } - catch ( NoSuchAlgorithmException e ) - { - setRandomMode( !SECURE ); - log.warn( "Unable to use SecureRandom", e ); - } - } - - if ( isRandomMode() == SECURE ) - { - secureRandom.nextBytes( vfour ); - } - } - - if ( isRandomMode() != SECURE ) - { - if ( random == null ) - { - random = new Random(); - } - - random.nextBytes( vfour ); - } - - vfour[6] &= 0x0F; - vfour[6] |= ( 4 << 4 ); - vfour[8] &= 0x3F; - vfour[8] |= 0x80; - - return Hex.encode( vfour ); + return UUID.randomUUID().toString(); } /** diff --git a/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/KeyNotFoundException.java b/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/KeyNotFoundException.java index 8294c10d..4bb0300b 100644 --- a/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/KeyNotFoundException.java +++ b/redback-keys/redback-keys-api/src/main/java/org/apache/archiva/redback/keys/KeyNotFoundException.java @@ -16,8 +16,6 @@ package org.apache.archiva.redback.keys; * limitations under the License. */ -import org.apache.archiva.redback.keys.KeyManagerException; - /** * KeyNotFoundException *