Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit e312520

Browse files
committed
Updates
1 parent 82a2e20 commit e312520

File tree

6 files changed

+16
-24
lines changed

6 files changed

+16
-24
lines changed

src/main/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipher.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
2222
import java.util.regex.Matcher;
2323
import java.util.regex.Pattern;
2424

25-
import org.eclipse.sisu.Typed;
26-
2725
/**
2826
* Default implementation of {@link PlexusCipher}. This class is thread safe.
2927
*
3028
* @author Oleg Gusakov
3129
*/
3230
@Singleton
33-
@Named("default")
34-
@Typed(PlexusCipher.class)
31+
@Named
3532
public class DefaultPlexusCipher implements PlexusCipher {
3633
private static final Pattern ENCRYPTED_STRING_PATTERN = Pattern.compile(".*?[^\\\\]?\\{(.*?[^\\\\])\\}.*");
3734

@@ -45,7 +42,7 @@ public DefaultPlexusCipher() {
4542
// ---------------------------------------------------------------
4643
@Override
4744
public String encrypt(final String str, final String passPhrase) throws PlexusCipherException {
48-
if (str == null || str.length() < 1) {
45+
if (str == null || str.isEmpty()) {
4946
return str;
5047
}
5148

@@ -61,7 +58,7 @@ public String encryptAndDecorate(final String str, final String passPhrase) thro
6158
// ---------------------------------------------------------------
6259
@Override
6360
public String decrypt(final String str, final String passPhrase) throws PlexusCipherException {
64-
if (str == null || str.length() < 1) {
61+
if (str == null || str.isEmpty()) {
6562
return str;
6663
}
6764

@@ -71,7 +68,7 @@ public String decrypt(final String str, final String passPhrase) throws PlexusCi
7168
// ---------------------------------------------------------------
7269
@Override
7370
public String decryptDecorated(final String str, final String passPhrase) throws PlexusCipherException {
74-
if (str == null || str.length() < 1) {
71+
if (str == null || str.isEmpty()) {
7572
return str;
7673
}
7774

@@ -85,7 +82,7 @@ public String decryptDecorated(final String str, final String passPhrase) throws
8582
// ----------------------------------------------------------------------------
8683
@Override
8784
public boolean isEncryptedString(final String str) {
88-
if (str == null || str.length() < 1) {
85+
if (str == null || str.isEmpty()) {
8986
return false;
9087
}
9188

@@ -98,11 +95,10 @@ public boolean isEncryptedString(final String str) {
9895
@Override
9996
public String unDecorate(final String str) throws PlexusCipherException {
10097
Matcher matcher = ENCRYPTED_STRING_PATTERN.matcher(str);
101-
10298
if (matcher.matches() || matcher.find()) {
10399
return matcher.group(1);
104100
} else {
105-
throw new PlexusCipherException("default.plexus.cipher.badEncryptedPassword");
101+
throw new PlexusCipherException("Malformed decorated string");
106102
}
107103
}
108104

src/main/java/org/sonatype/plexus/components/cipher/PBECipher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public String encrypt64(final String clearText, final String password) throws Pl
9595

9696
return Base64.getEncoder().encodeToString(allEncryptedBytes);
9797
} catch (Exception e) {
98-
throw new PlexusCipherException(e);
98+
throw new PlexusCipherException(e.getMessage(), e);
9999
}
100100
}
101101

@@ -122,7 +122,7 @@ public String decrypt64(final String encryptedText, final String password) throw
122122

123123
return new String(clearBytes, STRING_ENCODING);
124124
} catch (Exception e) {
125-
throw new PlexusCipherException(e);
125+
throw new PlexusCipherException(e.getMessage(), e);
126126
}
127127
}
128128
// -------------------------------------------------------------------------------
@@ -131,7 +131,7 @@ private Cipher createCipher(final char[] pwd, byte[] salt, final int mode)
131131
InvalidAlgorithmParameterException, InvalidKeySpecException {
132132

133133
KeySpec spec = new PBEKeySpec(pwd, salt, PBE_ITERATIONS, SPICE_SIZE * 16);
134-
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
134+
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
135135
byte[] keyAndIv = factory.generateSecret(spec).getEncoded();
136136

137137
byte[] key = new byte[SPICE_SIZE];

src/main/java/org/sonatype/plexus/components/cipher/PlexusCipher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* @author Oleg Gusakov
1717
*/
1818
public interface PlexusCipher {
19-
char ENCRYPTED_STRING_DECORATION_START = '{';
19+
String ENCRYPTED_STRING_DECORATION_START = "{";
2020

21-
char ENCRYPTED_STRING_DECORATION_STOP = '}';
21+
String ENCRYPTED_STRING_DECORATION_STOP = "}";
2222

2323
/**
2424
* encrypt given string with the given passPhrase and encode it into base64

src/main/java/org/sonatype/plexus/components/cipher/PlexusCipherException.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212
*/
1313
package org.sonatype.plexus.components.cipher;
1414

15-
public class PlexusCipherException extends Exception {
16-
public PlexusCipherException() {}
17-
15+
public class PlexusCipherException extends RuntimeException {
1816
public PlexusCipherException(String message) {
1917
super(message);
2018
}
2119

22-
public PlexusCipherException(Throwable cause) {
23-
super(cause);
24-
}
25-
2620
public PlexusCipherException(String message, Throwable cause) {
2721
super(message, cause);
2822
}

src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.sonatype.plexus.components.cipher;
1414

1515
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Disabled;
1617
import org.junit.jupiter.api.Test;
1718

1819
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -31,7 +32,7 @@ class DefaultPlexusCipherTest {
3132

3233
final String str = "my testing phrase";
3334

34-
final String encStr = "cYrPoOelYU0HGlsn3nERAIyiLVVgnsn/KC5ZqeAPG0beOZCYrFwWwBTp3uyxt/yx";
35+
final String encStr = "t4RzIMd8AT0H3xnTd5IBX9zKE94G+D29fGBuhAJ4RblNC5zJLqYOIkVaSXJQFT7t";
3536
PlexusCipher pc;
3637

3738
@BeforeEach
@@ -88,6 +89,7 @@ void testDefaultAlgorithmExists() throws Exception {
8889

8990
// -------------------------------------------------------------
9091

92+
@Disabled("This test is not really a test")
9193
@Test
9294
void stestFindDefaultAlgorithm() {
9395
String[] res = DefaultPlexusCipher.getServiceTypes();

src/test/java/org/sonatype/plexus/components/cipher/PBECipherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PBECipherTest {
3434

3535
final String clearText = "veryOpenText";
3636

37-
final String encryptedText = "F7eMV2QRQF4H0ODCA1nrTGUWacCXVvPemSjaQjGbO6U=";
37+
final String encryptedText = "0bzCbTRh5YQHZ2p7hkr6OZYrfhRqwc9ImgtYweX752k=";
3838

3939
final String password = "testtest";
4040

0 commit comments

Comments
 (0)