Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanskodje committed Apr 16, 2024
2 parents 99b1d03 + eb8efdd commit 31a61b6
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 38 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Pull push docker image"
run: "docker pull ghcr.io/curl/curl-container/curl:master && docker tag ghcr.io/curl/curl-container/curl:master ghcr.io/${{ github.repository }}/curl:master && docker push ghcr.io/${{ github.repository }}/curl:master"
- name: "Naisjob Readmail"
uses: "nais/deploy/actions/deploy@v1"
env:
APIKEY: "${{ secrets.NAIS_DEPLOY_APIKEY }}"
CLUSTER: "dev-fss"
RESOURCE: ".nais/naisjob-readmail.yaml"
IMAGE: "ghcr.io/${{ github.repository }}/curl:master"
#- name: "Naisjob Readmail"
# uses: "nais/deploy/actions/deploy@v1"
# env:
# APIKEY: "${{ secrets.NAIS_DEPLOY_APIKEY }}"
# CLUSTER: "dev-fss"
# RESOURCE: ".nais/naisjob-readmail.yaml"
# IMAGE: "ghcr.io/${{ github.repository }}/curl:master"
- name: "Naisjob CpaSync"
uses: "nais/deploy/actions/deploy@v1"
env:
Expand Down
15 changes: 15 additions & 0 deletions .nais/ebms-send-in-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ spec:
enabled: true
webproxy: true
image: {{image}}
liveness:
path: "/internal/health/liveness"
port: 8080
initialDelay: 30
timeout: 10
failureThreshold: 10
readiness:
path: "/internal/health/readiness"
port: 8080
initialDelay: 30
timeout: 10
failureThreshold: 10
prometheus:
enabled: true
path: /prometheus
replicas:
min: 1
max: 1
Expand Down
15 changes: 15 additions & 0 deletions .nais/ebms-send-in.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ spec:
enabled: true
webproxy: true
image: {{image}}
liveness:
path: "/internal/health/liveness"
port: 8080
initialDelay: 30
timeout: 10
failureThreshold: 10
readiness:
path: "/internal/health/readiness"
port: 8080
initialDelay: 30
timeout: 10
failureThreshold: 10
prometheus:
enabled: true
path: /prometheus
replicas:
min: 2
max: 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class SertifikatValidering(
try {
builder.build(pkixParams) as PKIXCertPathBuilderResult
} catch (e: CertPathBuilderException) {
log.warn("Sertifikatvalidering feilet <${certificate.serialNumber}> <${certificate.subjectX500Principal.name}> utstedt av <${certificate.issuerX500Principal.name}>", e)
throw CertificateValidationException("Sertifikatvalidering feilet for sertifikat utstedt av <${certificate.issuerX500Principal.name}>", e)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import no.nav.emottak.util.isSelfSigned
import java.security.cert.X509Certificate

fun KeyStore.getTrustedRootCerts(): Set<X509Certificate> {
return this.getPublicCertificates().values.filter { isSelfSigned(it) }.toSet()
return this.getPublicCertificates().values.filter { isSelfSigned(it) }.toSet().onEach {
log.info("Loaded root certificate: <${it.serialNumber}> <${it.subjectX500Principal.name}> <${it.issuerX500Principal}>")
}
}

internal fun KeyStore.getIntermediateCerts(): Set<X509Certificate> {
return this.getPublicCertificates().values.filter { !isSelfSigned(it) }.toSet()
return this.getPublicCertificates().values.filter { !isSelfSigned(it) }.toSet().onEach {
log.info("Loaded intermediate certificate: <${it.serialNumber}> <${it.subjectX500Principal.name}> <${it.issuerX500Principal}>")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SertifikatValideringTest : FunSpec({
every {
crlChecker.getCRLRevocationInfo(any(), any())
} just runs
System.setProperty("TRUSTSTORE_PATH", "truststore.p12")
val sertifikatValidering = SertifikatValidering(crlChecker, trustStoreConfig)

withData(
Expand Down
7 changes: 4 additions & 3 deletions ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ suspend fun ApplicationCall.respondEbmsDokument(ebmsDokument: EbMSDocument) {
if (ebmsDokument.dokumentType() == DokumentType.ACKNOWLEDGMENT) {
log.info("Successfuly processed Payload Message")
}
val ebxml = Base64.getMimeEncoder().encodeToString(ebmsDokument.dokument.asString().toByteArray())

this.response.headers.apply {
this.append(MimeHeaders.CONTENT_TYPE, ContentType.Text.Xml.toString())
}
if (ebmsDokument.dokumentType() == DokumentType.PAYLOAD) {
val ebxml = Base64.getMimeEncoder().encodeToString(ebmsDokument.dokument.asString().toByteArray())
val ebxmlFormItem = PartData.FormItem(
ebxml,
{},
Expand Down Expand Up @@ -278,7 +278,8 @@ suspend fun ApplicationCall.respondEbmsDokument(ebmsDokument: EbMSDocument) {
)
} else {
this.response.headers.append(MimeHeaders.CONTENT_TYPE, ContentType.Text.Xml.toString())
this.response.headers.append(MimeHeaders.CONTENT_TRANSFER_ENCODING, "base64")
this.respondText(status = HttpStatusCode.OK, text = ebxml)
this.response.headers.append(MimeHeaders.CONTENT_TRANSFER_ENCODING, "8bit")
this.response.headers.append(MimeHeaders.SOAP_ACTION, "ebXML")
this.respondText(status = HttpStatusCode.OK, text = ebmsDokument.dokument.asString())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import io.mockk.coVerify
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import no.nav.emottak.cpa.decodeBase64Mime
import no.nav.emottak.ebms.ebxml.errorList
import no.nav.emottak.ebms.ebxml.messageHeader
import no.nav.emottak.ebms.processing.ProcessingService
Expand Down Expand Up @@ -94,7 +93,7 @@ abstract class EbmsRoutFellesIT(val endpoint: String) {
@Test
fun `Feil på signature should answer with Feil Signal`() = validationTestApp {
val response = client.post("/ebms", validMultipartRequest.asHttpRequest())
val envelope = xmlMarshaller.unmarshal(response.bodyAsText().decodeBase64Mime(), Envelope::class.java)
val envelope = xmlMarshaller.unmarshal(response.bodyAsText(), Envelope::class.java)
with(envelope.assertErrorAndGet().error.first()) {
Assertions.assertEquals("Signature Fail", this.description.value)
Assertions.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockkObject
import no.nav.emottak.constants.SMTPHeaders
import no.nav.emottak.cpa.decodeBase64Mime
import no.nav.emottak.ebms.ebxml.acknowledgment
import no.nav.emottak.ebms.ebxml.messageHeader
import no.nav.emottak.ebms.validation.MimeHeaders
Expand All @@ -36,7 +35,7 @@ class EbmsRouteAsyncIT : EbmsRoutFellesIT("/ebms") {
coVerify(exactly = 1) {
processingService.processAsync(any(), any())
}
val envelope = xmlMarshaller.unmarshal(response.bodyAsText().decodeBase64Mime(), Envelope::class.java)
val envelope = xmlMarshaller.unmarshal(response.bodyAsText(), Envelope::class.java)
envelope.assertAcknowledgmen()
assertEquals(HttpStatusCode.OK, response.status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MimeValidationIT {
} returns validationResult

val response = client.post("/ebms", validMultipartRequest.asHttpRequest())
val envelope = xmlMarshaller.unmarshal(response.bodyAsText().decodeBase64Mime(), Envelope::class.java)
val envelope = xmlMarshaller.unmarshal(response.bodyAsText(), Envelope::class.java)
with(envelope.assertErrorAndGet().error.first()) {
assertEquals("Signature Fail", this.description?.value)
assertEquals(ErrorCode.SECURITY_FAILURE.value, this.errorCode)
Expand All @@ -107,7 +107,7 @@ class MimeValidationIT {
} returns validationResult

val response = client.post("/ebms", validMultipartRequest.asHttpRequest())
val envelope = xmlMarshaller.unmarshal(response.bodyAsText().decodeBase64Mime(), Envelope::class.java)
val envelope = xmlMarshaller.unmarshal(response.bodyAsText(), Envelope::class.java)
with(envelope.assertErrorAndGet().error.first()) {
assertEquals("Signature Fail", this.description?.value)
assertEquals(
Expand Down
1 change: 1 addition & 0 deletions ebms-send-in/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dependencies {
implementation(libs.labai.jsr305x.annotations)
implementation(libs.bundles.exposed)
implementation(libs.bundles.logging)
implementation(libs.bundles.prometheus)
implementation(libs.ebxml.protokoll)
implementation(libs.emottak.payload.xsd)
implementation(libs.jaxb.runtime)
Expand Down
20 changes: 12 additions & 8 deletions ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.ktor.server.application.install
import io.ktor.server.auth.Authentication
import io.ktor.server.auth.authenticate
import io.ktor.server.engine.embeddedServer
import io.ktor.server.metrics.micrometer.MicrometerMetrics
import io.ktor.server.netty.Netty
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.request.receive
Expand All @@ -16,6 +17,8 @@ import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import io.micrometer.prometheus.PrometheusConfig
import io.micrometer.prometheus.PrometheusMeterRegistry
import no.nav.emottak.auth.AZURE_AD_AUTH
import no.nav.emottak.auth.AuthConfig
import no.nav.emottak.fellesformat.addressing
Expand All @@ -34,6 +37,8 @@ import org.xmlsoap.schemas.soap.envelope.Envelope

internal val log = LoggerFactory.getLogger("no.nav.emottak.ebms.App")
fun main() {
// val database = Database(mapHikariConfig(DatabaseConfig()))
// database.migrate()
System.setProperty("io.ktor.http.content.multipart.skipTempFile", "true")
embeddedServer(Netty, port = 8080, module = Application::ebmsSendInModule, configure = {
this.maxChunkSize = 100000
Expand All @@ -47,6 +52,10 @@ fun Application.ebmsSendInModule() {
install(Authentication) {
tokenValidationSupport(AZURE_AD_AUTH, AuthConfig.getEbmsSendInConfig())
}
val appMicrometerRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)
install(MicrometerMetrics) {
registry = appMicrometerRegistry
}
routing {
get("/testFrikortEndepunkt") {
val testCpaString = String(this::class.java.classLoader.getResource("frikortRequest.xml")!!.readBytes())
Expand All @@ -64,14 +73,7 @@ fun Application.ebmsSendInModule() {
frikortsporring(wrapMessageInEIFellesFormat(request))
}.onSuccess {
log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem")
call.respond(
SendInResponse(
request.messageId,
request.conversationId,
it.eiFellesformat.addressing(request.addressing.from),
marshal(it.eiFellesformat.msgHead).toByteArray()
)
)
call.respond(SendInResponse(request.messageId, request.conversationId, it.eiFellesformat.addressing(request.addressing.from), marshal(it.eiFellesformat.msgHead).toByteArray()))
}.onFailure {
log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it)
call.respond(HttpStatusCode.BadRequest, it.localizedMessage)
Expand All @@ -83,5 +85,7 @@ fun Application.ebmsSendInModule() {
call.respondText("Hello world, but securely")
}
}

registerHealthEndpoints(appMicrometerRegistry)
}
}
22 changes: 22 additions & 0 deletions ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/Routes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package no.nav.emottak.ebms

import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.micrometer.prometheus.PrometheusMeterRegistry

fun Routing.registerHealthEndpoints(
collectorRegistry: PrometheusMeterRegistry
) {
get("/internal/health/liveness") {
call.respondText("I'm alive! :)")
}
get("/internal/health/readiness") {
call.respondText("I'm ready! :)")
}
get("/prometheus") {
call.respond(collectorRegistry.scrape())
}
}
17 changes: 12 additions & 5 deletions felles/src/main/kotlin/no/nav/emottak/crypto/KeyStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.emottak.crypto

import java.io.ByteArrayInputStream
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.security.KeyPair
import java.security.KeyStore
import java.security.PrivateKey
Expand All @@ -11,6 +10,7 @@ import java.security.cert.X509Certificate
import java.util.HashMap
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.slf4j.LoggerFactory
import java.io.File

internal val log = LoggerFactory.getLogger("no.nav.emottak.crypto.KeyStore")
interface KeyStoreConfig {
Expand All @@ -33,11 +33,18 @@ class KeyStore(private val keyStoreConfig: KeyStoreConfig) {
val keyStore = KeyStore.getInstance(keyStoreConfig.keyStoreStype)
val fileContent =
try {
FileInputStream(storePath)
} catch (e: FileNotFoundException) {
log.debug("Getting store file from $storePath")
if (File(storePath).exists()) {
log.debug("Getting store file from file <$storePath>")
FileInputStream(storePath)
} else {
log.debug("Getting store file from resources <$storePath>")
ByteArrayInputStream(this::class.java.classLoader.getResourceAsStream(storePath).readBytes())
}
} catch (e: Exception) {
//TODO Kast exception om keystore ikke kan leses
log.error("Unable to load keystore $storePath falling back to truststore",e)
ByteArrayInputStream(this::class.java.classLoader.getResourceAsStream("truststore.p12").readBytes())
log.error("Unable to load keystore $storePath falling back to truststore", e)
ByteArrayInputStream(this::class.java.classLoader.getResourceAsStream("truststore_test.p12").readBytes())
}
keyStore!!.load(fileContent, storePass)
return keyStore
Expand Down
19 changes: 12 additions & 7 deletions smtp-listeners/src/main/kotlin/no/nav/emottak/smtp/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,17 @@ fun Folder.batchDelete(batchSize: Int) { // fixme: Skriv en test for denne før
fun Folder.deleteAll() {
if (this is IMAPFolder) {
if (isOpen) close()
val deleteMeFolder = getFolder("DeleteMe")
if (!deleteMeFolder.exists()) create(HOLDS_MESSAGES)
this.renameTo(deleteMeFolder)
deleteMeFolder.delete(true)
log.info("${this.fullName} deleted.")
return
if (name.lowercase().contains("inbox")) {
val deleteMeFolder = getFolder("DeleteMe")
if (!deleteMeFolder.exists()) create(HOLDS_MESSAGES)
this.renameTo(deleteMeFolder)
deleteMeFolder.delete(true)
log.info("${this.fullName} deleted.")
} else {
delete(true)
log.info("${this.fullName} deleted.")
}
} else {
log.warn("DeleteAll strategy only valid for IMAP")
}
log.warn("DeleteAll strategy only valid for IMAP")
}

0 comments on commit 31a61b6

Please sign in to comment.