Hello Robert.
Thank you very much!. It works, although I have to change:
byte[] password = "admin".getBytes(StandardCharsets.UTF_8);
to
byte[] password = Encoder.encodeSecretKey("admin".getBytes(StandardCharsets.UTF_8),true);
because HS_SECKEY is encrypted as well (just in case someone has or could have the same issue).
In addition, and about with the private/public key method, I'm following now the documentation as well as the several examples of the "Community Software". However I get 401 error code -_-'.
This is what I get (I'm using of course other handle with HS_PUBKEY as authentication method): 1º Load private key PrivateKey privkey = Util.getPrivateKeyFromFileWithPassphrase(new File(path),passphrase);2º Concat nonce + cnonce and digest the result using algorithm (SHA1 in this case). byte[] serverNonce = Base64.getDecoder().decode("whatevernonce"); 3ºSign the digest using the privatekey Signature signature = Signature.getInstance("SHA1withRSA");I already check AuthenticationUtil.java from the Admintool (controller package) and supposedly is verified using the same class and instance. However, probably I'm missing something..
Any idea?
Thanks and best regards!
De: Robert R Tupelo-Schneck <schneck@cnri.reston.va.us>
Enviado: martes, 21 de marzo de 2017 4:05:02 Para: Ruiz-Zafra, Angel Cc: handle-info@cnri.reston.va.us Asunto: Re: [Handle-info] Authentication HS_SECKEY/PUBKEY via Authorization:Handle You want to concatenate 4 byte arrays:
(1) the bytes of the password
(2) the bytes of the server nonce---not the bytes of its Base64 encoding
(3) the bytes of the client nonce---not the bytes of its Base64 encoding
(4) the bytes of the password
Here's some Java code to produce the digest:
byte[]
serverNonce = Base64.getDecoder().decode("0K8M9tweMjqguVkD7NGtWA==");
byte[]
clientNonce = Base64.getDecoder().decode("sCXDGrQTeYTL+LMhTPTJpw==");
byte[]
password = "admin".getBytes(StandardCharsets.UTF_8);
ByteArrayOutputStream outputStream =
new ByteArrayOutputStream( );
outputStream.write(password);
outputStream.write(serverNonce);
outputStream.write(clientNonce);
outputStream.write(password);
byte[]
bytesToDigest = outputStream.toByteArray();
MessageDigest digester = MessageDigest.getInstance("SHA-1");
digester.update(bytesToDigest);
byte[]
digestBytes = digester.digest();
String digestString = Base64.getEncoder().encodeToString(digestBytes);
System.out.println(digestString);
There are better ways to verify a password; PBKDF2-HMAC-SHA1 is the best supported by the current generation of handle servers. But I'd encourage you to use a public/private keypair instead anyway.
Robert
|
_______________________________________________ Handle-Info mailing list Handle-Info@cnri.reston.va.us http://www.handle.net/mailman/listinfo/handle-info