JWT 安全性
启用JWT安全特性,Kapua必须加载一对RSA密钥(公钥和私钥)。
使用随机生成密钥
Kapua默认通过系统参数authentication.session.jwt.private.key
和authentication.session.jwt.public.key
指定路径查找密钥(见后文)。如果密钥文件无法找到,Kapua将抛出错误。如果参数未设置,Kapua将自动创建随机密钥和公钥。
使用自定义密钥
使用 OpenSSL 可以生成自定义RSA密钥,包括私钥和公钥。命令如下:
openssl genrsa -out rsa-2048bit-key-pair.pem 2048
openssl pkcs8 -topk8 -inform pem -in rsa-2048bit-key-pair.pem -outform pem -nocrypt -out private.key
openssl rsa -in rsa-2048bit-key-pair.pem -pubout -out public.key
密钥必须为 PEM PKCS8 不加密格式(目前不支持加密密钥)。
密钥创建后,需要在系统参数authentication.session.jwt.private.key
和 authentication.session.jwt.public.key
中指明路径,可以通过 -D 启动参数方式,或手动修改service/security/shiro/src/main/resources/kapua-authentication-setting.properties
。