wso2 / product-iots

Welcome to the WSO2 IoT Server source code! For info on working with the WSO2 IoT Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
184 stars 181 forks source link

Exception occurs when enrolling an iOS device #1796

Open madawas opened 6 years ago

madawas commented 6 years ago

Description: Following exception occurs when enrolling an iOS device to the system. The reason for the exception is when a device is enrolled, the server tries to push initial operations to the device. But in the case of iOS in order to send a push notification, DEVICE_TOKEN and MAGIC_TOKEN should be available in the system which will be available only after the profile is installed in the device successfully.

TID: [-1234] [] [2018-03-19 10:09:10,757] ERROR {org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl} -  Error occurred while sending push notifications to ios device carrying id 'deviceId {id='90b7ac2c11a0e59b2a4217b6625762b829ef0212', type='ios'}' {org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl}
org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException: Error occurred while sending the APNS message
    at org.wso2.carbon.device.mgt.mobile.impl.ios.apns.APNSPushNotificationStrategy.execute(APNSPushNotificationStrategy.java:49)
    at org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl.addOperation(OperationManagerImpl.java:239)
    at org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl.addOperation(DeviceManagementProviderServiceImpl.java:1420)
    at org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl.addInitialOperations(DeviceManagementProviderServiceImpl.java:2313)
    at org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl.enrollDevice(DeviceManagementProviderServiceImpl.java:298)
    at org.wso2.carbon.device.mgt.ios.core.publisher.TokenPersistence.saveDeviceTokens(TokenPersistence.java:86)
    at org.wso2.carbon.device.mgt.ios.core.impl.RequestHandler.signPKCSWithTokenPublish(RequestHandler.java:235)
    at org.wso2.carbon.device.mgt.ios.core.impl.RequestHandler.handleProfileRequest(RequestHandler.java:128)
    at org.wso2.carbon.device.mgt.ios.core.service.IOSEnrollmentService.handleProfileRequest(IOSEnrollmentService.java:55)
    at org.wso2.carbon.device.mgt.ios.services.impl.EnrollmentServiceImpl.getProfileRequest(EnrollmentServiceImpl.java:462)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104)
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204)
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:249)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:289)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.continueInvocation(CompositeValve.java:99)
    at org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve$1.invoke(CarbonTomcatValve.java:47)
    at org.wso2.carbon.webapp.mgt.TenantLazyLoaderValve.invoke(TenantLazyLoaderValve.java:57)
    at org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticationValve.invoke(WebappAuthenticationValve.java:46)
    at org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer.invokeValves(TomcatValveContainer.java:47)
    at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:62)
    at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:159)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
    at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:57)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1770)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1729)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.wso2.carbon.device.mgt.ios.apns.exception.APNSException: Device token and magic token cannot be null
    at org.wso2.carbon.device.mgt.ios.apns.service.impl.MDMPushNotificationSenderService.sendNotification(MDMPushNotificationSenderService.java:24)
    at org.wso2.carbon.device.mgt.ios.apns.service.impl.PushNotificationServiceImpl.sendMDMNotification(PushNotificationServiceImpl.java:33)
    at org.wso2.carbon.device.mgt.mobile.impl.ios.apns.APNSPushNotificationStrategy.execute(APNSPushNotificationStrategy.java:41)
    ... 59 more

Affected Product Version: wso2iot-3.2.0, ios-3.2.2

OS, DB, other environment details and versions:
Ubuntu 14.04, MySQL 5.6, JDK 1.8.0_144

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity.

scmfz commented 6 years ago

We're facing the same issue - do we have a resolution for this? on IoT 3.3.0

scmfz commented 6 years ago

Is there an update on this? This is a major blocker; IoT 3.3.0 wont work for iOS unless this issue is resolved.

madawas commented 6 years ago

@scmfz even though this exception is thrown, the iOS enrollment should work properly. This issue comes only when the server tries to push initial operations before the device enrollment is finished. If a device gets enrolled successfully the operations should work without an issue.

scmfz commented 6 years ago

@madawas For us the profile installation fails - however the device does show up in the wso2 device management section - but the profile installer fails.

scmfz commented 6 years ago

It passes enrolling certificate, then the status switches to installing profile and it then gives us an error Profile failed to install - and at the same time the exception shows up.

madawas commented 6 years ago

@scmfz That could be related to a different issue. Please open a new issue and mention the following information if possible.

  1. What kind of a deployment are you having? A single node server or a distributed setup.
  2. Are you deploying the IOT server on a remote server?
  3. What does it say in the device log? Please inspect the device log and see if there is a log related to the issue you are facing.
scmfz commented 6 years ago

@madawas The exception is identical to this - but if you feel it should be a separate issue, I'll open a different one.

  1. Its a single node server.
  2. Yes we are hosting it on a remote server, that has a valid SSL certificate installed - and we've got all MDM certificate from Apple configured.
  3. By the device log, do you mean the log on WSO2 or the iOS device's own log?
madawas commented 6 years ago

@scmfz This exception throws because the server cannot push the operations to the device as the device is not properly installed. So my guess is this exception is not related to the issue you are facing. Also, we have seen that this exception throws even when the enrollment is successful.

By the device log, do you mean the log on WSO2 or the iOS device's own log?

I mean the iOS device's own log. We might be able to get the correct reason for the "Profile Installation Failed" message from there.

Also please revisit all the iOS related configurations and double check if they are correct. Since there are tricky configuration parts there is a higher possibility of misconfigurations.

scmfz commented 6 years ago

@madawas Thank you for the information - we're going to do some debugging to find out what the cause is, if we dont find any issue on our end, I'll create a new issue.

madawas commented 6 years ago

@scmfz it is the expected behaviour. The device will be added to the database once the correct login details are provided. Then the server provides the profile to the device. For some reason, the profile installation has been failed on your device. IMO the easiest way to identify the reason is inspecting the device logs. Please provide us if you can find any input from the device logs.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity.