|
3 | 3 | import com.faforever.api.config.FafApiProperties; |
4 | 4 | import lombok.SneakyThrows; |
5 | 5 | import lombok.extern.slf4j.Slf4j; |
| 6 | +import org.apache.commons.codec.DecoderException; |
| 7 | +import org.apache.commons.codec.binary.Hex; |
6 | 8 | import org.kohsuke.github.GHEventPayload; |
7 | 9 | import org.kohsuke.github.GHEventPayload.Deployment; |
8 | 10 | import org.kohsuke.github.GHEventPayload.Push; |
|
16 | 18 | import org.springframework.web.bind.annotation.RestController; |
17 | 19 |
|
18 | 20 | import javax.crypto.spec.SecretKeySpec; |
19 | | -import javax.xml.bind.DatatypeConverter; |
| 21 | +import java.io.IOException; |
20 | 22 | import java.io.StringReader; |
21 | 23 | import java.nio.charset.StandardCharsets; |
22 | 24 |
|
@@ -55,18 +57,16 @@ public void onPush(@RequestBody String body, |
55 | 57 | } |
56 | 58 | } |
57 | 59 |
|
58 | | - @SneakyThrows |
59 | | - private <T extends GHEventPayload> T parseEvent(@RequestBody String body, Class<T> type) { |
| 60 | + private <T extends GHEventPayload> T parseEvent(@RequestBody String body, Class<T> type) throws IOException { |
60 | 61 | return gitHub.parseEventPayload(new StringReader(body), type); |
61 | 62 | } |
62 | 63 |
|
63 | | - @SneakyThrows |
64 | | - private void verifyRequest(String payload, String signature) { |
| 64 | + private void verifyRequest(String payload, String signature) throws DecoderException { |
65 | 65 | String secret = apiProperties.getGitHub().getWebhookSecret(); |
66 | 66 | MacSigner macSigner = new MacSigner(HMAC_SHA1, new SecretKeySpec(secret.getBytes(StandardCharsets.US_ASCII), HMAC_SHA1)); |
67 | 67 |
|
68 | 68 | byte[] content = payload.getBytes(StandardCharsets.US_ASCII); |
69 | 69 | // Signature starts with "sha1=" |
70 | | - macSigner.verify(content, DatatypeConverter.parseHexBinary(signature.substring(5))); |
| 70 | + macSigner.verify(content, Hex.decodeHex(signature.substring(5))); |
71 | 71 | } |
72 | 72 | } |
0 commit comments