@@ -5,11 +5,12 @@ import javax.naming.ldap.LdapName
55import kotlin.time.Clock
66import kotlin.time.Duration
77import kotlin.time.Instant
8+ import kotlinx.datetime.LocalDateTime
89import kotlinx.datetime.TimeZone
910import kotlinx.datetime.toLocalDateTime
1011
1112/* * Returns the subject common name (CN) from the certificate's distinguished name. */
12- val X509Certificate .commonName: String
13+ public val X509Certificate .commonName: String
1314 get() =
1415 LdapName (subjectX500Principal.name)
1516 .rdns
@@ -22,7 +23,7 @@ val X509Certificate.commonName: String
2223 *
2324 * SAN type OIDs: 1 = RFC822/email, 2 = DNS, 7 = IP address.
2425 */
25- val X509Certificate .subjectAltNames: List <String >
26+ public val X509Certificate .subjectAltNames: List <String >
2627 get() =
2728 subjectAlternativeNames
2829 .orEmpty()
@@ -37,11 +38,11 @@ val X509Certificate.subjectAltNames: List<String>
3738 }
3839
3940/* * Returns `true` if this certificate is signed by the given [ca] certificate. */
40- fun X509Certificate.signedBy (ca : X509Certificate ): Boolean =
41+ public fun X509Certificate.signedBy (ca : X509Certificate ): Boolean =
4142 issuerX500Principal == ca.subjectX500Principal && runCatching { verify(ca.publicKey) }.isSuccess
4243
4344/* * Returns `true` if this certificate is self-signed. */
44- val X509Certificate .selfSigned: Boolean
45+ public val X509Certificate .selfSigned: Boolean
4546 get() = signedBy(this )
4647
4748/* *
@@ -54,43 +55,43 @@ val X509Certificate.selfSigned: Boolean
5455 *
5556 * Self-signed certs often include only Basic Constraints without Key Usage.
5657 */
57- val X509Certificate .isCA: Boolean
58+ public val X509Certificate .isCA: Boolean
5859 get() = basicConstraints >= 0 || keyUsage?.get(5 ) == true
5960
6061/* * Returns `true` if this certificate is an intermediate CA (CA but not self-signed). */
61- val X509Certificate .isIntermediateCA: Boolean
62+ public val X509Certificate .isIntermediateCA: Boolean
6263 get() = isCA && ! selfSigned
6364
6465/* * Returns the certificate's start (notBefore) date/time in UTC. */
65- val X509Certificate .startDateUtc
66+ public val X509Certificate .startDateUtc: LocalDateTime
6667 get() = Instant .fromEpochMilliseconds(notBefore.time).toLocalDateTime(TimeZone .UTC )
6768
6869/* * Returns the certificate's start (notBefore) date/time in the system's local time zone. */
69- val X509Certificate .startDate
70+ public val X509Certificate .startDate: LocalDateTime
7071 get() =
7172 Instant .fromEpochMilliseconds(notBefore.time).toLocalDateTime(TimeZone .currentSystemDefault())
7273
7374/* * Returns the certificate's expiry (notAfter) date/time in UTC. */
74- val X509Certificate .expiryDateUtc
75+ public val X509Certificate .expiryDateUtc: LocalDateTime
7576 get() = Instant .fromEpochMilliseconds(notAfter.time).toLocalDateTime(TimeZone .UTC )
7677
7778/* * Returns the certificate's expiry (notAfter) date/time in the system's local time zone. */
78- val X509Certificate .expiryDate
79+ public val X509Certificate .expiryDate: LocalDateTime
7980 get() =
8081 Instant .fromEpochMilliseconds(notAfter.time).toLocalDateTime(TimeZone .currentSystemDefault())
8182
8283/* * Returns `true` if this certificate has expired. */
83- val X509Certificate .isExpired: Boolean
84+ public val X509Certificate .isExpired: Boolean
8485 get() = Clock .System .now() > Instant .fromEpochMilliseconds(notAfter.time)
8586
8687/* * Returns the remaining duration until this certificate expires (negative if already expired). */
87- val X509Certificate .expiresIn: Duration
88+ public val X509Certificate .expiresIn: Duration
8889 get() = Instant .fromEpochMilliseconds(notAfter.time) - Clock .System .now()
8990
9091/* *
9192 * Returns `true` if this certificate chain is signed by one of the given [root] CA certificates.
9293 */
93- fun List<X509Certificate>.isSignedByRoot (root : List <X509Certificate >): Boolean {
94+ public fun List<X509Certificate>.isSignedByRoot (root : List <X509Certificate >): Boolean {
9495 check(isNotEmpty()) { " Cert chain is empty" }
9596 val trustAnchors = root.map { TrustAnchor (it, null ) }.toSet()
9697 val params = PKIXParameters (trustAnchors).apply { isRevocationEnabled = false }
0 commit comments