Search in sources :

Example 1 with PSKLwM2MBootstrapServerCredential

use of org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.PSKLwM2MBootstrapServerCredential in project thingsboard by thingsboard.

the class AbstractSecurityLwM2MIntegrationTest method getBootstrapServerCredential.

private AbstractLwM2MBootstrapServerCredential getBootstrapServerCredential(LwM2MSecurityMode mode, boolean isBootstrap) {
    AbstractLwM2MBootstrapServerCredential bootstrapServerCredential;
    switch(mode) {
        case PSK:
            bootstrapServerCredential = new PSKLwM2MBootstrapServerCredential();
            bootstrapServerCredential.setServerPublicKey("");
            break;
        case RPK:
            bootstrapServerCredential = new RPKLwM2MBootstrapServerCredential();
            if (isBootstrap) {
                bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCertBs.getEncoded()));
            } else {
                bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCert.getEncoded()));
            }
            break;
        case X509:
            bootstrapServerCredential = new X509LwM2MBootstrapServerCredential();
            try {
                if (isBootstrap) {
                    bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509CertBs.getEncoded()));
                } else {
                    bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509Cert.getEncoded()));
                }
            } catch (CertificateEncodingException e) {
                e.printStackTrace();
            }
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + mode);
    }
    bootstrapServerCredential.setShortServerId(isBootstrap ? shortServerIdBs : shortServerId);
    bootstrapServerCredential.setBootstrapServerIs(isBootstrap);
    bootstrapServerCredential.setHost(isBootstrap ? hostBs : host);
    bootstrapServerCredential.setPort(isBootstrap ? securityPortBs : securityPort);
    return bootstrapServerCredential;
}
Also used : PSKLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.PSKLwM2MBootstrapServerCredential) X509LwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential) AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) RPKLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Aggregations

CertificateEncodingException (java.security.cert.CertificateEncodingException)1 AbstractLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential)1 PSKLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.PSKLwM2MBootstrapServerCredential)1 RPKLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential)1 X509LwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential)1