Skip to content

Commit

Permalink
Merge pull request #8 from lime-company/fix-possession
Browse files Browse the repository at this point in the history
Add check for possession factor on signature validation failure count update
  • Loading branch information
Petr Dvořák authored Aug 8, 2017
2 parents c224644 + c967e89 commit 56e300f
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.getlime.security.powerauth.app.server.repository.model.entity.ApplicationVersionEntity;
import io.getlime.security.powerauth.app.server.service.util.ModelUtil;
import io.getlime.security.powerauth.crypto.lib.config.PowerAuthConfiguration;
import io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes;
import io.getlime.security.powerauth.crypto.server.keyfactory.PowerAuthServerKeyFactory;
import io.getlime.security.powerauth.crypto.server.signature.PowerAuthServerSignature;
import io.getlime.security.powerauth.provider.CryptoProviderUtil;
Expand Down Expand Up @@ -115,10 +116,12 @@ public VerifySignatureResponse verifySignature(String activationId, String signa
activation.setCounter(activation.getCounter() + 1);

// Update failed attempts and block the activation, if necessary
activation.setFailedAttempts(activation.getFailedAttempts() + 1);
Long remainingAttempts = (activation.getMaxFailedAttempts() - activation.getFailedAttempts());
if (remainingAttempts <= 0) {
activation.setActivationStatus(ActivationStatus.BLOCKED);
if (notPossessionFactorSignature(signatureType)) {
activation.setFailedAttempts(activation.getFailedAttempts() + 1);
Long remainingAttempts = (activation.getMaxFailedAttempts() - activation.getFailedAttempts());
if (remainingAttempts <= 0) {
activation.setActivationStatus(ActivationStatus.BLOCKED);
}
}

// Update the last used date
Expand Down Expand Up @@ -177,7 +180,9 @@ public VerifySignatureResponse verifySignature(String activationId, String signa
activation.setCounter(lowestValidCounter + 1);

// Reset failed attempt count
activation.setFailedAttempts(0L);
if (notPossessionFactorSignature(signatureType)) {
activation.setFailedAttempts(0L);
}

// Update the last used date
activation.setTimestampLastUsed(currentTimestamp);
Expand All @@ -202,9 +207,11 @@ public VerifySignatureResponse verifySignature(String activationId, String signa
// Increment the activation record counter
activation.setCounter(activation.getCounter() + 1);

// Update failed attempts and block the activation, if
// necessary
activation.setFailedAttempts(activation.getFailedAttempts() + 1);
// Update failed attempts and block the activation, if necessary
if (notPossessionFactorSignature(signatureType)) {
activation.setFailedAttempts(activation.getFailedAttempts() + 1);
}

Long remainingAttempts = (activation.getMaxFailedAttempts() - activation.getFailedAttempts());
if (remainingAttempts <= 0) {
activation.setActivationStatus(ActivationStatus.BLOCKED);
Expand Down Expand Up @@ -271,4 +278,8 @@ public VerifySignatureResponse verifySignature(String activationId, String signa
}
}

private boolean notPossessionFactorSignature(String signatureType) {
return signatureType != null && !signatureType.equals(PowerAuthSignatureTypes.POSSESSION.toString());
}

}

0 comments on commit 56e300f

Please sign in to comment.