diff --git a/.gitignore b/.gitignore index 5a979af..07528d8 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ out/ ### Kotlin ### .kotlin + +### Cert ### +/keys/ diff --git a/README.md b/README.md index 68cc680..f272003 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,10 @@ Classes crafted, identities bestowed, Each device recorded, their functions unfo | name | required | info | |------------------------|----------|-------------------------| | spring.profiles.active | * | Spring Boot environment | -| spring.r2dbc.url | * | Postgreas host url | -| spring.r2dbc.username | * | Postgreas username | -| spring.r2dbc.password | ** | Postgreas password | +| spring.r2dbc.url | * | Postgres host url | +| spring.r2dbc.username | * | Postgres username | +| spring.r2dbc.password | ** | Postgres password | +| jwt.private-key | | JWT private cert | Required: * can be stored as text, and ** need to be stored as secret. @@ -17,7 +18,23 @@ Required: * can be stored as text, and ** need to be stored as secret. Run `release.sh` script from `master` branch. -## Development Configuration +## Development Information + +### Generate Private and Public RSA Key + +OpenSSL Project is dedicated to providing a simple installation of OpenSSL for Microsoft Windows. [Download](https://slproweb.com/products/Win32OpenSSL.html) + +Generate an RSA private key, of size 2048, and output it to a file named `private_key.pem` in to `./keys` + +```shell +openssl genrsa -out private_key.pem 2048 +``` + +Extract the public key from `private_key.pem` from `./keys`, and output it to a file named `public_key.pem` in to `./keys` + +```shell +openssl rsa -in private_key.pem -pubout -out public_key.pem +``` ### Global gradle properties diff --git a/build.gradle.kts b/build.gradle.kts index 6a86613..ea56b20 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,7 @@ plugins { dependencies { implementation(hlaeja.com.fasterxml.jackson.module.kotlin) + implementation(hlaeja.jjwt.api) implementation(hlaeja.kotlin.logging) implementation(hlaeja.kotlin.reflect) implementation(hlaeja.kotlinx.coroutines) @@ -16,6 +17,8 @@ dependencies { implementation(hlaeja.org.springframework.springboot.r2dbc.starter) implementation(hlaeja.org.springframework.springboot.webflux.starter) + runtimeOnly(hlaeja.jjwt.impl) + runtimeOnly(hlaeja.jjwt.jackson) runtimeOnly(hlaeja.org.postgresql) runtimeOnly(hlaeja.org.postgresql.r2dbc) @@ -30,3 +33,15 @@ dependencies { } group = "ltd.hlaeja" + +tasks { + named("processResources") { + dependsOn("copyPrivateKey") + } + register("copyPrivateKey") { + group = "hlaeja" + from("keys/private_key.pem") + into("${layout.buildDirectory.get()}/resources/main/keys") + onlyIf { file("keys/private_key.pem").exists() } + } +} diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 26fe8e1..1eb3135 100644 --- a/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -19,6 +19,11 @@ "name": "spring.application.build.os.version", "type": "java.lang.String", "description": "Application build os version." + }, + { + "name": "jwt.private-key", + "type": "java.lang.String", + "description": "Jwt private key file." } ] } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4a1d828..d420659 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,6 +10,9 @@ spring: name: "%APP_BUILD_OS_NAME%" version: "%APP_BUILD_OS_VERSION%" +jwt: + private-key: keys/private_key.pem + --- ############################### ### Development environment ### diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 0000000..6fc0193 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,8 @@ +jwt: + private-key: keys/valid-private-key.pem + +spring: + r2dbc: + url: r2dbc:postgresql://placeholder + username: placeholder + password: placeholder