8787import static ee .cyber .cdoc2 .KeyUtil .createSecretKey ;
8888import static ee .cyber .cdoc2 .KeyUtil .getKeyPairRsaInstance ;
8989import static ee .cyber .cdoc2 .container .EnvelopeTestUtils .checkContainerDecrypt ;
90+ import static ee .cyber .cdoc2 .container .EnvelopeTestUtils .createKeyLabelParams ;
9091import static ee .cyber .cdoc2 .container .EnvelopeTestUtils .getPublicKeyLabelParams ;
9192import static ee .cyber .cdoc2 .container .EnvelopeTestUtils .testContainer ;
9293import static ee .cyber .cdoc2 .container .EnvelopeTestUtils .testContainerWithKeyShares ;
9394import static ee .cyber .cdoc2 .crypto .AuthenticationIdentifier .createSemanticsIdentifier ;
94- import static ee .cyber .cdoc2 .crypto .KeyLabelTools .createKeySharesKeyLabelParams ;
9595import static ee .cyber .cdoc2 .fbs .header .Capsule .*;
9696import static ee .cyber .cdoc2 .fbs .header .Capsule .recipients_PBKDF2Capsule ;
9797import static ee .cyber .cdoc2 .smartid .SmartIdClientTest .getDemoEnvConfiguration ;
@@ -438,22 +438,26 @@ void testPasswordKeySerialization(@TempDir Path tempDir) throws Exception {
438438
439439 @ Test
440440 void testKeySharesSerializationWithSmartId (@ TempDir Path tempDir ) throws Exception {
441+ AuthenticationIdentifier .AuthenticationType authType
442+ = AuthenticationIdentifier .AuthenticationType .SID ;
441443 AuthenticationIdentifier keyLabel = AuthenticationIdentifier .forKeyShares (
442- createSemanticsIdentifier ("30303039914" ),
443- AuthenticationIdentifier . AuthenticationType . SID
444+ createSemanticsIdentifier ("30303039914" ), authType
445+
444446 );
445447
446- testKeySharesSerialization (tempDir , keyLabel );
448+ testKeySharesSerialization (tempDir , keyLabel , authType , "30303039914" );
447449 }
448450
449451 @ Test
450452 void testKeySharesSerializationWithMobileId (@ TempDir Path tempDir ) throws Exception {
453+ AuthenticationIdentifier .AuthenticationType authType
454+ = AuthenticationIdentifier .AuthenticationType .MID ;
451455 AuthenticationIdentifier keyLabel = AuthenticationIdentifier .forKeyShares (
452- createSemanticsIdentifier ("51307149560" ),
453- AuthenticationIdentifier . AuthenticationType . MID
456+ createSemanticsIdentifier ("51307149560" ), authType
457+
454458 );
455459
456- testKeySharesSerialization (tempDir , keyLabel );
460+ testKeySharesSerialization (tempDir , keyLabel , authType , "51307149560" );
457461 }
458462
459463 @ Test
@@ -550,13 +554,22 @@ void testKeySharesScenarioWithSmartId(@TempDir Path tempDir) throws Exception {
550554 // SID demo env that authenticates automatically
551555 setupKeyShareClientMocks ();
552556
557+ AuthenticationIdentifier .AuthenticationType authType
558+ = AuthenticationIdentifier .AuthenticationType .SID ;
559+ String idCode = "30303039914" ;
560+
553561 AuthenticationIdentifier authIdentifier = AuthenticationIdentifier .forKeyShares (
554- createSemanticsIdentifier ("30303039914" ),
555- AuthenticationIdentifier .AuthenticationType .SID
562+ createSemanticsIdentifier (idCode ), authType
556563 );
557564
558- EnvelopeTestUtils .DecryptionData decryptionData
559- = testContainerWithKeyShares (tempDir , authIdentifier , authIdentifier , shareClientFactory );
565+ EnvelopeTestUtils .DecryptionData decryptionData = testContainerWithKeyShares (
566+ tempDir ,
567+ authIdentifier ,
568+ authIdentifier ,
569+ shareClientFactory ,
570+ authType ,
571+ idCode
572+ );
560573
561574 verifyMockedKeyShareClients ();
562575
@@ -582,20 +595,23 @@ void testKeySharesScenarioWithSmartId(@TempDir Path tempDir) throws Exception {
582595 void testKeySharesScenarioWithMobileId (@ TempDir Path tempDir ) throws Exception {
583596 // MID demo env that authenticates automatically
584597 setupKeyShareClientMocks ();
598+ String idCode = "51307149560" ;
585599 AuthenticationIdentifier encAuthIdentifier = AuthenticationIdentifier .forKeyShares (
586- createSemanticsIdentifier ("51307149560" ),
600+ createSemanticsIdentifier (idCode ),
587601 AuthenticationIdentifier .AuthenticationType .MID
588602 );
589603 AuthenticationIdentifier decryptAuthIdentifier = AuthenticationIdentifier .forMidDecryption (
590- createSemanticsIdentifier ("51307149560" ),
604+ createSemanticsIdentifier (idCode ),
591605 "+37269930366"
592606 );
593607
594608 EnvelopeTestUtils .DecryptionData decryptionData = testContainerWithKeyShares (
595609 tempDir ,
596610 encAuthIdentifier ,
597611 decryptAuthIdentifier ,
598- shareClientFactory
612+ shareClientFactory ,
613+ AuthenticationIdentifier .AuthenticationType .MID ,
614+ idCode
599615 );
600616
601617 verifyMockedKeyShareClients ();
@@ -686,20 +702,23 @@ void testReEncryptionScenario(@TempDir Path tempDir) throws Exception {
686702 void testReEncryptionScenarioWithMobileId (@ TempDir Path tempDir ) throws Exception {
687703 // encrypt initial cdoc2 document
688704 setupKeyShareClientMocks ();
705+ String idCode = "60001017869" ;
689706 AuthenticationIdentifier encAuthIdentifier = AuthenticationIdentifier .forKeyShares (
690- createSemanticsIdentifier ("60001017869" ),
707+ createSemanticsIdentifier (idCode ),
691708 AuthenticationIdentifier .AuthenticationType .MID
692709 );
693710 AuthenticationIdentifier decryptAuthIdentifier = AuthenticationIdentifier .forMidDecryption (
694- createSemanticsIdentifier ("60001017869" ),
711+ createSemanticsIdentifier (idCode ),
695712 "+37268000769"
696713 );
697714
698715 EnvelopeTestUtils .DecryptionData decryptionData = testContainerWithKeyShares (
699716 tempDir ,
700717 encAuthIdentifier ,
701718 decryptAuthIdentifier ,
702- shareClientFactory
719+ shareClientFactory ,
720+ AuthenticationIdentifier .AuthenticationType .MID ,
721+ idCode
703722 );
704723
705724 verify (mockKeySharesClient1 ).storeKeyShare (keyShareCaptor1 .capture ());
@@ -1265,7 +1284,9 @@ private void setUpKeyLabelFormat(boolean isFormatted) {
12651284
12661285 private void testKeySharesSerialization (
12671286 Path tempDir ,
1268- AuthenticationIdentifier authIdentifier
1287+ AuthenticationIdentifier authIdentifier ,
1288+ AuthenticationIdentifier .AuthenticationType authType ,
1289+ String idCode
12691290 ) throws Exception {
12701291 setupKeyShareClientMocks ();
12711292
@@ -1280,7 +1301,7 @@ private void testKeySharesSerialization(
12801301
12811302 Envelope envelope = Envelope .prepare (
12821303 List .of (EncryptionKeyMaterial .fromAuthMeans (
1283- authIdentifier , createKeySharesKeyLabelParams ( authIdentifier . getIdentifier () ))
1304+ authIdentifier , createKeyLabelParams ( idCode , authType ))
12841305 ),
12851306 null , shareClientFactory
12861307 );
0 commit comments