/** * Specify the certificate used to connect to Apple APNS * servers. This relies on a keystore (*.p12) * containing the certificate, along with the given password. * * This library does not support password-less p12 certificates, due to a * Oracle Java library <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> * Bug 6415637</a>. There are three workarounds: use a password-protected * certificate, use a different boot Java SDK implementation, or constract * the `SSLContext` yourself! Needless to say, the password-protected * certificate is most recommended option. * * @param stream the keystore * @param password the password of the keystore * @return this * @throws InvalidSSLConfig if stream is invalid Keystore * or the password is invalid */ public ApnsServiceBuilder withCert(KeyStore keyStore, String password) throws InvalidSSLConfig { assertPasswordNotEmpty(password); return withSSLContext( newSSLContext(keyStore, password, KEY_ALGORITHM)); }
/** * Specify the certificate used to connect to Apple APNS * servers. This relies on the stream of keystore (*.p12) * containing the certificate, along with the given password. * * The keystore needs to be of PKCS12 and the keystore * needs to be encrypted using the SunX509 algorithm. Both * of these settings are the default. * * This library does not support password-less p12 certificates, due to a * Oracle Java library <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> * Bug 6415637</a>. There are three workarounds: use a password-protected * certificate, use a different boot Java SDK implementation, or constract * the `SSLContext` yourself! Needless to say, the password-protected * certificate is most recommended option. * * @param stream the keystore represented as input stream * @param password the password of the keystore * @return this * @throws InvalidSSLConfig if stream is invalid Keystore * or the password is invalid */ public ApnsServiceBuilder withCert(InputStream stream, String password) throws InvalidSSLConfig { assertPasswordNotEmpty(password); return withSSLContext( newSSLContext(stream, password, KEYSTORE_TYPE, KEY_ALGORITHM)); }
private void configureApnsCertificate(ApnsServiceBuilder builder) throws IOException, GeneralSecurityException { if (getSslContextParameters() != null) { builder.withSSLContext(getSslContextParameters().createSSLContext(getCamelContext())); return; } ObjectHelper.notNull(getCamelContext(), "camelContext"); StringHelper.notEmpty(getCertificatePath(), "certificatePath"); StringHelper.notEmpty(getCertificatePassword(), "certificatePassword"); InputStream certificateInputStream = null; try { certificateInputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, getCertificatePath()); builder.withCert(certificateInputStream, getCertificatePassword()); } finally { ResourceUtils.close(certificateInputStream); } }