11 changed files with 272 additions and 22 deletions
@ -0,0 +1,38 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import lombok.SneakyThrows; |
||||
|
import org.apache.commons.codec.binary.Base64; |
||||
|
import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public abstract class AbstractServerCredentials extends ServerSecurityConfig implements ServerCredentials { |
||||
|
|
||||
|
@JsonIgnore |
||||
|
public byte[] getDecodedCServerPublicKey() { |
||||
|
return getDecoded(serverPublicKey); |
||||
|
} |
||||
|
|
||||
|
@SneakyThrows |
||||
|
private static byte[] getDecoded(String key) { |
||||
|
return Base64.decodeBase64(key.getBytes()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode; |
||||
|
|
||||
|
public class NoSecServerCredentials extends AbstractServerCredentials{ |
||||
|
@Override |
||||
|
public LwM2MSecurityMode getSecurityMode() { |
||||
|
return LwM2MSecurityMode.NO_SEC; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode; |
||||
|
|
||||
|
public class PSKServerCredentials extends AbstractServerCredentials{ |
||||
|
@Override |
||||
|
public LwM2MSecurityMode getSecurityMode() { |
||||
|
return LwM2MSecurityMode.PSK; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode; |
||||
|
|
||||
|
public class RPKServerCredentials extends AbstractServerCredentials{ |
||||
|
@Override |
||||
|
public LwM2MSecurityMode getSecurityMode() { |
||||
|
return LwM2MSecurityMode.RPK; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class ServerConfig { |
||||
|
private Integer shortId = 123; |
||||
|
private Integer lifetime = 300; |
||||
|
private Integer defaultMinPeriod = 1; |
||||
|
private boolean notifIfDisabled = true; |
||||
|
private String binding = "U"; |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
||||
|
import com.fasterxml.jackson.annotation.JsonSubTypes; |
||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode; |
||||
|
|
||||
|
@JsonTypeInfo( |
||||
|
use = JsonTypeInfo.Id.NAME, |
||||
|
property = "securityMode") |
||||
|
@JsonSubTypes({ |
||||
|
@JsonSubTypes.Type(value = NoSecServerCredentials.class, name = "NO_SEC"), |
||||
|
@JsonSubTypes.Type(value = PSKServerCredentials.class, name = "PSK"), |
||||
|
@JsonSubTypes.Type(value = RPKServerCredentials.class, name = "RPK"), |
||||
|
@JsonSubTypes.Type(value = X509ServerCredentials.class, name = "X509") |
||||
|
}) |
||||
|
@JsonIgnoreProperties(ignoreUnknown = true) |
||||
|
public interface ServerCredentials { |
||||
|
@JsonIgnore |
||||
|
LwM2MSecurityMode getSecurityMode(); |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2021 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode; |
||||
|
|
||||
|
public class X509ServerCredentials extends AbstractServerCredentials{ |
||||
|
@Override |
||||
|
public LwM2MSecurityMode getSecurityMode() { |
||||
|
return LwM2MSecurityMode.X509; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue