duande1985 2014-06-29 03:24
浏览 52

如何使用Golang对manifest.json进行野生动物园推送通知签名?

What would be the correct way to sign a manifest.json file to be used for a safari push notification package?

func servePushPackage() func(w http.ResponseWriter, r *http.Request) {
    return func(w http.ResponseWriter, r *http.Request) {
        body, _ := ioutil.ReadAll(r.Body)
        fmt.Printf("servePushPackage() %s %s %s %s %v
", r.Method, r.RequestURI, r.RemoteAddr, body, r.FormValue)

        buf := new(bytes.Buffer)

        // Create a new zip archive.
        z := zip.NewWriter(buf)

        // Build the website.json file
        websiteJson :=
`{
    "websiteName": "Test",
    "websitePushID": "web.example.test",
    "allowedDomains": ["https://example.com"],
    "urlFormatString": "https://example.com/%@",
    "authenticationToken": "19f8d7a6e9fb8a7f6d9330dabe",
    "webServiceURL": "https://example.com"
}`

        // Build the manifest.json
        manifestJson := "{"

        // Add the icon files to the archive and to the manifest
        .... snip ....

        // Complete the manifest
        manifestJson = fmt.Sprintf("%s
\t\"website.json\":\"%x\"
}", manifestJson, sha1.Sum([]byte(websiteJson)) )

        addFileToArchive(z, "website.json", []byte([]byte(websiteJson)))
        addFileToArchive(z, "manifest.json", []byte([]byte(manifestJson)))
        addFileToArchive(z, "signature", []byte([]byte("test test test")))

        // Make sure to check the error on Close.
        err := z.Close()
        if err != nil {
            panic(err)
        }

        // Successfully built the push package
        w.Header().Set("Content-type", "application/zip")
        w.Write(buf.Bytes())
    }
}

Note that this all works correctly, the only issue is safari reporting the following:

{"logs":["Signature verification of push package failed"]}

The apple documentation indicates this is a built in feature of PHP, but no such luck finding an equivalent in go:

In PHP, you can do this with the openssl_pkcs7_sign function...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计