ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php-从ColdFusion中的Microsoft Teams自定义Bot验证HMAC

2019-11-08 06:30:25  阅读:365  来源: 互联网

标签:microsoft-teams coldfusion chatbot php hmac


我正在尝试使用ColdFusion,following the Microsoft instructions in C#对Microsoft Teams自定义Bot进行身份验证.我也在this PHP example之后进行了尝试.但是我没有任何运气.知道我在这里缺少什么吗?

<cfset secretKey       = "MsVx7SpJKnSiycvsUyLMiD8lDIFkEUDhuYuFAT94hXY=">
<cfset httpRequestData = GetHttpRequestData()>
<cfset c               = httpRequestData.content>
<cfset calculated_hmac = toBase64(hmac(c, secretKey, "HMACSHA256"))>

我得到这个…

calculated_hmac: NjE2RUY1RjREQTNEMzk1Q0RBNUJDMEE2NDhFNzk3RDIyNUMzRDJDMjk5NTYzMDgxODk0NkU3Njc3RTVEQTAyQQ==

来自Microsoft的headers.authorization是这个…

HMAC 6N0WyOW7g+LqShKYsouWOrPjgh0PD1gazfwNeNwpuS8=

对于此特定示例,GetHttpRequestData().content是…

{“type”:”message”,”id”:”1552059974228″,”timestamp”:”2019-03-08T15:46:14.225Z”,”localTimestamp”:”2019-03-08T09:46:14.225-06:00″,”serviceUrl”:”07002″,”channelId”:”msteams”,”from”:{“id”:”29:1lY_4faAJwr1qSsIBSpFnI3nYpy3wv5hLp5qZk1_uuc_3ET_aW1Ttu_vN-evUZ0TXVKIBoy8wEBzPT7a1WgwOTQ”,”name”:”Gordon
Frobenius”,”aadObjectId”:”be3510a6-204d-4b3f-b6c3-52bbddb303d5″},”conversation”:{“isGroup”:true,”id”:”19:a69ef3b3162a43018edb05db74138636@thread.skype;messageid=1552059031619″,”name”:null,”conversationType”:”channel”},”recipient”:null,”textFormat”:”plain”,”attachmentLayout”:null,”membersAdded”:[],”membersRemoved”:[],”topicName”:null,”historyDisclosed”:null,”locale”:”en-US”,”text”:”cmpro
bot help\n”,”speak”:null,”inputHint”:null,”summary”:null,”suggestedActions”:null,”attachments”:[{“contentType”:”text/html”,”contentUrl”:null,”content”:”http://schema.skype.com/Mention\”
itemid=\”0\”>cmpro
bot help\n”,”name”:null,”thumbnailUrl”:null}],”entities”:[{“type”:”clientInfo”,”locale”:”en-US”,”country”:”US”,”platform”:”Windows”}],”channelData”:{“teamsChannelId”:”19:a69ef3b3162a43018edb05db74138636@thread.skype”,”teamsTeamId”:”19:a69ef3b3162a43018edb05db74138636@thread.skype”,”channel”:{“id”:”19:a69ef3b3162a43018edb05db74138636@thread.skype”},”team”:{“id”:”19:a69ef3b3162a43018edb05db74138636@thread.skype”},”tenant”:{“id”:”0d78b7c2-75c2-4dad-966d-500250225e13″}},”action”:null,”replyToId”:null,”value”:null,”name”:null,”relatesTo”:null,”code”:null}

解决方法:

(请注意,我无法复制该“ calculated_hmac”,因为样本“ content”字符串必须与原始字符串有所不同-可能只是空白,但这足以完全改变结果…).

无论如何,基于the instructions,我猜主要问题是在哈希中使用字符串而不是二进制:

  1. Generate the hmac from the request body of the message…. You will need to convert the body to a byte array in UTF8.
  2. To compute the hash, provide the byte array of the security token provided by Microsoft Teams when you registered the outgoing webhook.

首先尝试将主体解码为二进制

<cfset bodyBinary = charsetDecode(GetHttpRequestData().content, "utf-8")>

使用密钥执行相同的操作

<cfset secretKey  = "MsVx7SpJKnSiycvsUyLMiD8lDIFkEUDhuYuFAT94hXY=">
<cfset secretBinary = binaryDecode(secretKey, "base64")>

最后,不要忘记HMAC()返回十六进制字符串.如果需要base64,则必须DIY:

<cfset hexHash = hmac(bodyBinary, secretBinary, "HMACSHA256")>
<cfset calculated_hmac = binaryEncode(binaryDecode(hexHash, "hex"), "base64")>

标签:microsoft-teams,coldfusion,chatbot,php,hmac
来源: https://codeday.me/bug/20191108/2006249.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有