Skip to content

Commit

Permalink
Base64 cannot be decoded to KeyStore with Java client (#1296)
Browse files Browse the repository at this point in the history
- Fixes encoder to generate same format as before
- Changes end-to-end tests to only accept the right format (and no longer accept Base64Mime)

Resolves #1295
{patch}

Signed-off-by: Esta Nagy <[email protected]>
  • Loading branch information
nagyesta authored Dec 29, 2024
1 parent e15a9fb commit a8f09ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ static byte[] decodeBase64String(final String certificateContent) {
}

static String encodeAsBase64String(final byte[] bytes) {
return Base64.getMimeEncoder().encodeToString(bytes);
return Base64.getEncoder().encodeToString(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.security.cert.CertificateEncodingException;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static com.github.nagyesta.lowkeyvault.service.certificate.impl.CertContentType.PEM;
Expand Down Expand Up @@ -468,7 +469,8 @@ void testEncodeAsBase64StringShouldProduceTheExpectedBase64String(final byte[] i
final String actual = CertContentType.encodeAsBase64String(input);

//then
Assertions.assertEquals(expected, actual);
final String expectedWithoutLineBreaks = expected.replaceAll(Pattern.quote("\r\n"), "");
Assertions.assertEquals(expectedWithoutLineBreaks, actual);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Objects;

import static java.util.Base64.getDecoder;
import static java.util.Base64.getMimeDecoder;

public class CertificateStepDefAssertion extends CommonAssertions {
Expand Down Expand Up @@ -305,7 +306,7 @@ private X509Certificate getX509Certificate(final CertificateContentType contentT
final CertificateFactory fact = CertificateFactory.getInstance("X.509");
certificate = (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(encodedCertificate));
} else {
final byte[] bytes = getMimeDecoder().decode(value);
final byte[] bytes = getDecoder().decode(value);
final KeyStore keyStore = getKeyStore(bytes, DEFAULT_PASSWORD);
final String alias = findAlias(keyStore);
certificate = (X509Certificate) keyStore.getCertificate(alias);
Expand Down

0 comments on commit a8f09ca

Please sign in to comment.