All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gatling.recorder.internal.bouncycastle.its.ETSIRecipientInfo Maven / Gradle / Ivy

There is a newer version: 1.78.1
Show newest version
package io.gatling.recorder.internal.bouncycastle.its;


import io.gatling.recorder.internal.bouncycastle.its.operator.ETSIDataDecryptor;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.AesCcmCiphertext;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.EncryptedData;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.EncryptedDataEncryptionKey;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.PKRecipientInfo;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.RecipientInfo;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.SymmetricCiphertext;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.basetypes.EccP256CurvePoint;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.basetypes.EciesP256EncryptedKey;
import io.gatling.recorder.internal.bouncycastle.util.Arrays;

public class ETSIRecipientInfo
{
    private final RecipientInfo recipientInfo;
    private final EncryptedData encryptedData;

    public ETSIRecipientInfo(EncryptedData encryptedData, RecipientInfo recipientInfo)
    {
        this.recipientInfo = recipientInfo;
        this.encryptedData = encryptedData;
    }

    public ETSIRecipientInfo(RecipientInfo recipientInfo)
    {
        this.recipientInfo = recipientInfo;
        this.encryptedData = null;
    }

    public RecipientInfo getRecipientInfo()
    {
        return recipientInfo;
    }


    public EncryptedData getEncryptedData()
    {
        return encryptedData;
    }

    public byte[] getContent(ETSIDataDecryptor ddec)
    {
        if (SymmetricCiphertext.aes128ccm != encryptedData.getCiphertext().getChoice())
        {
            throw new IllegalArgumentException("Encrypted data is no AES 128 CCM");
        }

        AesCcmCiphertext act = AesCcmCiphertext.getInstance(encryptedData.getCiphertext().getSymmetricCiphertext());

        // Test it is the correct kind of recipient info.
        PKRecipientInfo pkRecipientInfo = PKRecipientInfo.getInstance(recipientInfo.getRecipientInfo());
        EncryptedDataEncryptionKey edec = pkRecipientInfo.getEncKey();

        EciesP256EncryptedKey key = EciesP256EncryptedKey.getInstance(edec.getEncryptedDataEncryptionKey());
        EccP256CurvePoint point = EccP256CurvePoint.getInstance(key.getV());

        // [ephemeral public key][encrypted key][tag]
        byte[] wrappedKey = Arrays.concatenate(point.getEncodedPoint(), key.getC().getOctets(), key.getT().getOctets());

        return ddec.decrypt(wrappedKey, act.getCcmCiphertext().getContent(), act.getNonce().getOctets());
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy