3

我无法让这个工作。我不断收到以下错误:

[Error: No key provided to sign]

这是我的配置代码:

CloudKit.configure({
  services: {
    fetch: fetch
  },
  containers: [{
    containerIdentifier: 'iCloud.io.shakd.Command-Center',
    environment: 'development',
    serverToServerKeyAuth: {
        keyID: "MyKeyId",
        privateKeyFile: "./eckey.pem",
        privateKeyPassPhrase: "MyPassPhrase"
    }

  }]
})

另外,什么是 privateKeyPassPhrase?它是在终端中生成的代码吗?

4

2 回答 2

3

Apple 在CloudKit Catalog: An Introduction to CloudKit (Cocoa and JavaScript)中的示例代码表明,所需的语法privateKeyFile是将__dirname(执行节点脚本的目录)添加到eckey.pem文件中。来自config.js

serverToServerKeyAuth: {
    keyID: '<insert key ID>',
    privateKeyFile: __dirname + '/eckey.pem'
}

第二条关键信息是,在配置 CloudKit 之后,您必须使用setUpAuth(). 来自index.js

var container = CloudKit.getDefaultContainer();
var database = container.publicCloudDatabase; // We'll only make calls to the public database.

// Sign in using the keyID and public key file.
container.setUpAuth().then(function (userInfo) {
    println("userInfo", userInfo);
    return database.performQuery({ recordType: 'Test' });
}).then(function (response) {
    println("Queried Records", response.records);
}).catch(function (error) {
    console.warn(error);
});

在我的 JavaScript 代码中进行这两项更改后,我的脚本已通过身份验证,可以读取和写入我的 CloudKit 数据库。

于 2016-08-18T04:23:32.313 回答
1

如果您的 privateKeyFile 使用密码短语加密,您只需要 privateKeyPassPhrase。

错误

[Error: No key provided to sign] 

直接来自节点的加密模块。

看起来您的 eckey.pem 文件不包含私钥。您可以尝试以下方法来验证:

var fs = require('fs');
var crypto = require('crypto');
var privateKey = fs.readFileSync('./eckey.pem', 'utf8');
var signer = crypto.createSign('RSA-SHA256');
signer.update('message');
console.log(signer.sign(privateKey, 'base64'));

如果可行,那么您的配置应该是:

CloudKit.configure({
  services: {
    fetch: fetch
  },
  containers: [{
    containerIdentifier: 'iCloud.io.shakd.Command-Center',
    environment: 'development',
    serverToServerKeyAuth: {
        //that looks suspicious, please use the real keyID
        keyID: "MyKeyId",
        privateKeyFile: "./eckey.pem"
    }
  }]
})
于 2016-04-19T22:20:14.297 回答