use of com.github.zhenwei.core.asn1.x509.DigestInfo in project jss by dogtagpki.
the class PFX method verifyAuthSafes.
/**
* Verifies the HMAC on the authenticated safes, using the password
* provided.
*
* @param password The password to use to compute the HMAC.
* @param reason If supplied, the reason for the verification failure
* will be appended to this StringBuffer.
* @return true if the MAC verifies correctly, false otherwise. If
* this PFX does not contain a MacData, returns false.
*/
public boolean verifyAuthSafes(Password password, StringBuffer reason) throws NotInitializedException {
try {
if (reason == null) {
// this is just so we don't get a null pointer exception
reason = new StringBuffer();
}
if (macData == null) {
reason.append("No MAC present in PFX");
return false;
}
if (encodedAuthSafes == null) {
// We weren't decoded from a template, we were constructed,
// so just verify the encoding of the AuthSafes provided to
// the constructor.
encodedAuthSafes = ASN1Util.encode(authSafes);
}
// create a new MacData based on the encoded Auth Safes
DigestInfo macDataMac = macData.getMac();
MacData testMac = new MacData(password, macData.getMacSalt().toByteArray(), macData.getMacIterationCount().intValue(), encodedAuthSafes);
if (testMac.getMac().equals(macDataMac)) {
return true;
} else {
reason.append("Digests do not match");
return false;
}
} catch (java.security.DigestException e) {
e.printStackTrace();
reason.append("A DigestException occurred");
return false;
} catch (TokenException e) {
reason.append("A TokenException occurred");
return false;
} catch (CharConversionException e) {
reason.append("An exception occurred converting the password from chars to bytes");
return false;
}
}
Aggregations