-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
158 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 10 | ||
# - package-ecosystem: gradle | ||
# directory: "/" | ||
# schedule: | ||
# interval: daily | ||
# open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
/* | ||
* This Kotlin source file was generated by the Gradle 'init' task. | ||
*/ | ||
package no.nav.emottak.cpa | ||
|
||
import io.ktor.http.content.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.netty.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import no.nav.emottak.cpa.config.DatabaseConfig | ||
import no.nav.emottak.cpa.config.mapHikariConfig | ||
import io.ktor.server.application.call | ||
import io.ktor.server.engine.embeddedServer | ||
import io.ktor.server.netty.Netty | ||
import io.ktor.server.plugins.BadRequestException | ||
import io.ktor.server.plugins.NotFoundException | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.get | ||
import io.ktor.server.routing.routing | ||
|
||
fun main() { | ||
val database = Database(mapHikariConfig(DatabaseConfig())) | ||
database.migrate() | ||
|
||
embeddedServer(Netty, port = 8080) { | ||
|
||
routing { | ||
get("/cpa") { | ||
call.respondText("Hello, world!") | ||
get("/cpa/{id}") { | ||
val cpaId = call.parameters["id"] ?: throw BadRequestException("Mangler CPA ID") | ||
val cpa = getCpa(cpaId) ?: throw NotFoundException("Fant ikke CPA") | ||
call.respond(cpa) | ||
} | ||
|
||
get("/cpa/{id}/{herId}/certificate/encryption") { | ||
val cpaId = call.parameters["id"] ?: throw BadRequestException("Mangler CPA ID") | ||
val herId = call.parameters["herId"] ?: throw BadRequestException("Mangler HER ID") | ||
val cpa = getCpa(cpaId) ?: throw NotFoundException("Fant ikke CPA") | ||
|
||
call.respond(cpa.getCertificateForEncryption(herId)) | ||
} | ||
} | ||
}.start(wait = true) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package no.nav.emottak.cpa | ||
|
||
import org.oasis_open.committees.ebxml_cppa.schema.cpp_cpa_2_0.Certificate | ||
import org.oasis_open.committees.ebxml_cppa.schema.cpp_cpa_2_0.CollaborationProtocolAgreement | ||
import org.w3._2000._09.xmldsig_.X509DataType | ||
import javax.xml.bind.JAXBElement | ||
|
||
private val cpaUtil = CPAUtil() | ||
|
||
fun getCpa(id: String) = cpaUtil.getCpa(id) | ||
|
||
|
||
private class CPAUtil { | ||
|
||
fun getCpa(id: String): CollaborationProtocolAgreement? { | ||
//TODO | ||
val testCpaString = String(this::class.java.classLoader.getResource("nav-qass-35065.xml").readBytes()) | ||
return unmarshal(testCpaString, CollaborationProtocolAgreement::class.java) | ||
} | ||
|
||
} | ||
|
||
fun CollaborationProtocolAgreement.getCertificateForEncryption(herId: String): ByteArray { | ||
val partyInfo = this.partyInfo.first { partyInfo -> | ||
partyInfo.partyId.any { partyId -> | ||
partyId.type == "HER" && partyId.value == herId | ||
} | ||
} | ||
val encryptionCert = partyInfo.collaborationRole.first().applicationCertificateRef.first().certId as Certificate | ||
val datatype = | ||
encryptionCert.keyInfo.content?.filterIsInstance(JAXBElement::class.java)?.firstOrNull()?.value as X509DataType | ||
return datatype.x509IssuerSerialOrX509SKIOrX509SubjectName?.filterIsInstance(JAXBElement::class.java) | ||
?.firstOrNull()?.value as ByteArray | ||
} |
36 changes: 36 additions & 0 deletions
36
cpa-repo/src/main/kotlin/no/nav/emottak/cpa/XmlMarshaller.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package no.nav.emottak.cpa | ||
|
||
import java.io.StringWriter | ||
import javax.xml.bind.JAXBContext | ||
import javax.xml.stream.XMLInputFactory | ||
|
||
private val xmlMarshaller = XmlMarshaller() | ||
|
||
fun marshal(objekt: Any) = xmlMarshaller.marshal(objekt) | ||
fun <T> unmarshal(xml: String, clazz: Class<T>) : T = xmlMarshaller.unmarshal(xml , clazz) | ||
|
||
class XmlMarshaller { | ||
|
||
companion object { | ||
private val jaxbContext = JAXBContext.newInstance( | ||
org.oasis_open.committees.ebxml_cppa.schema.cpp_cpa_2_0.ObjectFactory::class.java, | ||
org.oasis_open.committees.ebxml_msg.schema.msg_header_2_0.ObjectFactory::class.java, | ||
org.xmlsoap.schemas.soap.envelope.ObjectFactory::class.java, | ||
org.w3._1999.xlink.ObjectFactory::class.java, | ||
org.w3._2009.xmldsig11_.ObjectFactory::class.java | ||
); | ||
private val marshaller = jaxbContext.createMarshaller() | ||
private val unmarshaller = jaxbContext.createUnmarshaller() | ||
} | ||
|
||
fun marshal(objekt: Any) : String { | ||
val writer = StringWriter() | ||
marshaller.marshal(objekt,writer) | ||
return writer.toString() | ||
} | ||
|
||
fun <T> unmarshal(xml: String, clazz: Class<T>) : T { | ||
val reader = XMLInputFactory.newInstance().createXMLStreamReader(xml.reader()) | ||
return unmarshaller.unmarshal(reader, clazz).value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
payload-processor/src/main/kotlin/no/nav/emottak/util/CommonUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package no.nav.emottak.util | ||
|
||
|
||
internal fun getEnvVar(varName: String, defaultValue: String? = null) = | ||
System.getenv(varName) ?: | ||
System.getProperty(varName) ?: | ||
defaultValue ?: throw RuntimeException("Missing required variable $varName") | ||
|
||
|
||
|
||
|
||
|
||
|
31 changes: 31 additions & 0 deletions
31
payload-processor/src/main/kotlin/no/nav/emottak/util/HttpClientUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package no.nav.emottak.util | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.cio.CIO | ||
import io.ktor.client.request.request | ||
import io.ktor.client.statement.HttpResponse | ||
import io.ktor.client.statement.readBytes | ||
import io.ktor.http.HttpMethod | ||
import kotlinx.coroutines.runBlocking | ||
|
||
|
||
private val httpClientUtil = HttpClientUtil() | ||
private val cpaRepoUrl = "http://cpa-repo" | ||
|
||
fun hentKrypteringssertifikat(cpaId: String, herId: String): ByteArray = runBlocking { | ||
httpClientUtil.makeHttpRequest("$cpaRepoUrl/cpa/$cpaId/$herId/certificate/encryption").readBytes() | ||
} | ||
|
||
class HttpClientUtil { | ||
|
||
private val client = HttpClient(CIO) { | ||
expectSuccess = true | ||
} | ||
|
||
suspend fun makeHttpRequest(urlString: String): HttpResponse { | ||
val response: HttpResponse = client.request(urlString) { | ||
method = HttpMethod.Get | ||
} | ||
return response | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters