@ -5,9 +5,11 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.crypto.Pkcs12KeyStore
import dev.openrs2.crypto.Pkcs12KeyStore
import dev.openrs2.util.io.DeterministicJarOutputStream
import dev.openrs2.util.io.DeterministicJarOutputStream
import dev.openrs2.util.io.entries
import dev.openrs2.util.io.entries
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.io.OutputStream
import java.nio.file.Files
import java.nio.file.Files
import java.nio.file.Path
import java.util.jar.JarInputStream
import java.util.jar.JarInputStream
import java.util.jar.Manifest
import java.util.jar.Manifest
@ -22,24 +24,24 @@ class SignedJarLibraryWriter(
ManifestJarLibraryWriter ( manifest ) . write ( unsignedOutput , classPath , library )
ManifestJarLibraryWriter ( manifest ) . write ( unsignedOutput , classPath , library )
}
}
val signedJar = Files . createTempFile ( TEMP _PREFIX , JAR _SUFFIX )
ByteArrayOutputStream ( ) . use { signedOutput ->
try {
keyStore . signJar ( unsignedJar , signedOutput )
keyStore . signJar ( unsignedJar , signedJar )
repack ( signedJar , output )
return ByteArrayInputStream ( signedOutput . toByteArray ( ) ) . use { signedInput ->
} finally {
repack ( signedInput , output )
Files . deleteIfExists ( signedJar )
}
}
}
} finally {
} finally {
Files . deleteIfExists ( unsignedJar )
Files . deleteIfExists ( unsignedJar )
}
}
}
}
private fun repack ( signedJar : Path , output : OutputStream ) {
private fun repack ( input : InputStream , output : OutputStream ) {
JarInputStream ( F iles . newI nputStream ( signedJar ) ) . use { i nput ->
JarInputStream ( input ) . use { jarI nput ->
DeterministicJarOutputStream ( output , i nput. manifest ) . use { o utput ->
DeterministicJarOutputStream ( output , jarI nput. manifest ) . use { jarO utput ->
for ( entry in i nput. entries ) {
for ( entry in jarI nput. entries ) {
o utput. putNextEntry ( entry )
jarO utput. putNextEntry ( entry )
i nput. copyTo ( o utput)
jarI nput. copyTo ( jarO utput)
}
}
}
}
}
}