Buscar este blog

lunes, 26 de diciembre de 2016

Windows 7 - Reboot and select proper boot device

My second windows 7 apocalypse in three weeks.

These are the steps and links I followed in order to not format (again) my system:
1) Ensure my main hard drive works properly
I disconnected the others hard drives (I have three) and I searched my main hard drive in BIOS.
The HD was there and was the first option to boot menu.

2) Try windows 7 gui repair tools
I booted from a win7 install DVD and tried to use all repair options. The problem was that my previous win7 installation was not recognized.

3) Try windows 7 command line repair tools
One of the repair win7 options is to open a DOS prompt. There I put the following commands:
bootrec /FixMbr
bootrec /FixBoot
bootrec /RebuildBcd
The first one was successful, but the other two prompted "element not found"

4) Reactivate main partition (https://aitorlozano.com/arreglando-el-arranque-de-windows/)
With these commands I could set the hard drive partition as active.
list disk
select disk = X
list partition
select partition = Y
active
exit X
X is the disk number associated with your main hard drive. You check this number with the list disk command.
Y is the disk partition. Usually has the value 1.

Then, I could execute the previous commands successful (bootrec).

5) Change boot order.
The next time I restarted the PC I got this error: "bootmgr is missing".
The only avaliable option was "Press Ctrl+Alt+Supr" to reboot, and then back to the same message.
In this situation I was not able to boot from win7 install DVD neither. So I went to BIOS again and I changed the devices boot order by selecting DVD as first option. In this way, next time it will try to boot front win7 install DVD again.

6) Replace bootmgr (https://answers.microsoft.com/en-us/windows/forum/all/bootrec-error-element-not-found/cac41df1-0590-4ea3-b7cd-134256e84c8f)
Using win7 disk I put the following commands:
bcdboot C:\windows /l es-ES

One more reboot and success!!!!

domingo, 25 de diciembre de 2016

Password hash 2016 - Argon2

Argon2 was the winner of Password Hashing Competition.

The project is written in C, but there is a java version that uses JNA (Java Native Access):  https://github.com/phxql/argon2-jvm

Maven configuration.
<dependency>
    <groupId>de.mkammerer</groupId>
    <artifactId>argon2-jvm</artifactId>
    <version>2.1</version>
</dependency>

Java example (most of the examples I saw are inaccurate due the fact that the password is actually wiped after the encryption);
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;

public class Main {

 public static void main(final String[] args) {
  final String hash = generateHash("secret".toCharArray());

  System.out.println(isValidPass("secret".toCharArray(), hash));
  System.out.println(isValidPass("otherPass".toCharArray(), hash));
 }

 private static String generateHash(final char[] pass) {
  final Argon2 argon2 = Argon2Factory.create(Argon2Factory.Argon2Types.ARGON2i, 64, 64);
     final char[] passwd = "secret".toCharArray();
  try {
   final int t = 2;
   final int m = 65536;
   final int p = 1;
      return argon2.hash(t, m, p, passwd);
  } finally {
      argon2.wipeArray(passwd);
  }
 }

 private static boolean isValidPass(final char[] passwd, final String hash) {
  final Argon2 argon2 = Argon2Factory.create(Argon2Factory.Argon2Types.ARGON2i, 64, 64);
  try {
   return argon2.verify(hash, passwd);
  } finally {
      argon2.wipeArray(passwd);
  }

 }
}