Skip to content

Commit c4b3781

Browse files
committed
Major changes with new sem versioning.
1 parent c810799 commit c4b3781

13 files changed

+678
-170
lines changed

build.gradle.kts

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import org.gradle.api.tasks.wrapper.Wrapper
22
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
33
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL
4-
import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
54
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
65
import us.kirchmeier.capsule.manifest.CapsuleManifest
76
import us.kirchmeier.capsule.spec.ReallyExecutableSpec
87
import us.kirchmeier.capsule.task.*
98
import org.gradle.jvm.tasks.Jar
9+
import java.time.ZonedDateTime
10+
import java.time.format.DateTimeFormatter
1011
import java.util.jar.Attributes.Name.*
1112

12-
1313
buildscript {
1414
var javaVersion: JavaVersion by extra
1515
var kotlinVersion: String by extra
1616
var kotlinEAPRepo: String by extra
17+
var wrapperVersion: String by extra
1718

1819
javaVersion = JavaVersion.VERSION_1_8
1920
kotlinVersion = "1.1.2-eap-44"
21+
wrapperVersion = "3.5-20170331195952+0000"
2022
kotlinEAPRepo = "https://dl.bintray.com/kotlin/kotlin-eap-1.1"
2123

2224
repositories {
@@ -29,6 +31,7 @@ val appAuthor by project
2931
val javaVersion: JavaVersion by extra
3032
val kotlinVersion: String by extra
3133
val kotlinEAPRepo: String by extra
34+
val wrapperVersion: String by extra
3235
printHeader()
3336

3437
plugins {
@@ -58,14 +61,7 @@ java {
5861
*/
5962
application {
6063
applicationName = rootProject.name
61-
mainClassName = "io.sureshg.InstallCertsKt"
62-
}
63-
64-
/**
65-
* Enable coroutines.
66-
*/
67-
kotlin {
68-
experimental.coroutines = ENABLE
64+
mainClassName = "io.sureshg.MainKt"
6965
}
7066

7167
/**
@@ -92,7 +88,8 @@ dependencies {
9288
*/
9389
tasks.withType<Jar> {
9490
manifest {
95-
attributes(mapOf("Author" to appAuthor,
91+
attributes(mapOf("Built-By" to appAuthor,
92+
"Built-Date" to buildDateTime,
9693
IMPLEMENTATION_VERSION.toString() to appVersion,
9794
IMPLEMENTATION_TITLE.toString() to application().applicationName,
9895
MAIN_CLASS.toString() to application().mainClassName))
@@ -114,7 +111,6 @@ task<FatCapsule>("makeExecutable") {
114111
applicationVersion = version
115112
jvmArgs = listOf("-client")
116113
minJavaVersion = minJavaVer
117-
//args = listOf("$@")
118114
}
119115
description = "Create $archiveName executable."
120116
dependsOn("clean")
@@ -128,9 +124,12 @@ task<FatCapsule>("makeExecutable") {
128124
* Generate Gradle Script Kotlin wrapper.
129125
*/
130126
task<Wrapper>("wrapper") {
131-
description = "Generate Gradle Script Kotlin wrapper v0.8"
127+
description = "Generate Gradle Script Kotlin wrapper v$wrapperVersion"
132128
distributionType = ALL
133-
distributionUrl = getGskURL("3.5-20170331195952+0000")
129+
distributionUrl = getGskURL(wrapperVersion)
130+
doFirst {
131+
println(description)
132+
}
134133
}
135134

136135

@@ -149,4 +148,6 @@ fun printHeader() {
149148
println()
150149
}
151150

151+
val buildDateTime get() = ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss a z"))
152+
152153
fun getGskURL(version: String, type: DistributionType = ALL) = "https://repo.gradle.org/gradle/dist-snapshots/gradle-script-kotlin-$version-${type.name.toLowerCase()}.zip"

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ org.gradle.script.lang.kotlin.accessors.auto=true
33

44
# Project custom properties
55
appAuthor=Suresh
6-
appVersion=1.0
6+
appVersion=1.0.0

gradle/wrapper/gradle-wrapper.jar

0 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Mon Apr 10 02:06:42 PDT 2017
1+
#Thu Apr 13 16:08:47 PDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME

src/main/kotlin/io/sureshg/InstallCerts.kt

-34
This file was deleted.

src/main/kotlin/io/sureshg/Main.kt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.sureshg
2+
3+
import io.airlift.airline.SingleCommand
4+
import io.sureshg.cmd.Install
5+
import io.sureshg.extn.*
6+
7+
/**
8+
* Main method that runs [InstallCerts]
9+
*
10+
* @author Suresh
11+
*/
12+
fun main(args: Array<String>) {
13+
val cmd = SingleCommand.singleCommand(Install::class.java)
14+
var install: Install? = null
15+
try {
16+
install = cmd.parse(*args)
17+
if (install.helpOption.showHelpIfRequested()) {
18+
return
19+
}
20+
install.run()
21+
} catch (e: Throwable) {
22+
println("""|${e.message?.err}
23+
|See ${"'installcerts --help'".bold}
24+
""".trimMargin())
25+
install?.let {
26+
if (it.verbose) e.printStackTrace()
27+
}
28+
}
29+
}

src/main/kotlin/io/sureshg/cmd/Install.kt

+28-11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import io.airlift.airline.Arguments
44
import io.airlift.airline.Command
55
import io.airlift.airline.HelpOption
66
import io.airlift.airline.Option
7-
import io.sureshg.extn.AnsiColor.*
8-
import io.sureshg.extn.color
9-
import io.sureshg.extn.sux
7+
import io.sureshg.crypto.InstallCerts
8+
import io.sureshg.extn.*
109
import java.net.URL
10+
import java.util.jar.Attributes.Name.*
1111
import javax.inject.Inject
1212

1313
/**
@@ -27,6 +27,9 @@ class Install {
2727
@Option(name = arrayOf("-p"), description = "Trust store password. Default is 'changeit'")
2828
var storePasswd = "changeit"
2929

30+
@Option(name = arrayOf("-a", "--all"), description = "Install all certs")
31+
var all = false
32+
3033
@Option(name = arrayOf("-v", "--verbose"), description = "Verbose mode")
3134
var verbose = false
3235

@@ -50,20 +53,34 @@ class Install {
5053
/**
5154
* Tool version.
5255
*/
53-
val version by lazy {
54-
Install::class.java.`package`.implementationVersion
56+
val buildInfo by lazy {
57+
Install::class.jarManifest?.let {
58+
val attr = it.mainAttributes
59+
BuildInfo(attr.getValue("Built-By"),
60+
attr.getValue("Built-Date"),
61+
attr.getValue(IMPLEMENTATION_VERSION))
62+
} ?: BuildInfo()
5563
}
5664

5765
/**
5866
* Executes the command
5967
*/
6068
fun run() {
61-
if (uri.isEmpty()) throw IllegalArgumentException("Server URL can't be empty!")
62-
if(showVersion) {
63-
println("".sux)
64-
System.exit(0)
69+
when {
70+
showVersion -> {
71+
val version = """|InstallCerts version: ${buildInfo.version ?: "N/A"}
72+
|Build Date: ${buildInfo.date ?: "N/A"}
73+
""".trimMargin()
74+
println(version.bold.cyan)
75+
System.exit(0)
76+
}
77+
uri.isEmpty() -> throw IllegalArgumentException("Server URL can't be empty!")
6578
}
79+
InstallCerts.exec(this)
6680
}
81+
}
6782

68-
override fun toString() = "Install(uri=$uri, hostPort=$hostPort)"
69-
}
83+
/**
84+
* Build info class
85+
*/
86+
data class BuildInfo(val by: String? = null, val date: String? = null, val version: String? = null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.sureshg.crypto
2+
3+
import io.sureshg.cmd.Install
4+
import io.sureshg.extn.*
5+
import java.io.File
6+
import javax.net.ssl.SSLException
7+
import javax.net.ssl.SSLSocket
8+
9+
/**
10+
* Creates a PKCS12 TrustStore by retrieving server's certificates
11+
* with JDK trusted certificates.
12+
*
13+
* @author Suresh
14+
*/
15+
object InstallCerts {
16+
17+
/**
18+
* Executes the action.
19+
*/
20+
fun exec(args: Install) {
21+
val (host, port) = args.hostPort
22+
val storePasswd = args.storePasswd
23+
24+
val keystoreFile = File(host.replace(".", "_").plus(".p12"))
25+
26+
if (keystoreFile.isFile) {
27+
val uin: String? = System.console()?.readLine(" $keystoreFile PKCS12 file exists. Do you want to overwrite it (y/n)? ".warn)
28+
if (uin?.toLowerCase() != "y") {
29+
println("Existing...".red)
30+
System.exit(-1)
31+
}
32+
}
33+
34+
println("Loading default ca truststore...".cyan)
35+
val keyStore = CACertsKeyStore
36+
val tm = keyStore.defaultTrustManager.saving()
37+
val sslFactory = getSSLSockFactory("TLS", trustManagers = arrayOf(tm))
38+
39+
println("Opening connection to $host:$port...".cyan)
40+
val socket = sslFactory.createSocket(host, port) as SSLSocket
41+
42+
try {
43+
with(socket) {
44+
soTimeout = 5_000
45+
startHandshake()
46+
close()
47+
}
48+
println(" No error, certificate is already trusted using jre ca certs!".sux)
49+
System.exit(0)
50+
} catch(e: SSLException) {
51+
e.printStackTrace()
52+
}
53+
54+
if (tm.chain.isEmpty()) {
55+
println("Could not obtain server certificate chain".err)
56+
System.exit(-1)
57+
} else {
58+
59+
tm.chain.forEach {
60+
println(it.info().fg256((RAND.nextDouble() * 255).toInt()))
61+
}
62+
63+
}
64+
65+
}
66+
67+
68+
}
69+
70+
71+
72+
73+

0 commit comments

Comments
 (0)