deno icon indicating copy to clipboard operation
deno copied to clipboard

Uncaught Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding

Open Asguho opened this issue 10 months ago • 4 comments

Describe the bug when using the mineflayer with deno instead of node it resolves in a Error Steps to Reproduce

  1. Create a script with the contents
import mineflayer from 'npm:mineflayer';

const bot = mineflayer.createBot({
  username: 'bot',
  host: 'localhost',
  version: '1.20.1',
  port: '2555',
});

bot.on('inject_allowed', () => {
  console.log('Inject allowed');
});
bot.on('login', () => {
  console.log('Succesfully logged in!');
});
bot.on('spawn', () => {
  console.log('Succesfully spawned in!');
});
  1. Execute the command
 deno run --allow-all index.js
  1. See error
error: Uncaught Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding
    at Object.publicEncrypt (ext:deno_node/internal/crypto/cipher.ts:199:14)
    at sendEncryptionKeyResponse (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.44.0/src/client/encrypt.js:49:52)
    at gotSharedSecret (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.44.0/src/client/encrypt.js:28:9)
    at ext:deno_node/internal/crypto/_randomBytes.ts:42:9
    at Object.action (ext:deno_web/02_timers.js:153:11)
    at handleTimerMacrotask (ext:deno_web/02_timers.js:67:10)
    at eventLoopTick (ext:core/01_core.js:189:21)

Expected behavior

Inject allowed
Succesfully logged in!'
Succesfully spawned in!'

Environment

  • OS: Windows 11
  • deno version: 1.36.4
  • std version: 0.195.0

Asguho avatar Sep 07 '23 09:09 Asguho

Is there any update on this problem?

Asguho avatar Oct 30 '23 13:10 Asguho

Is there anything i can do inorder to help getting this fixed?

Asguho avatar Dec 16 '23 22:12 Asguho

@littledivy please take a look and suggest a solution.

bartlomieju avatar Dec 19 '23 13:12 bartlomieju

The following code has same problem

import crypto from "node:crypto"
import { Buffer } from "node:buffer"

  let publicKey = `XXXX`
  let rsaKey = {
    key: publicKey,
    padding: crypto.constants.RSA_PKCS1_PADDING,
  }
  let buffer = Buffer.from(toEncrypt, "utf8")
  let encrypted = crypto.publicEncrypt(rsaKey, buffer)

error info:

error: Uncaught (in promise) Error: ASN.1 error: PEM error: PEM Base64 error: invalid Base64 encoding
  let encrypted = crypto.publicEncrypt(rsaKey, buffer)

DesistDaydream avatar Jan 19 '24 07:01 DesistDaydream

This is a bug in node-minecraft-protocol package. node-minecraft-protocol generates PEM of non-standard 65-character lines.

Deno follows the rfc7468 PEM strictly.

Generators MUST wrap the base64-encoded lines so that each line consists of exactly 64 characters except for the final line, which will encode the remainder of the data (within the 64-character line boundary), and they MUST NOT emit extraneous whitespace.

I've opened a PR on the node-minecraft-protocol repo to fix the generator bug: https://github.com/PrismarineJS/node-minecraft-protocol/pull/1292

littledivy avatar Mar 14 '24 11:03 littledivy