Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add KeyStorageService Interface & implement DBSKeytorage #7

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-assets/env-files/env.docker.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ENCRYPTION_KEY=
AUTHORITY_WALLET_BPN=BPNL000000000000
AUTHORITY_WALLET_DID=did:web:localhost:BPNL000000000000
AUTHORITY_WALLET_NAME=Catena-X
AUTHORITY_WALLET_KEY_STORAGE_TYPE=DB
KEYCLOAK_REALM=miw_test
VC_SCHEMA_LINK="https://www.w3.org/2018/credentials/v1, https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json"
VC_EXPIRY_DATE=01-01-2025
Expand Down
1 change: 1 addition & 0 deletions dev-assets/env-files/env.local.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ENCRYPTION_KEY=
AUTHORITY_WALLET_BPN=BPNL000000000000
AUTHORITY_WALLET_DID=did:web:localhost:BPNL000000000000
AUTHORITY_WALLET_NAME=Catena-X
AUTHORITY_WALLET_KEY_STORAGE_TYPE=DB
KEYCLOAK_REALM=miw_test
VC_SCHEMA_LINK="https://www.w3.org/2018/credentials/v1, https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json"
VC_EXPIRY_DATE=01-01-2025
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import com.smartsensesolutions.java.commons.specification.SpecificationUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.text.StringEscapeUtils;
import org.eclipse.tractusx.managedidentitywallets.domain.SigningServiceType;
import org.eclipse.tractusx.managedidentitywallets.signing.KeyProvider;
import org.eclipse.tractusx.managedidentitywallets.signing.LocalSigningService;
import org.eclipse.tractusx.managedidentitywallets.signing.SigningService;
import org.springdoc.core.properties.SwaggerUiConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -40,6 +44,10 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.StandardCharsets;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* The type Application config.
Expand All @@ -50,11 +58,13 @@ public class ApplicationConfig implements WebMvcConfigurer {

private final SwaggerUiConfigProperties properties;
private final String resourceBundlePath;
private final MIWSettings miwSettings;

@Autowired
public ApplicationConfig(@Value("${resource.bundle.path:classpath:i18n/language}") String resourceBundlePath, SwaggerUiConfigProperties properties) {
public ApplicationConfig(@Value("${resource.bundle.path:classpath:i18n/language}") String resourceBundlePath, SwaggerUiConfigProperties properties, MIWSettings miwSettings) {
this.resourceBundlePath = resourceBundlePath;
this.properties = properties;
this.miwSettings = miwSettings;
}

/**
Expand Down Expand Up @@ -98,4 +108,23 @@ public LocalValidatorFactoryBean validator() {
beanValidatorFactory.setValidationMessageSource(messageSource());
return beanValidatorFactory;
}

@Bean
public Map<SigningServiceType, SigningService> availableKeyStorages(List<SigningService> storages, List<KeyProvider> keyProviders) {
KeyProvider localSigningKeyProvider = keyProviders.stream().filter(s -> s.getKeyStorageType().equals(miwSettings.localSigningKeyStorageType()))
.findFirst()
.orElseThrow(() -> new IllegalStateException("no key provider with type %s found".formatted(miwSettings.localSigningKeyStorageType())));

Map<SigningServiceType, SigningService> available = new EnumMap<>(SigningServiceType.class);
storages.forEach(
s -> {
if(s instanceof LocalSigningService local){
local.setKeyProvider(localSigningKeyProvider);
}
available.put(s.getSupportedServiceType(), s);
}
);

return available;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package org.eclipse.tractusx.managedidentitywallets.config;

import org.eclipse.tractusx.managedidentitywallets.domain.KeyStorageType;
import org.eclipse.tractusx.managedidentitywallets.domain.SigningServiceType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.format.annotation.DateTimeFormat;

Expand All @@ -39,5 +41,7 @@ public record MIWSettings(String host, String encryptionKey, String authorityWal
@DateTimeFormat(pattern = "dd-MM-yyyy") Date vcExpiryDate,
Set<String> supportedFrameworkVCTypes,
boolean enforceHttps, String contractTemplatesUrl,
List<URI> didDocumentContextUrls) {
}
List<URI> didDocumentContextUrls,
KeyStorageType localSigningKeyStorageType,
SigningServiceType authoritySigningServiceType) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ private StringPool() {
public static final String BEARER_SPACE = "Bearer ";

public static final String BPN_NUMBER_REGEX = "^(BPN)(L|S|A)[0-9A-Z]{12}";

public static final String W3_ID_JWS_2020_V1_CONTEXT_URL = "https://w3id.org/security/suites/jws-2020/v1";
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
PManaras marked this conversation as resolved.
Show resolved Hide resolved
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;
import org.eclipse.tractusx.managedidentitywallets.domain.KeyStorageType;
import org.eclipse.tractusx.managedidentitywallets.domain.SigningServiceType;
import org.eclipse.tractusx.managedidentitywallets.utils.StringToDidDocumentConverter;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
Expand Down Expand Up @@ -60,10 +62,16 @@ public class Wallet extends MIWBaseEntity {
@Column(nullable = false)
private String algorithm;

@Enumerated(EnumType.STRING)
@Column(name="key_storage_type",nullable = false)
private SigningServiceType signingServiceType;

@Column(nullable = false)
@Convert(converter = StringToDidDocumentConverter.class)
private DidDocument didDocument;



@Transient
private List<VerifiableCredential> verifiableCredentials;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* *******************************************************************************
* Copyright (c) 2021;2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License; Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* ******************************************************************************
*/

package org.eclipse.tractusx.managedidentitywallets.domain;

import lombok.Builder;
import lombok.Getter;
import org.eclipse.tractusx.ssi.lib.model.did.DidDocument;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialStatus;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredentialSubject;

import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Builder
@Getter
public class CredentialCreationConfig {
private VerifiableCredentialSubject subject;
private VerifiableCredentialStatus verifiableCredentialStatus;
private DidDocument issuerDoc;
private String holderDid;
private List<String> types;
private List<URI> contexts;
private URI vcId;
private Date expiryDate;
private boolean selfIssued;

// this will be used by the DB-Impl of storage to retrieve privateKey
private String keyName;

private VerifiableEncoding encoding;

public static class CredentialCreationConfigBuilder {
public CredentialCreationConfigBuilder vcId(Object object) {
if (!(object instanceof URI) && !(object instanceof String)) {
throw new IllegalArgumentException("vcId must be of type String or URI, argument has type%s".formatted(object.getClass().getName()));
}

if (object instanceof URI uri) {
this.vcId = uri;
} else {
this.vcId = URI.create((String) object);
}

return this;

}

public CredentialCreationConfig build() {
PManaras marked this conversation as resolved.
Show resolved Hide resolved

try {
Objects.requireNonNull(subject);
} catch (NullPointerException e) {
throw new IllegalArgumentException("subject must not be null");
}

try {
Objects.requireNonNull(types);
} catch (NullPointerException e) {
throw new IllegalArgumentException("types must not be null");
}


try {
Objects.requireNonNull(issuerDoc);
} catch (NullPointerException e) {
throw new IllegalArgumentException("issuer did document must not be null");
}

try {
Objects.requireNonNull(holderDid);
} catch (NullPointerException e) {
throw new IllegalArgumentException("holder did must not be null");
}

try {
Objects.requireNonNull(contexts);
} catch (NullPointerException e) {
throw new IllegalArgumentException("contexts must not be null");
}

try {
Objects.requireNonNull(encoding);
} catch (NullPointerException e) {
throw new IllegalArgumentException("encoding must not be null");
}

return new CredentialCreationConfig(subject, verifiableCredentialStatus, issuerDoc, holderDid, types, contexts, vcId, expiryDate, selfIssued, keyName, encoding);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* ******************************************************************************
*/

package org.eclipse.tractusx.managedidentitywallets.domain;

import com.nimbusds.jose.jwk.Curve;
import com.nimbusds.jose.jwk.KeyType;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class KeyCreationConfig {
private String keyName;
private Curve curve;
private KeyType keyType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* ******************************************************************************
*/

package org.eclipse.tractusx.managedidentitywallets.domain;

public enum KeyStorageType {
DB,
REMOTE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* ******************************************************************************
*/

package org.eclipse.tractusx.managedidentitywallets.domain;

import lombok.Builder;
import lombok.Getter;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;

import java.net.URI;
import java.util.List;

@Builder
@Getter
public class PresentationCreationConfig {

private VerifiableEncoding encoding;
private String keyName;
private List<VerifiableCredential> verifiableCredentials;
private Did vpIssuerDid;

// all for JWT
private String audience;

// all for JsonLD
URI verificationMethod;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* *******************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* ******************************************************************************
*/

package org.eclipse.tractusx.managedidentitywallets.domain;

public enum SigningServiceType {
LOCAL,
AZURE,
REMOTE
}
Loading
Loading