Example #1
0
func TestNew(t *testing.T) {
	website := pushpackage.Website{
		Name:                "Bay Airlines",
		PushID:              "web.com.example.domain",
		AllowedDomains:      []string{"http://domain.example.com"},
		URLFormatString:     `http://domain.example.com/%@/?flight=%@`,
		AuthenticationToken: "19f8d7a6e9fb8a7f6d9330dabe",
		WebServiceURL:       "https://example.com/push",
	}

	cert, privateKey, err := certificate.Load("../fixtures/cert.p12", "")
	if err != nil {
		t.Fatal(err)
	}

	buf := new(bytes.Buffer)

	pkg := pushpackage.New(buf)
	pkg.EncodeJSON("website.json", website)
	pkg.File("icon.iconset/[email protected]", "../fixtures/gopher.png")
	if err := pkg.Sign(cert, privateKey, nil); err != nil {
		t.Fatal(err)
	}

	expected := map[string]string{
		"website.json":  `{"websiteName":"Bay Airlines","websitePushID":"web.com.example.domain","allowedDomains":["http://domain.example.com"],"urlFormatString":"http://domain.example.com/%@/?flight=%@","authenticationToken":"19f8d7a6e9fb8a7f6d9330dabe","webServiceURL":"https://example.com/push"}`,
		"manifest.json": `{"icon.iconset/[email protected]":"5d31b7d2ea66ec7087c3789b2c6ca2aad67e459c","website.json":"8225d6cdd71f00888ff576aaab8d7ec4a27553c7"}`,
	}

	z, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
	for _, f := range z.File {
		if exp, ok := expected[f.Name]; ok {
			b, err := zipReadFile(f)
			if err != nil {
				t.Fatal(err)
			}
			if string(b) != exp {
				t.Errorf("Unexpected content for %s: %s", f.Name, b)
			}
		} else {
			t.Log(f.Name)
		}
	}
}
Example #2
0
func pushPackagesHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	log.Println("building push package for", vars["websitePushID"])

	w.Header().Set("Content-Type", "application/zip")

	// create a push package and sign it with Cert/Key.
	pkg := pushpackage.New(w)
	pkg.EncodeJSON("website.json", website)
	pkg.File("icon.iconset/[email protected]", "../../fixtures/gopher.png")
	pkg.File("icon.iconset/icon_128x128.png", "../../fixtures/gopher.png")
	pkg.File("icon.iconset/[email protected]", "../../fixtures/gopher.png")
	pkg.File("icon.iconset/icon_32x32.png", "../../fixtures/gopher.png")
	pkg.File("icon.iconset/[email protected]", "../../fixtures/gopher.png")
	pkg.File("icon.iconset/icon_16x16.png", "../../fixtures/gopher.png")
	if err := pkg.Sign(cert, privateKey, nil); err != nil {
		log.Fatal(err)
	}
}
Example #3
0
func main() {
	var filename, password, intermediate string

	flag.StringVar(&filename, "c", "", "Path to p12 certificate file")
	flag.StringVar(&password, "p", "", "Password for p12 file.")
	flag.StringVar(&intermediate, "i", "", "Path to WWDR intermediate .cer file")
	flag.Parse()

	cert, privateKey, err := certificate.Load(filename, password)
	failIfError(err)

	wwdr, err := loadWWDR(intermediate)
	failIfError(err)

	f, err := os.Create("Event.pkpass")
	failIfError(err)
	defer f.Close()

	passFiles := []string{
		"pass.json",
		"background.png",
		"[email protected]",
		"icon.png",
		"[email protected]",
		"logo.png",
		"[email protected]",
		"thumbnail.png",
		"[email protected]",
	}

	pkg := pushpackage.New(f)
	for _, name := range passFiles {
		pkg.File(name, "./Event.pass/"+name)
	}

	err = pkg.Sign(cert, privateKey, wwdr)
	failIfError(err)
}