-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP getting rid to hardcoded key in the code. Now it is in the local …
…sample config
- Loading branch information
Showing
10 changed files
with
84 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 21 additions & 4 deletions
25
...m/vauthenticator/server/keys/adapter/local/BouncyCastleKeyGeneratorMasterKeyRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
package com.vauthenticator.server.keys.adapter.local | ||
|
||
import com.vauthenticator.server.keys.domain.MasterKid | ||
val toSha256 = "CrZKwm8YWGN5xYeKlaC9vXUBAFFzKYsqfaOFSrrqQgA=" | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Profile | ||
|
||
class BouncyCastleKeyGeneratorMasterKeyRepository { | ||
|
||
//TODO to improve | ||
class BouncyCastleKeyGeneratorMasterKeyRepository( | ||
val storage: BouncyCastleKeyGeneratorMasterKeyStorage | ||
) { | ||
|
||
fun maskerKeyFor(masterKeyId: MasterKid): String { | ||
return toSha256 | ||
return storage.content[masterKeyId.content()]!! | ||
} | ||
|
||
} | ||
|
||
@Profile("!kms") | ||
@Configuration(proxyBeanMethods = false) | ||
@EnableConfigurationProperties(BouncyCastleKeyGeneratorMasterKeyStorage::class) | ||
class BouncyCastleKeyGeneratorMasterKeyRepositoryConfig { | ||
|
||
} | ||
|
||
@ConfigurationProperties(prefix = "key.master-key.storage") | ||
data class BouncyCastleKeyGeneratorMasterKeyStorage(val content: Map<String, String>) { | ||
|
||
} |
29 changes: 18 additions & 11 deletions
29
src/main/kotlin/com/vauthenticator/server/keys/adapter/local/KeyInitJob.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
package com.vauthenticator.server.keys.adapter.local | ||
|
||
import com.vauthenticator.server.keys.domain.KeyPurpose | ||
import com.vauthenticator.server.keys.domain.KeyRepository | ||
import com.vauthenticator.server.keys.domain.KeyType | ||
import com.vauthenticator.server.keys.domain.* | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.ApplicationArguments | ||
import org.springframework.boot.ApplicationRunner | ||
import org.springframework.context.annotation.Profile | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
@Profile("!kms") | ||
class KeyInitJob(private val keyRepository: KeyRepository) : ApplicationRunner { | ||
class KeyInitJob( | ||
@Value("\${key.master-key}") private val maserKid: String, | ||
private val keyStorage: KeyStorage, | ||
private val keyRepository: KeyRepository | ||
) : ApplicationRunner { | ||
|
||
override fun run(args: ApplicationArguments) { | ||
|
||
if (keyStorage.signatureKeys().keys.isEmpty()) { | ||
val kid = keyRepository.createKeyFrom( | ||
masterKid = MasterKid(maserKid), | ||
keyPurpose = KeyPurpose.SIGNATURE, | ||
keyType = KeyType.ASYMMETRIC, | ||
) | ||
println(kid) | ||
} | ||
|
||
override fun run(args: ApplicationArguments?) { | ||
val kid = keyRepository.createKeyFrom( | ||
masterKid = MasterKeyGenrator.aMasterKey, | ||
keyPurpose = KeyPurpose.SIGNATURE, | ||
keyType = KeyType.ASYMMETRIC, | ||
) | ||
println(kid) | ||
} | ||
|
||
} |
8 changes: 0 additions & 8 deletions
8
src/main/kotlin/com/vauthenticator/server/keys/adapter/local/MasterKeyGenrator.kt
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/test/kotlin/com/vauthenticator/server/keys/adapter/local/BouncyCastleKeyDecrypterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.vauthenticator.server.keys.adapter.local | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
|
||
// TODO | ||
class BouncyCastleKeyDecrypterTest { | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...uthenticator/server/keys/adapter/local/BouncyCastleKeyGeneratorMasterKeyRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.vauthenticator.server.keys.adapter.local | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
|
||
//todo | ||
class BouncyCastleKeyGeneratorMasterKeyRepositoryTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...est/kotlin/com/vauthenticator/server/keys/adapter/local/KeyCryptographicOperationsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.vauthenticator.server.keys.adapter.local | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
|
||
//todo | ||
class KeyCryptographicOperationsTest |