Skip to content

Commit

Permalink
MOSIP-25197: NullPointer Exception for Sonarcloud (#314) (#315)
Browse files Browse the repository at this point in the history
* NullPointer Exception for Sonarcloud



* MOSIP-25197: NullPointer Exception



* MOSIP-25197: NullPointer Exception for Sonarcloud



---------

Signed-off-by: nagendra0721 <[email protected]>
  • Loading branch information
nagendra0721 authored Oct 16, 2024
1 parent 3b8ffea commit 83d1076
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ public byte[] encrypt(byte[] publicKey, byte[] dataToEncrypt) {
public boolean validateSignature(ClientType clientType, byte[] publicKey, byte[] signature, byte[] actualData) {
clientType = isTPMKey(publicKey) ? ClientType.TPM : clientType;

switch (clientType == null ? clientType.LOCAL : clientType) {
switch (clientType == null ? ClientType.LOCAL : clientType) {
case TPM:
return TPMClientCryptoServiceImpl.validateSignature(publicKey, signature, actualData);
case ANDROID:
return AndroidClientCryptoServiceImpl.validateSignature(publicKey, signature, actualData);
default:
LOGGER.warn("USING LOCAL CLIENT SECURITY USED TO SIGN DATA, IGNORING IF THIS IS NON-PROD ENV");
return LocalClientCryptoServiceImpl.validateSignature(publicKey, signature, actualData);
}
LOGGER.warn("USING LOCAL CLIENT SECURITY USED TO SIGN DATA, IGNORE IF THIS IS NON-PROD ENV");
return LocalClientCryptoServiceImpl.validateSignature(publicKey, signature, actualData);
}

public byte[] encrypt(ClientType clientType, byte[] publicKey, byte[] dataToEncrypt) {
Expand All @@ -134,7 +135,7 @@ public byte[] encrypt(ClientType clientType, byte[] publicKey, byte[] dataToEncr
byte[] cipher = cryptoCore.symmetricEncrypt(secretKey, dataToEncrypt, iv, aad);

byte[] encryptedSecretKey = null;
switch (clientType == null ? clientType.LOCAL : clientType) {
switch (clientType == null ? ClientType.LOCAL : clientType) {
case TPM:
encryptedSecretKey = TPMClientCryptoServiceImpl.asymmetricEncrypt(publicKey, secretKey.getEncoded());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,13 @@ public Argon2GenerateHashResponseDto generateArgon2Hash(Argon2GenerateHashReques
if (!cryptomanagerUtil.isDataValid(saltData)) {
SecretKey aesKey = (SecretKey) saltGenParamsCache.get(CryptomanagerConstant.CACHE_AES_KEY);
AtomicLong intCounter = (AtomicLong) saltGenParamsCache.get(CryptomanagerConstant.CACHE_INT_COUNTER);
long saltInput = intCounter.getAndIncrement();
if (Objects.isNull(intCounter)) {
if(secureRandom == null)
secureRandom = new SecureRandom();
intCounter = new AtomicLong(secureRandom.nextLong());
}
long saltInput = intCounter.getAndIncrement();

saltGenParamsCache.put(CryptomanagerConstant.CACHE_INT_COUNTER, intCounter);
saltBytes = getSaltBytes(getLongBytes(saltInput), aesKey);
saltData = CryptoUtil.encodeToURLSafeBase64(saltBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public void storeKeyInAlias(String applicationId, LocalDateTime timeStamp, Strin
*
* @param alias alias
* @param masterAlias masterAlias
* @param publicKey publicKey
* @param encryptedPrivateKey encryptedPrivateKey
*/
public void storeKeyInDBStore(String alias, String masterAlias, String certificateData, String encryptedPrivateKey) {
Expand All @@ -209,10 +208,12 @@ public void storeKeyInDBStore(String alias, String masterAlias, String certifica
* referenceId with key "keyAlias"; and a list of all keyalias with
* matching timestamp with key "currentKeyAlias"
*/
@SuppressWarnings({"JAVA:S2221","JAVA:S2699", "null"}) //Suppress the potential NullPointer exception
public Map<String, List<KeyAlias>> getKeyAliases(String applicationId, String referenceId, LocalDateTime timeStamp) {
LOGGER.info(KeymanagerConstant.SESSIONID, KeymanagerConstant.EMPTY, KeymanagerConstant.EMPTY, KeymanagerConstant.GETALIAS);
Map<String, List<KeyAlias>> hashmap = new HashMap<>();
String appIdRefIdKey = applicationId + KeymanagerConstant.APP_REF_ID_SEP + referenceId;

List<KeyAlias> keyAliases = keyAliasCache.get(appIdRefIdKey).stream()
.sorted((alias1, alias2) -> alias1.getKeyGenerationTime().compareTo(alias2.getKeyGenerationTime()))
.collect(Collectors.toList());
Expand Down

0 comments on commit 83d1076

Please sign in to comment.