Merge pull request #361 from ayyoob/st2

removed certificate configuration from device types
revert-dabc3590
Ruwan 8 years ago committed by GitHub
commit 7b98bb0b73

@ -1,108 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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.wso2.carbon.device.mgt.iot.devicetype.config;
import org.wso2.carbon.device.mgt.iot.devicetype.util.DeviceTypeConfigUtil;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Class for holding CertificateKeystore data.
*/
@XmlRootElement(name = "CertificateKeystore")
public class CertificateKeystoreConfig {
private String certificateKeystoreLocation;
private String certificateKeystoreType;
private String certificateKeystorePassword;
private String caCertAlias;
private String caPrivateKeyPassword;
private String raCertAlias;
private String raPrivateKeyPassword;
@XmlElement(name = "CertificateKeystoreLocation", required = true)
public String getCertificateKeystoreLocation() {
return certificateKeystoreLocation;
}
public void setCertificateKeystoreLocation(String certificateKeystoreLocation) {
if (certificateKeystoreLocation != null && certificateKeystoreLocation.toLowerCase().
contains(DeviceTypeConfigUtil.CARBON_HOME_ENTRY)) {
certificateKeystoreLocation = certificateKeystoreLocation.replace(DeviceTypeConfigUtil.CARBON_HOME_ENTRY,
System.getProperty(DeviceTypeConfigUtil.CARBON_HOME));
}
this.certificateKeystoreLocation = certificateKeystoreLocation;
}
@XmlElement(name = "CertificateKeystoreType", required = true)
public String getCertificateKeystoreType() {
return certificateKeystoreType;
}
public void setCertificateKeystoreType(String certificateKeystoreType) {
this.certificateKeystoreType = certificateKeystoreType;
}
@XmlElement(name = "CertificateKeystorePassword", required = true)
public String getCertificateKeystorePassword() {
return certificateKeystorePassword;
}
public void setCertificateKeystorePassword(String certificateKeystorePassword) {
this.certificateKeystorePassword = certificateKeystorePassword;
}
@XmlElement(name = "CACertAlias", required = true)
public String getCACertAlias() {
return caCertAlias;
}
public void setCACertAlias(String caCertAlias) {
this.caCertAlias = caCertAlias;
}
@XmlElement(name = "CAPrivateKeyPassword", required = true)
public String getCAPrivateKeyPassword() {
return caPrivateKeyPassword;
}
public void setCAPrivateKeyPassword(String caPrivateKeyPassword) {
this.caPrivateKeyPassword = caPrivateKeyPassword;
}
@XmlElement(name = "RACertAlias", required = true)
public String getRACertAlias() {
return raCertAlias;
}
public void setRACertAlias(String raCertAlias) {
this.raCertAlias = raCertAlias;
}
@XmlElement(name = "RAPrivateKeyPassword", required = true)
public String getRAPrivateKeyPassword() {
return raPrivateKeyPassword;
}
public void setRAPrivateKeyPassword(String raPrivateKeyPassword) {
this.raPrivateKeyPassword = raPrivateKeyPassword;
}
}

@ -30,7 +30,6 @@ public class DeviceManagementConfiguration {
private DeviceManagementConfigRepository deviceManagementConfigRepository;
private PushNotificationConfig pushNotificationConfig;
private String deviceType;
private CertificateKeystoreConfig certificateKeystoreConfig;
private static final Log log = LogFactory.getLog(DeviceManagementConfiguration.class);
@ -63,14 +62,4 @@ public class DeviceManagementConfiguration {
public void setPushNotificationConfig(PushNotificationConfig pushNotificationConfig) {
this.pushNotificationConfig = pushNotificationConfig;
}
@XmlElement(name = "CertificateKeystore", required = false)
public CertificateKeystoreConfig getCertificateKeystoreConfig() {
return certificateKeystoreConfig;
}
public void setCertificateKeystoreConfig(
CertificateKeystoreConfig certificateKeystoreConfig) {
this.certificateKeystoreConfig = certificateKeystoreConfig;
}
}

@ -76,8 +76,7 @@
javax.crypto,
org.apache.commons.codec.binary,
org.json.*;version="${commons-json.version.range}",
org.wso2.carbon.certificate.mgt.core.exception,
org.wso2.carbon.certificate.mgt.core.service,
org.wso2.carbon.certificate.mgt.core.*,
org.wso2.carbon.certificate.mgt.core.util,
org.wso2.carbon.device.mgt.analytics.data.publisher.exception,
org.wso2.carbon.device.mgt.analytics.data.publisher.service,

@ -21,12 +21,10 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.util;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.device.mgt.iot.devicetype.config.CertificateKeystoreConfig;
import org.wso2.carbon.device.mgt.iot.devicetype.config.DeviceManagementConfiguration;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
import org.wso2.carbon.certificate.mgt.core.config.CertificateConfigurationManager;
import org.wso2.carbon.certificate.mgt.core.config.CertificateKeystoreConfig;
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.VirtualFirealarmManagementDataHolder;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@ -53,21 +51,16 @@ public class VirtualFirealarmSecurityManager {
private static final Log log = LogFactory.getLog(VirtualFirealarmSecurityManager.class);
private static PrivateKey serverPrivateKey;
private static CertificateKeystoreConfig certificateKeystoreConfig;
private static final String SIGNATURE_ALG = "SHA1withRSA";
private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding";
private static CertificateKeystoreConfig certificateKeystoreConfig;
private VirtualFirealarmSecurityManager() {
}
private static CertificateKeystoreConfig getCertKeyStoreConfig() {
private static CertificateKeystoreConfig getCertKeyStoreConfig() throws CertificateManagementException {
if (certificateKeystoreConfig == null) {
DeviceManagementConfiguration deviceManagementConfiguration = VirtualFirealarmManagementDataHolder.getInstance().
getDeviceTypeConfigService().getConfiguration(
VirtualFireAlarmConstants.DEVICE_TYPE,
VirtualFireAlarmConstants.DEVICE_TYPE_PROVIDER_DOMAIN);
certificateKeystoreConfig = deviceManagementConfiguration.getCertificateKeystoreConfig();
certificateKeystoreConfig = CertificateConfigurationManager.getInstance().getCertificateKeyStoreConfig();
}
return certificateKeystoreConfig;
}
@ -80,8 +73,8 @@ public class VirtualFirealarmSecurityManager {
PrivateKey privateKey = null;
InputStream inputStream = null;
KeyStore keyStore;
CertificateKeystoreConfig certificateKeystoreConfig = getCertKeyStoreConfig();
try {
CertificateKeystoreConfig certificateKeystoreConfig = getCertKeyStoreConfig();
keyStore = KeyStore.getInstance(certificateKeystoreConfig.getCertificateKeystoreType());
inputStream = new FileInputStream(certificateKeystoreConfig.getCertificateKeystoreLocation());
@ -108,6 +101,9 @@ public class VirtualFirealarmSecurityManager {
} catch (UnrecoverableKeyException e) {
String errorMsg = "Key is unrecoverable when retrieving CA private key";
log.error(errorMsg, e);
} catch (CertificateManagementException e) {
String errorMsg = "Failed to load the certificate";
log.error(errorMsg, e);
} finally {
try {
if (inputStream != null) {

@ -43,20 +43,4 @@
<Property Name="clearSession">true</Property>
</Properties>
</PushNotificationConfiguration>
<CertificateKeystore>
<!-- Certificate Keystore file location-->
<CertificateKeystoreLocation>${carbon.home}/repository/resources/security/wso2certs.jks</CertificateKeystoreLocation>
<!-- Certificate Keystore type (JKS/PKCS12 etc.)-->
<CertificateKeystoreType>JKS</CertificateKeystoreType>
<!-- Certificate Keystore password-->
<CertificateKeystorePassword>wso2carbon</CertificateKeystorePassword>
<!-- Certificate authority certificate alias -->
<CACertAlias>cacert</CACertAlias>
<!-- Certificate authority private key password -->
<CAPrivateKeyPassword>cacert</CAPrivateKeyPassword>
<!-- Registration authority certificate alias -->
<RACertAlias>racert</RACertAlias>
<!-- Registration authority private key password -->
<RAPrivateKeyPassword>racert</RAPrivateKeyPassword>
</CertificateKeystore>
</DeviceManagementConfiguration>

@ -30,20 +30,4 @@
<SharedWithAllTenants>false</SharedWithAllTenants>
</ProvisioningConfig>
</ManagementRepository>
<CertificateKeystore>
<!-- Certificate Keystore file location-->
<CertificateKeystoreLocation>${carbon.home}/repository/resources/security/wso2certs.jks</CertificateKeystoreLocation>
<!-- Certificate Keystore type (JKS/PKCS12 etc.)-->
<CertificateKeystoreType>JKS</CertificateKeystoreType>
<!-- Certificate Keystore password-->
<CertificateKeystorePassword>wso2carbon</CertificateKeystorePassword>
<!-- Certificate authority certificate alias -->
<CACertAlias>cacert</CACertAlias>
<!-- Certificate authority private key password -->
<CAPrivateKeyPassword>cacert</CAPrivateKeyPassword>
<!-- Registration authority certificate alias -->
<RACertAlias>racert</RACertAlias>
<!-- Registration authority private key password -->
<RAPrivateKeyPassword>racert</RAPrivateKeyPassword>
</CertificateKeystore>
</DeviceManagementConfiguration>

@ -43,20 +43,4 @@
<Property Name="clearSession">true</Property>
</Properties>
</PushNotificationConfiguration>
<CertificateKeystore>
<!-- Certificate Keystore file location-->
<CertificateKeystoreLocation>${carbon.home}/repository/resources/security/wso2certs.jks</CertificateKeystoreLocation>
<!-- Certificate Keystore type (JKS/PKCS12 etc.)-->
<CertificateKeystoreType>JKS</CertificateKeystoreType>
<!-- Certificate Keystore password-->
<CertificateKeystorePassword>wso2carbon</CertificateKeystorePassword>
<!-- Certificate authority certificate alias -->
<CACertAlias>cacert</CACertAlias>
<!-- Certificate authority private key password -->
<CAPrivateKeyPassword>cacert</CAPrivateKeyPassword>
<!-- Registration authority certificate alias -->
<RACertAlias>racert</RACertAlias>
<!-- Registration authority private key password -->
<RAPrivateKeyPassword>racert</RAPrivateKeyPassword>
</CertificateKeystore>
</DeviceManagementConfiguration>

@ -54,20 +54,4 @@
<Property Name="server.name">localhost</Property>
</Properties-->
</PushNotificationConfiguration>
<CertificateKeystore>
<!-- Certificate Keystore file location-->
<CertificateKeystoreLocation>${carbon.home}/repository/resources/security/wso2certs.jks</CertificateKeystoreLocation>
<!-- Certificate Keystore type (JKS/PKCS12 etc.)-->
<CertificateKeystoreType>JKS</CertificateKeystoreType>
<!-- Certificate Keystore password-->
<CertificateKeystorePassword>wso2carbon</CertificateKeystorePassword>
<!-- Certificate authority certificate alias -->
<CACertAlias>cacert</CACertAlias>
<!-- Certificate authority private key password -->
<CAPrivateKeyPassword>cacert</CAPrivateKeyPassword>
<!-- Registration authority certificate alias -->
<RACertAlias>racert</RACertAlias>
<!-- Registration authority private key password -->
<RAPrivateKeyPassword>racert</RAPrivateKeyPassword>
</CertificateKeystore>
</DeviceManagementConfiguration>

Loading…
Cancel
Save