-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#162:Remove DTLSConnection when corresponding SecurityInfo is removed
- Loading branch information
1 parent
36938b0
commit 57bbbeb
Showing
10 changed files
with
171 additions
and
10 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
79 changes: 79 additions & 0 deletions
79
leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/ConnectionCleaner.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,79 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.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.security.Principal; | ||
import java.security.PublicKey; | ||
|
||
import javax.security.auth.x500.X500Principal; | ||
|
||
import org.eclipse.californium.elements.auth.PreSharedKeyIdentity; | ||
import org.eclipse.californium.elements.auth.RawPublicKeyIdentity; | ||
import org.eclipse.californium.elements.auth.X509CertPath; | ||
import org.eclipse.californium.elements.util.LeastRecentlyUsedCache.Predicate; | ||
import org.eclipse.californium.scandium.DTLSConnector; | ||
import org.eclipse.leshan.core.californium.EndpointContextUtil; | ||
import org.eclipse.leshan.server.security.SecurityInfo; | ||
|
||
/** | ||
* This class is responsible to remove DTLS connection for a given SecurityInfo. | ||
*/ | ||
public class ConnectionCleaner { | ||
|
||
private DTLSConnector connector; | ||
|
||
public ConnectionCleaner(DTLSConnector connector) { | ||
this.connector = connector; | ||
} | ||
|
||
public void cleanConnectionFor(final SecurityInfo... infos) { | ||
connector.startTerminateConnectionsForPrincipal(new Predicate<Principal>() { | ||
@Override | ||
public boolean accept(Principal principal) { | ||
if (principal != null) { | ||
for (SecurityInfo info : infos) { | ||
if (info != null) { | ||
// PSK | ||
if (info.usePSK() && principal instanceof PreSharedKeyIdentity) { | ||
String identity = ((PreSharedKeyIdentity) principal).getIdentity(); | ||
if (info.getIdentity().equals(identity)) { | ||
return true; | ||
} | ||
} | ||
// RPK | ||
else if (info.useRPK() && principal instanceof RawPublicKeyIdentity) { | ||
PublicKey publicKey = ((RawPublicKeyIdentity) principal).getKey(); | ||
if (info.getRawPublicKey().equals(publicKey)) { | ||
return true; | ||
} | ||
} | ||
// x509 | ||
else if (info.useX509Cert() && principal instanceof X500Principal | ||
|| principal instanceof X509CertPath) { | ||
// Extract common name | ||
String x509CommonName = EndpointContextUtil.extractCN(principal.getName()); | ||
if (x509CommonName.equals(info.getEndpoint())) { | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
}); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...n-server-core/src/main/java/org/eclipse/leshan/server/security/SecurityStoreListener.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,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.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.security; | ||
|
||
/** | ||
* A Listener for {@link SecurityStore} | ||
*/ | ||
public interface SecurityStoreListener { | ||
/** | ||
* Called when {@link SecurityInfo} are removed. | ||
* | ||
* @param infosAreCompromised True if info are compromised and should not be used immediately | ||
* @param infos Array of removed {@link SecurityInfo} | ||
*/ | ||
void securityInfoRemoved(boolean infosAreCompromised, SecurityInfo... infos); | ||
} |
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