From faec826c0d976301b075500b079241bc88619658 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 15 Oct 2003 16:41:45 +0000 Subject: Verify remote peer cert during MMTP handshake --- src/org/noreply/fancydress/type3/mmtp/MMTP.java | 3 +- .../fancydress/type3/mmtp/MMTPTrustManager.java | 59 +++++++++++++++------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/org/noreply/fancydress/type3/mmtp/MMTP.java b/src/org/noreply/fancydress/type3/mmtp/MMTP.java index 1d03eed..bc19e8e 100644 --- a/src/org/noreply/fancydress/type3/mmtp/MMTP.java +++ b/src/org/noreply/fancydress/type3/mmtp/MMTP.java @@ -20,7 +20,7 @@ public class MMTP { byte[] ackExpected = Util.concat( Util.toOctets("RECEIVED\r\n"), CryptoPrimitives.hash(packet.asOctets(), Util.toOctets("RECEIVED"))); byte[] ackRead = new byte[30]; - MMTPTrustManager trustManager = new MMTPTrustManager(); + MMTPTrustManager trustManager = new MMTPTrustManager(packet.getRoute().getKeyID()); TrustManager[] trustManagers = { trustManager }; SSLContext context = SSLContext.getInstance("TLS"); context.init(null, trustManagers, null); @@ -58,7 +58,6 @@ public class MMTP { } else { System.out.println("Got ACK"); }; - System.out.println(Util.asHex(packet.getRoute().getKeyID())); in.close(); out.close(); socket.close(); diff --git a/src/org/noreply/fancydress/type3/mmtp/MMTPTrustManager.java b/src/org/noreply/fancydress/type3/mmtp/MMTPTrustManager.java index e39f5f9..4748a84 100644 --- a/src/org/noreply/fancydress/type3/mmtp/MMTPTrustManager.java +++ b/src/org/noreply/fancydress/type3/mmtp/MMTPTrustManager.java @@ -5,13 +5,28 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.X509TrustManager; import java.security.AlgorithmParameters; -import java.math.*; +import java.security.NoSuchAlgorithmException; +import java.security.InvalidKeyException; +import java.security.NoSuchProviderException; +import java.security.SignatureException; +import java.math.BigInteger; import org.bouncycastle.util.encoders.Base64; import org.noreply.fancydress.misc.*; import org.noreply.fancydress.crypto.*; public class MMTPTrustManager implements X509TrustManager { - public MMTPTrustManager() { + /** + * Hash of the expected identity key. + */ + private byte[] identity; + + /** + * Create a new MMTPTrustManager instance. + * + * @param keyid fingerprint (== keyid, == hash of the key) of the identity key. + */ + public MMTPTrustManager(byte[] identity) { + this.identity = identity; } /** @@ -55,20 +70,31 @@ public class MMTPTrustManager implements X509TrustManager { public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - System.out.println("call to checkServerTrusted()\n"); - System.out.println("certs: " + chain.length); - for (int i=0; i