Skip to content

Commit

Permalink
Fix #424: Coverity: Dereference null return value (#425)
Browse files Browse the repository at this point in the history
* Fix #424: Coverity: Dereference null return value
  • Loading branch information
banterCZ authored Feb 26, 2024
1 parent e58ecee commit 1a944b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ public void processResponse(StepContext<M, R> stepContext) throws Exception { }
* @throws Exception when an error during response processing occurred
*/
public final void processResponse(StepContext<M, R> stepContext, byte[] responseBody, Class<R> responseObjectClass) throws Exception {
R responseBodyObject = HttpUtil.fromBytes(responseBody, responseObjectClass);
ResponseEntity<R> responseEntity = ResponseEntity.of(Optional.of(responseBodyObject));
final R responseBodyObject = HttpUtil.fromBytes(responseBody, responseObjectClass);
final ResponseEntity<R> responseEntity = ResponseEntity.ofNullable(responseBodyObject);
addResponseContext(stepContext, responseEntity);
processResponse(stepContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -144,7 +145,16 @@ public void processResponse(StepContext<GetStatusStepModel, ObjectResponse<Activ
final Map<String, Object> customObject = responseObject.getCustomObject();
byte[] challenge = (byte[]) stepContext.getAttributes().get(ATTRIBUTE_CHALLENGE);

final ActivationStatusBlobInfo statusBlobRaw = ACTIVATION.getStatusFromEncryptedBlob(cStatusBlob, challenge, cStatusBlobNonce, resultStatusObject.getTransportMasterKeyObject());
final SecretKey transportMasterKey = resultStatusObject.getTransportMasterKeyObject();
if (transportMasterKey == null) {
stepContext.getStepLogger().writeError(
getStep().id() + "-failed",
"Get Status Failed",
"transportMasterKey is null");
return;
}

final ActivationStatusBlobInfo statusBlobRaw = ACTIVATION.getStatusFromEncryptedBlob(cStatusBlob, challenge, cStatusBlobNonce, transportMasterKey);
final ExtendedActivationStatusBlobInfo statusBlob = ExtendedActivationStatusBlobInfo.copy(statusBlobRaw);

final Map<String, Object> objectMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,15 @@ public void processResponse(StepContext<VaultUnlockStepModel, EciesEncryptedResp

ResultStatusObject resultStatusObject = stepContext.getModel().getResultStatus();

SecretKey transportMasterKey = resultStatusObject.getTransportMasterKeyObject();
final SecretKey transportMasterKey = resultStatusObject.getTransportMasterKeyObject();
if (transportMasterKey == null) {
stepContext.getStepLogger().writeError(
getStep().id() + "-vault-unlock-failed",
"Vault Unlock Failed",
"transportMasterKey is null");
return;
}

byte[] encryptedDevicePrivateKeyBytes = resultStatusObject.getEncryptedDevicePrivateKeyBytes();

byte[] encryptedVaultEncryptionKey = Base64.getDecoder().decode(responsePayload.getEncryptedVaultEncryptionKey());
Expand Down

0 comments on commit 1a944b2

Please sign in to comment.