我们的想法是让这个简单的请求正常工作,然后发出更复杂的请求,例如上传资产。
下面的代码从请求中返回错误。
import (
"bytes"
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"math/big"
"net/http"
"time"
//...
)
func main() {
fmt.Printf("\nprivate key:\n")
const privPEM = `-----BEGIN EC PRIVATE KEY-----
MyProvateKey
-----END EC PRIVATE KEY-----`
// https://golang.org/pkg/crypto/x509/#example_ParsePKIXPublicKey
privBlock, _ := pem.Decode([]byte(privPEM))
if privBlock == nil {
panic("failed to parse PEM block containing the public key")
}
requestPathStr := "/database/1/iCloud.<MyContainer>/development/public/users/discover"
var requestPath []byte
requestPath = []byte(requestPathStr)
fmt.Printf("requestPath: %s\n", requestPath)
requestBody := ""
var jsonStr = []byte(requestBody)
//
h := sha256.New()
h.Write([]byte(requestBody))
b := h.Sum(nil)
hashedBody := base64.StdEncoding.EncodeToString(b)
//
f := "2006-01-02T15:04:05Z"
requestDate := time.Now().UTC().Format(f)
fmt.Println(requestDate)
rawPayload := []byte(requestDate + ":" + hashedBody + ":" + requestPathStr)
r, s, err := pkSign(rawPayload, privBlock)
if err != nil {
fmt.Printf("signing hash error: %s\n", err)
}
fmt.Printf("r: %v\n", r)
fmt.Printf("s: %v\n", s)
fmt.Printf("\npublic key:\n")
const pubPEM = `-----BEGIN PUBLIC KEY-----
我得到的错误如下:
resp:&{503 服务不可用 503 HTTP/1.1 1 1 映射[Access-Control-Expose-Headers:[X-Apple-Request-UUID Via] 连接:[keep-alive] 内容长度:[0] 内容类型:[text/plain] 日期:[2019 年 6 月 24 日星期一 07:47:52 GMT] 重试后:[30] 服务器:[AppleHttpServer/70a91026] 通过:[icloudedge:mi01p00ic-zteu02110401:7401:19RC207:迈阿密] X-Apple-Cache:[false] X-Apple-Request-Uuid:[ddeb0fa3-ea16-40e9-a15b-c2e68cb5fe78]] {} 0 [] false false 地图[] 0xc00015c000 0xc0000ce2c0}
分别是:{}
呼唤远方
相关分类