Skip to content

Commit

Permalink
chore(deps): bump org.jlleitschuh.gradle.ktlint from 11.6.1 to 12.1.1 (
Browse files Browse the repository at this point in the history
…#136)

Bumps org.jlleitschuh.gradle.ktlint from 11.6.1 to 12.1.1.


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=org.jlleitschuh.gradle.ktlint&package-manager=gradle&previous-version=11.6.1&new-version=12.1.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

> **Note**
> Automatic rebases have been disabled on this pull request as it has been open for over 30 days.
  • Loading branch information
dependabot[bot] authored Jul 25, 2024
1 parent bc2e595 commit 43b6754
Show file tree
Hide file tree
Showing 13 changed files with 1,098 additions and 943 deletions.
19 changes: 10 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
// Apply the java-library plugin for API and implementation separation.
`java-library`

id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
id("org.jlleitschuh.gradle.ktlint") version "12.1.1"

jacoco

Expand Down Expand Up @@ -104,9 +104,10 @@ tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true
freeCompilerArgs = freeCompilerArgs + arrayOf(
"-opt-in=kotlin.RequiresOptIn"
)
freeCompilerArgs = freeCompilerArgs +
arrayOf(
"-opt-in=kotlin.RequiresOptIn",
)
}
}

Expand All @@ -129,7 +130,7 @@ publishing {
pom {
name.set(rootProject.name)
description.set(
"JVM implementation of file-based Private and Public Key Stores for Awala"
"JVM implementation of file-based Private and Public Key Stores for Awala",
)
url.set("https://github.com/relaycorp/awala-keystore-file-jvm")
developers {
Expand All @@ -146,10 +147,10 @@ publishing {
}
scm {
connection.set(
"scm:git:https://github.com/relaycorp/awala-keystore-file-jvm.git"
"scm:git:https://github.com/relaycorp/awala-keystore-file-jvm.git",
)
developerConnection.set(
"scm:git:https://github.com/relaycorp/awala-keystore-file-jvm.git"
"scm:git:https://github.com/relaycorp/awala-keystore-file-jvm.git",
)
url.set("https://github.com/relaycorp/awala-keystore-file-jvm")
}
Expand All @@ -171,7 +172,7 @@ nexusPublishing {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"),
)
username.set(System.getenv("MAVEN_USERNAME"))
password.set(System.getenv("MAVEN_PASSWORD"))
Expand All @@ -183,7 +184,7 @@ tasks.publish {
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
version.set("0.42.1")
version.set("1.3.1")
}

gradleEnterprise {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ import java.time.ZoneId
import java.time.ZonedDateTime
import tech.relaycorp.relaynet.keystores.CertificateStore

public class FileCertificateStore(keystoreRoot: FileKeystoreRoot) : CertificateStore() {

public class FileCertificateStore(
keystoreRoot: FileKeystoreRoot,
) : CertificateStore() {
@Suppress("MemberVisibilityCanBePrivate")
public val rootDirectory: File = keystoreRoot.directory.resolve("certificate")

override suspend fun saveData(
subjectId: String,
leafCertificateExpiryDate: ZonedDateTime,
certificationPathData: ByteArray,
issuerId: String
issuerId: String,
) {
val expirationTimestamp = leafCertificateExpiryDate.toTimestamp()
val dataDigest = certificationPathData.toDigest()
val certFile = getNodeSubdirectory(subjectId, issuerId).resolve(
"$expirationTimestamp-$dataDigest"
)
val certFile =
getNodeSubdirectory(subjectId, issuerId).resolve(
"$expirationTimestamp-$dataDigest",
)
saveCertificationFile(certFile, certificationPathData)
}

override suspend fun retrieveData(
subjectId: String,
issuerId: String
issuerId: String,
): List<ByteArray> {
val certificateFiles =
getNodeSubdirectory(subjectId, issuerId).listFiles()
Expand All @@ -57,22 +59,28 @@ public class FileCertificateStore(keystoreRoot: FileKeystoreRoot) : CertificateS
}

@Throws(FileKeystoreException::class)
override fun delete(subjectId: String, issuerId: String) {
override fun delete(
subjectId: String,
issuerId: String,
) {
val deletionSucceeded =
getNodeSubdirectory(subjectId, issuerId).deleteRecursively()
if (!deletionSucceeded) {
throw FileKeystoreException(
"Failed to delete node directory for $subjectId"
"Failed to delete node directory for $subjectId",
)
}
}

private fun saveCertificationFile(certFile: File, serialization: ByteArray) {
private fun saveCertificationFile(
certFile: File,
serialization: ByteArray,
) {
val parentDirectory = certFile.parentFile
val wereDirectoriesCreated = parentDirectory.mkdirs()
if (!wereDirectoriesCreated && !parentDirectory.exists()) {
throw FileKeystoreException(
"Failed to create address directory for certification files"
"Failed to create address directory for certification files",
)
}
try {
Expand All @@ -85,35 +93,34 @@ public class FileCertificateStore(keystoreRoot: FileKeystoreRoot) : CertificateS
}
}

private fun retrieveData(file: File): ByteArray {
return try {
private fun retrieveData(file: File): ByteArray =
try {
FileInputStream(file).use { it.readBytes() }
} catch (exc: IOException) {
throw FileKeystoreException("Failed to read certification file", exc)
}
}

private fun ZonedDateTime.toTimestamp() =
toInstant().toEpochMilli()
private fun ZonedDateTime.toTimestamp() = toInstant().toEpochMilli()

private fun Long.toZonedDateTime() =
ZonedDateTime.ofInstant(Instant.ofEpochMilli(this), ZoneId.of("UTC"))

private fun File.getExpiryDateFromName(): ZonedDateTime =
name.split("-")
name
.split("-")
.first()
.toLongOrNull()
?.toZonedDateTime()
?: throw FileKeystoreException("Invalid certificate file name: $name")

private fun getNodeSubdirectory(
subjectId: String,
issuerId: String
) =
rootDirectory.resolve(issuerId).resolve(subjectId)
issuerId: String,
) = rootDirectory.resolve(issuerId).resolve(subjectId)
}

internal fun ByteArray.toDigest() =
MessageDigest.getInstance("SHA-256")
MessageDigest
.getInstance("SHA-256")
.digest(this)
.joinToString("") { "%02x".format(it) }
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ package tech.relaycorp.awala.keystores.file

import tech.relaycorp.relaynet.keystores.KeyStoreBackendException

public class FileKeystoreException(message: String, cause: Throwable? = null) :
KeyStoreBackendException(message, cause)
public class FileKeystoreException(
message: String,
cause: Throwable? = null,
) : KeyStoreBackendException(message, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ package tech.relaycorp.awala.keystores.file

import java.io.File

public class FileKeystoreRoot @Throws(FileKeystoreException::class) constructor(
internal val directory: File
) {
init {
if (directory.exists()) {
if (!directory.isDirectory) {
throw FileKeystoreException("Root '${directory.path}' isn't a directory")
}
public class FileKeystoreRoot
@Throws(FileKeystoreException::class)
constructor(
internal val directory: File,
) {
init {
if (directory.exists()) {
if (!directory.isDirectory) {
throw FileKeystoreException("Root '${directory.path}' isn't a directory")
}

// Check permissions (read and write operations are always allowed on Windows)
if (!directory.canRead()) {
throw FileKeystoreException("Root '${directory.path}' isn't readable")
}
if (!directory.canWrite()) {
throw FileKeystoreException("Root '${directory.path}' isn't writable")
// Check permissions (read and write operations are always allowed on Windows)
if (!directory.canRead()) {
throw FileKeystoreException("Root '${directory.path}' isn't readable")
}
if (!directory.canWrite()) {
throw FileKeystoreException("Root '${directory.path}' isn't writable")
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import java.io.OutputStream
import tech.relaycorp.relaynet.keystores.PrivateKeyData
import tech.relaycorp.relaynet.keystores.PrivateKeyStore

public abstract class FilePrivateKeyStore(keystoreRoot: FileKeystoreRoot) : PrivateKeyStore() {
public abstract class FilePrivateKeyStore(
keystoreRoot: FileKeystoreRoot,
) : PrivateKeyStore() {
@Suppress("MemberVisibilityCanBePrivate")
public val rootDirectory: File = keystoreRoot.directory.resolve("private")

@Suppress("BlockingMethodInNonBlockingContext")
override suspend fun saveIdentityKeyData(
nodeId: String,
keyData: PrivateKeyData
keyData: PrivateKeyData,
) {
val keyFile = getNodeSubdirectory(nodeId).resolve("identity")
saveKeyFile(keyFile, keyData.privateKeyDer)
Expand Down Expand Up @@ -51,7 +53,10 @@ public abstract class FilePrivateKeyStore(keystoreRoot: FileKeystoreRoot) : Priv
return retrieveKeyData(boundKeyPath) ?: retrieveKeyData(unboundKeyPath)
}

private fun saveKeyFile(keyFile: File, serialization: ByteArray) {
private fun saveKeyFile(
keyFile: File,
serialization: ByteArray,
) {
val parentDirectory = keyFile.parentFile
val wereDirectoriesCreated = parentDirectory.mkdirs()
if (!wereDirectoriesCreated && !parentDirectory.exists()) {
Expand Down Expand Up @@ -82,18 +87,19 @@ public abstract class FilePrivateKeyStore(keystoreRoot: FileKeystoreRoot) : Priv
private fun resolveSessionKeyFile(
nodeId: String,
keyId: String,
peerId: String?
peerId: String?,
): File {
val nodeSubdirectory = getNodeSubdirectory(nodeId).resolve("session")
val parentDirectory = if (peerId != null)
nodeSubdirectory.resolve(peerId)
else
nodeSubdirectory
val parentDirectory =
if (peerId != null) {
nodeSubdirectory.resolve(peerId)
} else {
nodeSubdirectory
}
return parentDirectory.resolve(keyId)
}

private fun getNodeSubdirectory(nodeId: String) =
rootDirectory.resolve(nodeId)
private fun getNodeSubdirectory(nodeId: String) = rootDirectory.resolve(nodeId)

private fun getNodeDirectories() = rootDirectory.listFiles()?.filter(File::isDirectory)

Expand All @@ -116,14 +122,18 @@ public abstract class FilePrivateKeyStore(keystoreRoot: FileKeystoreRoot) : Priv
* Delete all the private keys associated with [peerId].
*/
@Throws(FileKeystoreException::class)
override suspend fun deleteBoundSessionKeys(nodeId: String, peerId: String) {
val deletionSucceeded = getNodeSubdirectory(nodeId)
.resolve("session")
.resolve(peerId)
.deleteRecursively()
override suspend fun deleteBoundSessionKeys(
nodeId: String,
peerId: String,
) {
val deletionSucceeded =
getNodeSubdirectory(nodeId)
.resolve("session")
.resolve(peerId)
.deleteRecursively()
if (!deletionSucceeded) {
throw FileKeystoreException(
"Failed to delete session keys for node $nodeId and peer $peerId"
"Failed to delete session keys for node $nodeId and peer $peerId",
)
}
}
Expand Down
Loading

0 comments on commit 43b6754

Please sign in to comment.