2013-12-17 51 views
1

我需要一個.p12文件才能使用Apple的通知服務器進行身份驗證,並且發現了一些問題。據我所知,我需要生成.csr和我的私鑰來識別我的機器。所以,我需要在我的本地機器來執行這樣的命令:嘗試初始化時出現異常ApnsServiceBuilder

*[email protected]:~/Escritorio/curro/certificados$ openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key 
Generating a 2048 bit RSA private key 

寫入新的私鑰「privateKey.key」現在

,我CSR.csr文件,我需要登錄到:

https://developer.apple.com/account/ios/certificate/certificateCreate.action?formID=62653259 

然後我提供之前生成的.csr文件文件和系統 給了我一個.CER文件(aps_development.cer)。現在,通過這個.cer文件,我必須生成.p12等效文件。爲了做到這一點,我需要從Apple生成的.cer生成的文件開始製作一個.pem文件。這是命令:

[email protected]:~/Escritorio/curro/certificados$ openssl pkcs12 -export -inkey privateKey.key -in developer_identity.pem -out iphone_dev.p12 
Enter Export Password: 
Verifying 
Enter Export Password: 

之後,我有一個.p12文件,我需要初始化ApnsService例如,

@Component 
public class NotificationServer implements Runnable, BeanFactoryAware { 

@Autowired 
// APNS channel 
private ApnsService serviceApns; 
private String apns_payload; 

@PostConstruct 
public void init() { 
// build apns service path_to_apns_certificate, absolute path .p12 file 
String path_to_apns_certificate = config.getProperty("kurento.apns.path"); 
//pass used to generate the .p12 file  
String password_apns_cert = config.getProperty("kurento.apns.path_password"); 
log.debug("path_to_apns_certificate: " + path_to_apns_certificate); 
//keep an eye with this!, this builder is non thread safe! 
ApnsServiceBuilder apnsbuilder = new ApnsServiceBuilder(); 

String sMaxConections = config.getProperty("kurento.apns.maxConections"); 
log.debug("sMaxConections: " + sMaxConections); 
int maxConections = Integer.parseInt(sMaxConections); 
apnsbuilder.asPool(maxConections); 
String connectWithAppleApns = config.getProperty("kurento.apns.production"); 
log.debug("connectWithAppleApns: " + connectWithAppleApns); 
apnsbuilder.withAppleDestination(new Boolean(connectWithAppleApns)); 
//here the exception is launched!  
apnsbuilder.withCert(path_to_apns_certificate, password_apns_cert); 
serviceApns =apnsbuilder.build();  
} 
} 

以下是錯誤消息:

Caused by: com.notnoop.exceptions.InvalidSSLConfig: java.io.IOException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded 
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:88) 
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:167) 
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:134) 
    at com.kurento.agenda.utils.NotificationServer.init(NotificationServer.java:122) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:346) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:299) 
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:132) 
    ... 164 more 
Caused by: java.io.IOException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded 
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1304) 
    at java.security.KeyStore.load(KeyStore.java:1214) 
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:85) 
    ... 174 more 
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded 
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811) 
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676) 
    at com.sun.crypto.provider.PKCS12PBECipherCore.implDoFinal(PKCS12PBECipherCore.java:355) 
    at com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_40.engineDoFinal(PKCS12PBECipherCore.java:462) 
    at javax.crypto.Cipher.doFinal(Cipher.java:2087) 
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1295) 
    ... 176 more 

任何人都可以給我任何觀點嗎?

+0

我回應我自己。該錯誤涉及通過或用戶的錯誤,在我的情況下,通過引號保存!幾天沒有看到那個錯誤。 – aironman

回答

0

我回應我自己。該錯誤涉及通過或用戶的錯誤,在我的情況下,通過引號保存!幾天沒有看到那個錯誤。