Skip to content

Commit

Permalink
Refactoring add bsserver module - no file content changes [dont build]
Browse files Browse the repository at this point in the history
Move Bootstrap Server code in dedicated maven modules.

This is part of  :
eclipse-leshan#1295

Refactoring was done in 2 commits to try to keep git history :
https://stackoverflow.com/questions/2314652/is-it-possible-to-move-rename-files-in-git-and-maintain-their-history
This commit doesn't build.
  • Loading branch information
sbernard31 committed Jul 2, 2024
1 parent 6d2ff69 commit 2869625
Show file tree
Hide file tree
Showing 87 changed files with 1,220 additions and 0 deletions.
35 changes: 35 additions & 0 deletions leshan-lwm2m-bsserver/logback-leshan-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<configuration>
<!--
This file will only be used by maven by default.
If you want to use it in your IDE, just :
- use -Dlogback.configurationFile=logback-test-.xml argument
or
- put a logback-test.xml file in your classpath (it will be ignore by git)
-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %p %C{1} [%t] %m%n</pattern>
</encoder>
</appender>

<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>

56 changes: 56 additions & 0 deletions leshan-lwm2m-bsserver/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
Bosch Software Innovations GmbH - OSGi support
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.leshan</groupId>
<artifactId>lib-build-config</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../build-config/lib-build-config/pom.xml</relativePath>
</parent>
<artifactId>leshan-lwm2m-bsserver</artifactId>
<packaging>bundle</packaging>
<name>leshan - bsserver</name>
<description>A LWM2M bootstrap server implementation which abstracts transport layer. A transport implementation like "leshan-tl-cf-bsserver-coap" is needed.</description>

<dependencies>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-lwm2m-core</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
35 changes: 35 additions & 0 deletions leshan-lwm2m-servers-shared/logback-leshan-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<configuration>
<!--
This file will only be used by maven by default.
If you want to use it in your IDE, just :
- use -Dlogback.configurationFile=logback-test-.xml argument
or
- put a logback-test.xml file in your classpath (it will be ignore by git)
-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %p %C{1} [%t] %m%n</pattern>
</encoder>
</appender>

<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>

56 changes: 56 additions & 0 deletions leshan-lwm2m-servers-shared/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
Bosch Software Innovations GmbH - OSGi support
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.leshan</groupId>
<artifactId>lib-build-config</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../build-config/lib-build-config/pom.xml</relativePath>
</parent>
<artifactId>leshan-lwm2m-servers-shared</artifactId>
<packaging>bundle</packaging>
<name>leshan - servers - shared</name>
<description>Shared classes between server and bsserver.</description>

<dependencies>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-lwm2m-core</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
35 changes: 35 additions & 0 deletions leshan-tl-cf-bsserver-coap/logback-leshan-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<configuration>
<!--
This file will only be used by maven by default.
If you want to use it in your IDE, just :
- use -Dlogback.configurationFile=logback-test-.xml argument
or
- put a logback-test.xml file in your classpath (it will be ignore by git)
-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %p %C{1} [%t] %m%n</pattern>
</encoder>
</appender>

<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>

76 changes: 76 additions & 0 deletions leshan-tl-cf-bsserver-coap/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
Bosch Software Innovations GmbH - OSGi support
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.leshan</groupId>
<artifactId>lib-build-config</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../build-config/lib-build-config/pom.xml</relativePath>
</parent>
<artifactId>leshan-tl-cf-bsserver-coap</artifactId>
<packaging>bundle</packaging>
<name>leshan - transport - californium - bsserver - coap</name>
<description>A transport implementation for leshan bootstrap server based on Californium for CoAP protocol</description>

<dependencies>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-tl-cf-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.leshan</groupId>
<artifactId>leshan-lwm2m-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>scandium</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- We need to launch each tests in its own JVM to be able to check number
of active threads in LeshanBootstrapServerTest and LeshanServerTest -->
<reuseForks>false</reuseForks>
</configuration>
</plugin>
</plugins>
</build>
</project>
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 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.transport.californium.server;

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.Filter;
import org.eclipse.californium.scandium.DTLSConnector;
import org.eclipse.leshan.core.security.certificate.util.X509CertUtil;
import org.eclipse.leshan.server.security.SecurityInfo;

/**
* This class is responsible to remove DTLS connection for a given SecurityInfo.
*/
public class ConnectionCleaner {

private final DTLSConnector connector;

public ConnectionCleaner(DTLSConnector connector) {
this.connector = connector;
}

public void cleanConnectionFor(final SecurityInfo... infos) {
connector.startTerminateConnectionsForPrincipal(new Filter<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.getPskIdentity().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 = X509CertUtil.extractCN(principal.getName());
if (x509CommonName.equals(info.getEndpoint())) {
return true;
}
}
}
}
}
return false;
}
});
}
}
Loading

0 comments on commit 2869625

Please sign in to comment.