Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Aug 28, 2023
1 parent 418ece8 commit e438a11
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ q61T4oqBdehevVmBq54rGiwL0DGv1DlXQlwiJZP4qni2KnOEFcnvL3gVtRnQjXQ+
kHvlMshkK6w021EMV5NfjG2zg67wC65rLaej5f6Ssp2S7g2VtmE4aXq1bjAuEbqk
4TiyZHLDdsJuqzyGyyOpMV7i9ucXDoaZt9cGS9hT2vRxTrSH63vKR8Xeig9+stLw
t9ONcUqCKP7hd8rajtxM4JIIRExwD8OkgARWGg==
-----END CERTIFICATE-----"""

val johnPrivateKey =
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDuPcSvlhqElPQsCdJEuGmptGj4TUBWe33yu+ncOYR8Ec3M0H4NL0gEORJJcz9i18ByLpNzDy6NUGOtlf9YSat/zKdAfFiZJolKc/y4BPfTr8xx5ml2mu4Rz39LXRru+nnhluV3g1h2Z9LvWhUVUqAztz9W2HH6uC7jx+7HNtYC9VgsVzHjuHPQMlOePPZlr9Hry5enF/Psn24RdiKqwCz8WhsOwtmW5PdHLLBVHAoF53URnFR4sgmLLGlS2GEZ8hvxvdV/2NmhRWLebmCZziyklAe9gCR9lgfN32tqzyMG7VptBHFy7YJidWjpjSZPGEqFBL+fmCO/cTGJAXfCn9djAgMBAAECggEAV2QBCgedopShHKZdoyeiWsX621o7B341LR0RI99VYc2GGGNCWcPGPwZQVvEXh0JtLXU4UTR4dw3OApbLG6+qYS7JCzaRqVwhcFYrlbT804HhFMbYWNFsEsxyfUqh3peyrbWUZsqfYI+lKHd61F+CtHW7nje3V6jISnXEeP78cgioKOX8gsCG8DEWsmaLrQz0PyMwdhucRfa8Bm6qeXNY+wCMg8lyH/+OLlyCZTdk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H+YtV5+nFBRwx881U2g2TgDKF1lPMK/y3d8B8mh
UtW+lFxRpvyNUDpsMjOErOrtNFEYbgoUJLtqwBMmyGR+nmmh6xna331QWcRAmw0P
nDO4ew==
-----END CERTIFICATE-----"""

@Throws(java.lang.Exception::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,33 @@ nDO4ew==
// assertTrue(encryptionUtilsV2.verifySignedMessage(signature1, metadata1, listOf(certJohn, t1cert)))
// }

@Test
fun testMarino() {
val metadata =
"""{"filedrop":{},"users":[{"certificate":"-----BEGIN CERTIFICATE-----\nMIIDkDCCAnigAwIBAgIBADANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJERTEb\nMBkGA1UECAwSQmFkZW4tV3VlcnR0ZW1iZXJnMRIwEAYDVQQHDAlTdHV0dGdhcnQx\nEjAQBgNVBAoMCU5leHRjbG91ZDENMAsGA1UEAwwEam9objAeFw0yMzA3MTQwNzM0\nNTZaFw00MzA3MDkwNzM0NTZaMGExCzAJBgNVBAYTAkRFMRswGQYDVQQIDBJCYWRl\nbi1XdWVydHRlbWJlcmcxEjAQBgNVBAcMCVN0dXR0Z2FydDESMBAGA1UECgwJTmV4\ndGNsb3VkMQ0wCwYDVQQDDARqb2huMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\nCgKCAQEA7j3Er5YahJT0LAnSRLhpqbRo+E1AVnt98rvp3DmEfBHNzNB+DS9IBDkS\nSXM\/YtfAci6Tcw8ujVBjrZX\/WEmrf8ynQHxYmSaJSnP8uAT306\/MceZpdpruEc9\/\nS10a7vp54Zbld4NYdmfS71oVFVKgM7c\/Vthx+rgu48fuxzbWAvVYLFcx47hz0DJT\nnjz2Za\/R68uXpxfz7J9uEXYiqsAs\/FobDsLZluT3RyywVRwKBed1EZxUeLIJiyxp\nUthhGfIb8b3Vf9jZoUVi3m5gmc4spJQHvYAkfZYHzd9ras8jBu1abQRxcu2CYnVo\n6Y0mTxhKhQS\/n5gjv3ExiQF3wp\/XYwIDAQABo1MwUTAdBgNVHQ4EFgQUmTeILVuB\ntv70fTGkXWGAueDp5kAwHwYDVR0jBBgwFoAUmTeILVuBtv70fTGkXWGAueDp5kAw\nDwYDVR0TAQH\/BAUwAwEB\/zANBgkqhkiG9w0BAQUFAAOCAQEAyVtq9XAvW7nxSW\/8\nhp30z6xbzGiuviXhy\/Jo91VEa8IRsWCCn3OmDFiVduTEowx76tf8clJP0gk7Pozi\n6dg\/7Fin+FqQGXfCk8bLAh9gXKAikQ2GK8yRN3slRFwYC2mm23HrLdKXZHUqJcpB\nMz2zsSrOGPj1YsYOl\/U8FU6KA7Yj7U3q7kDMYTAgzUPZAH+d1DISGWpZsMa0RYid\nvigCCLByiccmS\/Co4Sb1esF58H+YtV5+nFBRwx881U2g2TgDKF1lPMK\/y3d8B8mh\nUtW+lFxRpvyNUDpsMjOErOrtNFEYbgoUJLtqwBMmyGR+nmmh6xna331QWcRAmw0P\nnDO4ew==\n-----END CERTIFICATE-----\n","userId":"john","encryptedMetadataKey":"zW63bgTlsxhqzBUHFA4KLG+\/TP6mimg56JMnrOssNY3rDtdRAo19kr8CzFSGPx9M4elpBxp3OtJbarT02E\/+Bz9RqH3zVqSJyvjA2sg\/q32p1O2ausVfORtkpQTMgf+KgmeHqvg5PHF0sVeUn\/udx4i8kK8G+r6OjyhZqXns4C\/sRlZzbo3onVYYGygXWW2S+kFfnC7BWIva3R75gyUIaXOl8EEsgOQi94gIEt13v6tO9O1BhXdIhhFXA6EblKTiLhondpHDzbXLzwGgT9riynJoIOVVd4y6PiHbulEXfG5x0cGLhvdJwOIElPoydgLpQ6bvKmHYazWHuQXU4eECkQ=="}],"metadata":{"nonce":"q7Xt1gBr4qL96VlsqxspCg==","ciphertext":"ks4xnkISO+3Nh+2938cRv2gWSxRFie3Q9juBNgqhaW1Ed5T4BnBi3bRv8\/C2vzhHIisQIDZqctBRJ\/O2r0VNSqUSMvj65gtAmUmfg4B+r1V9Z9ftIHTrLyMFDofCs+2Bn+vaU86TfSIu\/Z3dGmWyLJRC6WKMT6St3bKhL3YZqX70DnjsjC8wqq59IY0ietangg+LAKyxVwtW3E75AMXA2SdLC\/+qWfRuNLvcXGTWy6s6IDvZHI3+pidHglMmRM7q5JiJAdMHOBmFTiqt+UYqPiuFCFBKMRR1HQY3bRAvpsDxemWHKL6QBna6BjrYkBXUDPam93OyA2WTRe0uLB81lAMUokLc0g8wSwTxRa5KrZAeMTO1XPf0zlljVvuf1Jq7PFxZ\/4GNXRPKw9Zt8SlnXW0gA2\/+cjMrcp0KiS5+jDZf+kR9P9BXVsLBjqEgTxTqP6DkJu4qp0ns7ofzr+p2zef0HOBX26gLOJ4aZ1gaq6wi|q7Xt1gBr4qL96VlsqxspCg==","authenticationTag":"9BzgV9uoCzieGmdYGqusIg=="},"version":"2.0"}"""
val base64Metadata = EncryptionUtils.encodeStringToBase64String(metadata)

val privateKey = EncryptionUtils.PEMtoPrivateKey(encryptionTestUtils.johnPrivateKey)
val certificateJohn = EncryptionUtils.convertCertFromString(encryptionTestUtils.johnPublicKey)
val certificateEnc2 = EncryptionUtils.convertCertFromString(enc2Cert)

val signed = encryptionUtilsV2.signMessage(
certificateJohn,
privateKey,
metadata
)

val base64Ans = encryptionUtilsV2.extractSignedString(signed)

// verify
val certs = listOf(
certificateEnc2,
certificateJohn
)
assertTrue(encryptionUtilsV2.verifySignedMessage(signed, certs))
assertTrue(encryptionUtilsV2.verifySignedMessage(base64Ans, base64Metadata, certs))
}

@Test
fun testSigning() {
val metadata =
Expand Down

0 comments on commit e438a11

Please sign in to comment.