0

Safari プッシュ通知パッケージに使用する manifest.json ファイルに署名する正しい方法は何でしょうか?

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\n", 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\n\t\"website.json\":\"%x\"\n}", 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())
    }
}

これはすべて正しく機能することに注意してください。唯一の問題は、次のことを報告するサファリです。

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

Appleのドキュメントは、これが PHP の組み込み機能であることを示していますが、go で同等の機能を見つけることはできません。

PHP では、openssl_pkcs7_sign 関数を使用してこれを行うことができます...

4

0 に答える 0