From 697a71bfbb16fdc2e05c2b243f3ecc055125f1f5 Mon Sep 17 00:00:00 2001 From: Julien Vermillard Date: Fri, 27 Jun 2014 10:40:37 +0200 Subject: [PATCH] Store PSK Identity in the DTLS Session Once the DTLS session is started successfully the applicative level will want to know the used identity. So I'm storing it in the DTLS session --- .../scandium/dtls/ClientHandshaker.java | 3 ++- .../californium/scandium/dtls/DTLSSession.java | 18 +++++++++++++++++- .../scandium/dtls/ServerHandshaker.java | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/eclipse/californium/scandium/dtls/ClientHandshaker.java b/src/main/java/org/eclipse/californium/scandium/dtls/ClientHandshaker.java index 8221760f..a2a6408c 100644 --- a/src/main/java/org/eclipse/californium/scandium/dtls/ClientHandshaker.java +++ b/src/main/java/org/eclipse/californium/scandium/dtls/ClientHandshaker.java @@ -434,9 +434,10 @@ private DTLSFlight receivedServerHelloDone(ServerHelloDone message) throws Hands case PSK: String identity = ScProperties.std.getProperty("PSK_IDENTITY"); + session.setPskIdentity(identity); + clientKeyExchange = new PSKClientKeyExchange(identity); byte[] psk = pskStore.getKey(identity); - if (psk == null) { AlertMessage alert = new AlertMessage(AlertLevel.FATAL, AlertDescription.HANDSHAKE_FAILURE); throw new HandshakeException("No preshared secret found for identity: " + identity, alert); diff --git a/src/main/java/org/eclipse/californium/scandium/dtls/DTLSSession.java b/src/main/java/org/eclipse/californium/scandium/dtls/DTLSSession.java index 1355e18a..9dd1c3f8 100644 --- a/src/main/java/org/eclipse/californium/scandium/dtls/DTLSSession.java +++ b/src/main/java/org/eclipse/californium/scandium/dtls/DTLSSession.java @@ -67,6 +67,14 @@ public class DTLSSession { private boolean isResumable = false; /** + * The identity used for PSK authentication + */ + private String pskIdentity; + + + + + /** * Whether the session is active and application data can be sent to the * peer. */ @@ -277,4 +285,12 @@ public void setReceiveRawPublicKey(boolean receiveRawPublicKey) { public InetSocketAddress getPeer() { return peer; } -} + + public String getPskIdentity() { + return pskIdentity; + } + + public void setPskIdentity(String pskIdentity) { + this.pskIdentity = pskIdentity; + } +} \ No newline at end of file diff --git a/src/main/java/org/eclipse/californium/scandium/dtls/ServerHandshaker.java b/src/main/java/org/eclipse/californium/scandium/dtls/ServerHandshaker.java index cc3a0531..112ed5b4 100644 --- a/src/main/java/org/eclipse/californium/scandium/dtls/ServerHandshaker.java +++ b/src/main/java/org/eclipse/californium/scandium/dtls/ServerHandshaker.java @@ -576,6 +576,7 @@ private byte[] receivedClientKeyExchange(PSKClientKeyExchange message) throws Ha // use the client's PSK identity to get right preshared key String identity = message.getIdentity(); + session.setPskIdentity(identity); byte[] psk = pskStore.getKey(identity);