Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Philogyny recapitulates erogeny; erogeny recapitulates philogyny.


devel / comp.security.ssh / PPK Version3 file generation using Java (With Argon2 Hashing) failing with wrong passphrase while converting to PEM

SubjectAuthor
* PPK Version3 file generation using Java (With Argon2 Hashing) failing with wrongArivazhagan Jeganathan
`- PPK Version3 file generation using Java (With Argon2 Hashing) failing with wrongArivazhagan Jeganathan

1
PPK Version3 file generation using Java (With Argon2 Hashing) failing with wrong passphrase while converting to PEM

<9b29d921-593d-4f58-ada2-05e2e09997d0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=233&group=comp.security.ssh#233

  copy link   Newsgroups: comp.security.ssh
X-Received: by 2002:a05:620a:404c:b0:759:15da:1b5c with SMTP id i12-20020a05620a404c00b0075915da1b5cmr3864367qko.7.1684853871241;
Tue, 23 May 2023 07:57:51 -0700 (PDT)
X-Received: by 2002:aca:ba54:0:b0:38e:eba8:378d with SMTP id
k81-20020acaba54000000b0038eeba8378dmr2855432oif.7.1684853870863; Tue, 23 May
2023 07:57:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.security.ssh
Date: Tue, 23 May 2023 07:57:50 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=49.205.83.19; posting-account=0B9X9AoAAACAO4m_XjzjtaX0vCMGFGOR
NNTP-Posting-Host: 49.205.83.19
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9b29d921-593d-4f58-ada2-05e2e09997d0n@googlegroups.com>
Subject: PPK Version3 file generation using Java (With Argon2 Hashing) failing
with wrong passphrase while converting to PEM
From: arivazhagan@mookambikainfo.com (Arivazhagan Jeganathan)
Injection-Date: Tue, 23 May 2023 14:57:51 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3293
 by: Arivazhagan Jeganath - Tue, 23 May 2023 14:57 UTC

Hi Team,

We are trying to generate PPK Version3 using Java code.

Followed this documentation for generating the same:
https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html#ppk-keys

Able to generate PPK file successfully with and without encryption. Facing issues while we try to convert PPK to PEM file via puttygen.

1. Built the PPK file version 3 format as specified by the document
2. public-lines are written as Base64 encoded
3. Private-lines - Argon2 KDF generated 80 bytes of data (CipherKey + IV + MAC Key)
4. Private-MAC key is generated as per the document specification
i) algorithm name, encryption, comment, public-lines (base64), private-lines with padding (unencrypted + base64)

But when the generated PPK is converted to PEM with passphrase, getting "wrong passphrase" error in PuttyGen tool.

Could you please help if any specific step is missing during PPK file generation via Java?

Sharing Argon2 logic:
*************************************
byte[] out = new byte[80];

Argon2BytesGenerator encoder = new Argon2BytesGenerator();

Argon2Parameters parameters = new Argon2Parameters.Builder(Argon2Parameters.ARGON2_id).withParallelism(parallelism).withIterations(iterations)
.withMemoryAsKB(memoryInKB).withSalt(salt.getBytes()).withSecret("".getBytes()).withAdditional("".getBytes()).build();
encoder.init(parameters);
encoder.generateBytes(password, out, 0, 80);

return out;

encryption/decryption logic: (bouncy castle)
SecretKey keyValue = new SecretKeySpec(Arrays.copyOfRange(keyIVMac, 0, 32), "AES");
AlgorithmParameterSpec ivSpec = new IvParameterSpec(Arrays.copyOfRange(keyIVMac, 32, 48));
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", BouncyCastleProvider.PROVIDER_NAME);

cipher.init(Cipher.ENCRYPT_MODE, keyValue, ivSpec);
data = cipher.doFinal(keyWriter.array(), 0, encrypted_len);

Please share any suggestions on this.

Re: PPK Version3 file generation using Java (With Argon2 Hashing) failing with wrong passphrase while converting to PEM

<493789af-2fef-4ec2-87ff-75ae19359a4cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=234&group=comp.security.ssh#234

  copy link   Newsgroups: comp.security.ssh
X-Received: by 2002:a05:620a:4623:b0:759:1798:d849 with SMTP id br35-20020a05620a462300b007591798d849mr5701304qkb.3.1684932426241;
Wed, 24 May 2023 05:47:06 -0700 (PDT)
X-Received: by 2002:a05:6830:378a:b0:6aa:fa0b:cad4 with SMTP id
bi10-20020a056830378a00b006aafa0bcad4mr7301205otb.2.1684932425827; Wed, 24
May 2023 05:47:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!1.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.security.ssh
Date: Wed, 24 May 2023 05:47:05 -0700 (PDT)
In-Reply-To: <9b29d921-593d-4f58-ada2-05e2e09997d0n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=49.205.86.211; posting-account=FiYLKQoAAACDmeBYM61LSYidQj_7mVTI
NNTP-Posting-Host: 49.205.86.211
References: <9b29d921-593d-4f58-ada2-05e2e09997d0n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <493789af-2fef-4ec2-87ff-75ae19359a4cn@googlegroups.com>
Subject: Re: PPK Version3 file generation using Java (With Argon2 Hashing)
failing with wrong passphrase while converting to PEM
From: arivazhagan.jeganathan@gmail.com (Arivazhagan Jeganathan)
Injection-Date: Wed, 24 May 2023 12:47:06 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 8
 by: Arivazhagan Jeganath - Wed, 24 May 2023 12:47 UTC

Hi Team,

Issue was due to wrong Salt value passed in Argon2 KDF.

Argon2 requires Salt as byte[] and while writing in PPK it should be hexadecimal string.

I was trying to pass in hexadecimal string salt to Argon function and it did not work well.

Thank you.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor