Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cf-2.5.0 : remove usage of deprecated PskStore
- Loading branch information
1 parent
d12e6ed
commit caa03d1
Showing
10 changed files
with
203 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...-server-cf/src/main/java/org/eclipse/leshan/server/californium/LwM2mAdvancedPskStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2013-2015 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.server.californium; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import javax.crypto.SecretKey; | ||
|
||
import org.eclipse.californium.scandium.dtls.ConnectionId; | ||
import org.eclipse.californium.scandium.dtls.PskPublicInformation; | ||
import org.eclipse.californium.scandium.dtls.PskSecretResult; | ||
import org.eclipse.californium.scandium.dtls.pskstore.AdvancedPskStore; | ||
import org.eclipse.californium.scandium.util.SecretUtil; | ||
import org.eclipse.californium.scandium.util.ServerNames; | ||
import org.eclipse.leshan.server.registration.Registration; | ||
import org.eclipse.leshan.server.registration.RegistrationStore; | ||
import org.eclipse.leshan.server.security.SecurityInfo; | ||
import org.eclipse.leshan.server.security.SecurityStore; | ||
|
||
/** | ||
* A {@link AdvancedPskStore} which retrieve PSK information from Leshan {@link SecurityStore}. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
public class LwM2mAdvancedPskStore implements AdvancedPskStore { | ||
|
||
private SecurityStore securityStore; | ||
private RegistrationStore registrationStore; | ||
|
||
public LwM2mAdvancedPskStore(SecurityStore securityStore) { | ||
this(securityStore, null); | ||
} | ||
|
||
public LwM2mAdvancedPskStore(SecurityStore securityStore, RegistrationStore registrationStore) { | ||
this.securityStore = securityStore; | ||
this.registrationStore = registrationStore; | ||
} | ||
|
||
@Override | ||
public boolean hasEcdhePskSupported() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public PskSecretResult requestPskSecretResult(ConnectionId cid, ServerNames serverName, | ||
PskPublicInformation identity, String hmacAlgorithm, SecretKey otherSecret, byte[] seed) { | ||
if (securityStore == null) | ||
return null; | ||
|
||
SecurityInfo info = securityStore.getByIdentity(identity.getPublicInfoAsString()); | ||
if (info == null || info.getPreSharedKey() == null) { | ||
return new PskSecretResult(cid, identity, null); | ||
} else { | ||
// defensive copy | ||
return new PskSecretResult(cid, identity, SecretUtil.create(info.getPreSharedKey(), "PSK")); | ||
} | ||
} | ||
|
||
@Override | ||
public void setResultHandler( | ||
@SuppressWarnings("deprecation") org.eclipse.californium.scandium.dtls.PskSecretResultHandler resultHandler) { | ||
// we don't use async mode. | ||
} | ||
|
||
@Override | ||
public PskPublicInformation getIdentity(InetSocketAddress peerAddress, ServerNames virtualHost) { | ||
if (registrationStore == null) | ||
return null; | ||
|
||
Registration registration = registrationStore.getRegistrationByAdress(peerAddress); | ||
if (registration != null) { | ||
SecurityInfo securityInfo = securityStore.getByEndpoint(registration.getEndpoint()); | ||
if (securityInfo != null) { | ||
return new PskPublicInformation(securityInfo.getIdentity()); | ||
} | ||
return null; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
.../java/org/eclipse/leshan/server/californium/bootstrap/LwM2mAdvancedBootstrapPskStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2013-2015 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.server.californium.bootstrap; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import javax.crypto.SecretKey; | ||
|
||
import org.eclipse.californium.scandium.dtls.ConnectionId; | ||
import org.eclipse.californium.scandium.dtls.PskPublicInformation; | ||
import org.eclipse.californium.scandium.dtls.PskSecretResult; | ||
import org.eclipse.californium.scandium.dtls.pskstore.AdvancedPskStore; | ||
import org.eclipse.californium.scandium.util.SecretUtil; | ||
import org.eclipse.californium.scandium.util.ServerNames; | ||
import org.eclipse.leshan.server.security.BootstrapSecurityStore; | ||
import org.eclipse.leshan.server.security.SecurityInfo; | ||
|
||
/** | ||
* an {@link AdvancedPskStore} to feed a Bootstrap server. | ||
* | ||
* Only supports getting the PSK key for a given identity. (Getting identity from IP only makes sense when we initiate | ||
* DTLS Connection) side.) | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
public class LwM2mAdvancedBootstrapPskStore implements AdvancedPskStore { | ||
|
||
private BootstrapSecurityStore bsSecurityStore; | ||
|
||
public LwM2mAdvancedBootstrapPskStore(BootstrapSecurityStore bsSecurityStore) { | ||
this.bsSecurityStore = bsSecurityStore; | ||
} | ||
|
||
@Override | ||
public boolean hasEcdhePskSupported() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public PskSecretResult requestPskSecretResult(ConnectionId cid, ServerNames serverName, | ||
PskPublicInformation identity, String hmacAlgorithm, SecretKey otherSecret, byte[] seed) { | ||
SecurityInfo info = bsSecurityStore.getByIdentity(identity.getPublicInfoAsString()); | ||
if (info == null || info.getPreSharedKey() == null) { | ||
return new PskSecretResult(cid, identity, null); | ||
} else { | ||
// defensive copy | ||
return new PskSecretResult(cid, identity, SecretUtil.create(info.getPreSharedKey(), "PSK")); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void setResultHandler( | ||
@SuppressWarnings("deprecation") org.eclipse.californium.scandium.dtls.PskSecretResultHandler resultHandler) { | ||
// we don't use async mode. | ||
} | ||
|
||
@Override | ||
public PskPublicInformation getIdentity(InetSocketAddress peerAddress, ServerNames virtualHost) { | ||
throw new UnsupportedOperationException("Getting PSK Id by IP addresss dos not make sense on BS server side."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters