[jitsi-dev] Otr failed to parse q parameter after import


#1

Hello,
I'm working on an Otr key importer and when trying to import an otr key
with Jitsi and parse p,q,g,x and y parameters I got always an empty q
parameter.

I'm getting KeyPair from file the same way that Jitsi does.
here is the code :

public KeyPair construct(String privK,String pubK) { // Load
Private Key. byte[] privKey = privK.getBytes();

// Load Private Key. byte[] b64PrivKey =
Base64.decodeBase64(privKey); if (b64PrivKey == null) return null;

PKCS8EncodedKeySpec privateKeySpec = new
PKCS8EncodedKeySpec(b64PrivKey);

// Load Public Key. byte[] pubKey = pubK.getBytes(); byte[]
b64PubKey = Base64.decodeBase64(pubKey);

if (b64PubKey == null) return null;

X509EncodedKeySpec publicKeySpec = new
X509EncodedKeySpec(b64PubKey); PublicKey publicKey; PrivateKey
privateKey; // Generate KeyPair. KeyFactory keyFactory; try {
keyFactory = KeyFactory.getInstance("DSA"); publicKey =
keyFactory.generatePublic(publicKeySpec); privateKey =
keyFactory.generatePrivate(privateKeySpec); } catch
(NoSuchAlgorithmException e) { e.printStackTrace(); return null; }
catch (InvalidKeySpecException e) { e.printStackTrace(); return
null; } keyPair =new KeyPair(publicKey, privateKey); return new
KeyPair(publicKey, privateKey); }

then I'm trying to get parameters this way :

System.out.println(" p: #"+parmPriv.get("p")+"#");
System.out.println(" q:#"+parmPriv.get("q")+"#");
System.out.println(" g: #"+parmPriv.get("g")+"#");
System.out.println(" y: #"+ parmPub.get("y")+"#");
System.out.println(" x: #"+ parmPriv.get("x")+"#");

and always the q parameter is empty .
Am asking how can I get this parameter , does anyone have an idea ?

All bests,

- --
Mohamed Akram Tabka
Tech intern at Access | AccessNow.org
Student at the National School of Computer Sciences
PGP ID : 0x82000BEF
PGP FingerPrint : 40DF DB6B D10B 107B 7609 362F 1045 B72D 8200 0BEF


#2

Hi Mohamed,

Hello, I'm working on an Otr key importer and when trying to import
an otr key with Jitsi and parse p,q,g,x and y parameters I got
always an empty q parameter.

I'm getting KeyPair from file the same way that Jitsi does. here is
the code :

public KeyPair construct(String privK,String pubK) { // Load
Private Key. byte[] privKey = privK.getBytes();

// Load Private Key. byte[] b64PrivKey =
Base64.decodeBase64(privKey); if (b64PrivKey == null) return
null;

PKCS8EncodedKeySpec privateKeySpec = new
PKCS8EncodedKeySpec(b64PrivKey);

// Load Public Key. byte[] pubKey = pubK.getBytes(); byte[]
b64PubKey = Base64.decodeBase64(pubKey);

if (b64PubKey == null) return null;

X509EncodedKeySpec publicKeySpec = new
X509EncodedKeySpec(b64PubKey); PublicKey publicKey; PrivateKey
privateKey; // Generate KeyPair. KeyFactory keyFactory; try {
keyFactory = KeyFactory.getInstance("DSA"); publicKey =
keyFactory.generatePublic(publicKeySpec); privateKey =
keyFactory.generatePrivate(privateKeySpec); } catch
(NoSuchAlgorithmException e) { e.printStackTrace(); return null;
} catch (InvalidKeySpecException e) { e.printStackTrace();
return null; } keyPair =new KeyPair(publicKey, privateKey);
return new KeyPair(publicKey, privateKey); }

then I'm trying to get parameters this way :

System.out.println(" p: #"+parmPriv.get("p")+"#");
System.out.println(" q:#"+parmPriv.get("q")+"#");
System.out.println(" g: #"+parmPriv.get("g")+"#");
System.out.println(" y: #"+ parmPub.get("y")+"#");
System.out.println(" x: #"+ parmPriv.get("x")+"#");

and always the q parameter is empty . Am asking how can I get this
parameter , does anyone have an idea ?

I can not see in your code where the variables "parmPriv" and
"parmPub" comes from.

As you have an instance of the PrivateKey you should be able to get
all the parameters from that. Example:
- ---
   // Note: Might print private key in clear text!
   System.out.println("privateKey: " + privateKey);
   if (privateKey instanceof java.security.interfaces.DSAPrivateKey) {
      DSAPrivateKey dsaPriv = (DSAPrivateKey) privateKey;
      System.out.println("Q: " + dsaPriv.getParams().getQ());
   }
- ---

Best regards,
Markus

···

On 2013-09-05 13:48, Mohamed Akram Tabka wrote:

All bests,

_______________________________________________ dev mailing list
dev@jitsi.org Unsubscribe instructions and other list options:
http://lists.jitsi.org/mailman/listinfo/dev


#3

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Mohamed,

> Hello, I'm working on an Otr key importer and when trying to import
> an otr key with Jitsi and parse p,q,g,x and y parameters I got
> always an empty q parameter.

> I'm getting KeyPair from file the same way that Jitsi does. here is
> the code :

>> public KeyPair construct(String privK,String pubK) { // Load
>> Private Key. byte[] privKey = privK.getBytes();

>> // Load Private Key. byte[] b64PrivKey =
>> Base64.decodeBase64(privKey); if (b64PrivKey == null) return
>> null;

>> PKCS8EncodedKeySpec privateKeySpec = new
>> PKCS8EncodedKeySpec(b64PrivKey);

>> // Load Public Key. byte[] pubKey = pubK.getBytes(); byte[]
>> b64PubKey = Base64.decodeBase64(pubKey);

>> if (b64PubKey == null) return null;

>> X509EncodedKeySpec publicKeySpec = new
>> X509EncodedKeySpec(b64PubKey); PublicKey publicKey; PrivateKey
>> privateKey; // Generate KeyPair. KeyFactory keyFactory; try {
>> keyFactory = KeyFactory.getInstance("DSA"); publicKey =
>> keyFactory.generatePublic(publicKeySpec); privateKey =
>> keyFactory.generatePrivate(privateKeySpec); } catch
>> (NoSuchAlgorithmException e) { e.printStackTrace(); return null;
>> } catch (InvalidKeySpecException e) { e.printStackTrace();
>> return null; } keyPair =new KeyPair(publicKey, privateKey);
>> return new KeyPair(publicKey, privateKey); }

> then I'm trying to get parameters this way :

>> System.out.println(" p: #"+parmPriv.get("p")+"#");
>> System.out.println(" q:#"+parmPriv.get("q")+"#");
>> System.out.println(" g: #"+parmPriv.get("g")+"#");
>> System.out.println(" y: #"+ parmPub.get("y")+"#");
>> System.out.println(" x: #"+ parmPriv.get("x")+"#");

> and always the q parameter is empty . Am asking how can I get this
> parameter , does anyone have an idea ?

I can not see in your code where the variables "parmPriv" and
"parmPub" comes from.

As you have an instance of the PrivateKey you should be able to get
all the parameters from that. Example:
---
   // Note: Might print private key in clear text!
   System.out.println("privateKey: " + privateKey);
   if (privateKey instanceof java.security.interfaces.DSAPrivateKey) {
      DSAPrivateKey dsaPriv = (DSAPrivateKey) privateKey;
      System.out.println("Q: " + dsaPriv.getParams().getQ());
   }
---

Best regards,
Markus

> All bests,

> _______________________________________________ dev mailing list
> dev@jitsi.org Unsubscribe instructions and other list options:
> http://lists.jitsi.org/mailman/listinfo/dev

Thanks Markus for help,

This line was missing in my code:
   DSAPrivateKey dsaPriv = (DSAPrivateKey) privateKey;

I didn't cast to DSAprivateKey, I just used PrivateKey type and I parsed
my parameters manually .
And, it didn't work when I imported the key and gave me an empty Q
parameter (It only worked when I generate a new key. I don't know why ) .
Anyway , your code is easier and I got all the parameters with using
DSAPrivateKey. It works now !

Thanks,
Bests,
- --
Mohamed Akram Tabka
Tech intern at Access | AccessNow.org
Student at the National School of Computer Sciences
PGP ID : 0x82000BEF
PGP FingerPrint : 40DF DB6B D10B 107B 7609 362F 1045 B72D 8200 0BEF

···

On 08/09/13 15:34, Markus Kil�s wrote:

On 2013-09-05 13:48, Mohamed Akram Tabka wrote: