the signature base created in the verify method of the AbstractJwtSigner did not match how the Jwt.getSignatureBase creates the signature base. also, modified the testGenerateHmacSignature to exercise
parent
267f1b2de3
commit
6c8661f3ad
|
@ -70,7 +70,7 @@ public abstract class AbstractJwtSigner implements JwtSigner {
|
||||||
String c64 = parts.get(1);
|
String c64 = parts.get(1);
|
||||||
String s64 = parts.get(2);
|
String s64 = parts.get(2);
|
||||||
|
|
||||||
String expectedSignature = generateSignature(h64 + "." + c64 + ".");
|
String expectedSignature = generateSignature(h64 + "." + c64);
|
||||||
|
|
||||||
return Strings.nullToEmpty(s64).equals(Strings.nullToEmpty(expectedSignature));
|
return Strings.nullToEmpty(s64).equals(Strings.nullToEmpty(expectedSignature));
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
||||||
|
|
||||||
public static final String DEFAULT_PASSPHRASE = "changeit";
|
public static final String DEFAULT_PASSPHRASE = "changeit";
|
||||||
|
|
||||||
public static final String DEFAULT_ALGORITHM = JwsAlgorithm.HS256.toString();
|
public static final String DEFAULT_ALGORITHM = JwsAlgorithm.HS256
|
||||||
|
.toString();
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(HmacSigner.class);
|
private static Log logger = LogFactory.getLog(HmacSigner.class);
|
||||||
|
|
||||||
|
@ -49,7 +50,8 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
||||||
*/
|
*/
|
||||||
public HmacSigner(byte[] passphraseAsRawBytes)
|
public HmacSigner(byte[] passphraseAsRawBytes)
|
||||||
throws NoSuchAlgorithmException {
|
throws NoSuchAlgorithmException {
|
||||||
this(DEFAULT_ALGORITHM, new String(passphraseAsRawBytes, Charset.forName("UTF-8")));
|
this(DEFAULT_ALGORITHM, new String(passphraseAsRawBytes,
|
||||||
|
Charset.forName("UTF-8")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +74,8 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
||||||
*/
|
*/
|
||||||
public HmacSigner(String algorithmName, byte[] passphraseAsRawBytes)
|
public HmacSigner(String algorithmName, byte[] passphraseAsRawBytes)
|
||||||
throws NoSuchAlgorithmException {
|
throws NoSuchAlgorithmException {
|
||||||
this(algorithmName, new String(passphraseAsRawBytes, Charset.forName("UTF-8")));
|
this(algorithmName, new String(passphraseAsRawBytes,
|
||||||
|
Charset.forName("UTF-8")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,12 +104,13 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
|
||||||
mac = Mac.getInstance(JwsAlgorithm.getByName(super.getAlgorithm()).getStandardName());
|
mac = Mac.getInstance(JwsAlgorithm.getByName(super.getAlgorithm())
|
||||||
|
.getStandardName());
|
||||||
|
|
||||||
logger.debug(JwsAlgorithm.getByName(getAlgorithm()).getStandardName() + " ECDSA Signer ready for business");
|
logger.debug(JwsAlgorithm.getByName(getAlgorithm()).getStandardName()
|
||||||
|
+ " ECDSA Signer ready for business");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
@ -121,7 +125,8 @@ public class HmacSigner extends AbstractJwtSigner implements InitializingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mac.init(new SecretKeySpec(getPassphrase().getBytes(), mac.getAlgorithm()));
|
mac.init(new SecretKeySpec(getPassphrase().getBytes(), mac
|
||||||
|
.getAlgorithm()));
|
||||||
|
|
||||||
mac.update(signatureBase.getBytes("UTF-8"));
|
mac.update(signatureBase.getBytes("UTF-8"));
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException e) {
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class JwtTest {
|
||||||
|
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
assertThat(jwt.getSignature(), equalTo(signature));
|
assertThat(jwt.getSignature(), equalTo(signature));
|
||||||
|
assertThat(signer.verify(actual), equalTo(true));
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue