Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
key length error fix
  • Loading branch information
mrFlick72 committed Nov 16, 2024
1 parent b0d617f commit 6f31c0d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion local-environment/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ spring:
password: postgres
config:
activate:
on-profile: experimental_database_persistence
on-profile: default
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import org.springframework.context.annotation.Profile

@Configuration
@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, DataSourceTransactionManagerAutoConfiguration::class, HibernateJpaAutoConfiguration::class])
@Profile("!aws")
@Profile("aws")
class ExcludeDatabaseConfig

4 changes: 2 additions & 2 deletions src/main/kotlin/com/vauthenticator/server/keys/KeyConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class KeyConfig {
)

@Bean("keyStorage")
@Profile("!aws")
@Profile("aws")
fun dynamoDbKeyStorage(
clock: Clock,
dynamoDbClient: DynamoDbClient,
Expand All @@ -56,7 +56,7 @@ class KeyConfig {
) = DynamoDbKeyStorage(clock, dynamoDbClient, signatureTableName, mfaTableName)

@Bean("keyStorage")
@Profile("aws")
@Profile("!aws")
fun jdbcKeyStorage(jdbcTemplate: JdbcTemplate, clock: Clock) = JdbcKeyStorage(jdbcTemplate, clock)

@Bean("keyRepository")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.vauthenticator.server.keys.domain.MasterKid

class BouncyCastleKeyDecrypter(private val keyCryptographicOperations: KeyCryptographicOperations) : KeyDecrypter {
override fun decryptKey(encrypted: String): String {
return encoder.encode(keyCryptographicOperations.decryptKeyWith(MasterKid(""), encrypted.toByteArray()))
return encoder.encode(keyCryptographicOperations.decryptKeyWith(MasterKeyGenrator.aMasterKey, encrypted.toByteArray()))
.decodeToString()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.vauthenticator.server.keys.adapter.local

import com.vauthenticator.server.extentions.toSha256
import com.vauthenticator.server.keys.domain.MasterKid
val toSha256 = "CrZKwm8YWGN5xYeKlaC9vXUBAFFzKYsqfaOFSrrqQgA="

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class KeyCryptographicOperations(
val key = SecretKeySpec(masterKey, "AES")
val cipher = Cipher.getInstance("AES")
cipher.init(Cipher.ENCRYPT_MODE, key)
return cipher.doFinal(decoder.decode(encodedPlainText))
return cipher.doFinal(encodedPlainText)
}

fun decryptKeyWith(masterKid: MasterKid, encodedEncryptedText: ByteArray): ByteArray {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Service

@Service
@Profile("!aws")
class KeyInitJob(private val keyRepository: KeyRepository) : ApplicationRunner {

override fun run(args: ApplicationArguments?) {
val kid = keyRepository.createKeyFrom(
masterKid = MasterKeyGenrator.aMasterKey,
keyPurpose = KeyPurpose.SIGNATURE,
keyType = KeyType.ASYMMETRIC,
)
println(kid)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.vauthenticator.server.keys.adapter.local

import com.vauthenticator.server.keys.domain.MasterKid

object MasterKeyGenrator {

val aMasterKey = MasterKid("")
}

0 comments on commit 6f31c0d

Please sign in to comment.