/spring-hmac-rest-verify

spring-hmac-rest-verify

Primary LanguageJavaMIT LicenseMIT

spring-hmac-rest-verify

Another spring HMAC authentication filter for RESTfull webservice example.

Support http method: GET, HEAD, POST, PUT, DELETE, support Content-Type: application/x-www-form-urlencoded, application/json

You can define the NONCE, ACCESS-KEY, AUTHORIZATION header as follow, also can define the server.scheme, server.host, server.port.

hmac-verify:
  header:
    nonce: nonce
    access-key: accesskey
    authorization: authorization
  server:
    scheme: http
    host: localhost
    port: 8080

Both client and server digest of the following string:

METHOD\n
SCHEME\n
HOST\n
PATH\n
QUERY\n
CONTENT-TYPE\n
PAYLOAD\n
NONCE
  • METHOD: http method, such as GET, POST
  • SCHEME: http or https
  • HOST: localhost or other domain name.
  • PATH: http uri
  • QUERY: http query string
  • CONTENT-TYPE: content-type, support application/x-www-form-urlencoded or application/json
  • PAYLOAD: form format or json format
  • NONCE: nonce

main code

See the package io.github.qyvlik.springhmacrestverify.modules.hmac.

  • CachingRequestFilter : read the payload from request, so you don't need sorting the form-data.
  • HmacSignature: build hmac signature from HttpServletRequestWrapper.
  • HmacVerifyHelper: verify the client signature

example

server side

  • HmacVerifyHelper: verify the client signature, you can consult it for you own server.
  • CredentialsProviderMapImpl: simple provider for access-key, secret-key.

client side by okhttp

  • OkHTTPHMACInterceptor: okhttp interceptor for hmac
  • postman-pre.js: postman hmac signature pre-script

test case

See more test cases in SpringHmacRestVerifyApplicationTests.java.

same code

kpavlov/spring-hmac-rest

ref

spring boot 学习笔记(5) 解决HttpServletRequest inputStream只能读取一次的问题

springboot-拦截器-过滤器-Required request body is missing 异常

spring boot 配置Filter过滤器方法总结

SpringMVC 中 request.getInputStream() 为空解惑

HTTP 请求方法

HTTP请求方法:GET、HEAD、POST、PUT、DELETE、CONNECT、OPTIONS、TRACE

Spring security not calling my custom authentication filter when running JUnit tests

使用了https后,还有必要对数据进行签名来确保数据没有被篡改吗?