Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bouncycastle.asn1.crmf.PKMACValue;
import org.bouncycastle.asn1.crmf.POPOSigningKey;
import org.bouncycastle.asn1.crmf.ProofOfPossession;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.operator.ContentVerifier;
import org.bouncycastle.operator.ContentVerifierProvider;
Expand Down Expand Up @@ -146,6 +147,10 @@ public Control getControl(ASN1ObjectIdentifier type)
{
return new AuthenticatorControl(ASN1UTF8String.getInstance(found.getValue()));
}
if (found.getType().equals(CRMFObjectIdentifiers.id_regCtrl_protocolEncrKey))
{
return new ProtocolEncrKeyControl(SubjectPublicKeyInfo.getInstance(found.getValue()));
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.bouncycastle.cert.crmf;

import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.crmf.CRMFObjectIdentifiers;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;

/**
* Carrier for a protocol encryption key control.
*/
public class ProtocolEncrKeyControl
implements Control
{
private static final ASN1ObjectIdentifier type = CRMFObjectIdentifiers.id_regCtrl_protocolEncrKey;

private final SubjectPublicKeyInfo publicKeyInfo;

/**
* Basic constructor - build from the public key to use for protocol encryption.
*
* @param publicKeyInfo the public key to use for protocol encryption.
*/
public ProtocolEncrKeyControl(SubjectPublicKeyInfo publicKeyInfo)
{
this.publicKeyInfo = publicKeyInfo;
}

/**
* Return the type of this control.
*
* @return CRMFObjectIdentifiers.id_regCtrl_protocolEncrKey
*/
public ASN1ObjectIdentifier getType()
{
return type;
}

/**
* Return the public key associated with this control.
*
* @return a SubjectPublicKeyInfo structure.
*/
public ASN1Encodable getValue()
{
return publicKeyInfo;
}
}
35 changes: 35 additions & 0 deletions pkix/src/test/java/org/bouncycastle/cert/crmf/test/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.bouncycastle.cert.crmf.EncryptedValueParser;
import org.bouncycastle.cert.crmf.PKIArchiveControl;
import org.bouncycastle.cert.crmf.PKMACBuilder;
import org.bouncycastle.cert.crmf.ProtocolEncrKeyControl;
import org.bouncycastle.cert.crmf.ValueDecryptorGenerator;
import org.bouncycastle.cert.crmf.bc.BcCRMFEncryptorBuilder;
import org.bouncycastle.cert.crmf.bc.BcEncryptedValueBuilder;
Expand Down Expand Up @@ -228,6 +229,40 @@ public void testBasicMessageWithRegInfo()
TestCase.assertEquals(atavArr[0], certReqMsgASN1.getRegInfo()[0]);
}

public void testBasicMessageWithProtocolEncrKeyControl()
throws Exception
{
KeyPairGenerator kGen = KeyPairGenerator.getInstance("RSA", BC);

kGen.initialize(512);

KeyPair kp = kGen.generateKeyPair();
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(kp.getPublic().getEncoded());

JcaCertificateRequestMessageBuilder certReqBuild = new JcaCertificateRequestMessageBuilder(BigInteger.ONE);

certReqBuild.setSubject(new X500Principal("CN=Test"))
.setPublicKey(kp.getPublic())
.addControl(new ProtocolEncrKeyControl(publicKeyInfo));

CertificateRequestMessage certReqMsg = certReqBuild.build();

checkCertReqMsgWithProtocolEncrKeyControl(certReqMsg, publicKeyInfo);
checkCertReqMsgWithProtocolEncrKeyControl(new CertificateRequestMessage(certReqMsg.getEncoded()), publicKeyInfo);
}

private void checkCertReqMsgWithProtocolEncrKeyControl(CertificateRequestMessage certReqMsg,
SubjectPublicKeyInfo publicKeyInfo)
{
TestCase.assertTrue(certReqMsg.hasControl(CRMFObjectIdentifiers.id_regCtrl_protocolEncrKey));

ProtocolEncrKeyControl protocolEncrKeyControl = (ProtocolEncrKeyControl)certReqMsg.getControl(
CRMFObjectIdentifiers.id_regCtrl_protocolEncrKey);

TestCase.assertEquals(CRMFObjectIdentifiers.id_regCtrl_protocolEncrKey, protocolEncrKeyControl.getType());
TestCase.assertEquals(publicKeyInfo, protocolEncrKeyControl.getValue());
}

public void testBasicMessageWithArchiveControl()
throws Exception
{
Expand Down