2014-12-18 23 views
15

Sto usando Spring Boot con bootRepackle gradle per creare il file jar di rilascio. Il mio progetto necessita di codice offuscatore prima di consegnarlo al cliente. Ho provato proguard e qualche altro strumento ma si sono verificati molti problemi. Posso avere consigli su come configurare questi strumenti per l'avvio a molla.Spring Boot offfuscator

ho cercato ProGuard con questi config

-injars ./build/libs/webservice-1.0.jar 
-outjars ./build/libs/webservice-obs-1.0.jar 
-libraryjars <java.home>/lib/rt.jar 
-keep class !myapplicationpackage.** { *; } 
-keep class myapplicationpackage.Application { *; } 

-ignorewarnings 
-keepdirectories ** 
-dontshrink 
-keepattributes *Annotation* 

-keepclassmembers class com.yumyumlabs.** { java.lang.Long id; } 
-keepnames class com.yumyumlabs.** implements java.io.Serializable 

-keepclassmembers class * implements java.io.Serializable { 
    static final long serialVersionUID; 
    private static final java.io.ObjectStreamField[] serialPersistentFields; 
    !static !transient <fields>; 
    private void writeObject(java.io.ObjectOutputStream); 
    private void readObject(java.io.ObjectInputStream); 
    java.lang.Object writeReplace(); 
    java.lang.Object readResolve(); 
} 


-keepclassmembers class * { 
    @org.springframework.beans.factory.annotation.Autowired *; 
    @org.springframework.beans.factory.annotation.Qualifier *; 
    @org.springframework.beans.factory.annotation.Value *; 
    @org.springframework.beans.factory.annotation.Required *; 
    @org.springframework.context.annotation.Bean *; 
    @javax.annotation.PostConstruct *; 
    @javax.annotation.PreDestroy *; 
    @org.aspectj.lang.annotation.AfterReturning *; 
    @org.aspectj.lang.annotation.Pointcut *; 
    @org.aspectj.lang.annotation.AfterThrowing *; 
    @org.aspectj.lang.annotation.Around *; 
} 
-keep @org.springframework.stereotype.Service class * 
-keep @org.springframework.stereotype.Controller class * 
-keep @org.springframework.stereotype.Component class * 
-keep @org.springframework.stereotype.Repository class * 
-keep @org.springframework.cache.annotation.EnableCaching class * 
-keep @org.springframework.context.annotation.Configuration class * 
-keepattributes Signature 

-dontwarn com.yumyumlabs.web.controllers.auth.AuthController 



-dontwarn com.google.apphosting.api.ReflectionUtils 
-dontwarn sun.misc.Unsafe 




-dontwarn org.tartarus.snowball.** 
-dontnote 

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault 

Ma il vaso generato non posso correre

java.lang.IllegalStateException: Unable to open nested entry 'lib/spring-boot-starter-web-1.2.0.RELEASE.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file 
at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(Unknown Source) 
at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(Unknown Source) 
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(Unknown Source) 
at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(Unknown Source) 
at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(Unknown Source) 
at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(Unknown Source) 
at org.springframework.boot.loader.Launcher.launch(Unknown Source) 
at org.springframework.boot.loader.JarLauncher.main(Unknown Source) 
+2

Per favore spiegate più in dettaglio cosa avete provato e quali problemi avete avuto, in modo che possiamo aiutarvi a risolvere questi problemi. – Jesper

+0

Il problema è molto semplice se si dispone di un jar con dipendenze nidificate e si tenta di offuscare con proguard che comprime i jar annidati e il caricatore di avvio spring non è in grado di caricare quei jar. – telebog

+0

Sei riuscito a offuscare la tua applicazione Spring-Boot? – Modi

risposta

1

E si sta dicendo il problema. Sta comprimendo i file JAR incorporati che non sono consentiti. È necessario ottenerlo per saltare la compressione degli elementi figlio. Probabilmente è meglio saltare la compressione del tutto.

In realtà si potrebbe saltare tutto ciò in quanto ciò rende un po 'più difficile il reverse engineering, ma non lo ferma. Se si ha realmente bisogno di tenerlo segreto che male allora la vostra unica vera scelta è quella di vendere la vostra applicazione come servizio piuttosto che fornire un JAR, WAR, EAR, ecc

IllegalStateException: impossibile aprire nidificato entry 'lib/primavera -boot-starter-web-1.2.0.RELEASE.jar'. È stato compresso e i file jar nidificati devono essere memorizzati senza compressione. Controllare il meccanismo utilizzato per creare il file jar eseguibile

1

Questo può essere fatto reimballando la libreria non compressa. Questo può essere fatto usando lo strumento jar con il seguente script bash. Lo script deve essere semplicemente eseguito nella directory principale dei progetti.

# some constant settings we use 
work_dir=work 
uncompress_dir=uncompress 
library_dir=lib 

# parameters for input and output files 
# the name of the library that should be uncompressed 
library_name="spring-boot-starter-web-1.2.0.RELEASE.jar" 
# the obfuscated artifact 
original_jar='webservice-obs-1.0.jar' 
# the new obfuscated artifact (can be the same) 
repacked_jar='webservice-obs-repack-1.0.jar' 

# build the obfuscated library 
mvn clean package -Dobfuscation 

# create working directory and copy obfuscated artifact 
mkdir target/$work_dir 
cp target/$original_jar target/$work_dir 
cd target/$work_dir 

# extract contents of obfuscated artifact 
jar xvf $original_jar 
rm $original_jar 

# uncompress the target library and jar again without compression (c0) 
mkdir $uncompress_dir 
mv $library_dir/$library_name $uncompress_dir 
cd $uncompress_dir 
jar xvf $library_name 
rm $library_name 
jar c0mf ./META-INF/MANIFEST.MF $library_name * 
mv $library_name ../$library_dir 
cd .. 
rm -r $uncompress_dir 

# jar the complete obfuscated artifact again 
# it is important here to copy the manifest as otherwise the library would not be executeable any more by spring-boot 
jar c0mf ./META-INF/MANIFEST.MF ../$repacked_jar * 

# cleanup work dir 
cd .. 
rm -r $work_dir 

Probabilmente è necessario ripetere l'operazione se altri file richiedono questa gestione speciale. Una delle librerie che fanno questo è ad esempio il quarzo.