snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

Beta 4.0 error on recrypt

Open NCATS-Lab opened this issue 9 years ago • 18 comments

Expected Behavior (or desired behavior if a feature request)

Testing a Snipe It 3.6.6 to v4-beta3


Actual Behavior

php artisan snipeit:legacy-recrypt
ERROR: Your LEGACY_APP_KEY is not the correct length (32 characters). Please locate your old APP_KEY and use that as your LEGACY_APP_KEY in your .env file to continue.

.env:

APP_TIMEZONE=America/New_York
DB_HOST=Snipe-It
DB_DATABASE=snipe-it-db
DB_USERNAME=snipe-it-db-user
DB_PASSWORD=password
APP_URL=https://192.168.1.1
APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LEGACY_APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
APP_CIPHER=AES-256-CBC
DB_DUMP_PATH='/usr/bin'
APP_DEBUG=true

Please confirm you have done the following before posting your bug report:


Please provide answers to these questions before posting your bug report:

  • Version of Snipe-IT you're running - v3.6.6
  • What OS and web server you're running Snipe-IT on - CentOS 7.3, Apache
  • What method you used to install Snipe-IT (install.sh, manual installation, docker, etc) Manual
  • WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error

ERROR: Your LEGACY_APP_KEY is not the correct length (32 characters). Please locate your old APP_KEY and use that as your LEGACY_APP_KEY in your .env file to continue.

  • What specific Snipe-IT page you're on, and what specific element you're interacting with to trigger the error php artisan snipeit:legacy-recrypt
  • If a stacktrace is provided in the error, include that too.
  • Any errors that appear in your browser's error console.
  • Confirm whether the error is reproduceable on the demo.
  • Include any additional information you can find in app/storage/logs and your webserver's logs.
  • Include what you've done so far in the installation, and if you got any error messages along the way.

I have followed exactly the instructions found at https://github.com/snipe/snipe-it/releases/tag/v4-beta3 php artisan migrate also throws:

[Illuminate\Database\QueryException]                                         
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name o  
  r service not known (SQL: select * from information_schema.tables where tab  
  le_schema = snipedb and table_name = migrations)                             
                                                                               

                                                                               
  [PDOException]                                                               
  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name o  
  r service not known                                                          
                                                                               

                                                                               
  [ErrorException]                                                             
  PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or s  
  ervice not known                                      
  • Indicate whether or not you've manually edited any data directly in the database - no

NCATS-Lab avatar Sep 01 '17 19:09 NCATS-Lab

ERROR: Your LEGACY_APP_KEY is not the correct length (32 characters). Please locate your old APP_KEY and use that as your LEGACY_APP_KEY in your .env file to continue.

How many characters is your legacy key?

The MySQL error looks unrelated. https://stackoverflow.com/questions/2661546/php-network-getaddresses-getaddrinfo-failed-name-or-service-not-known

snipe avatar Sep 06 '17 01:09 snipe

APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LEGACY_APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

There are 44 characters after the base64:

NCATS-Lab avatar Sep 06 '17 13:09 NCATS-Lab

What was your encryption set to in your old install? (I think look in config/app.php?)

snipe avatar Sep 07 '17 00:09 snipe

My guess is that you might not need to recrypt - you might have been using openSSL all along.

snipe avatar Sep 07 '17 00:09 snipe

'cipher' => 'rijndael-256'

NCATS-Lab avatar Sep 07 '17 13:09 NCATS-Lab

Thanks so much for the additional info - we're sussing out how to help you (and other folks who I think have later versions of Snipe-IT, but not so late that they're not using mcrypt.) We'll have a fix out for you shortly.

snipe avatar Sep 08 '17 00:09 snipe

I've just pushed out a change to the recrypter that might help. Try grabbing the latest from develop and giving that a shot.

snipe avatar Sep 14 '17 23:09 snipe

@NCATS-Lab have you had a chance to check out whether the change worked for you?

snipe avatar Sep 18 '17 22:09 snipe

Hello Snipe,

I am experiencing the same problem. My settings and outputs are pretty much the same as NCATS-Lab. Today I have tried beta6, but the problem continues to occur. This is sample of my .env file:

APP_ENV=production
APP_DEBUG=false
APP_KEY
LEGACY_APP_KEY=base64:MYKEY=
APP_URL=MYURL
APP_TIMEZONE='UTC'
APP_LOCALE=en`

The error I am getting is:

ERROR: You do not have a LEGACY_APP_KEY set in your .env file. Please locate your old APP_KEY and ADD a line to your .env file like: LEGACY_APP_KEY=YOUR_OLD_APP_KEY

Diniver avatar Sep 19 '17 11:09 Diniver

I apologize it took so long to get back with you. I tried Beta6. This is what I get (no debug errors show)

[root@SnipeTest snipeit]# su -s /bin/bash apache -c "php artisan snipeit:legacy-recrypt"
ERROR: You do not have a LEGACY_APP_KEY set in your .env file. Please locate your old APP_KEY and ADD a line to your .env file like: LEGACY_APP_KEY=YOUR_OLD_APP_KEY

I started with 3.66, added the LEGACY_APP_KEY, then downloaded the update, unziped, and ran rsync. Restored ownership and permissions. ran the following:

mv bootstrap/cache/compiled.php bootstrap/cache/compiled.old
su -s /bin/bash apache -c "php composer.phar install --no-dev --prefer-source"
su -s /bin/bash apache -c "php composer.phar dump-autoload"
su -s /bin/bash apache -c "php artisan view:clear"
su -s /bin/bash apache -c "php artisan cache:clear"
su -s /bin/bash apache -c "php artisan config:clear"
su -s /bin/bash apache -c "php artisan config:cache"
su -s /bin/bash apache -c "php artisan snipeit:legacy-recrypt"

All goes fine until I run the recrypt command. My hunch is it relates to the 64bit nature of the key, but don't know how to work around that.

NCATS-Lab avatar Sep 19 '17 12:09 NCATS-Lab

You state:

You MUST make sure you've backed up your original APP_KEY. The recrypter attempts to use mcrypt to decrypt any encrypted custom fields you have. If you do not run the recrypter and you change your APP_KEY, it will:

make any encrypted fields undecryptable
make your LDAP password undecryptable
void all browser sessions

What fields would normally be encrypted that I should be concerned about?

NCATS-Lab avatar Sep 19 '17 12:09 NCATS-Lab

For some reason, the code in RecryptFromMcrypt.php doesn't seem to be picking up the LEGACY_APP_KEY variable. Since it's reading it as an environment variable, I just ran the legacy-recrypt command like this:

LEGACY_APP_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx php artisan snipeit:legacy-recrypt

It got the job done and at this point I'm just testing beta6 in preparation for the eventual release.

Also, don't forget to run php artisan key:generate afterwards or you'll still have a bunch of cipher errors.

ghaberek avatar Sep 21 '17 19:09 ghaberek

@ghaberek @NCATS-Lab did you both clear your config cache AFTER adding the legacy key to your .env?

snipe avatar Sep 22 '17 02:09 snipe

IIRC, effectively yes. I had added the legacy key at one point and then completely started over on my migration, which means the legacy key was in place when I ran the various "artisan clear" commands.

I'm testing this on a dev VM, so I can snapshot it and start over again to try once more.

ghaberek avatar Sep 22 '17 13:09 ghaberek

Yes, first thing I did was add the legacy app key. Correct me if I am wrong, but we should start out with both an APP_KEY and a LEGACY_APP_KEY, correct? And initially, they are equal (before running the legacy-recrypt command)?

NCATS-Lab avatar Sep 22 '17 16:09 NCATS-Lab

@NCATS-Lab They should both be in your .env, and I think they CAN be the same but don’t have to be. I think.

snipe avatar Sep 22 '17 16:09 snipe

@NCATS-Lab the only fields that would be encrypted would be your stored LDAP password if you use LDAP, and any custom fields you have marked as encrypted when you created them.

snipe avatar Sep 22 '17 16:09 snipe

Welp, I don't have either of those scenarios, so I should be able to just generate a new key without worry. I will test this out when I get back from vacation.

NCATS-Lab avatar Sep 22 '17 18:09 NCATS-Lab