Skip to content

Commit

Permalink
La til SertifikatUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
thburnett committed Sep 20, 2023
1 parent b7ffb21 commit 20b1242
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package no.nav.emottak.util

import io.ktor.server.plugins.BadRequestException
import java.io.ByteArrayInputStream
import java.security.cert.CertificateException
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate

internal fun isSelfSigned(certificate: X509Certificate) =
certificate.subjectX500Principal == certificate.issuerX500Principal

internal fun createX509Certificate(byteArray: ByteArray): X509Certificate {
val cf = CertificateFactory.getInstance("X.509")
return try {
cf.generateCertificate(ByteArrayInputStream(byteArray)) as X509Certificate
}
catch (e: CertificateException) {
throw BadRequestException("")
}
}

0 comments on commit 20b1242

Please sign in to comment.