Search in sources :

Example 1 with GetNewSecretsResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementService method getNewKey.

/**
 * Retrieve a new (not yet activated) key of a certain type for a specified device
 *
 * @param messageMetadata the metadata of the request message
 * @param deviceIdentification the device identification string of the device
 * @param keyType the requested key type
 * @return the key or NULL if not present
 */
public byte[] getNewKey(final MessageMetadata messageMetadata, final String deviceIdentification, final SecurityKeyType keyType) {
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Retrieving new {} for device {}", keyType.name(), deviceIdentification);
    }
    final GetNewSecretsRequest getNewSecretsRequest = this.createGetNewSecretsRequest(deviceIdentification, Arrays.asList(keyType));
    final GetNewSecretsResponse getNewSecretsResponse = this.secretManagementClient.getNewSecretsRequest(messageMetadata, getNewSecretsRequest);
    final List<TypedSecret> typedSecrets = getNewSecretsResponse.getTypedSecrets().getTypedSecret();
    if (typedSecrets.isEmpty()) {
        return null;
    }
    return this.convertSoapSecretsToSecretMapByType(typedSecrets).get(keyType);
}
Also used : GetNewSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse) GetNewSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsRequest) TypedSecret(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret)

Example 2 with GetNewSecretsResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementService method getNewOrActiveKeyPerSecretType.

/**
 * Requests the New key for a specific device identification. Depending on the New key type
 * (Authentication or Encryption) that will be retrieved, the other Active key type
 * (Authentication or Encryption) will be requested. Once both key types are retrieved, this new
 * keypair can be returned for connection with this device.
 *
 * @param messageMetadata the metadata of the request message
 * @param deviceIdentification the device identification string of the device
 * @param keyTypes the requested key types
 * @return the requested keys in a map by key type, with value NULL if not present
 */
public Map<SecurityKeyType, byte[]> getNewOrActiveKeyPerSecretType(final MessageMetadata messageMetadata, final String deviceIdentification, final List<SecurityKeyType> keyTypes) {
    final List<TypedSecret> newKeyPairForConnection = new ArrayList<>();
    final GetNewSecretsRequest getNewSecretsRequest = this.createGetNewSecretsRequest(deviceIdentification, keyTypes);
    final GetNewSecretsResponse getNewSecretsResponse = this.secretManagementClient.getNewSecretsRequest(messageMetadata, getNewSecretsRequest);
    this.validateGetNewResponse(keyTypes, getNewSecretsResponse);
    for (final TypedSecret secretTypeNewKey : getNewSecretsResponse.getTypedSecrets().getTypedSecret()) {
        if (secretTypeNewKey.getSecret() != null && secretTypeNewKey.getSecret().length() > 0) {
            newKeyPairForConnection.add(secretTypeNewKey);
        } else {
            final SecurityKeyType keyTypeActiveKey = SecurityKeyType.fromSecretType(secretTypeNewKey.getType());
            final GetSecretsRequest getSecretsRequest = this.createGetSecretsRequest(deviceIdentification, Arrays.asList(keyTypeActiveKey));
            final GetSecretsResponse getSecretsResponse = this.secretManagementClient.getSecretsRequest(messageMetadata, getSecretsRequest);
            this.validateGetResponse(Arrays.asList(keyTypeActiveKey), getSecretsResponse);
            newKeyPairForConnection.add(getSecretsResponse.getTypedSecrets().getTypedSecret().get(0));
        }
    }
    return this.convertSoapSecretsToSecretMapByType(newKeyPairForConnection);
}
Also used : GetNewSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse) GetSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse) GetSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsRequest) GetNewSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsRequest) ArrayList(java.util.ArrayList) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) TypedSecret(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret)

Example 3 with GetNewSecretsResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse in project open-smart-grid-platform by OSGP.

the class SecretManagementEndpoint method getNewSecrets.

public GetNewSecretsResponse getNewSecrets(final GetNewSecretsRequest request) throws OsgpException {
    final GetNewSecretsResponse response = new GetNewSecretsResponse();
    final SecretTypes soapSecretTypes = request.getSecretTypes();
    final List<SecretType> secretTypeList = this.converter.convertToSecretTypes(soapSecretTypes);
    final List<TypedSecret> typedSecrets = this.secretManagementService.retrieveNewSecrets(request.getDeviceId(), secretTypeList);
    final TypedSecrets soapTypedSecrets = this.converter.convertToSoapTypedSecrets(typedSecrets);
    response.setTypedSecrets(soapTypedSecrets);
    return response;
}
Also used : GetNewSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse) SecretType(org.opensmartgridplatform.secretmanagement.application.domain.SecretType) SecretTypes(org.opensmartgridplatform.ws.schema.core.secret.management.SecretTypes) TypedSecrets(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets) TypedSecret(org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)

Aggregations

GetNewSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsResponse)3 GetNewSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.GetNewSecretsRequest)2 TypedSecret (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecret)2 ArrayList (java.util.ArrayList)1 SecurityKeyType (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)1 SecretType (org.opensmartgridplatform.secretmanagement.application.domain.SecretType)1 TypedSecret (org.opensmartgridplatform.secretmanagement.application.domain.TypedSecret)1 GetSecretsRequest (org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsRequest)1 GetSecretsResponse (org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse)1 SecretTypes (org.opensmartgridplatform.ws.schema.core.secret.management.SecretTypes)1 TypedSecrets (org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets)1