Search in sources :

Example 1 with GetSecretsResponse

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

the class SecretManagementService method getKeys.

/**
 * Retrieves the active keys of requested types for a specified 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[]> getKeys(final MessageMetadata messageMetadata, final String deviceIdentification, final List<SecurityKeyType> keyTypes) {
    final GetSecretsRequest request = this.createGetSecretsRequest(deviceIdentification, keyTypes);
    final GetSecretsResponse response = this.secretManagementClient.getSecretsRequest(messageMetadata, request);
    this.validateGetResponse(keyTypes, response);
    return this.convertSoapSecretsToSecretMapByType(response.getTypedSecrets().getTypedSecret());
}
Also used : GetSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse) GetSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsRequest)

Example 2 with GetSecretsResponse

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

the class SecretManagementServiceTest method testGetKeys.

@Test
public void testGetKeys() {
    // SETUP
    final List<SecurityKeyType> keyTypes = Arrays.asList(KEY_TYPE);
    final GetSecretsResponse response = new GetSecretsResponse();
    response.setResult(OsgpResultType.OK);
    response.setTypedSecrets(new TypedSecrets());
    response.getTypedSecrets().getTypedSecret().add(TYPED_SECRET);
    when(this.secretManagementClient.getSecretsRequest(same(messageMetadata), any(GetSecretsRequest.class))).thenReturn(response);
    when(this.decrypterForProtocolAdapterDlms.decrypt(SOAP_SECRET)).thenReturn(UNENCRYPTED_SECRET);
    // EXECUTE
    final Map<SecurityKeyType, byte[]> result = this.secretManagementTestService.getKeys(messageMetadata, DEVICE_IDENTIFICATION, keyTypes);
    // ASSERT
    assertThat(result).isNotNull();
    assertThat(result.size()).isEqualTo(1);
    assertThat(result.keySet().iterator().next()).isEqualTo(KEY_TYPE);
    assertThat(result.values().iterator().next()).isEqualTo(UNENCRYPTED_SECRET);
}
Also used : GetSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse) GetSecretsRequest(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsRequest) TypedSecrets(org.opensmartgridplatform.ws.schema.core.secret.management.TypedSecrets) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) Test(org.junit.jupiter.api.Test)

Example 3 with GetSecretsResponse

use of org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse 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 4 with GetSecretsResponse

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

the class SecretManagementEndpoint method getSecrets.

public GetSecretsResponse getSecrets(final GetSecretsRequest request) throws OsgpException {
    final GetSecretsResponse response = new GetSecretsResponse();
    final SecretTypes soapSecretTypes = request.getSecretTypes();
    final List<SecretType> secretTypeList = this.converter.convertToSecretTypes(soapSecretTypes);
    final List<TypedSecret> typedSecrets = this.secretManagementService.retrieveSecrets(request.getDeviceId(), secretTypeList);
    final TypedSecrets soapTypedSecrets = this.converter.convertToSoapTypedSecrets(typedSecrets);
    response.setTypedSecrets(soapTypedSecrets);
    return response;
}
Also used : GetSecretsResponse(org.opensmartgridplatform.ws.schema.core.secret.management.GetSecretsResponse) 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

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