【问题标题】:Error: error:1E08010C:DECODER routines::unsupported with Google auth library错误:error:1E08010C:DECODER routines::unsupported with Google auth library
【发布时间】:2022-11-08 22:16:53
【问题描述】:

我最近在 Node.js 上使用谷歌云存储 SDK 时遇到了这个错误。 我知道这在过去没有任何更改就可以工作,但是我有一段时间没有接触过代码并且可能是错误的。

这是错误本身:

Error: error:1E08010C:DECODER routines::unsupported
    at Sign.sign (node:internal/crypto/sig:131:29)
    at Object.sign (node_modules/jwa/index.js:152:45)
    at Object.jwsSign [as sign] (node_modules/jws/lib/sign-stream.js:32:24)
    at GoogleToken.requestToken (node_modules/gtoken/build/src/index.js:232:31)
    at GoogleToken.getTokenAsyncInner (node_modules/gtoken/build/src/index.js:166:21)
    at GoogleToken.getTokenAsync (node_modules/gtoken/build/src/index.js:145:55)
    at GoogleToken.getToken (node_modules/gtoken/build/src/index.js:97:21)
    at JWT.refreshTokenNoCache (node_modules/google-auth-library/build/src/auth/jwtclient.js:172:36)
    at JWT.refreshToken (node_modules/google-auth-library/build/src/auth/oauth2client.js:153:24)
    at JWT.getRequestMetadataAsync (node_modules/google-auth-library/build/src/auth/oauth2client.js:298:28) {
  library: 'DECODER routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_UNSUPPORTED'
}

引发此错误的代码如下:

const credentials = {
    type: process.env.TYPE,
    project_id: process.env.PROJECT_ID,
    private_key_id: process.env.PRIVATE_KEY_ID,
    private_key: process.env.PRIVATE_KEY,
    client_email: process.env.CLIENT_EMAIL,
    client_id: process.env.CLIENT_ID,
    auth_uri: process.env.AUTH_URI,
    token_uri: process.env.TOKEN_URI,
    auth_provider_x509_cert_url: process.env.AUTH_PROVIDER_X509_CERT_URL,
    client_x509_cert_url: process.env.CLIENT_X509_CERT_URL,
  };

  const storage = new Storage({
    credentials,
  });
  if (!req.file) {
    logger('POST /profile_image', logLevels.error, 'No file uploaded!');
    ResponseError.badRequest(res);
  }
  const bucketName = process.env.BUCKET_NAME;
  const bucket = storage.bucket(bucketName);
  const fileName = `profile_pics/${req.user}/${req.file.originalname}`;
  const file = bucket.file(fileName);
  const stream = file.createWriteStream({
    metadata: {
      contentType: req.file.mimetype,
    },
  });
  stream.on('error', (err) => {
    console.error('Error pushing the picture: ', err); <--- error
    throw err;
  });
  stream.on('finish', () => {
    return file.makePublic().then(async () => {
       ...
      })
  });
  stream.end(req.file.buffer);

process.env 包含所有正确的值,我确保尝试使用新的私钥但同样的错误。有人见过这个吗?

蒂亚!

【问题讨论】:

  • 1) 不要将服务帐户存储在环境变量中。 2)如果这样做,请不要将服务帐户分成几部分。 Base64 对整个服务帐户进行编码,将其存储在一个变量中,然后在需要时进行 Base64 解码。 3)您的代码失败,因为客户端设置了错误的凭据。很可能是损坏的私钥。
  • 问题是损坏的私钥吗?
  • 我不能说。我按照您的建议进行了编码,问题似乎已经消失了。我开始认为,分解成碎片的部分可能已经损坏了各个键。
  • 我相当有信心你破坏了私钥基于堆栈跟踪的字段。

标签: node.js google-cloud-storage google-api-nodejs-client


【解决方案1】:

作为社区维基回答这个问题。正如上面在 cmets 中提到的那样约翰·汉利

  1. 不要将服务帐户存储在环境变量中。
  2. 如果这样做,请不要将服务帐户分成几部分。 Base64 对整个服务帐户进行编码,将其存储在一个变量中,然后在需要时进行 Base64 解码。
  3. 您的代码失败,因为客户端设置的凭据错误。很可能是损坏的私钥。

【讨论】:

    猜你喜欢
    • 2022-11-13
    • 2023-01-26
    • 2023-01-25
    • 2023-02-13
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    相关资源
    最近更新 更多