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);