Generated certificate stops working when moving to resource folder

I'm having problems with the generated certificate, which I use to connect to apple push services. Everything works fine when the generated p12 file was in my src / main / java folder, but I moved it to src / main / resources and decided to stop working with the following error:

DerInputStream.getLength(): lengthTag=111, too big. 

For more information: I use the notnoop push notifications library and follow the Ray Wenderlich manual to create certificates. after that I used the following commands to create a p12 file for use in java:

 openssl x509 -in aps_development.cer -inform DER -out aps_development.pem -outform PEM openssl pkcs12 -nocerts -in single.p12 -out single.pem openssl pkcs12 -export -inkey single.pem -in aps_development.pem -out dual.p12 

after that I moved double.p12 to my java project. First, the file was in the / src / main / java folder, say, in com.company.push.certificates (while the code requesting the file is in com.company.push ). I am requesting input using

 InputStream stream = this.getClass().getResourceAsStream("certificates/dual.p12"); 

This works great in development, but not when creating a project (using maven), so I moved the resource to the resource folder using the same package. The resource is still found, but now I get the above java.io.IOException

Does anyone know what could be causing this?

Ps: when I move the file back to the package in src / main / java everything works fine, so the certificate seems to be valid.

+7
source share
3 answers

Check the contents of the certificate file AFTER the assembly, when maven copied it for purposes / classes / ... Probably filtering maven resources or something else in your assembly modifies the file. Check what is in the classes folder, EXACTLY the same as in the resources folder.

http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

+18
source

This is because maven resource filtering distorts your p12 file.

We solved this by excluding p12 files from maven resource filtering using this parameter in pom.xml :

 <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>**/*.p12</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.p12</include> </includes> </resource> </resources> 
+11
source

Personally, I don't like duplicating the exceptions / inclusions section in the maven assembly and having two resource sections that need to be synchronized, so I prefer to use the maven resource plugin to configure instead of nonFilteredFileExtensions.

The resource section in the build section is then simple (plus any specific ones you might need):

 <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> 

Tell maven-resources-plugin whose files are NOT filtered when it is turned on:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <configuration> <delimiters> <delimiter>@</delimiter> </delimiters> <nonFilteredFileExtensions> <nonFilteredFileExtension>p12</nonFilteredFileExtension> <nonFilteredFileExtension>pfx</nonFilteredFileExtension> <nonFilteredFileExtension>pem</nonFilteredFileExtension> </nonFilteredFileExtensions> </configuration> </plugin> 

See: http://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html

+8
source

All Articles