BotBuilder-Samples icon indicating copy to clipboard operation
BotBuilder-Samples copied to clipboard

botFileSecret : The encrypted value is not a valid format 24.bot-authentication-msgraph

Open jenkinsns opened this issue 8 years ago • 5 comments

  1. Type: samples/javascript_nodejs/24.bot-authentication-msgraph/
  2. Language:nodejs
  3. Name: 24.bot-authentication-msgraph

Describe the bug

When I execute the bot, it throws Error: The encrypted value is not a valid format, While processing botConfig

Code const BOT_FILE = path.join(__dirname, (process.env.botFilePath || '')); let botConfig; try { // Read bot configuration from .bot file. console.log(BOT_FILE); botConfig = BotConfiguration.loadSync(BOT_FILE, process.env.botFileSecret);

} catch (err) { console.error(err); console.error(\nError reading bot file. Please ensure you have valid botFilePath and botFileSecret set for your environment.); console.error(\n - The botFileSecret is available under appsettings for your Azure Bot Service bot.); console.error(\n - If you are running this bot locally, consider adding a .env file with botFilePath and botFileSecret.); console.error(\n - See https://aka.ms/about-bot-file to learn more about .bot file its use and bot configuration.\n\n); process.exit(); }

Error

node ./index.js

C:\Jenkins\BOT\Office365PeopleSearchBOT.bot Error: The encrypted value is not a valid format at decryptString (C:\Jenkins\BOT\node_modules\botframework-config\lib\encrypt.js:54:15) at EndpointService.decrypt (C:\Jenkins\BOT\node_modules\botframework-config\lib\models\endpointService.js:22:32) at BotConfiguration.decrypt (C:\Jenkins\BOT\node_modules\botframework-config\lib\botConfiguration.js:178:35) at Function.internalLoad (C:\Jenkins\BOT\node_modules\botframework-config\lib\botConfiguration.js:155:17) at Function.loadSync (C:\Jenkins\BOT\node_modules\botframework-config\lib\botConfiguration.js:83:38) at Object. (C:\Jenkins\BOT\index.js:19:34) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

Error reading bot file. Please ensure you have valid botFilePath and botFileSecret set for your environment.

  • The botFileSecret is available under appsettings for your Azure Bot Service bot.

  • If you are running this bot locally, consider adding a .env file with botFilePath and botFileSecret.

  • See https://aka.ms/about-bot-file to learn more about .bot file its use and bot configuration.

To Reproduce

index.js file

[bug]

jenkinsns avatar Oct 11 '18 04:10 jenkinsns

What version of node and NPM are you using?

JasonSowers avatar Oct 11 '18 15:10 JasonSowers

node : v10.11.0 npm : 6.4.1

jenkinsns avatar Oct 11 '18 20:10 jenkinsns

@jenkinsns this error occurs when your values in the .bot file don't align with what the bot is looking for.

It's hard to see what value is "off" in the .bot file versus the .env file (i.e. is it the "appPassword"? is it the "padlock"? "botFileSecret"? etc.), so let's start by just generating a new bot file secret

In the terminal, navigate to the folder with your .bot file.

run command: "msbot secret --new" to generate new bot secret

You should see the following output that looks like this with your own secret: image

You'll also notice that in your .bot file (in this sample it's called authentication-msgraph.bot) the values for "appPassword" and "padlock" are encrypted now after running the command

copy and paste the new bot secret into your .env file

Specifically copy the value that is right after "Your bot is encrypted with secret:" from the terminal into your .env file image

Testing the bot in emulator, open the .bot file, and copy and paste the botFileSecret value as well when prompted

Zerryth avatar Oct 16 '18 18:10 Zerryth

.env file with a secret was mistakenly checked in. rotate the secret and remove the secret

sgellock avatar Oct 16 '18 20:10 sgellock

@sgellock Done. @JasonSowers rotated it ASAP (ty)

  • Bot appPassword, botFileSecret rotated
  • Revision history of .bot file deleted as well (comment version's existence visible in timeline, but content can't seen)

Zerryth avatar Oct 16 '18 20:10 Zerryth