Skip to content

Commit

Permalink
feat: Added KEYS-V2 allowing to upload private key entries (#4917)
Browse files Browse the repository at this point in the history
* feat: Added KEYS-V2 allowing to upload private key entries

Signed-off-by: Nicola Timeus <[email protected]>

* Added support for updating existng entry certificate chain

Signed-off-by: Nicola Timeus <[email protected]>

---------

Signed-off-by: Nicola Timeus <[email protected]>
  • Loading branch information
nicolatimeus authored Oct 27, 2023
1 parent fa92595 commit 21f5f5c
Show file tree
Hide file tree
Showing 26 changed files with 995 additions and 352 deletions.
1 change: 1 addition & 0 deletions kura/org.eclipse.kura.core.keystore/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Import-Package: com.eclipsesource.json;version="0.9.5",
org.eclipse.kura.crypto;version="[1.1,2.0)",
org.eclipse.kura.marshalling;version="[1.0,2.0)",
org.eclipse.kura.message;version="[1.4,2.0)",
org.eclipse.kura.request.handler.jaxrs;version="[1.0,2.0)",
org.eclipse.kura.rest.utils;version="[1.0,2.0)",
org.eclipse.kura.security.keystore;version="[1.1,1.2)",
org.eclipse.kura.system;version="[1.5,2.0)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,7 +13,7 @@
Eurotech
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" enabled="true" immediate="true" name="org.eclipse.kura.core.keystore.request.handler.KeystoreRequestHandler">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" enabled="true" immediate="true" name="org.eclipse.kura.core.keystore.request.handler.KeystoreRequestHandlerV1">
<implementation class="org.eclipse.kura.core.keystore.request.handler.KeystoreServiceRequestHandlerV1"/>

<property name="service.pid" value="org.eclipse.kura.core.keystore.request.handler.KeystoreServiceRequestHandlerV1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
Eurotech
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" enabled="true" immediate="true" name="org.eclipse.kura.core.keystore.request.handler.KeystoreRequestHandlerV2">
<implementation class="org.eclipse.kura.core.keystore.request.handler.KeystoreServiceRequestHandlerV2"/>

<property name="service.pid" value="org.eclipse.kura.core.keystore.request.handler.KeystoreServiceRequestHandlerV2"/>
<reference bind="setRequestHandlerRegistry" cardinality="0..n" interface="org.eclipse.kura.cloudconnection.request.RequestHandlerRegistry" name="RequestHandlerRegistry" policy="dynamic" unbind="unsetRequestHandlerRegistry"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
Contributors:
Eurotech
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" enabled="true" immediate="true" name="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestServiceV1">
<implementation class="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestServiceV1"/>

<property name="service.pid" value="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestServiceV1"/>
<reference bind="setUserAdmin" cardinality="1..1" interface="org.osgi.service.useradmin.UserAdmin" name="UserAdmin" policy="static"/>
<service>
<provide interface="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestService"/>
</service>
</scr:component>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021 Eurotech and/or its affiliates and others
Copyright (c) 2023 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,10 +13,10 @@
Eurotech
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" enabled="true" immediate="true" name="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestService">
<implementation class="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestService"/>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" deactivate="deactivate" enabled="true" immediate="true" name="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestServiceV2">
<implementation class="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestServiceV2"/>

<property name="service.pid" value="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestService"/>
<property name="service.pid" value="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestServiceV2"/>
<reference bind="setUserAdmin" cardinality="1..1" interface="org.osgi.service.useradmin.UserAdmin" name="UserAdmin" policy="static"/>
<service>
<provide interface="org.eclipse.kura.core.keystore.rest.provider.KeystoreRestService"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2022, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,7 +14,7 @@

import java.security.KeyStore;

interface KeystoreInstance {
public interface KeystoreInstance {

public KeyStore getKeystore();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.core.keystore.request;

import org.eclipse.kura.core.keystore.util.CsrInfo;
import org.eclipse.kura.rest.utils.Validable;

public class CsrReadRequest extends CsrInfo implements Validable {

public CsrReadRequest(String keystoreServicePid, String alias) {
super(keystoreServicePid, alias);
}

public CsrReadRequest(final CsrInfo csrInfo) {
super(csrInfo.getKeystoreServicePid(), csrInfo.getAlias());
this.setSignatureAlgorithm(csrInfo.getSignatureAlgorithm());
this.setAttributes(csrInfo.getAttributes());
}

@Override
public String toString() {
return "ReadRequest [keystoreServicePid=" + this.getKeystoreServicePid() + ", alias=" + this.getAlias()
+ ", algorithm="
+ this.getSignatureAlgorithm() + ", attributes=" + this.getAttributes() + "]";
}

@Override
public boolean isValid() {
return this.getKeystoreServicePid() != null && this.getAlias() != null && this.getSignatureAlgorithm() != null
&& this.getAttributes() != null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.core.keystore.request;

import org.eclipse.kura.core.keystore.util.EntryInfo;
import org.eclipse.kura.rest.utils.Validable;

public class EntryRequest extends EntryInfo implements Validable {

public EntryRequest(String keystoreServicePid, String alias) {
super(keystoreServicePid, alias);
}

public EntryRequest(final EntryInfo entryInfo) {
super(entryInfo.getKeystoreServicePid(), entryInfo.getAlias());
}

@Override
public String toString() {
return "DeleteRequest [keystoreServicePid=" + this.getKeystoreServicePid() + ", alias=" + this.getAlias() + "]";
}

@Override
public boolean isValid() {
return this.getKeystoreServicePid() != null && this.getAlias() != null;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Eurotech and/or its affiliates and others
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,7 +11,7 @@
* Eurotech
*
*******************************************************************************/
package org.eclipse.kura.core.keystore.rest.provider;
package org.eclipse.kura.core.keystore.request;

import org.eclipse.kura.core.keystore.util.KeyPairInfo;
import org.eclipse.kura.rest.utils.Validable;
Expand All @@ -22,6 +22,14 @@ public KeyPairWriteRequest(String keystoreName, String alias) {
super(keystoreName, alias);
}

public KeyPairWriteRequest(final KeyPairInfo keyPairInfo) {
super(keyPairInfo.getKeystoreServicePid(), keyPairInfo.getAlias());
this.setAlgorithm(keyPairInfo.getAlgorithm());
this.setAttributes(keyPairInfo.getAttributes());
this.setSignatureAlgorithm(keyPairInfo.getSignatureAlgorithm());
this.setSize(keyPairInfo.getSize());
}

@Override
public boolean isValid() {
if (getKeystoreServicePid() == null || getAlias() == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.core.keystore.request;

import org.eclipse.kura.core.keystore.util.PrivateKeyInfo;
import org.eclipse.kura.rest.utils.Validable;

public class PrivateKeyWriteRequest extends PrivateKeyInfo implements Validable {

public PrivateKeyWriteRequest(String keystoreServicePid, String alias) {
super(keystoreServicePid, alias);
}

public PrivateKeyWriteRequest(final PrivateKeyInfo other) {
super(other.getAlias(), other.getKeystoreServicePid());
this.setAlgorithm(other.getAlgorithm());
this.setSize(other.getSize());
this.setPrivateKey(other.getPrivateKey());
this.setCertificateChain(other.getCertificateChain());
}

@Override
public boolean isValid() {
return getKeystoreServicePid() != null && getAlias() != null && getCertificateChain() != null
&& getCertificateChain().length > 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Eurotech and/or its affiliates and others
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,15 +10,27 @@
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.core.keystore.rest.provider;
package org.eclipse.kura.core.keystore.request;

import org.eclipse.kura.core.keystore.util.CertificateInfo;
import org.eclipse.kura.rest.utils.Validable;

public class TrustedCertificateWriteRequest extends CertificateInfo implements Validable {

public TrustedCertificateWriteRequest(String alias, String keystoreName) {
super(alias, keystoreName);
public TrustedCertificateWriteRequest(String keystoreServicePid, String alias) {
super(keystoreServicePid, alias);
}

public TrustedCertificateWriteRequest(final CertificateInfo other) {
super(other.getKeystoreServicePid(), other.getAlias());
this.setSubjectDN(other.getSubjectDN());
this.setSubjectAN(other.getSubjectAN());
this.setIssuer(other.getIssuer());
this.setStartDate(other.getStartDate());
this.setExpirationDate(other.getExpirationDate());
this.setAlgorithm(other.getAlgorithm());
this.setSize(other.getSize());
this.setCertificate(other.getCertificate());
}

@Override
Expand Down
Loading

0 comments on commit 21f5f5c

Please sign in to comment.