{"action":"created","issue":{"url":"https://api.github.com/repos/TheHive-Project/Synapse/issues/1","repository_url":"https://api.github.com/repos/TheHive-Project/Synapse","labels_url":"https://api.github.com/repos/TheHive-Project/Synapse/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/TheHive-Project/Synapse/issues/1/comments","events_url":"https://api.github.com/repos/TheHive-Project/Synapse/issues/1/events","html_url":"https://github.com/TheHive-Project/Synapse/issues/1","id":350797840,"node_id":"MDU6SXNzdWUzNTA3OTc4NDA=","number":1,"title":"Synapse to O365 cloud connection error","user":{"login":"cameronkinsel","id":42279251,"node_id":"MDQ6VXNlcjQyMjc5MjUx","avatar_url":"https://avatars3.githubusercontent.com/u/42279251?v=4","gravatar_id":"","url":"https://api.github.com/users/cameronkinsel","html_url":"https://github.com/cameronkinsel","followers_url":"https://api.github.com/users/cameronkinsel/followers","following_url":"https://api.github.com/users/cameronkinsel/following{/other_user}","gists_url":"https://api.github.com/users/cameronkinsel/gists{/gist_id}","starred_url":"https://api.github.com/users/cameronkinsel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cameronkinsel/subscriptions","organizations_url":"https://api.github.com/users/cameronkinsel/orgs","repos_url":"https://api.github.com/users/cameronkinsel/repos","events_url":"https://api.github.com/users/cameronkinsel/events{/privacy}","received_events_url":"https://api.github.com/users/cameronkinsel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-08-15T12:51:30Z","updated_at":"2018-08-28T18:57:32Z","closed_at":null,"author_association":"NONE","body":"Hello, opening this issue as per request from Danni.\r\nThis is a combination of efforts between [TheHive's community page](https://groups.google.com/a/thehive-project.org/forum/#!topic/users/rvQ2k4HY9uI), [and an issue opened with exchangelib](https://github.com/ecederstrand/exchangelib/issues/456).\r\n\r\n**Problem:**\r\nUnable to configure Synapse in a way that successfully connects to cloud O365 mailboxes. Consistently getting the following output: (included below to seed google searches)\r\n\r\n> 2018-08-03 12:03:35,788 :: INFO :: workflows.common.common.getConf starts\r\n> 2018-08-03 12:03:38,234 :: INFO :: workflows.Ews2Case.connectEws starts\r\n> 2018-08-03 12:03:38,234 :: INFO :: common.common.getConf starts\r\n> 2018-08-03 12:03:38,234 :: INFO :: objects.EwsConnector. getAccount starts\r\n> 2018-08-03 12:03:38,969 :: ERROR :: Failed to get account\r\n> Traceback (most recent call last):\r\n>   File \"/home/flast/Synapse/workflows/objects/EwsConnector.py\", line 28, in getAccount\r\n> \tauth_type=NTLM)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/configuration.py\", line 46, in __init__\r\n> \tversion=version\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/protocol.py\", line 176, in __call__\r\n> \tprotocol = super(CachingProtocol, cls).__call__(*args, **kwargs)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/protocol.py\", line 230, in __init__\r\n> \tself.version = Version.guess(self)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/version.py\", line 206, in guess\r\n> \treturn cls._guess_version_from_service(protocol=protocol, hint=api_version)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/version.py\", line 239, in _guess_version_from_service\r\n> \tlist(ResolveNames(protocol=protocol).call(unresolved_entries=[protocol.credentials.username]))\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/services.py\", line 1557, in call\r\n> \tcontact_data_shape=contact_data_shape,\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/services.py\", line 88, in _get_elements\r\n> \tresponse = self._get_response_xml(payload=payload)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/services.py\", line 164, in _get_response_xml\r\n> \tallow_redirects=False)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/util.py\", line 547, in post_ratelimited\r\n> \t_raise_response_errors(r, protocol, log_msg, log_vals)  # Always raises an exception\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/util.py\", line 601, in _raise_response_errors\r\n> \traise UnauthorizedError('Wrong username or password for %s' % r.url)\r\n> exchangelib.errors.UnauthorizedError: Wrong username or password for https://outlook.office365.com/EWS/Exchange.asmx\r\n> 2018-08-03 12:03:38,971 :: ERROR :: Failed to create case from email\r\n> Traceback (most recent call last):\r\n>   File \"/home/flast/Synapse/workflows/Ews2Case.py\", line 25, in connectEws\r\n> \tewsConnector = EwsConnector(cfg)\r\n>   File \"/home/flast/Synapse/workflows/objects/EwsConnector.py\", line 13, in __init__\r\n> \tself.account = self.getAccount()\r\n>   File \"/home/flast/Synapse/workflows/objects/EwsConnector.py\", line 28, in getAccount\r\n> \tauth_type=NTLM)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/configuration.py\", line 46, in __init__\r\n> \tversion=version\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/protocol.py\", line 176, in __call__\r\n> \tprotocol = super(CachingProtocol, cls).__call__(*args, **kwargs)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/protocol.py\", line 230, in __init__\r\n> \tself.version = Version.guess(self)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/version.py\", line 206, in guess\r\n> \treturn cls._guess_version_from_service(protocol=protocol, hint=api_version)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/version.py\", line 239, in _guess_version_from_service\r\n> \tlist(ResolveNames(protocol=protocol).call(unresolved_entries=[protocol.credentials.username]))\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/services.py\", line 1557, in call\r\n> \tcontact_data_shape=contact_data_shape,\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/services.py\", line 88, in _get_elements\r\n> \tresponse = self._get_response_xml(payload=payload)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/services.py\", line 164, in _get_response_xml\r\n> \tallow_redirects=False)\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/util.py\", line 547, in post_ratelimited\r\n> \t_raise_response_errors(r, protocol, log_msg, log_vals)  # Always raises an exception\r\n>   File \"/usr/local/lib/python3.5/dist-packages/exchangelib/util.py\", line 601, in _raise_response_errors\r\n> \traise UnauthorizedError('Wrong username or password for %s' % r.url)\r\n> exchangelib.errors.UnauthorizedError: Wrong username or password for https://outlook.office365.com/EWS/Exchange.asmx\r\n\r\n---------------------------\r\n\r\n**Reproduction**\r\nConfigure synapse.conf as follows:\r\n```\r\n[api]\r\ndebug:False\r\nhost:0.0.0.0\r\nport:5000\r\nthreaded:True\r\n\r\n[account]\r\nurl:http://127.0.0.1:9000\r\nuser:synapse\r\napi_key:[redacted - generated from user management in TheHive]\r\n\r\n[EWS]\r\n#ip or domain to EWS server\r\nserver:outlook.office365.com\r\n#According to exchangelib doc:\r\n#\"username is usually in WINDOMAIN\\username format\r\n#some servers also accept usernames in PrimarySMTPAddress\r\n#('myusername@example.com') format (Office365 requires it)\r\nusername:account@company.com\r\npassword:[redacted]\r\nsmtp_address:account@company.com\r\nfolder_name:TheHive\r\n\r\n```\r\nSpecifically, the issue revolves around specifying any account where **server = outlook.office365.com**\r\n\r\n-------------\r\n**Diagnosis**\r\nWhile working with the exchangelib dev, I determined that the following code SUCCESSFULLY pulls O365 mailbox information:\r\n\r\n```\r\nfrom exchangelib import DELEGATE, Account, Credentials, Configuration\r\n\r\ncredentials = Credentials('first.last@company.com', 'password')\r\n\r\nconfig = Configuration(server='outlook.office365.com', credentials=credentials)\r\naccount = Account(primary_smtp_address='first.last@company.com', config=config, autodiscover=False, access_type=DELEGATE)\r\n\r\nfor item in account.inbox.all().order_by('-datetime_received')[:100]:\r\n    print(item.subject, item.sender, item.datetime_received)\r\n\r\n```\r\n\r\nNote, there are two differences between the above connection, and what I believe Synapse is performing.\r\n\r\n1. When using `config =`, the exchangelib dev states that you also need to explicitly set `access_type=DELEGATE`\r\n\r\nSee his quote here: \r\n\r\n> Setting access_type to DELEGATE explicitly is needed when you use the config argument to Account. It's a bit inconsistent, because it's the default if you don't, which is probably why it's not set explicitly in the Synapse code. Delegate is the proper access type if you're accessing your own account.\r\n> \r\n> Disabling autodiscover (or disabling TLS verification) is needed for O365 due to a bug in our autodiscover implementation that's not yet solved, but tracked in [#337](https://github.com/ecederstrand/exchangelib/issues/337)\r\n\r\n2. When connecting to O365, you cannot use `auth_type=NTLM`. And instead need to leave `auth_type` blank. (looking at exchangelib code, I believe it defaults to `auth_type=None`)\r\n\r\n---------------------\r\n**Suggested changes**\r\nEnable Synapse to do the following:\r\n\r\n1. Allow users to specify `auth_type` in Synapse.conf\r\n2. Allow users to specify `access_type` in Synapse.conf\r\n\r\nI assume that anyone else with a cloud O365 mail service will run into similar issues.  And it seems we need to be able to specify `auth_type=None` and `access_type=DELEGATE`"},"comment":{"url":"https://api.github.com/repos/TheHive-Project/Synapse/issues/comments/416701808","html_url":"https://github.com/TheHive-Project/Synapse/issues/1#issuecomment-416701808","issue_url":"https://api.github.com/repos/TheHive-Project/Synapse/issues/1","id":416701808,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNjcwMTgwOA==","user":{"login":"ninSmith","id":7642274,"node_id":"MDQ6VXNlcjc2NDIyNzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/7642274?v=4","gravatar_id":"","url":"https://api.github.com/users/ninSmith","html_url":"https://github.com/ninSmith","followers_url":"https://api.github.com/users/ninSmith/followers","following_url":"https://api.github.com/users/ninSmith/following{/other_user}","gists_url":"https://api.github.com/users/ninSmith/gists{/gist_id}","starred_url":"https://api.github.com/users/ninSmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ninSmith/subscriptions","organizations_url":"https://api.github.com/users/ninSmith/orgs","repos_url":"https://api.github.com/users/ninSmith/repos","events_url":"https://api.github.com/users/ninSmith/events{/privacy}","received_events_url":"https://api.github.com/users/ninSmith/received_events","type":"User","site_admin":false},"created_at":"2018-08-28T18:57:32Z","updated_at":"2018-08-28T18:57:32Z","author_association":"COLLABORATOR","body":"Yeah seems like there is a conflict between variable ```auth_type``` and parameter ```auth_type```.\r\nI changed ```auth_type``` into ```authType```, I really want to first force ```auth_type``` to ```NTLM``` and then set it as ```None``` if required.\r\n\r\nI've just pushed the change, please try it and let me know if it is better. "}}
{"actor":{"display_login":"ninSmith"}}