Example usage for org.bouncycastle.asn1 ASN1InputStream ASN1InputStream

List of usage examples for org.bouncycastle.asn1 ASN1InputStream ASN1InputStream

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1InputStream ASN1InputStream.

Prototype

public ASN1InputStream(byte[] input) 

Source Link

Document

Create an ASN1InputStream based on the input byte array.

Usage

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the certificate message generation prepared for remote key generation
 *
 * @throws OperatorCreationException/*from   ww w  .  j a  va 2  s.co  m*/
 * @throws PKICMPMessageException
 * @throws CertificateEncodingException
 * @throws IOException
 * @throws CRMFException
 * @throws CMPException
 * @throws CMSException
 */
@Test
public void testCertificationWithRemoteKeyGeneration()
        throws OperatorCreationException, PKICMPMessageException, CertificateEncodingException, IOException,
        CRMFException, CMPException, CMSException, NoSuchFieldException, IllegalAccessException {
    String distinguishedName = pki.getTestUser1Cert().getSubjectX500Principal().getName();

    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    byte[] result = pkiMessages.createCertificateMessageWithRemoteKey(distinguishedName);

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);
    CertReqMsg[] certReqMsgs = CertReqMessages.getInstance(pkiMessage.getBody().getContent())
            .toCertReqMsgArray();

    Assert.assertNull(certReqMsgs[0].getCertReq().getCertTemplate().getPublicKey());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test certification message with a predefined transactionId
 * @throws OperatorCreationException//from  ww w .j  a va 2  s . c  o m
 * @throws PKICMPMessageException
 * @throws CertificateEncodingException
 * @throws IOException
 * @throws CRMFException
 * @throws CMPException
 * @throws CMSException
 */
@Test
public void testCertificationWithTransactionId()
        throws OperatorCreationException, PKICMPMessageException, CertificateEncodingException, IOException,
        CRMFException, CMPException, CMSException, NoSuchFieldException, IllegalAccessException {
    String distinguishedName = pki.getTestUser1Cert().getSubjectX500Principal().getName();
    byte[] transactionId = { 0x01, 0x02, 0x03, 0x04 };

    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    pkiMessages.setTransactionId(transactionId);
    byte[] result = pkiMessages.createCertificateMessageWithRemoteKey(distinguishedName);

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    Assert.assertArrayEquals(transactionId, pkiMessage.getHeader().getTransactionID().getOctets());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException//from   www. ja va  2 s  .  c om
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testCertificateConfirm() throws IOException, CertificateEncodingException,
        OperatorCreationException, CMPException, PKICMPMessageException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    byte[] result = pkiMessages.createConfirmationMessage(pki.getTestUser1Cert(), BigInteger.ONE);

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);
    // Check the body
    CertConfirmContent certConfirmContent = CertConfirmContent.getInstance(pkiMessage.getBody().getContent());
    CertStatus[] certStatuses = certConfirmContent.toCertStatusArray();
    Assert.assertEquals(BigInteger.ONE, certStatuses[0].getCertReqId().getValue());
    Assert.assertNotNull(certStatuses[0].getCertHash().getOctets());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException//from   w  ww .  j a v a  2  s.  c o  m
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testKeyUpdateWithLocalKeyChangeKey()
        throws IOException, CertificateEncodingException, OperatorCreationException, CMPException,
        PKICMPMessageException, CRMFException, IllegalAccessException, CMSException, NoSuchFieldException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    KeyPair keyPair = new KeyPair(pki.getTestUser2Cert().getPublicKey(), pki.getTestUser2CertPrivateKey());

    byte[] result = pkiMessages.createKeyUpdateMessageWithLocalKey(pki.getTestUser1Cert(), keyPair);

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    // Check the Body
    Assert.assertEquals(PKIBody.TYPE_KEY_UPDATE_REQ, pkiMessage.getBody().getType());
    CertReqMsg[] certReqMsgs = CertReqMessages.getInstance(pkiMessage.getBody().getContent())
            .toCertReqMsgArray();
    Assert.assertEquals(BigInteger.ZERO.toString(), certReqMsgs[0].getCertReq().getCertReqId().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getSubjectDN().getName().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getSubject().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getSerialNumber(),
            certReqMsgs[0].getCertReq().getCertTemplate().getSerialNumber().getValue());
    Assert.assertEquals(pki.getTestUser1Cert().getIssuerDN().getName().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getIssuer().toString());
    // KeyPair check
    Assert.assertArrayEquals(pki.getTestUser2Cert().getPublicKey().getEncoded(),
            certReqMsgs[0].getCertReq().getCertTemplate().getPublicKey().getEncoded());
    AttributeTypeAndValue[] attributeTypeAndValue = certReqMsgs[0].getCertReq().getControls()
            .toAttributeTypeAndValueArray();
    Assert.assertEquals(CRMFObjectIdentifiers.id_regCtrl_pkiArchiveOptions, attributeTypeAndValue[0].getType());
    // Validity
    Assert.assertEquals(pki.getTestUser1Cert().getNotBefore().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getValidity().getNotBefore().getDate().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getNotAfter().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getValidity().getNotAfter().getDate().toString());
    // Extensions check
    Assert.assertNull(certReqMsgs[0].getCertReq().getCertTemplate().getExtensions());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException//from w ww. j  av a2s  .co m
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testKeyUpdateWithLocalKeyChangeValidity()
        throws IOException, CertificateEncodingException, OperatorCreationException, CMPException,
        PKICMPMessageException, CRMFException, IllegalAccessException, CMSException, NoSuchFieldException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    KeyPair keyPair = new KeyPair(pki.getTestUser2Cert().getPublicKey(), pki.getTestUser2CertPrivateKey());

    Date notBefore = new Date(System.currentTimeMillis() - 500L * 60 * 60 * 24 * 30);
    Date notAfter = new Date(System.currentTimeMillis() + 500L * 60 * 60 * 24 * 30);

    pkiMessages.setValidity(notBefore, notAfter);
    byte[] result = pkiMessages.createKeyUpdateMessageWithLocalKey(pki.getTestUser1Cert(), keyPair);

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    // Check the Body
    Assert.assertEquals(PKIBody.TYPE_KEY_UPDATE_REQ, pkiMessage.getBody().getType());
    CertReqMsg[] certReqMsgs = CertReqMessages.getInstance(pkiMessage.getBody().getContent())
            .toCertReqMsgArray();
    // Validity
    Assert.assertEquals(notBefore.toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getValidity().getNotBefore().getDate().toString());
    Assert.assertEquals(notAfter.toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getValidity().getNotAfter().getDate().toString());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException/*w w  w.j  av  a 2  s  . co  m*/
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testKeyUpdateWithLocalKeyWithExtensions()
        throws IOException, CertificateEncodingException, OperatorCreationException, CMPException,
        PKICMPMessageException, CRMFException, IllegalAccessException, CMSException, NoSuchFieldException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    KeyPair keyPair = new KeyPair(pki.getTestUser2Cert().getPublicKey(), pki.getTestUser2CertPrivateKey());

    List<Extension> extensionList = new ArrayList<Extension>();
    // KeyUsage
    extensionList.add(new Extension(X509Extension.keyUsage, true,
            new KeyUsage(KeyUsage.digitalSignature | KeyUsage.nonRepudiation).getEncoded()));
    // Extended keyUsage
    List<KeyPurposeId> keyPurposeIds = new ArrayList<KeyPurposeId>();
    keyPurposeIds.add(KeyPurposeId.getInstance(KeyPurposeId.id_kp_clientAuth));
    keyPurposeIds.add(KeyPurposeId.getInstance(KeyPurposeId.id_kp_emailProtection));
    extensionList.add(new Extension(X509Extension.extendedKeyUsage, false,
            new ExtendedKeyUsage(keyPurposeIds.toArray(new KeyPurposeId[keyPurposeIds.size()])).getEncoded()));

    pkiMessages.setExtensions(extensionList.toArray(new Extension[extensionList.size()]));
    byte[] result = pkiMessages.createKeyUpdateMessageWithLocalKey(pki.getRACert(), keyPair);

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    // Check the Body
    CertReqMsg[] certReqMsgs = CertReqMessages.getInstance(pkiMessage.getBody().getContent())
            .toCertReqMsgArray();
    // Extensions check
    // KeyUsage
    KeyUsage verifyKeyUsage = KeyUsage.getInstance(certReqMsgs[0].getCertReq().getCertTemplate().getExtensions()
            .getExtensionParsedValue(Extension.keyUsage));
    Assert.assertEquals(KeyUsage.digitalSignature | KeyUsage.nonRepudiation,
            verifyKeyUsage.getBytes()[0] & 0xFF);
    // Extended KeyUsage
    ExtendedKeyUsage verifyExtendedKeyUsage = ExtendedKeyUsage
            .fromExtensions(certReqMsgs[0].getCertReq().getCertTemplate().getExtensions());
    Assert.assertTrue(verifyExtendedKeyUsage.hasKeyPurposeId(KeyPurposeId.id_kp_clientAuth));
    Assert.assertTrue(verifyExtendedKeyUsage.hasKeyPurposeId(KeyPurposeId.id_kp_emailProtection));
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException//from ww  w  .j a v  a  2 s . c o m
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testKeyUpdateWithRemoteKey()
        throws IOException, CertificateEncodingException, OperatorCreationException, CMPException,
        PKICMPMessageException, CRMFException, IllegalAccessException, CMSException, NoSuchFieldException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);

    byte[] result = pkiMessages.createKeyUpdateMessageWithRemoteKey(pki.getTestUser1Cert());

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    // Check the Body
    Assert.assertEquals(PKIBody.TYPE_KEY_UPDATE_REQ, pkiMessage.getBody().getType());
    CertReqMsg[] certReqMsgs = CertReqMessages.getInstance(pkiMessage.getBody().getContent())
            .toCertReqMsgArray();
    Assert.assertEquals(BigInteger.ZERO.toString(), certReqMsgs[0].getCertReq().getCertReqId().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getSubjectDN().getName().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getSubject().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getSerialNumber(),
            certReqMsgs[0].getCertReq().getCertTemplate().getSerialNumber().getValue());
    Assert.assertEquals(pki.getTestUser1Cert().getIssuerDN().getName().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getIssuer().toString());
    // KeyPair check: should be not there
    Assert.assertNull(certReqMsgs[0].getCertReq().getCertTemplate().getPublicKey());
    Assert.assertNull(certReqMsgs[0].getCertReq().getControls());
    // Validity
    Assert.assertEquals(pki.getTestUser1Cert().getNotBefore().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getValidity().getNotBefore().getDate().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getNotAfter().toString(),
            certReqMsgs[0].getCertReq().getCertTemplate().getValidity().getNotAfter().getDate().toString());
    // Extensions check
    Assert.assertNull(certReqMsgs[0].getCertReq().getCertTemplate().getExtensions());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException//from  w w w .jav a 2s .  c  om
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testRevocationMessage()
        throws IOException, CertificateEncodingException, OperatorCreationException, CMPException,
        PKICMPMessageException, CRMFException, IllegalAccessException, CMSException, NoSuchFieldException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    List<RevocationInput> revocationInputs = new ArrayList<RevocationInput>(2);
    revocationInputs.add(new RevocationInput(pki.getTestUser1Cert()));
    revocationInputs.add(new RevocationInput(pki.getTestUser2Cert()));

    byte[] result = pkiMessages
            .createRevocationMessage(revocationInputs.toArray(new RevocationInput[revocationInputs.size()]));

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    // Check the Body
    Assert.assertEquals(PKIBody.TYPE_REVOCATION_REQ, pkiMessage.getBody().getType());
    RevDetails[] revDetailses = RevReqContent.getInstance(pkiMessage.getBody().getContent())
            .toRevDetailsArray();
    Assert.assertEquals(pki.getTestUser1Cert().getIssuerDN().getName().toString(),
            revDetailses[0].getCertDetails().getIssuer().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getSerialNumber(),
            revDetailses[0].getCertDetails().getSerialNumber().getValue());
    Assert.assertEquals(pki.getTestUser1Cert().getSubjectDN().getName().toString(),
            revDetailses[0].getCertDetails().getSubject().toString());
    Assert.assertArrayEquals(pki.getTestUser1Cert().getPublicKey().getEncoded(),
            revDetailses[0].getCertDetails().getPublicKey().getEncoded());
    Assert.assertNull(revDetailses[0].getCrlEntryDetails());
    Assert.assertEquals(pki.getTestUser2Cert().getIssuerDN().getName().toString(),
            revDetailses[1].getCertDetails().getIssuer().toString());
    Assert.assertEquals(pki.getTestUser2Cert().getSerialNumber(),
            revDetailses[1].getCertDetails().getSerialNumber().getValue());
    Assert.assertEquals(pki.getTestUser2Cert().getSubjectDN().getName().toString(),
            revDetailses[1].getCertDetails().getSubject().toString());
    Assert.assertArrayEquals(pki.getTestUser2Cert().getPublicKey().getEncoded(),
            revDetailses[1].getCertDetails().getPublicKey().getEncoded());
    Assert.assertNull(revDetailses[1].getCrlEntryDetails());
}

From source file:org.cryptable.pki.communication.PKICMPMessagesTest.java

License:Open Source License

/**
 * Test the confirmation message from the certification authority
 *
 * @throws IOException/*from ww  w  .j a v a2 s  .c om*/
 * @throws CertificateEncodingException
 * @throws OperatorCreationException
 * @throws CMPException
 */
@Test
public void testRevocationMessageWithExtensions()
        throws IOException, CertificateEncodingException, OperatorCreationException, CMPException,
        PKICMPMessageException, CRMFException, IllegalAccessException, CMSException, NoSuchFieldException {
    PKICMPMessages pkiMessages = new PKICMPMessages();
    pkiMessages.setPkiKeyStore(pkiKeyStoreRA);
    List<RevocationInput> revocationInputs = new ArrayList<RevocationInput>(2);
    Date invalidityDate = new Date(System.currentTimeMillis() - 500L * 60 * 60 * 24 * 30);
    revocationInputs.add(new RevocationInput(pki.getTestUser1Cert(), RevocationInput.aACompromise));
    revocationInputs
            .add(new RevocationInput(pki.getTestUser2Cert(), RevocationInput.noReasonCode, invalidityDate));

    byte[] result = pkiMessages
            .createRevocationMessage(revocationInputs.toArray(new RevocationInput[revocationInputs.size()]));

    ASN1InputStream asn1InputStream = new ASN1InputStream(result);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    PKIMessage pkiMessage = PKIMessage.getInstance(asn1Primitive);

    // Check the Body
    Assert.assertEquals(PKIBody.TYPE_REVOCATION_REQ, pkiMessage.getBody().getType());
    RevDetails[] revDetailses = RevReqContent.getInstance(pkiMessage.getBody().getContent())
            .toRevDetailsArray();
    Assert.assertEquals(pki.getTestUser1Cert().getIssuerDN().getName().toString(),
            revDetailses[0].getCertDetails().getIssuer().toString());
    Assert.assertEquals(pki.getTestUser1Cert().getSerialNumber(),
            revDetailses[0].getCertDetails().getSerialNumber().getValue());
    Assert.assertEquals(pki.getTestUser1Cert().getSubjectDN().getName().toString(),
            revDetailses[0].getCertDetails().getSubject().toString());
    Assert.assertArrayEquals(pki.getTestUser1Cert().getPublicKey().getEncoded(),
            revDetailses[0].getCertDetails().getPublicKey().getEncoded());
    Assert.assertNotNull(revDetailses[0].getCrlEntryDetails());
    Assert.assertNull(revDetailses[0].getCrlEntryDetails().getExtensionParsedValue(Extension.invalidityDate));
    ReasonFlags reasonFlags = new ReasonFlags(ReasonFlags
            .getInstance(revDetailses[0].getCrlEntryDetails().getExtensionParsedValue(Extension.reasonCode)));
    Assert.assertEquals(RevocationInput.aACompromise, reasonFlags.intValue());
    Assert.assertEquals(pki.getTestUser2Cert().getIssuerDN().getName().toString(),
            revDetailses[1].getCertDetails().getIssuer().toString());
    Assert.assertEquals(pki.getTestUser2Cert().getSerialNumber(),
            revDetailses[1].getCertDetails().getSerialNumber().getValue());
    Assert.assertEquals(pki.getTestUser2Cert().getSubjectDN().getName().toString(),
            revDetailses[1].getCertDetails().getSubject().toString());
    Assert.assertArrayEquals(pki.getTestUser2Cert().getPublicKey().getEncoded(),
            revDetailses[1].getCertDetails().getPublicKey().getEncoded());
    Assert.assertNotNull(revDetailses[1].getCrlEntryDetails());
    Assert.assertNull(revDetailses[1].getCrlEntryDetails().getExtensionParsedValue(Extension.reasonCode));
    Time tmp = new Time(revDetailses[1].getCrlEntryDetails().getExtensionParsedValue(Extension.invalidityDate)
            .toASN1Primitive());
    Assert.assertEquals(invalidityDate.toString(), tmp.getDate().toString());
}

From source file:org.cryptoworkshop.ximix.client.verify.ECDecryptionChallengeVerifier.java

License:Apache License

/**
 * Verify that the decryption challenge transcript is valid, throwing an exception if an issue is found..
 *
 * @throws TranscriptVerificationException on verification failure.
 *//*from   w w w. j  av  a2  s . co m*/
public void verify() throws TranscriptVerificationException {
    ASN1InputStream aIn = new ASN1InputStream(logStream);
    ASN1InputStream resultIn = new ASN1InputStream(resultStream);
    ASN1InputStream lastIn = new ASN1InputStream(lastStageStream);

    try {
        int messageIndex = -1;
        ECPair[] encPairs = null;

        ASN1Object obj;
        while ((obj = aIn.readObject()) != null) {
            ChallengeLogMessage logMessage = ChallengeLogMessage.getInstance(obj);

            ECPoint[] sourceMessage = logMessage.getSourceMessage();
            ECDecryptionProof[] proofs = logMessage.getProofs();

            ECPublicKeyParameters currentPubKey = (ECPublicKeyParameters) PublicKeyFactory
                    .createKey(logMessage.getKeyInfo());
            if (!isSameParameters(pubKey.getParameters(), currentPubKey.getParameters())) {
                throw new TranscriptVerificationException(
                        "Log message indicates inconsistent public key parameters.");
            }

            if (messageIndex != logMessage.getIndex()) {
                if (activePeers.length != 0) {
                    LagrangeWeightCalculator weightCalculator = new LagrangeWeightCalculator(maxSequenceNo + 1,
                            pubKey.getParameters().getN());

                    ECPoint accumulatedQ = null;

                    BigInteger[] weights = weightCalculator.computeWeights(activePeers);

                    // verify the partial public keys represent the one we have.
                    for (int i = 0; i != weights.length; i++) {
                        if (weights[i] != null) {
                            if (accumulatedQ == null) {
                                accumulatedQ = activePeers[i].getQ().multiply(weights[i]);
                            } else {
                                accumulatedQ = accumulatedQ.add(activePeers[i].getQ().multiply(weights[i]));
                            }
                        }
                    }

                    if (!pubKey.getQ().equals(accumulatedQ)) {
                        throw new TranscriptVerificationException(
                                "Log message indicates inconsistent public key.");
                    }

                    // verify the partial decrypts result in the final message

                    int len = activeMsgParts[0].length;
                    for (int i = 1; i != activeMsgParts.length; i++) {
                        if (activeMsgParts[i].length != len) {
                            throw new TranscriptVerificationException("Partial decrypt length mismatch");
                        }
                    }

                    int baseIndex = 0;
                    for (int i = 0; i != activeMsgParts.length; i++) {
                        if (activeMsgParts[i] != null) {
                            baseIndex = i;
                            break;
                        }
                    }

                    BigInteger baseWeight = weights[baseIndex];

                    ECPoint[] decryptions = reassemblePoints(activeMsgParts, encPairs, weights, baseIndex,
                            baseWeight);

                    ECPoint[] recordedDecrypts = PointSequence
                            .getInstance(pubKey.getParameters().getCurve(), resultIn.readObject())
                            .getECPoints();

                    if (!Arrays.areEqual(decryptions, recordedDecrypts)) {
                        throw new TranscriptVerificationException(
                                "Recorded decrypts do not match partial ones.");
                    }

                    // reset the peers array.
                    for (int i = 0; i != activePeers.length; i++) {
                        activePeers[i] = null;
                    }
                    for (int i = 0; i != activeMsgParts.length; i++) {
                        activeMsgParts[i] = null;
                    }
                } else if (messageIndex != -1) {
                    throw new TranscriptVerificationException("Nothing to verify!");
                }

                messageIndex = logMessage.getIndex();
                PostedMessage pM = PostedMessage.getInstance(lastIn.readObject());
                encPairs = PairSequence.getInstance(pubKey.getParameters().getCurve(), pM.getMessage())
                        .getECPairs();
            }

            addPeer(logMessage.getSequenceNo(), currentPubKey, sourceMessage);

            if (!logMessage.hasPassed()) {
                throw new TranscriptVerificationException("Log message indicates challenge did not pass.");
            }

            for (int i = 0; i != proofs.length; i++) {
                if (!proofs[i].isVerified(activePeers[logMessage.getSequenceNo()], encPairs[i].getX(),
                        sourceMessage[i])) {
                    throw new TranscriptVerificationException(
                            "Proof results do not match combined source message and cipher text.");
                }
            }
        }
    } catch (TranscriptVerificationException e) {
        throw e;
    } catch (Exception e) {
        throw new TranscriptVerificationException(
                "Exception validating decryption challenge transcript: " + e.getMessage(), e);
    }
}