Skip to content

Commit

Permalink
Merge pull request #129 from deltacv/dev
Browse files Browse the repository at this point in the history
4.0.0
  • Loading branch information
serivesmejia authored Nov 28, 2024
2 parents 75d9586 + f52c1a3 commit 6bef9ea
Show file tree
Hide file tree
Showing 61 changed files with 1,154 additions and 226 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.JRELEASER_MAVENCENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
run: ./gradlew -Penv=release :Common:publishToMavenCentral :Vision:publishToMavenCentral :EOCV-Sim:publishToMavenCentral -x test :EOCV-Sim:shadowJar
run: ./gradlew -Penv=release :Common:publishToMavenCentral :Vision:publishToMavenCentral :EOCV-Sim:publishToMavenCentral -x test -x :EOCV-Sim:shadowJar
if: ${{ startsWith(github.ref, 'refs/tags/v') }}

- name: Build release shadow jar with Gradle
Expand Down
17 changes: 17 additions & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
plugins {
id 'kotlin'
id 'signing'
id 'com.github.johnrengelman.shadow'
id "com.vanniktech.maven.publish" version "0.30.0"
}

apply from: '../build.common.gradle'

components.java {
tasks.named("shadowJar").configure {
// only run shadowJar when explicitly specified by the user
// check if user invoked gradle with :shadowJar
enabled = project.gradle.startParameter.taskNames.contains("shadowJar")
}
}

shadowJar {
dependencies {
exclude "nu/pattern/*"
}
}

dependencies {
api "org.openpnp:opencv:$opencv_version"

implementation "com.moandjiezana.toml:toml4j:$toml4j_version"
implementation "info.picocli:picocli:$picocli_version"
implementation "org.slf4j:slf4j-api:$slf4j_version"
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@

package com.github.serivesmejia.eocvsim.util.extension

import com.github.serivesmejia.eocvsim.util.SysUtil
import java.io.File
import java.security.MessageDigest

val appData: File = File(System.getProperty("user.home") + File.separator)

/**
* Operator function to concatenate a string to a file path
*/
operator fun File.plus(str: String): File {
return File(this.absolutePath, str)
}


fun File.fileHash(algorithm: String = "SHA-256"): String {
val messageDigest = MessageDigest.getInstance(algorithm)
messageDigest.update(readBytes())
return SysUtil.byteArray2Hex(messageDigest.digest())
return byteArrayToHex(messageDigest.digest())
}

private val hex = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')

fun byteArrayToHex(bytes: ByteArray): String {
val sb = StringBuilder(bytes.size * 2)
for (b in bytes) {
sb.append(hex[(b.toInt() and 0xF0) shr 4])
sb.append(hex[b.toInt() and 0x0F])
}
return sb.toString()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.serivesmejia.eocvsim.util.extension

import com.github.serivesmejia.eocvsim.util.SysUtil
import java.security.MessageDigest

/**
Expand All @@ -20,5 +19,5 @@ val Any.hashString get() = Integer.toHexString(hashCode())!!
val String.hashString: String get() {
val messageDigest = MessageDigest.getInstance("SHA-256")
val hash = messageDigest.digest(toByteArray())
return SysUtil.byteArray2Hex(hash)
return byteArrayToHex(hash)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.serivesmejia.eocvsim.util.io

import com.github.serivesmejia.eocvsim.util.SysUtil
import com.github.serivesmejia.eocvsim.util.extension.appData
import com.github.serivesmejia.eocvsim.util.loggerForThis
import java.io.File

Expand All @@ -10,7 +10,7 @@ import java.io.File
* Also handles locking the folder to prevent multiple instances
* from running at the same time (which could cause issues).
*/
object EOCVSimFolder : File(SysUtil.getAppData().absolutePath + separator + ".eocvsim") {
object EOCVSimFolder : File(appData.absolutePath + separator + ".eocvsim") {

val logger by loggerForThis()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.serivesmejia.eocvsim.util.io

import com.github.serivesmejia.eocvsim.util.SysUtil
import com.github.serivesmejia.eocvsim.util.loggerForThis
import java.io.File
import java.io.RandomAccessFile
Expand All @@ -12,14 +11,6 @@ import java.nio.channels.FileLock
*/
class LockFile(pathname: String) : File(pathname) {

companion object {
val POR_UNA_NOCHE = try {
SysUtil.loadResStr("/.lock")
} catch(ex: Exception) {
"lock"
}
}

private var raf = RandomAccessFile(this, "rw")

var lock: FileLock? = null
Expand All @@ -45,7 +36,7 @@ class LockFile(pathname: String) : File(pathname) {
throw IllegalArgumentException("Lock file cannot be a directory")

if(!exists())
SysUtil.saveFileStr(this, POR_UNA_NOCHE)
createNewFile()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ParsedVersion(val version: String) {
*/
val patch = splitVersion.getOrNull(2)?.toIntOrNull() ?: 0

constructor(major: Int, minor: Int, patch: Int = 0) : this("$major.$minor.$patch")

/**
* Compare this version to another ParsedVersion
* @param o the other ParsedVersion to compare to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.deltacv.eocvsim.plugin

import com.github.serivesmejia.eocvsim.util.extension.plus
import com.github.serivesmejia.eocvsim.util.io.EOCVSimFolder
import java.io.File

val PLUGIN_FOLDER = (EOCVSimFolder + File.separator + "plugins").apply { mkdir() }
val PLUGIN_CACHING_FOLDER = (PLUGIN_FOLDER + File.separator + "caching").apply { mkdir() }
val FILESYSTEMS_FOLDER = (PLUGIN_FOLDER + File.separator + "filesystems").apply { mkdir() }
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@

package io.github.deltacv.eocvsim.plugin.security

import com.github.serivesmejia.eocvsim.util.SysUtil
import com.github.serivesmejia.eocvsim.util.loggerForThis
import com.github.serivesmejia.eocvsim.util.extension.plus
import com.github.serivesmejia.eocvsim.util.io.LockFile
import com.github.serivesmejia.eocvsim.util.io.lockDirectory
import com.moandjiezana.toml.Toml
import io.github.deltacv.eocvsim.plugin.loader.PluginManager
import com.github.serivesmejia.eocvsim.util.loggerForThis
import io.github.deltacv.eocvsim.plugin.PLUGIN_CACHING_FOLDER
import java.io.File
import java.net.URL
import java.security.KeyFactory
Expand Down Expand Up @@ -59,8 +56,8 @@ object AuthorityFetcher {

const val AUTHORITY_SERVER_URL = "https://raw.githubusercontent.com/deltacv/Authorities/refs/heads/master"

private val AUTHORITIES_FILE = PluginManager.PLUGIN_CACHING_FOLDER + File.separator + "authorities.toml"
private val AUTHORITIES_LOCK_FILE = LockFile(PluginManager.PLUGIN_CACHING_FOLDER + File.separator + "authorities.lock")
private val AUTHORITIES_FILE = PLUGIN_CACHING_FOLDER + File.separator + "authorities.toml"
private val AUTHORITIES_LOCK_FILE = LockFile(PLUGIN_CACHING_FOLDER + File.separator + "authorities.lock")

private val AUTHORITIES_LOCK_FILE_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(3)

Expand All @@ -81,7 +78,7 @@ object AuthorityFetcher {
// Load authorities from file if it exists
if (AUTHORITIES_FILE.exists() && tryLockAuthoritiesFile()) {
try {
val authoritiesToml = Toml().read(AUTHORITIES_FILE)
val authoritiesToml = com.moandjiezana.toml.Toml().read(AUTHORITIES_FILE)
val timestamp = authoritiesToml.getLong("timestamp")

if(System.currentTimeMillis() - timestamp > TTL_DURATION_MS) {
Expand Down Expand Up @@ -138,13 +135,13 @@ object AuthorityFetcher {
val currentTime = System.currentTimeMillis()

if(!AUTHORITIES_FILE.exists()) {
SysUtil.saveFileStr(AUTHORITIES_FILE, "timestamp = $currentTime\n")
AUTHORITIES_FILE.writeText("timestamp = $currentTime\n")
}

val authoritiesToml = Toml().read(AUTHORITIES_FILE)
val authoritiesToml = com.moandjiezana.toml.Toml().read(AUTHORITIES_FILE)
val timestamp = authoritiesToml.getLong("timestamp")

if(currentTime - timestamp > TTL_DURATION_MS) {
if(timestamp != null && currentTime - timestamp > TTL_DURATION_MS) {
AUTHORITIES_FILE.delete()
logger.info("Authorities file has expired, clearing cache")
cache.clear()
Expand Down Expand Up @@ -175,7 +172,7 @@ object AuthorityFetcher {
sb.appendLine("timestamp = ${System.currentTimeMillis()}")

// Write the updated content to the file
SysUtil.saveFileStr(AUTHORITIES_FILE, sb.toString())
AUTHORITIES_FILE.writeText(sb.toString())
} catch (e: Exception) {
logger.error("Failed to save authority to file", e)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ import java.security.KeyPairGenerator
import java.security.PrivateKey
import java.util.Base64

fun main() {
// Generate RSA key pair
val keyPair: KeyPair = generateKeyPair()
object KeyGeneratorTool {
@JvmStatic
fun main(args: Array<String>) {
// Generate RSA key pair
val keyPair: KeyPair = generateKeyPair()

// Save keys to files
saveKeyToFile("private_key.pem", keyPair.private)
saveKeyToFile("public_key.pem", keyPair.public)
// Save keys to files
saveKeyToFile("private_key.pem", keyPair.private)
saveKeyToFile("public_key.pem", keyPair.public)

println("Keys generated and saved to files.")
println("Keys generated and saved to files 'private_key.pem' and 'public_key.pem'")
}
}

fun generateKeyPair(): KeyPair {
Expand Down
Loading

0 comments on commit 6bef9ea

Please sign in to comment.