From 0a1e11d192a617a5ec7fb5de72855c6713effdbf Mon Sep 17 00:00:00 2001 From: hasuniea Date: Wed, 24 Feb 2016 07:46:53 +0530 Subject: [PATCH 1/4] fixed import issue --- .../mgt/core/impl/CertificateGenerator.java | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index 3dfe16854f1..267753c4b5f 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -44,7 +44,14 @@ import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.util.Store; -import org.jscep.message.*; +import org.jscep.message.PkcsPkiEnvelopeDecoder; +import org.jscep.message.PkcsPkiEnvelopeEncoder; +import org.jscep.message.CertRep; +import org.jscep.message.PkiMessageEncoder; +import org.jscep.message.PkiMessageDecoder; +import org.jscep.message.PkiMessage; +import org.jscep.message.MessageEncodingException; +import org.jscep.message.MessageDecodingException; import org.jscep.transaction.FailInfo; import org.jscep.transaction.Nonce; import org.jscep.transaction.TransactionId; @@ -61,10 +68,30 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException; import javax.security.auth.x500.X500Principal; import javax.xml.bind.DatatypeConverter; -import java.io.*; -import java.security.*; +import java.io.DataInputStream; +import java.io.FileNotFoundException; +import java.io.FileInputStream; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.File; +import java.security.Security; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.SecureRandom; +import java.security.NoSuchAlgorithmException; +import java.security.InvalidKeyException; +import java.security.KeyFactory; +import java.security.NoSuchProviderException; +import java.security.SignatureException; +import java.security.PrivateKey; import java.security.cert.Certificate; -import java.security.cert.*; +import java.security.cert.X509Certificate; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.util.ArrayList; @@ -266,7 +293,7 @@ public class CertificateGenerator { public boolean verifySignature(String headerSignature) throws KeystoreException { Certificate certificate = extractCertificateFromSignature(headerSignature); - return (certificate != null); + return (certificate != null); } public X509Certificate extractCertificateFromSignature(String headerSignature) throws KeystoreException { @@ -289,12 +316,12 @@ public class CertificateGenerator { X509Certificate reqCert = (X509Certificate) certificateFactory. generateCertificate(byteArrayInputStream); - if(reqCert != null && reqCert.getSerialNumber() != null) { + if (reqCert != null && reqCert.getSerialNumber() != null) { Certificate lookUpCertificate = keyStoreReader.getCertificateByAlias( reqCert.getSerialNumber().toString()); if (lookUpCertificate != null && (lookUpCertificate instanceof X509Certificate)) { - return (X509Certificate)lookUpCertificate; + return (X509Certificate) lookUpCertificate; } } @@ -317,8 +344,8 @@ public class CertificateGenerator { } public X509Certificate generateCertificateFromCSR(PrivateKey privateKey, - PKCS10CertificationRequest request, - String issueSubject) + PKCS10CertificationRequest request, + String issueSubject) throws KeystoreException { CommonUtil commonUtil = new CommonUtil(); @@ -350,10 +377,10 @@ public class CertificateGenerator { certificateBuilder.addExtension(X509Extension.keyUsage, true, new KeyUsage( KeyUsage.digitalSignature | KeyUsage.keyEncipherment)); - if(attributes != null) { + if (attributes != null) { ASN1Encodable extractedValue = getChallengePassword(attributes); - if(extractedValue != null) { + if (extractedValue != null) { certificateBuilder.addExtension(PKCSObjectIdentifiers.pkcs_9_at_challengePassword, true, extractedValue); } @@ -387,7 +414,7 @@ public class CertificateGenerator { for (Attribute attribute : attributes) { if (PKCSObjectIdentifiers.pkcs_9_at_challengePassword.equals(attribute.getAttrType())) { - if(attribute.getAttrValues() != null && attribute.getAttrValues().size() > 0) { + if (attribute.getAttrValues() != null && attribute.getAttrValues().size() > 0) { return attribute.getAttrValues().getObjectAt(0); } } @@ -552,7 +579,7 @@ public class CertificateGenerator { log.error(errorMsg, e); CertificateManagementDAOFactory.rollbackTransaction(); throw new KeystoreException(errorMsg, e); - }finally { + } finally { CertificateManagementDAOFactory.closeConnection(); } } From abd018afd6af8c8108fdcca75d69c4331af1a6c8 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Mon, 4 Apr 2016 14:24:40 +0530 Subject: [PATCH 2/4] refactored imports in Certificate Generator --- .../mgt/core/impl/CertificateGenerator.java | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java index caefc7111a5..20843c8b96d 100755 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/impl/CertificateGenerator.java @@ -39,18 +39,17 @@ import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSSignedData; import org.bouncycastle.cms.CMSSignedDataGenerator; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.openssl.PEMWriter; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.util.Store; import org.jscep.message.PkcsPkiEnvelopeDecoder; -import org.jscep.message.PkcsPkiEnvelopeEncoder; -import org.jscep.message.CertRep; -import org.jscep.message.PkiMessageEncoder; import org.jscep.message.PkiMessageDecoder; import org.jscep.message.PkiMessage; +import org.jscep.message.CertRep; +import org.jscep.message.PkcsPkiEnvelopeEncoder; +import org.jscep.message.PkiMessageEncoder; import org.jscep.message.MessageEncodingException; import org.jscep.message.MessageDecodingException; import org.jscep.transaction.FailInfo; @@ -66,34 +65,15 @@ import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.util.CommonUtil; import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil; import org.wso2.carbon.certificate.mgt.core.util.Serializer; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.TransactionManagementException; import javax.security.auth.x500.X500Principal; import javax.xml.bind.DatatypeConverter; -import java.io.DataInputStream; -import java.io.FileNotFoundException; -import java.io.FileInputStream; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.IOException; -import java.io.File; -import java.security.Security; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.SecureRandom; -import java.security.NoSuchAlgorithmException; -import java.security.InvalidKeyException; -import java.security.KeyFactory; -import java.security.NoSuchProviderException; -import java.security.SignatureException; -import java.security.PrivateKey; +import java.io.*; +import java.security.*; import java.security.cert.Certificate; -import java.security.cert.X509Certificate; -import java.security.cert.CertificateFactory; -import java.security.cert.CertificateEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateExpiredException; -import java.security.cert.CertificateNotYetValidException; +import java.security.cert.*; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.util.ArrayList; @@ -315,7 +295,7 @@ public class CertificateGenerator { public static String getCommonName(X509Certificate requestCertificate) { String distinguishedName = requestCertificate.getSubjectDN().getName(); - if(distinguishedName != null && !distinguishedName.isEmpty()) { + if (distinguishedName != null && !distinguishedName.isEmpty()) { String[] dnSplits = distinguishedName.split(","); for (String dnSplit : dnSplits) { if (dnSplit.contains("CN=")) { @@ -641,7 +621,6 @@ public class CertificateGenerator { } - public String extractChallengeToken(X509Certificate certificate) { byte[] challengePassword = certificate.getExtensionValue( From 73222e347bd7e116bcebd8aca0e4410a9147cca3 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 11 May 2016 15:59:35 +0530 Subject: [PATCH 3/4] Fixed https://wso2.org/jira/browse/IOTS-104 --- .../jaggeryapps/devicemgt/app/modules/utility.js | 11 +++-------- .../devicemgt/app/pages/cdmf.page.devices/devices.js | 10 +++++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index 185c2fa0298..38cb7032ba7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -80,18 +80,13 @@ utility = function () { }; publicMethods.getDeviceTypeConfig = function (deviceType) { - var JFile = Packages.java.io.File; - var sep = JFile.separator; - - var systemProcess = require('process'); - var parent = 'file:///' + (systemProcess.getProperty('jaggery.home') || systemProcess.getProperty('carbon.home')).replace(/[\\]/g, '/').replace(/^[\/]/g, ''); - + var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view"); + if (deviceType in deviceTypeConfigMap) { return deviceTypeConfigMap[deviceType]; } var deviceTypeConfig; - var deviceTypeConfigFile = new File(parent + sep + "repository" + sep + "conf" + sep - + "device-types" + sep + deviceType + ".json"); + var deviceTypeConfigFile = new File("/app/units/" + unitName + "/private/config.json"); if (deviceTypeConfigFile.isExists()) { try { deviceTypeConfigFile.open("r"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index e56c529cc9f..085f1f5a694 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -54,12 +54,16 @@ function onRequest(context) { var deviceTypes = []; if (data) { for (var i = 0; i < data.length; i++) { - var deviceType = utility.getDeviceTypeConfig(data[i].name).deviceType; + var config = utility.getDeviceTypeConfig(data[i].name); + if (!config){ + continue; + } + var deviceType = config.deviceType; deviceTypes.push({ "type": data[i].name, "category": deviceType.category, - "label": deviceType.label, - "thumb": utility.getDeviceThumb(data[i].name) + "label": deviceType.label, + "thumb": utility.getDeviceThumb(data[i].name) }); } } From 1267db52cef4a594f637d9a55893a85f6851e645 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Thu, 12 May 2016 21:11:51 +0530 Subject: [PATCH 4/4] added swagger annotations for TenantConfiguration --- .../org.wso2.carbon.device.mgt.common/pom.xml | 11 +++++++++-- .../common/configuration/mgt/TenantConfiguration.java | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 94a50811c3b..28dad8f8b03 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -17,7 +17,8 @@ ~ under the License. --> - + device-mgt org.wso2.carbon.devicemgt @@ -52,5 +53,11 @@ - + + + io.swagger + swagger-annotations + provided + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java index ece6a23a788..df19ddf1dc2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/configuration/mgt/TenantConfiguration.java @@ -18,6 +18,9 @@ package org.wso2.carbon.device.mgt.common.configuration.mgt; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -30,10 +33,16 @@ import java.util.List; */ @XmlRootElement(name = "tenantConfiguration") @XmlAccessorType(XmlAccessType.NONE) + +@ApiModel(value = "TenantConfiguration", + description = "This class carries all information related to a Tenant configuration") public class TenantConfiguration implements Serializable { @XmlElement(name = "type") + @ApiModelProperty(name = "type", value = "type of device", required = true) private String type; + + @ApiModelProperty(name = "configuration", value = "List of Configuration Entries", required = true) @XmlElement(name = "configuration") private List configuration;