Skip to content

Commit

Permalink
Add resource method to list code signers
Browse files Browse the repository at this point in the history
This allows for secure (spec-compliant) class loader implementation by allowing correct protection domains to be defined.
  • Loading branch information
dmlloyd committed Oct 21, 2024
1 parent 7785002 commit f821243
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.attribute.FileTime;
import java.security.CodeSigner;
import java.time.Instant;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -116,6 +118,11 @@ public Instant modifiedTime() {
return fileTime == null ? null : fileTime.toInstant();
}

public List<CodeSigner> codeSigners() {
CodeSigner[] array = jarEntry.getCodeSigners();
return array == null ? List.of() : List.of(array);
}

public InputStream openStream() throws IOException {
return jarFile.getInputStream(jarEntry);
}
Expand Down
11 changes: 11 additions & 0 deletions resource/src/main/java/io/smallrye/common/resource/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.security.CodeSigner;
import java.security.ProtectionDomain;
import java.time.Instant;
import java.util.List;
import java.util.function.Function;

import io.smallrye.common.constraint.Assert;
Expand Down Expand Up @@ -193,6 +195,15 @@ public Instant modifiedTime() {
return null;
}

/**
* {@return the list of code signers for this resource}
* The resource must have been fully read, or else consumed {@linkplain #asBuffer() as a buffer}.
* By default, the base implementation returns an empty list.
*/
public List<CodeSigner> codeSigners() {
return List.of();
}

/**
* {@return the size of the resource, or <code>-1</code> if the size is not known}
*/
Expand Down

0 comments on commit f821243

Please sign in to comment.