Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<!-- Plugin version -->
<build.helper-maven-plugin.version>3.6.1</build.helper-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.15</jacoco-maven-plugin.version>
<spotless-maven-plugin.version>3.10.1</spotless-maven-plugin.version>
<spotless-maven-plugin.version>3.10.2</spotless-maven-plugin.version>
<maven-compiler-plugin.version>3.16.0</maven-compiler-plugin.version>
<maven-clean-plugin.version>3.5.0</maven-clean-plugin.version>
<maven-install-plugin.version>3.1.4</maven-install-plugin.version>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/land/oras/OCILayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void pullArtifact(LayoutRef ref, Path path, PullOptions options) {
.formatted(layer.getAnnotations().get(Const.ANNOTATION_TITLE)));
}
if (options.isOverwrite()) {
Files.copy(blobPath, targetPath, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
Files.copy(blobPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
} else {
Files.copy(blobPath, targetPath);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/land/oras/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HexFormat;
import java.util.List;
Expand Down Expand Up @@ -1167,7 +1168,7 @@ private String uploadChunks(ContainerRef ref, InputStream stream, long totalSize
}
long rangeEnd = offset + read - 1;
String contentRange = "%d-%d".formatted(offset, rangeEnd);
final byte[] chunk = java.util.Arrays.copyOf(buffer, read);
final byte[] chunk = Arrays.copyOf(buffer, read);
URI patchUri = URI.create(location);
HttpClient.ResponseWrapper<String> patchResponse = client.patch(
patchUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package land.oras.auth;

import java.util.Base64;
import land.oras.ContainerRef;
import org.jspecify.annotations.NonNull;

Expand Down Expand Up @@ -67,7 +68,7 @@ public String getPassword() {
@Override
@NonNull
public String getAuthHeader(ContainerRef registry) {
return "Basic " + java.util.Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
return "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/land/oras/auth/AuthStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -183,7 +184,7 @@ static ConfigFile fromCredential(Credential credential) {
"auths",
Map.of(
"auth",
java.util.Base64.getEncoder()
Base64.getEncoder()
.encodeToString(
(credential.username + ":" + credential.password).getBytes()))),
Map.of(),
Expand Down Expand Up @@ -229,8 +230,7 @@ public static Config load(List<ConfigFile> configFiles) throws OrasException {
configFile.auths.forEach((host, value) -> {
String auth = value.get("auth");
if (auth != null) {
String base64Decoded =
new String(java.util.Base64.getDecoder().decode(auth), StandardCharsets.UTF_8);
String base64Decoded = new String(Base64.getDecoder().decode(auth), StandardCharsets.UTF_8);
String[] parts = base64Decoded.split(":", 2);
if (parts.length != 2) {
LOG.warn(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/land/oras/utils/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import org.jspecify.annotations.NullMarked;

/**
Expand Down Expand Up @@ -376,7 +377,7 @@ private Const() {
*/
public static String currentTimestamp() {
return Instant.now()
.truncatedTo(java.time.temporal.ChronoUnit.SECONDS)
.truncatedTo(ChronoUnit.SECONDS)
.atOffset(ZoneOffset.UTC)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/land/oras/RegistryWireMockTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.http.Fault;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import com.github.tomakehurst.wiremock.stubbing.Scenario;
Expand Down Expand Up @@ -1226,16 +1227,15 @@ void pullArtifactShouldRejectInvalidTitleAnnotation(WireMockRuntimeInfo wmRuntim
String registryUrl = wmRuntimeInfo.getHttpBaseUrl().replace("http://", "");

// Craft a blob and build a manifest whose layer title contains a invalid sequence
byte[] blobContent = "malicious content".getBytes(java.nio.charset.StandardCharsets.UTF_8);
byte[] blobContent = "malicious content".getBytes(StandardCharsets.UTF_8);
String blobDigest = SupportedAlgorithm.SHA256.digest(blobContent);

Layer maliciousLayer = Layer.fromDigest(blobDigest, blobContent.length)
.withAnnotations(Map.of(Const.ANNOTATION_TITLE, "../traversed-file.txt"));

Manifest manifest = Manifest.empty().withLayers(List.of(maliciousLayer));
String manifestJson = JsonUtils.toJson(manifest);
String manifestDigest =
SupportedAlgorithm.SHA256.digest(manifestJson.getBytes(java.nio.charset.StandardCharsets.UTF_8));
String manifestDigest = SupportedAlgorithm.SHA256.digest(manifestJson.getBytes(StandardCharsets.UTF_8));

// Stub HEAD manifest
wireMock.register(head(urlEqualTo("/v2/library/malicious-artifact/manifests/latest"))
Expand Down Expand Up @@ -1372,7 +1372,7 @@ void shouldRetryOnNetworkError(WireMockRuntimeInfo wmRuntimeInfo) {
wireMock.register(get(urlEqualTo("/v2/library/network-error-retry/tags/list"))
.inScenario("network-error-retry")
.whenScenarioStateIs(Scenario.STARTED)
.willReturn(aResponse().withFault(com.github.tomakehurst.wiremock.http.Fault.CONNECTION_RESET_BY_PEER))
.willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER))
.willSetStateTo("retry"));

wireMock.register(get(urlEqualTo("/v2/library/network-error-retry/tags/list"))
Expand Down
17 changes: 7 additions & 10 deletions src/test/java/land/oras/auth/AuthStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import java.util.List;
import land.oras.ContainerRef;
import land.oras.exception.OrasException;
Expand Down Expand Up @@ -482,8 +484,7 @@ void testConfigLoad_success() throws Exception {
void testPasswordContainingColonIsPreserved() throws Exception {
String user = "user";
String password = "p@ss:with:colons";
String auth = java.util.Base64.getEncoder()
.encodeToString((user + ":" + password).getBytes(java.nio.charset.StandardCharsets.UTF_8));
String auth = Base64.getEncoder().encodeToString((user + ":" + password).getBytes(StandardCharsets.UTF_8));
// language=json
String config = """
{
Expand All @@ -505,10 +506,8 @@ void testPasswordContainingColonIsPreserved() throws Exception {

@Test
void testMalformedEntryIsSkippedWithoutDroppingOtherCredentials() throws Exception {
String malformed = java.util.Base64.getEncoder()
.encodeToString("no-colon-here".getBytes(java.nio.charset.StandardCharsets.UTF_8));
String valid = java.util.Base64.getEncoder()
.encodeToString("user:password".getBytes(java.nio.charset.StandardCharsets.UTF_8));
String malformed = Base64.getEncoder().encodeToString("no-colon-here".getBytes(StandardCharsets.UTF_8));
String valid = Base64.getEncoder().encodeToString("user:password".getBytes(StandardCharsets.UTF_8));
// language=json
String config = """
{
Expand All @@ -531,8 +530,7 @@ void testMalformedEntryIsSkippedWithoutDroppingOtherCredentials() throws Excepti

@Test
void testEmptyPasswordIsPreserved() throws Exception {
String auth =
java.util.Base64.getEncoder().encodeToString("user:".getBytes(java.nio.charset.StandardCharsets.UTF_8));
String auth = Base64.getEncoder().encodeToString("user:".getBytes(StandardCharsets.UTF_8));
// language=json
String config = """
{
Expand All @@ -556,8 +554,7 @@ void testEmptyPasswordIsPreserved() throws Exception {
void testPasswordWithArbitraryCharactersIsPreserved() throws Exception {
String user = "user";
String password = "p:ä ss\"w0rd\\:with=🔒:tail";
String auth = java.util.Base64.getEncoder()
.encodeToString((user + ":" + password).getBytes(java.nio.charset.StandardCharsets.UTF_8));
String auth = Base64.getEncoder().encodeToString((user + ":" + password).getBytes(StandardCharsets.UTF_8));
// language=json
String config = """
{
Expand Down
Loading