summaryrefslogtreecommitdiff
path: root/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/javax/crypto/key/srp6/SRP6TLSClient.java')
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6TLSClient.java62
1 files changed, 13 insertions, 49 deletions
diff --git a/gnu/javax/crypto/key/srp6/SRP6TLSClient.java b/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
index 5474a1e8e..af0be02df 100644
--- a/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
+++ b/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
@@ -51,62 +51,38 @@ import java.util.HashMap;
import java.util.Map;
/**
- * <p>A variation of the SRP6 key agreement protocol, for the client-side as
- * proposed in
- * <a href="http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-05.txt">Using
+ * A variation of the SRP6 key agreement protocol, for the client-side as
+ * proposed in <a
+ * href="http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-05.txt">Using
* SRP for TLS Authentication</a>. The only difference between it and the SASL
* variant is that the shared secret is the entity <code>S</code> and not
- * <code>H(S)</code>.</p>
+ * <code>H(S)</code>.
*/
-public class SRP6TLSClient extends SRP6KeyAgreement
+public class SRP6TLSClient
+ extends SRP6KeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The user's identity. */
private String I;
-
/** The user's cleartext password. */
private byte[] p;
-
/** The user's ephemeral key pair. */
private KeyPair userKeyPair;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(final Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
-
final String md = (String) attributes.get(HASH_FUNCTION);
- if (md == null || "".equals(md.trim()))
- {
- throw new KeyAgreementException("missing hash function");
- }
+ if (md == null || md.trim().length() == 0)
+ throw new KeyAgreementException("missing hash function");
srp = SRP.instance(md);
-
I = (String) attributes.get(USER_IDENTITY);
if (I == null)
- {
- throw new KeyAgreementException("missing user identity");
- }
+ throw new KeyAgreementException("missing user identity");
p = (byte[]) attributes.get(USER_PASSWORD);
if (p == null)
- {
- throw new KeyAgreementException("missing user password");
- }
+ throw new KeyAgreementException("missing user password");
}
protected OutgoingMessage engineProcessMessage(final IncomingMessage in)
@@ -131,14 +107,11 @@ public class SRP6TLSClient extends SRP6KeyAgreement
super.engineReset();
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage sendIdentity(final IncomingMessage in)
throws KeyAgreementException
{
final OutgoingMessage result = new OutgoingMessage();
result.writeString(I);
-
return result;
}
@@ -149,19 +122,15 @@ public class SRP6TLSClient extends SRP6KeyAgreement
g = in.readMPI();
final BigInteger s = in.readMPI();
final BigInteger B = in.readMPI();
-
// generate an ephemeral keypair
final SRPKeyPairGenerator kpg = new SRPKeyPairGenerator();
final Map attributes = new HashMap();
if (rnd != null)
- {
- attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
- }
+ attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
attributes.put(SRPKeyPairGenerator.SHARED_MODULUS, N);
attributes.put(SRPKeyPairGenerator.GENERATOR, g);
kpg.setup(attributes);
userKeyPair = kpg.generate();
-
final BigInteger A = ((SRPPublicKey) userKeyPair.getPublic()).getY();
final BigInteger u = uValue(A, B); // u = H(A | B)
final BigInteger x;
@@ -173,18 +142,13 @@ public class SRP6TLSClient extends SRP6KeyAgreement
{
throw new KeyAgreementException("computeSharedSecret()", e);
}
-
// compute S = (B - 3g^x) ^ (a + ux)
final BigInteger a = ((SRPPrivateKey) userKeyPair.getPrivate()).getX();
- final BigInteger S = B.subtract(THREE.multiply(g.modPow(x, N))).modPow(
- a.add(u.multiply(x)),
- N);
-
+ final BigInteger S = B.subtract(THREE.multiply(g.modPow(x, N)))
+ .modPow(a.add(u.multiply(x)), N);
K = S;
-
final OutgoingMessage result = new OutgoingMessage();
result.writeMPI(A);
-
complete = true;
return result;
}