- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
Google App Engine 的 Go 运行时有一个 SignBytes功能,一个PublicCertificates功能,和一个Certificate结构。
func SignBytes
func SignBytes(c Context, bytes []byte) (keyName string, signature []byte, err error)
SignBytes signs bytes using a private key unique to your application.
func PublicCertificates
func PublicCertificates(c Context) ([]Certificate, error)
PublicCertificates retrieves the public certificates for the app. They can be used to verify a signature returned by SignBytes.
type Certificate
type Certificate struct {
KeyName string
Data []byte // PEM-encoded X.509 certificate
}Certificate represents a public certificate for the app.
很明显,应用程序需要遍历公共(public)证书来验证签名。但目前尚不清楚签名是如何生成或验证的。围棋的rsa package有两个函数来验证签名,VerifyPKCS1v15和 VerifyPSS , 而这些函数中的每一个都需要一个 crypto.Hash标识符作为参数。目前,有 15 种不同的哈希标识符(例如,crypto.MD5、crypto.SHA256)提供 2x15=30 种验证函数和哈希标识符的组合。
SignBytes 生成的签名是如何验证的?
最佳答案
我通过尝试验证方案和哈希类型的所有组合发现了这一点;我没有找到保证这是将要使用的签名方案的文档。
但是对于勇敢的人来说,下面是一个代码示例,它可以对数据进行签名并验证签名。
package yourpackage
import (
"crypto"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"google.golang.org/appengine"
"net/http"
)
func signAndVerify(request *http.Request) error {
c := appengine.NewContext(request)
data := []byte("test data to sign")
_, sig, err := appengine.SignBytes(c, data)
if err != nil {
return err
}
certs, err := appengine.PublicCertificates(c)
if err != nil {
return err
}
lastErr := errors.New("ErrNoPublicCertificates")
for _, cert := range certs {
block, _ := pem.Decode(cert.Data)
if block == nil {
lastErr = errors.New("ErrPemDecodeFailure")
continue
}
x509Cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
lastErr = err
continue
}
pubkey, ok := x509Cert.PublicKey.(*rsa.PublicKey)
if !ok {
lastErr = errors.New("ErrNotRSAPublicKey")
continue
}
signBytesHash := crypto.SHA256
h := signBytesHash.New()
h.Write(data)
hashed := h.Sum(nil)
err = rsa.VerifyPKCS1v15(pubkey, signBytesHash, hashed, sig)
if err != nil {
lastErr = err
continue
}
return nil
}
return lastErr
}
我还在 package 中发布了验证步骤在 github 上。
Google 提供了一些 sample code验证 SignBytes。其中,有一个文件 app-identity-samples-read-only/python/app_identity_test.py
有一个名为 buildjwt
的方法,它创建一个由 SignBytes 签名的 JWT,并且JWT 算法是 RS256,在 RFC 7518 中定义使用 SHA-256 成为 RSASSA-PKCS1-v1_5。
注意:我使用的是 Go App Engine for Managed VMs (请参阅“google.golang.org/appengine”导入)而不是经典的 Go App Engine 运行时,尽管对于 SignBytes 的用途并没有太大的不同。
关于google-app-engine - 如何验证 appengine.SignBytes 返回的签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32486427/
Google Cloud Compute 中的 Google Compute Engine、App Engine 和 Container Engine 之间的实际区别是什么?什么时候使用什么? 有什么
我有一个在 Google App Engine 中运行的应用程序,它访问在 Google Compute Engine 中的机器上运行的服务。 Google App Engine 应用程序是该服务唯一
我们正在谷歌云中构建一个应用程序。我们使用 App Engine 作为前端,使用 Compute Engine 作为后端。在这些 Compute Engine 实例上,我正在运行一个接受特定“命令”消
我有一个现有的 GAE 应用程序(我们称之为应用程序 A)正在运行的情况,但由于非技术原因无法修改。当用户迁移到新的客户端版本时,我们需要将他们的数据从应用程序 A 迁移到新的 GAE 应用程序(我称
我正在尝试发现 App Engine 上的其他已部署服务。类似于 this文章建议。 我的代码是这样的: import ( "fmt" "net/http" "google.g
我想在我的网站上为“图像处理”事件设置服务器。如果我在 GCE 中使用“n1-standard-1”实例,GAE 中的可比功率是多少?是因为我算错了,还是同一个功率两者价格相差很大? 最佳答案 按小时
我在 Googl Compute Engine 和 Google App Engine 标准环境中的应用程序中创建了一个 VM 实例。我打算在 App Engine 中使用我的应用程序,在 Compu
我像往常一样使用 appcfg.py 更新我的应用程序,但收到一条错误消息。我试过 appcfg.py 回滚,两次尝试之间等了十分钟,但我仍然收到相同的错误消息。我该怎么办? 无法对 apps/dev
我想在 Google Compute Engine 上放置一个 Redis 服务器,并通过 AppEngine 的套接字支持与其对话。唯一的问题是似乎没有特定的防火墙规则说“此 AppEngine 应
我想知道 App Engine 和 Compute Engine 之间有什么区别。任何人都可以向我解释其中的区别吗? 最佳答案 App Engine 是一种平台即服务。这意味着您只需部署代码,平台会为
我正在编写一个在 App Engine 的 Go 运行时上运行的 Go 应用程序。 我注意到几乎所有使用 App Engine 服务(例如 Datastore、Mail 甚至 Capabilities
是否有人有在 Grid Engine/Sun Grid Engine/Son of Grid Engine 上运行 Docker 的经验,并且能够 monitor the resource used
我读了很多论坛,因为 grails app-engine 插件多年来没有更新,所以不可能将 grails 应用程序部署到谷歌应用程序引擎。当我准备放弃时,我发现使用 intellij 部署项目是可能的
当前设置, 运行 Windows Server 2012 (GCE Server 2012) 的谷歌计算引擎 运行 Debian Wheezy(GCE 服务器 Wheezy)的 Google 计算引擎
特定于基于 Docker 的部署,这两者之间有什么区别?由于 Google App Engine Flexible 现在也支持基于 Dockerfile 的部署,并且它也是完全托管的服务,因此它似乎比
我相信 Google Kubernetes Engine (GKE) 在 Google Compute Engine (GCE) 上运行。那么,在服务器管理方面使用 Google Kubernetes
TLDR;关于这个问题有任何更新吗? Google App Engine communicate with Compute Engine over internal network -- 是否可以在同
我正在尝试使用 Go SDK 为 App Engine 编写应用程序,但它似乎与单元测试有一种有趣的关系。人有written libraries左右this original, outdated一组工
在 App Engine 中,我想对在同一个 Google 云项目中创建的 Compute Engine 实例上运行的网络服务器进行 http fetch 调用,我想知道是否可以在不启用的情况下对实例
在编写 Go App Engine 标准应用程序时,过去的情况是您必须使用 App Engine SDK访问数据存储。然而,最近(从 Go 1.11 开始?),如果你只使用 Cloud Datasto
我是一名优秀的程序员,十分优秀!