コード例 #1
0
        public void testClearIdentities()
        {
            /* foreach */
            foreach (PibDataFixture2 fixture  in  pibImpls)
            {
                PibImpl pib = fixture.pib;

                pib.setTpmLocator("tpmLocator");

                // Add id, key, and cert.
                pib.addCertificate(fixture.id1Key1Cert1);
                Assert.AssertTrue(pib.hasIdentity(fixture.id1));
                Assert.AssertTrue(pib.hasKey(fixture.id1Key1Name));
                Assert.AssertTrue(pib.hasCertificate(fixture.id1Key1Cert1.getName()));

                // Clear identities.
                pib.clearIdentities();
                Assert.AssertEquals(0, pib.getIdentities().Count);
                Assert.AssertEquals(0, pib.getKeysOfIdentity(fixture.id1).Count);
                Assert.AssertEquals(0, pib.getCertificatesOfKey(fixture.id1Key1Name).Count);
                Assert.AssertEquals("tpmLocator", pib.getTpmLocator());
            }
        }
コード例 #2
0
        public void testKeyManagement()
        {
            /* foreach */
            foreach (PibDataFixture2 fixture  in  pibImpls)
            {
                PibImpl pib = fixture.pib;

                // There is no default setting. This should throw an Error.
                Assert.AssertEquals(false, pib.hasIdentity(fixture.id2));
                try {
                    pib.getDefaultKeyOfIdentity(fixture.id1);
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex) {
                } catch (Exception ex_0) {
                    Assert.Fail("Did not throw the expected exception");
                }

                // Check for id1Key1, which should not exist. Neither should id1.
                Assert.AssertEquals(false, pib.hasKey(fixture.id1Key1Name));
                Assert.AssertEquals(false, pib.hasIdentity(fixture.id1));

                // Add id1Key1, which should be the default. id1 should be added implicitly.
                pib.addKey(fixture.id1, fixture.id1Key1Name, fixture.id1Key1.buf());
                Assert.AssertEquals(true, pib.hasKey(fixture.id1Key1Name));
                Assert.AssertEquals(true, pib.hasIdentity(fixture.id1));
                Blob keyBits = pib.getKeyBits(fixture.id1Key1Name);
                Assert.AssertTrue(keyBits.equals(fixture.id1Key1));
                try {
                    pib.getDefaultKeyOfIdentity(fixture.id1);
                } catch (Exception ex_1) {
                    Assert.Fail("Unexpected exception: " + ex_1.Message);
                }
                Assert.AssertEquals(fixture.id1Key1Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id1));

                // Add id1Key2, which should not be the default.
                pib.addKey(fixture.id1, fixture.id1Key2Name, fixture.id1Key2.buf());
                Assert.AssertEquals(true, pib.hasKey(fixture.id1Key2Name));
                Assert.AssertEquals(fixture.id1Key1Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id1));

                // Explicitly Set id1Key2 as the default.
                pib.setDefaultKeyOfIdentity(fixture.id1, fixture.id1Key2Name);
                Assert.AssertEquals(fixture.id1Key2Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id1));

                // Set a non-existing key as the default. This should throw an Error.
                try {
                    pib.setDefaultKeyOfIdentity(fixture.id1, new Name(
                                                    "/non-existing"));
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex_2) {
                } catch (Exception ex_3) {
                    Assert.Fail("Did not throw the expected exception");
                }

                // Remove id1Key2. The PIB should not have a default key.
                pib.removeKey(fixture.id1Key2Name);
                Assert.AssertEquals(false, pib.hasKey(fixture.id1Key2Name));
                try {
                    pib.getKeyBits(fixture.id1Key2Name);
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex_4) {
                } catch (Exception ex_5) {
                    Assert.Fail("Did not throw the expected exception");
                }

                try {
                    pib.getDefaultKeyOfIdentity(fixture.id1);
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex_6) {
                } catch (Exception ex_7) {
                    Assert.Fail("Did not throw the expected exception");
                }

                // Add id1Key2 back, which should be the default.
                pib.addKey(fixture.id1, fixture.id1Key2Name, fixture.id1Key2.buf());
                try {
                    pib.getKeyBits(fixture.id1Key2Name);
                } catch (Exception ex_8) {
                    Assert.Fail("Unexpected exception: " + ex_8.Message);
                }
                Assert.AssertEquals(fixture.id1Key2Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id1));

                // Get all the keys, which should have id1Key1 and id1Key2.
                HashedSet <Name> keyNames = pib.getKeysOfIdentity(fixture.id1);
                Assert.AssertEquals(2, keyNames.Count);
                Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Contains(fixture.id1Key1Name, keyNames));
                Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Contains(fixture.id1Key2Name, keyNames));

                // Remove id1, which should remove all the keys.
                pib.removeIdentity(fixture.id1);
                keyNames = pib.getKeysOfIdentity(fixture.id1);
                Assert.AssertEquals(0, keyNames.Count);
            }
        }